mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
100% Coverage for libdispatcher.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
83bc492db3
commit
5c7493e41e
@@ -1195,3 +1195,122 @@ func TestLibDispatcherLoadStrategyDispatcherCacheError5(t *testing.T) {
|
||||
engine.Cache = cacheInit
|
||||
engine.IntRPC = tmp
|
||||
}
|
||||
func TestLibDispatcherSingleResultstrategyDispatcherCase1(t *testing.T) {
|
||||
cacheInit := engine.Cache
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
dm := engine.NewDataManager(nil, nil, nil)
|
||||
newCache := engine.NewCacheS(cfg, dm, nil)
|
||||
engine.Cache = newCache
|
||||
value := &engine.DispatcherHost{
|
||||
Tenant: "testTenant",
|
||||
RemoteHost: &config.RemoteHost{
|
||||
ID: "testID",
|
||||
Address: rpcclient.InternalRPC,
|
||||
Transport: utils.MetaInternal,
|
||||
Synchronous: false,
|
||||
TLS: false,
|
||||
},
|
||||
}
|
||||
tmp := engine.IntRPC
|
||||
engine.IntRPC = map[string]*rpcclient.RPCClient{}
|
||||
chanRPC := make(chan rpcclient.ClientConnector, 1)
|
||||
chanRPC <- new(mockTypeConDispatch)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC)
|
||||
engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID",
|
||||
value, nil, true, utils.NonTransactional)
|
||||
wgDsp := &singleResultstrategyDispatcher{}
|
||||
err := wgDsp.dispatch(dm, "", utils.MetaAttributes, "testTenant", []string{"testID"}, utils.AttributeSv1Ping, &utils.CGREvent{}, &wgDsp)
|
||||
if err == nil {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", "connection is shut down", err)
|
||||
}
|
||||
engine.Cache = cacheInit
|
||||
engine.IntRPC = tmp
|
||||
}
|
||||
|
||||
type mockTypeConDispatch2 struct{}
|
||||
|
||||
func (*mockTypeConDispatch2) Call(serviceMethod string, args, reply interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestLibDispatcherSingleResultstrategyDispatcherCase2(t *testing.T) {
|
||||
cacheInit := engine.Cache
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
dm := engine.NewDataManager(nil, nil, nil)
|
||||
newCache := engine.NewCacheS(cfg, dm, nil)
|
||||
engine.Cache = newCache
|
||||
value := &engine.DispatcherHost{
|
||||
Tenant: "testTenant",
|
||||
RemoteHost: &config.RemoteHost{
|
||||
ID: "testID",
|
||||
Address: rpcclient.InternalRPC,
|
||||
Transport: utils.MetaInternal,
|
||||
Synchronous: false,
|
||||
TLS: false,
|
||||
},
|
||||
}
|
||||
tmp := engine.IntRPC
|
||||
engine.IntRPC = map[string]*rpcclient.RPCClient{}
|
||||
chanRPC := make(chan rpcclient.ClientConnector, 1)
|
||||
chanRPC <- new(mockTypeConDispatch2)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC)
|
||||
engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID",
|
||||
value, nil, true, utils.NonTransactional)
|
||||
wgDsp := &singleResultstrategyDispatcher{}
|
||||
err := wgDsp.dispatch(dm, "routeID", utils.MetaAttributes, "testTenant", []string{"testID"}, utils.AttributeSv1Ping, &utils.CGREvent{}, &wgDsp)
|
||||
if err != nil {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
|
||||
}
|
||||
engine.Cache = cacheInit
|
||||
engine.IntRPC = tmp
|
||||
}
|
||||
|
||||
func TestLibDispatcherSingleResultstrategyDispatcherCase3(t *testing.T) {
|
||||
cacheInit := engine.Cache
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.CacheCfg().ReplicationConns = []string{"con"}
|
||||
cfg.CacheCfg().Partitions[utils.CacheDispatcherRoutes].Replicate = true
|
||||
cfg.RPCConns()["con"] = &config.RPCConn{
|
||||
Strategy: "",
|
||||
PoolSize: 0,
|
||||
Conns: []*config.RemoteHost{
|
||||
{
|
||||
ID: "testID",
|
||||
Address: "",
|
||||
Transport: "",
|
||||
Synchronous: false,
|
||||
TLS: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
rpcCl := map[string]chan rpcclient.ClientConnector{}
|
||||
connMng := engine.NewConnManager(cfg, rpcCl)
|
||||
dm := engine.NewDataManager(nil, nil, connMng)
|
||||
newCache := engine.NewCacheS(cfg, dm, nil)
|
||||
engine.Cache = newCache
|
||||
value := &engine.DispatcherHost{
|
||||
Tenant: "testTenant",
|
||||
RemoteHost: &config.RemoteHost{
|
||||
ID: "testID",
|
||||
Address: rpcclient.InternalRPC,
|
||||
Transport: utils.MetaInternal,
|
||||
Synchronous: false,
|
||||
TLS: false,
|
||||
},
|
||||
}
|
||||
tmp := engine.IntRPC
|
||||
engine.IntRPC = map[string]*rpcclient.RPCClient{}
|
||||
chanRPC := make(chan rpcclient.ClientConnector, 1)
|
||||
chanRPC <- new(mockTypeConDispatch2)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC)
|
||||
engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID",
|
||||
value, nil, true, utils.NonTransactional)
|
||||
wgDsp := &singleResultstrategyDispatcher{}
|
||||
err := wgDsp.dispatch(dm, "routeID", utils.MetaAttributes, "testTenant", []string{"testID"}, utils.AttributeSv1Ping, &utils.CGREvent{}, &wgDsp)
|
||||
expected := "DISCONNECTED"
|
||||
if err == nil || err.Error() != expected {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err)
|
||||
}
|
||||
engine.Cache = cacheInit
|
||||
engine.IntRPC = tmp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user