Covered cachecfg to 100% and updated rpccon load test%

This commit is contained in:
porosnicuadrian
2020-10-01 12:07:22 +03:00
committed by Dan Christian Bogos
parent 6bc7c289bb
commit 1982f2a36c
5 changed files with 2579 additions and 2514 deletions

View File

@@ -104,7 +104,6 @@ func (cCfg *CacheCfg) loadFromJsonCfg(jsnCfg *CacheJsonCfg) (err error) {
cCfg.ReplicationConns[idx] = connID
}
}
return nil
}

View File

@@ -85,7 +85,19 @@ func TestCacheCfgloadFromJsonCfg(t *testing.T) {
}
}
func TestCacheParamCfgloadFromJsonCfg(t *testing.T) {
func TestReplicationConnsLoadFromJsonCfg(t *testing.T) {
jsonCfg := &CacheJsonCfg{
Replication_conns: &[]string{utils.MetaInternal},
}
expErrMessage := "replication connection ID needs to be different than *internal"
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
t.Error(err)
} else if err = jsnCfg.cacheCfg.loadFromJsonCfg(jsonCfg); err == nil || err.Error() != expErrMessage {
t.Errorf("Expected %+v , recevied %+v", expErrMessage, err)
}
}
func TestCacheParamCfgloadFromJsonCfg1(t *testing.T) {
json := &CacheParamJsonCfg{
Limit: utils.IntPointer(5),
Ttl: utils.StringPointer("1s"),
@@ -108,6 +120,46 @@ func TestCacheParamCfgloadFromJsonCfg(t *testing.T) {
}
}
func TestCacheParamCfgloadFromJsonCfg2(t *testing.T) {
jsonCfg := &CacheJsonCfg{
Partitions: &map[string]*CacheParamJsonCfg{
utils.MetaDestinations: {
Ttl: utils.StringPointer("1ss"),
},
},
}
expErrMessage := "time: unknown unit \"ss\" in duration \"1ss\""
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
t.Error(err)
} else if err = jsnCfg.cacheCfg.loadFromJsonCfg(jsonCfg); err == nil || err.Error() != expErrMessage {
t.Errorf("Expected %+v \n, recevied %+v", expErrMessage, err)
}
}
func TestAddTmpCaches(t *testing.T) {
cfgJSON := &CacheJsonCfg{
Partitions: &map[string]*CacheParamJsonCfg{
utils.CacheRatingProfilesTmp: {
Limit: utils.IntPointer(-1),
Ttl: utils.StringPointer(time.Minute.String()),
},
},
}
expected := &CacheCfg{
Partitions: map[string]*CacheParamCfg{},
}
expected.AddTmpCaches()
if json, err := NewDefaultCGRConfig(); err != nil {
t.Error(err)
} else if err = json.cacheCfg.loadFromJsonCfg(cfgJSON); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected.Partitions[utils.CacheRatingProfilesTmp],
json.cacheCfg.Partitions[utils.CacheRatingProfilesTmp]) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected.Partitions[utils.CacheRatingProfilesTmp]),
utils.ToJSON(json.cacheCfg.Partitions[utils.CacheRatingProfilesTmp]))
}
}
func TestCachesCfgAsMapInterface1(t *testing.T) {
cfgJSONStr := `{
"caches":{

View File

@@ -397,7 +397,6 @@ func (cfg *CGRConfig) loadRPCConns(jsnCfg *CgrJsonCfg) (err error) {
return
}
// hardoded the *internal connection
cfg.rpcConns = make(RpcConns)
cfg.rpcConns[utils.MetaInternal] = &RPCConn{
Strategy: rpcclient.PoolFirst,
PoolSize: 0,

File diff suppressed because it is too large Load Diff

View File

@@ -27,7 +27,7 @@ import (
func TestRPCConnsloadFromJsonCfg(t *testing.T) {
cfgJSONStr := `{
"rpc_conn": {}
"rpc_conn": {}
}`
expected := RpcConns{
utils.MetaInternal: {
@@ -42,8 +42,23 @@ func TestRPCConnsloadFromJsonCfg(t *testing.T) {
},
},
},
utils.MetaLocalHost: {
Strategy: utils.MetaFirst,
PoolSize: 0,
Conns: []*RemoteHost{
{
Address: "127.0.0.1:2012",
Transport: utils.MetaJSON,
Synchronous: false,
TLS: false,
},
},
},
}
newCfg, err := NewDefaultCGRConfig()
if err != nil {
t.Fatal(err)
}
newCfg := new(CGRConfig)
if jsonCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
t.Error(err)
} else if err = newCfg.loadRPCConns(jsonCfg); err != nil {