Added *tenant in AttributeS NavigableMap

This commit is contained in:
Trial97
2021-04-19 11:53:26 +03:00
committed by Dan Christian Bogos
parent d72308ad0a
commit fb5b2815ef
3 changed files with 118 additions and 62 deletions

View File

@@ -392,6 +392,7 @@ func (alS *AttributeService) processEvent(ctx *context.Context, tnt string, args
} else {
rply.CGREvent.Tenant = substitute
}
evNm[utils.MetaTenant] = substitute
continue
}
if substitute == utils.MetaRemove {
@@ -466,6 +467,7 @@ func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *AttrArgs
utils.MetaVars: utils.MapStorage{
utils.ProcessRuns: 0,
},
utils.MetaTenant: tnt,
}
var lastID string
matchedIDs := make([]string, 0, processRuns)

View File

@@ -64,10 +64,12 @@ func (dDP *dynamicDP) RemoteHost() net.Addr {
return utils.LocalAddr()
}
var initialDPPrefixes = utils.NewStringSet([]string{utils.MetaReq, utils.MetaVars,
utils.MetaCgreq, utils.MetaCgrep, utils.MetaRep,
utils.MetaAct, utils.MetaEC, utils.MetaUCH, utils.MetaOpts,
utils.MetaHdr, utils.MetaTrl, utils.MetaCfg})
var initialDPPrefixes = utils.NewStringSet([]string{
utils.MetaReq, utils.MetaVars, utils.MetaCgreq,
utils.MetaCgrep, utils.MetaRep, utils.MetaAct,
utils.MetaEC, utils.MetaUCH, utils.MetaOpts,
utils.MetaHdr, utils.MetaTrl, utils.MetaCfg,
utils.MetaTenant})
func (dDP *dynamicDP) FieldAsInterface(fldPath []string) (val interface{}, err error) {
if len(fldPath) == 0 {

View File

@@ -30,7 +30,7 @@ import (
var (
expTimeAttributes = time.Now().Add(20 * time.Minute)
attrService *AttributeService
attrS *AttributeService
dmAtr *DataManager
attrEvs = []*AttrArgsProcessEvent{
{
@@ -156,7 +156,7 @@ func TestAttributePopulateAttrService(t *testing.T) {
defaultCfg.AttributeSCfg().PrefixIndexedFields = nil
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
}
func TestAttributeAddFilters(t *testing.T) {
@@ -238,7 +238,7 @@ func TestAttributeCache(t *testing.T) {
}
func TestAttributeProfileForEvent(t *testing.T) {
atrp, err := attrService.attributeProfileForEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[0].Context,
atrp, err := attrS.attributeProfileForEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[0].Context,
attrEvs[0].AttributeIDs, attrEvs[0].Time, utils.MapStorage{
utils.MetaReq: attrEvs[0].CGREvent.Event,
utils.MetaOpts: attrEvs[0].APIOpts,
@@ -252,7 +252,7 @@ func TestAttributeProfileForEvent(t *testing.T) {
if !reflect.DeepEqual(atrPs[0], atrp) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[0]), utils.ToJSON(atrp))
}
atrp, err = attrService.attributeProfileForEvent(context.TODO(), attrEvs[1].Tenant, attrEvs[1].Context,
atrp, err = attrS.attributeProfileForEvent(context.TODO(), attrEvs[1].Tenant, attrEvs[1].Context,
attrEvs[1].AttributeIDs, attrEvs[1].Time, utils.MapStorage{
utils.MetaReq: attrEvs[1].CGREvent.Event,
utils.MetaOpts: attrEvs[1].APIOpts,
@@ -267,7 +267,7 @@ func TestAttributeProfileForEvent(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[1]), utils.ToJSON(atrp))
}
atrp, err = attrService.attributeProfileForEvent(context.TODO(), attrEvs[2].Tenant, attrEvs[2].Context,
atrp, err = attrS.attributeProfileForEvent(context.TODO(), attrEvs[2].Tenant, attrEvs[2].Context,
attrEvs[2].AttributeIDs, attrEvs[2].Time, utils.MapStorage{
utils.MetaReq: attrEvs[2].CGREvent.Event,
utils.MetaOpts: attrEvs[2].APIOpts,
@@ -297,7 +297,7 @@ func TestAttributeProcessEvent(t *testing.T) {
utils.ProcessRuns: 0,
},
}
atrp, err := attrService.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[0], eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
atrp, err := attrS.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[0], eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -315,7 +315,7 @@ func TestAttributeProcessEventWithNotFound(t *testing.T) {
utils.ProcessRuns: 0,
},
}
if _, err := attrService.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[3], eNM,
if _, err := attrS.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[3], eNM,
newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString); err == nil || err != utils.ErrNotFound {
t.Errorf("Error: %+v", err)
}
@@ -336,7 +336,7 @@ func TestAttributeProcessEventWithIDs(t *testing.T) {
utils.ProcessRuns: 0,
},
}
if atrp, err := attrService.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[3], eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString); err != nil {
if atrp, err := attrS.processEvent(context.TODO(), attrEvs[0].Tenant, attrEvs[3], eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString); err != nil {
} else if !reflect.DeepEqual(eRply, atrp) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eRply), utils.ToJSON(atrp))
}
@@ -588,7 +588,7 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -697,7 +697,7 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -806,7 +806,7 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -896,7 +896,7 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1008,7 +1008,7 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1117,7 +1117,7 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1187,7 +1187,7 @@ func TestAttributeProcessValue(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1267,7 +1267,7 @@ func TestAttributeAttributeFilterIDs(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1339,7 +1339,7 @@ func TestAttributeProcessEventConstant(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1417,7 +1417,7 @@ func TestAttributeProcessEventVariable(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1500,7 +1500,7 @@ func TestAttributeProcessEventComposed(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Fatalf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1575,7 +1575,7 @@ func TestAttributeProcessEventSum(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1652,7 +1652,7 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1729,7 +1729,7 @@ func TestAttributeProcessEventValueExponent(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -1748,7 +1748,7 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) {
defaultCfg.AttributeSCfg().ProcessRuns = 1
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
//refresh the DM
if err := dmAtr.DataDB().Flush(""); err != nil {
b.Error(err)
@@ -1795,7 +1795,7 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) {
var reply AttrSProcessEventReply
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
b.Errorf("Error: %+v", err)
}
}
@@ -1806,7 +1806,7 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) {
defaultCfg.AttributeSCfg().ProcessRuns = 1
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
//refresh the DM
if err := dmAtr.DataDB().Flush(""); err != nil {
@@ -1854,7 +1854,7 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) {
var reply AttrSProcessEventReply
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
b.Errorf("Error: %+v", err)
}
}
@@ -1895,7 +1895,7 @@ func TestProcessAttributeConstant(t *testing.T) {
defaultCfg.AttributeSCfg().ProcessRuns = 1
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_CONSTANT",
@@ -1932,7 +1932,7 @@ func TestProcessAttributeConstant(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1953,7 +1953,7 @@ func TestProcessAttributeVariable(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_VARIABLE",
@@ -1992,7 +1992,7 @@ func TestProcessAttributeVariable(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2014,7 +2014,7 @@ func TestProcessAttributeComposed(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_COMPOSED",
@@ -2059,7 +2059,7 @@ func TestProcessAttributeComposed(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2081,7 +2081,7 @@ func TestProcessAttributeUsageDifference(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_USAGE_DIFF",
@@ -2121,7 +2121,7 @@ func TestProcessAttributeUsageDifference(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2143,7 +2143,7 @@ func TestProcessAttributeSum(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_SUM",
@@ -2183,7 +2183,7 @@ func TestProcessAttributeSum(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2205,7 +2205,7 @@ func TestProcessAttributeDiff(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_DIFF",
@@ -2245,7 +2245,7 @@ func TestProcessAttributeDiff(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2267,7 +2267,7 @@ func TestProcessAttributeMultiply(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_MULTIPLY",
@@ -2307,7 +2307,7 @@ func TestProcessAttributeMultiply(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2329,7 +2329,7 @@ func TestProcessAttributeDivide(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_DIVIDE",
@@ -2369,7 +2369,7 @@ func TestProcessAttributeDivide(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2391,7 +2391,7 @@ func TestProcessAttributeValueExponent(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_VAL_EXP",
@@ -2431,7 +2431,7 @@ func TestProcessAttributeValueExponent(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2453,7 +2453,7 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_UNIX_TIMESTAMP",
@@ -2493,7 +2493,7 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2515,7 +2515,7 @@ func TestProcessAttributePrefix(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_PREFIX",
@@ -2554,7 +2554,7 @@ func TestProcessAttributePrefix(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2576,7 +2576,7 @@ func TestProcessAttributeSuffix(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_SUFFIX",
@@ -2615,7 +2615,7 @@ func TestProcessAttributeSuffix(t *testing.T) {
utils.ProcessRuns: 0,
},
}
rcv, err := attrService.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
rcv, err := attrS.processEvent(context.TODO(), ev.Tenant, ev, eNM, newDynamicDP(context.TODO(), nil, nil, nil, "cgrates.org", eNM), utils.EmptyString)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2640,7 +2640,7 @@ func TestAttributeIndexSelectsFalse(t *testing.T) {
defaultCfg.AttributeSCfg().IndexedSelects = false
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
//refresh the DM
if err := dmAtr.DataDB().Flush(""); err != nil {
@@ -2685,7 +2685,7 @@ func TestAttributeIndexSelectsFalse(t *testing.T) {
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err == nil || err != utils.ErrNotFound {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err == nil || err != utils.ErrNotFound {
t.Errorf("Expected not found, reveiced: %+v", err)
}
@@ -2697,7 +2697,7 @@ func TestProcessAttributeWithSameWeight(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_1",
@@ -2747,7 +2747,7 @@ func TestProcessAttributeWithSameWeight(t *testing.T) {
},
}
var rcv AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), ev, &rcv); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), ev, &rcv); err != nil {
t.Errorf("Error: %+v", err)
}
clnEv := ev.CGREvent.Clone()
@@ -2771,7 +2771,7 @@ func TestAttributeMultipleProcessWithFiltersExists(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf1Exists := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_1_EXISTS",
@@ -2844,7 +2844,7 @@ func TestAttributeMultipleProcessWithFiltersExists(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -2865,7 +2865,7 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) {
data := NewInternalDB(nil, nil, true)
dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrService = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, defaultCfg)
attrPrf1NotEmpty := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_1_NOTEMPTY",
@@ -2938,7 +2938,7 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) {
},
}
var reply AttrSProcessEventReply
if err := attrService.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
if err := attrS.V1ProcessEvent(context.TODO(), attrArgs, &reply); err != nil {
t.Errorf("Error: %+v", err)
}
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
@@ -2952,3 +2952,55 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) {
t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, reply.CGREvent.Event)
}
}
func TestAttributeMetaTenant(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.AttributeSCfg().IndexedSelects = false
dm := NewDataManager(NewInternalDB(nil, nil, true), config.CgrConfig().CacheCfg(), nil)
Cache.Clear(nil)
attrS = NewAttributeService(dm, &FilterS{dm: dm, cfg: cfg}, cfg)
attr1 := &AttributeProfile{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "ATTR_TNT",
Contexts: []string{utils.MetaSessionS},
FilterIDs: []string{},
Attributes: []*Attribute{{
Type: utils.MetaPrefix,
Path: utils.MetaTenant,
Value: config.NewRSRParsersMustCompile("prfx_", utils.InfieldSep),
}},
Weight: 10,
}
// Add attribute in DM
if err := dm.SetAttributeProfile(context.TODO(), attr1, true); err != nil {
t.Error(err)
}
if _, err := dm.GetAttributeProfile(context.TODO(), attr1.Tenant, attr1.ID, true, false, utils.NonTransactional); err != nil {
t.Error(err)
}
args := &AttrArgsProcessEvent{
Context: utils.StringPointer(utils.MetaSessionS),
CGREvent: &utils.CGREvent{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
Event: map[string]interface{}{},
APIOpts: map[string]interface{}{},
},
}
eRply := AttrSProcessEventReply{
MatchedProfiles: []string{"ATTR_TNT"},
AlteredFields: []string{utils.MetaTenant},
CGREvent: &utils.CGREvent{
Tenant: "prfx_" + config.CgrConfig().GeneralCfg().DefaultTenant,
Event: map[string]interface{}{},
APIOpts: map[string]interface{}{},
},
}
var reply AttrSProcessEventReply
if err := attrS.V1ProcessEvent(context.TODO(), args, &reply); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(eRply, reply) {
t.Errorf("Expecting %s, received: %s", utils.ToJSON(eRply), utils.ToJSON(reply))
}
}