From 546c5f6035280b567809ac77dbe6972c19de1034 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Thu, 20 May 2021 08:36:23 +0300 Subject: [PATCH] Upgrade Attribute version and revisit fixed conflicts --- apis/libadmin.go | 12 ---- apis/libadmin_test.go | 157 ++++++++++++++++++++++------------------- apis/rates_test.go | 1 - engine/version.go | 2 +- engine/version_test.go | 2 +- 5 files changed, 86 insertions(+), 88 deletions(-) diff --git a/apis/libadmin.go b/apis/libadmin.go index 37da06850..23bbfc713 100644 --- a/apis/libadmin.go +++ b/apis/libadmin.go @@ -291,18 +291,6 @@ func composeCacheArgsForFilter(dm *engine.DataManager, ctx *context.Context, flt args[cField] = append(args[cField], utils.ConcatenatedKey(tnt, indx)) } } - // case utils.CacheAttributeFilterIndexes: // this is slow - // for attrID := range ids { - // var attr *engine.AttributeProfile - // if attr, err = dm.GetAttributeProfile(ctx, tnt, attrID, true, true, utils.NonTransactional); err != nil { - // return - // } - // for _, ctx := range attr.Contexts { - // for _, indx := range indxIDs { - // args[utils.AttributeFilterIndexIDs] = append(args[utils.AttributeFilterIndexIDs], utils.ConcatenatedKey(tnt, ctx, indx)) - // } - // } - // } case utils.CacheDispatcherFilterIndexes: // this is slow for attrID := range ids { var attr *engine.DispatcherProfile diff --git a/apis/libadmin_test.go b/apis/libadmin_test.go index 825ddb5d8..266473d13 100644 --- a/apis/libadmin_test.go +++ b/apis/libadmin_test.go @@ -18,77 +18,88 @@ along with this program. If not, see package apis -// func TestCallCacheForFilter(t *testing.T) { -// cfg := config.NewDefaultCGRConfig() -// dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true), cfg.CacheCfg(), nil) -// tnt := "cgrates.org" -// flt := &engine.Filter{ -// Tenant: tnt, -// ID: "FLTR1", -// Rules: []*engine.FilterRule{{ -// Type: utils.MetaString, -// Element: "~*req.Account", -// Values: []string{"1001"}, -// }}, -// } -// if err := flt.Compile(); err != nil { -// t.Fatal(err) -// } -// if err := dm.SetFilter(context.TODO(), flt, true); err != nil { -// t.Fatal(err) -// } -// th := &engine.ThresholdProfile{ -// Tenant: tnt, -// ID: "TH1", -// FilterIDs: []string{flt.ID}, -// } -// if err := dm.SetThresholdProfile(th, true); err != nil { -// t.Fatal(err) -// } -// attr := &engine.AttributeProfile{ -// Tenant: tnt, -// ID: "Attr1", -// FilterIDs: []string{flt.ID}, -// } -// if err := dm.SetAttributeProfile(context.TODO(), attr, true); err != nil { -// t.Fatal(err) -// } +import ( + "reflect" + "testing" -// exp := map[string][]string{ -// utils.FilterIDs: {"cgrates.org:FLTR1"}, -// utils.AttributeFilterIndexIDs: {"cgrates.org:*any:*string:*req.Account:1001"}, -// utils.ThresholdFilterIndexIDs: {"cgrates.org:*string:*req.Account:1001"}, -// } -// rpl, err := composeCacheArgsForFilter(dm, context.TODO(), flt, tnt, flt.TenantID(), map[string][]string{utils.FilterIDs: {"cgrates.org:FLTR1"}}) -// if err != nil { -// t.Fatal(err) -// } else if !reflect.DeepEqual(rpl, exp) { -// t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rpl)) -// } -// flt = &engine.Filter{ -// Tenant: tnt, -// ID: "FLTR1", -// Rules: []*engine.FilterRule{{ -// Type: utils.MetaString, -// Element: "~*req.Account", -// Values: []string{"1002"}, -// }}, -// } -// if err := flt.Compile(); err != nil { -// t.Fatal(err) -// } -// if err := dm.SetFilter(context.TODO(), flt, true); err != nil { -// t.Fatal(err) -// } -// exp = map[string][]string{ -// utils.FilterIDs: {"cgrates.org:FLTR1"}, -// utils.AttributeFilterIndexIDs: {"cgrates.org:*any:*string:*req.Account:1001", "cgrates.org:*any:*string:*req.Account:1002"}, -// utils.ThresholdFilterIndexIDs: {"cgrates.org:*string:*req.Account:1001", "cgrates.org:*string:*req.Account:1002"}, -// } -// rpl, err = composeCacheArgsForFilter(dm, context.TODO(), flt, tnt, flt.TenantID(), rpl) -// if err != nil { -// t.Fatal(err) -// } else if !reflect.DeepEqual(rpl, exp) { -// t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rpl)) -// } -// } + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func TestCallCacheForFilter(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true), cfg.CacheCfg(), nil) + tnt := "cgrates.org" + flt := &engine.Filter{ + Tenant: tnt, + ID: "FLTR1", + Rules: []*engine.FilterRule{{ + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{"1001"}, + }}, + } + if err := flt.Compile(); err != nil { + t.Fatal(err) + } + if err := dm.SetFilter(context.TODO(), flt, true); err != nil { + t.Fatal(err) + } + th := &engine.ThresholdProfile{ + Tenant: tnt, + ID: "TH1", + FilterIDs: []string{flt.ID}, + } + if err := dm.SetThresholdProfile(th, true); err != nil { + t.Fatal(err) + } + dsp := &engine.DispatcherProfile{ + Tenant: tnt, + Subsystems: []string{utils.MetaAny}, + ID: "Dsp1", + FilterIDs: []string{flt.ID}, + } + if err := dm.SetDispatcherProfile(context.TODO(), dsp, true); err != nil { + t.Fatal(err) + } + + exp := map[string][]string{ + utils.FilterIDs: {"cgrates.org:FLTR1"}, + utils.DispatcherFilterIndexIDs: {"cgrates.org:*any:*string:*req.Account:1001"}, + utils.ThresholdFilterIndexIDs: {"cgrates.org:*string:*req.Account:1001"}, + } + rpl, err := composeCacheArgsForFilter(dm, context.TODO(), flt, tnt, flt.TenantID(), map[string][]string{utils.FilterIDs: {"cgrates.org:FLTR1"}}) + if err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rpl, exp) { + t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rpl)) + } + flt = &engine.Filter{ + Tenant: tnt, + ID: "FLTR1", + Rules: []*engine.FilterRule{{ + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{"1002"}, + }}, + } + if err := flt.Compile(); err != nil { + t.Fatal(err) + } + if err := dm.SetFilter(context.TODO(), flt, true); err != nil { + t.Fatal(err) + } + exp = map[string][]string{ + utils.FilterIDs: {"cgrates.org:FLTR1"}, + utils.DispatcherFilterIndexIDs: {"cgrates.org:*any:*string:*req.Account:1001", "cgrates.org:*any:*string:*req.Account:1002"}, + utils.ThresholdFilterIndexIDs: {"cgrates.org:*string:*req.Account:1001", "cgrates.org:*string:*req.Account:1002"}, + } + rpl, err = composeCacheArgsForFilter(dm, context.TODO(), flt, tnt, flt.TenantID(), rpl) + if err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rpl, exp) { + t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rpl)) + } +} diff --git a/apis/rates_test.go b/apis/rates_test.go index 4f596789c..7e74c4afd 100644 --- a/apis/rates_test.go +++ b/apis/rates_test.go @@ -594,7 +594,6 @@ func TestApisRateCostForEvent(t *testing.T) { CGREvent: &utils.CGREvent{ Tenant: "tenant", ID: "ID", - Time: nil, Event: nil, APIOpts: nil, }, diff --git a/engine/version.go b/engine/version.go index ec139c34f..19de6602b 100644 --- a/engine/version.go +++ b/engine/version.go @@ -145,7 +145,7 @@ func CurrentDataDBVersions() Versions { utils.Actions: 2, utils.Thresholds: 4, utils.Routes: 2, - utils.Attributes: 6, + utils.Attributes: 7, utils.RQF: 5, utils.Resource: 1, utils.Subscribers: 1, diff --git a/engine/version_test.go b/engine/version_test.go index 8771f116e..7b5616230 100644 --- a/engine/version_test.go +++ b/engine/version_test.go @@ -73,7 +73,7 @@ func TestVersionCompare(t *testing.T) { func TestCurrentDBVersions(t *testing.T) { expVersDataDB := Versions{ utils.StatS: 4, utils.Accounts: 3, utils.Actions: 2, - utils.Thresholds: 4, utils.Routes: 2, utils.Attributes: 6, + utils.Thresholds: 4, utils.Routes: 2, utils.Attributes: 7, utils.RQF: 5, utils.Resource: 1, utils.Subscribers: 1, utils.Chargers: 2,