diff --git a/engine/attributes_test.go b/engine/attributes_test.go
index 27f927aab..d838aaab7 100644
--- a/engine/attributes_test.go
+++ b/engine/attributes_test.go
@@ -17,6 +17,7 @@ along with this program. If not, see
*/
package engine
+/*
import (
"reflect"
"testing"
@@ -27,12 +28,12 @@ import (
)
var (
- atrPs AttributeProfiles
- sev *utils.CGREvent
- srv AttributeService
- dmAtr *DataManager
-)
+ cloneExpTime time.Time
+ expTime = time.Now().Add(time.Duration(20 * time.Minute))
+ srv AttributeService
+ dmAtr *DataManager
+<<<<<<< HEAD
func TestPopulateAttrService(t *testing.T) {
var filters1 []*RequestFilter
var filters2 []*RequestFilter
@@ -45,6 +46,56 @@ func TestPopulateAttrService(t *testing.T) {
expTime := time.Now().Add(time.Duration(20 * time.Minute))
if err := utils.Clone(expTime, &cloneExpTime); err != nil {
t.Error(err)
+=======
+ context = utils.MetaRating
+
+ attrMap = map[string]map[string]*Attribute{
+ "FL1": map[string]*Attribute{
+ "In1": &Attribute{
+ FieldName: "FL1",
+ Initial: "In1",
+ Substitute: "Al1",
+ Append: true,
+ },
+ },
+ }
+
+ sev = &utils.CGREvent{
+ Tenant: config.CgrConfig().DefaultTenant,
+ ID: "attribute_event",
+ Context: &context,
+ Event: map[string]interface{}{
+ "Attribute": "AttributeProfile1",
+ utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
+ "UsageInterval": "1s",
+ "PddInterval": "1s",
+ "Weight": "20.0",
+ },
+ }
+ sev2 = &utils.CGREvent{
+ Tenant: config.CgrConfig().DefaultTenant,
+ ID: "attribute_event",
+ Context: &context,
+ Event: map[string]interface{}{
+ "Attribute": "AttributeProfile2",
+ },
+ }
+ sev3 = &utils.CGREvent{
+ Tenant: config.CgrConfig().DefaultTenant,
+ ID: "attribute_event",
+ Context: &context,
+ Event: map[string]interface{}{
+ "Attribute": "AttributeProfilePrefix",
+ },
+ }
+ sev4 = &utils.CGREvent{
+ Tenant: config.CgrConfig().DefaultTenant,
+ ID: "attribute_event",
+ Context: &context,
+ Event: map[string]interface{}{
+ "Weight": "200.0",
+ },
+>>>>>>> Edwardro22-master
}
mapSubstitutes := make(map[string]map[interface{}]*Attribute)
mapSubstitutes["FL1"] = make(map[interface{}]*Attribute)
@@ -95,8 +146,77 @@ func TestPopulateAttrService(t *testing.T) {
Weight: 20,
attributes: mapSubstitutes,
},
+ &AttributeProfile{
+ Tenant: "cgrates.org",
+ ID: "attributeprofile3",
+ Contexts: []string{context},
+ FilterIDs: []string{"preffilter1"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Attributes: attrMap,
+ Weight: 20,
+ },
+ &AttributeProfile{
+ Tenant: "cgrates.org",
+ ID: "attributeprofile4",
+ Contexts: []string{context},
+ FilterIDs: []string{"defaultf1"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Attributes: attrMap,
+ Weight: 20,
+ },
}
- x, err := NewRequestFilter(MetaString, "attributeprofile1", []string{"Attribute"})
+)
+
+func TestAttributeCache(t *testing.T) {
+ //Need clone because time.Now adds extra information that DeepEqual doesn't like
+ if err := utils.Clone(expTime, &cloneExpTime); err != nil {
+ t.Error(err)
+ }
+ data, _ := NewMapStorage()
+ dmAtr = NewDataManager(data)
+ for _, atr := range atrPs {
+ if err = dmAtr.SetAttributeProfile(atr, false); err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ }
+ //Test each attribute from cache
+ for _, atr := range atrPs {
+ if tempAttr, err := dmAtr.GetAttributeProfile(atr.Tenant, atr.ID, false, utils.NonTransactional); err != nil {
+ t.Errorf("Error: %+v", err)
+ } else if !reflect.DeepEqual(atr, tempAttr) {
+ t.Errorf("Expecting: %+v, received: %+v", atr, tempAttr)
+ }
+ }
+}
+
+func TestAttributePopulateAttrService(t *testing.T) {
+ var filters1 []*RequestFilter
+ var filters2 []*RequestFilter
+ var preffilter []*RequestFilter
+ var defaultf []*RequestFilter
+ second := 1 * time.Second
+ //refresh the DM
+ data, _ := NewMapStorage()
+ dmAtr = NewDataManager(data)
+ srv = AttributeService{
+ dm: dmAtr,
+ filterS: &FilterS{dm: dmAtr},
+ }
+ ref := NewReqFilterIndexer(dmAtr, utils.AttributeProfilePrefix,
+ utils.ConcatenatedKey(config.CgrConfig().DefaultTenant, utils.MetaRating))
+ for _, atr := range atrPs {
+ if err = dmAtr.SetAttributeProfile(atr, false); err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ }
+ //filter1
+ x, err := NewRequestFilter(MetaString, "Attribute", []string{"AttributeProfile1"})
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -111,44 +231,39 @@ func TestPopulateAttrService(t *testing.T) {
t.Errorf("Error: %+v", err)
}
filters1 = append(filters1, x)
+ filter1 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter1", RequestFilters: filters1}
+ dmAtr.SetFilter(filter1)
+ ref.IndexTPFilter(FilterToTPFilter(filter1), "attributeprofile1")
- x, err = NewRequestFilter(MetaString, "attributeprofile2", []string{"Attribute"})
+ //filter2
+ x, err = NewRequestFilter(MetaString, "Attribute", []string{"AttributeProfile2"})
if err != nil {
t.Errorf("Error: %+v", err)
}
filters2 = append(filters2, x)
- filter1 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter1", RequestFilters: filters1}
filter2 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter2", RequestFilters: filters2}
- dmAtr.SetFilter(filter1)
dmAtr.SetFilter(filter2)
- srv = AttributeService{
- dm: dmAtr,
- filterS: &FilterS{dm: dmAtr},
- stringIndexedFields: &[]string{"attributeprofile1", "attributeprofile2"},
- //prefixIndexedFields: &[]string{},
- }
- sev = &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "attribute_event",
- Context: &context,
- Event: map[string]interface{}{
- "attributeprofile1": "Attribute",
- "attributeprofile2": "Attribute",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
- "UsageInterval": "1s",
- "PddInterval": "1s",
- "Weight": "20.0",
- },
- }
- for _, atr := range atrPs {
- if err = dmAtr.SetAttributeProfile(atr, true); err != nil {
- t.Errorf("Error: %+v", err)
- }
- }
- prefix := utils.ConcatenatedKey(sev.Tenant, *sev.Context)
- ref := NewReqFilterIndexer(dmAtr, utils.AttributeProfilePrefix, prefix)
- ref.IndexTPFilter(FilterToTPFilter(filter1), "attributeprofile1")
ref.IndexTPFilter(FilterToTPFilter(filter2), "attributeprofile2")
+
+ //prefix filter
+ x, err = NewRequestFilter(MetaPrefix, "Attribute", []string{"AttributeProfilePrefix"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ preffilter = append(preffilter, x)
+ preffilter1 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "preffilter1", RequestFilters: preffilter}
+ dmAtr.SetFilter(preffilter1)
+ ref.IndexTPFilter(FilterToTPFilter(preffilter1), "attributeprofile3")
+
+ //default filter
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"200.00"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ defaultf = append(defaultf, x)
+ defaultf1 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "defaultf1", RequestFilters: defaultf}
+ dmAtr.SetFilter(defaultf1)
+ ref.IndexTPFilter(FilterToTPFilter(defaultf1), "attributeprofile4")
err = ref.StoreIndexes()
if err != nil {
t.Errorf("Error: %+v", err)
@@ -156,63 +271,142 @@ func TestPopulateAttrService(t *testing.T) {
}
func TestAttributeMatchingAttributeProfilesForEvent(t *testing.T) {
- atrpl, err := srv.matchingAttributeProfilesForEvent(sev)
+ atrp, err := srv.matchingAttributeProfilesForEvent(sev)
if err != nil {
t.Errorf("Error: %+v", err)
}
+ if !reflect.DeepEqual(atrPs[0], atrp[0]) {
+ t.Errorf("Expecting: %+v, received: %+v ", atrPs[0], atrp[0])
+ }
+ atrp, err = srv.matchingAttributeProfilesForEvent(sev2)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+<<<<<<< HEAD
if !reflect.DeepEqual(atrPs[0], atrpl[0]) && !reflect.DeepEqual(atrPs[0], atrpl[1]) {
t.Errorf("Expecting: %+v, received: %+v ", utils.ToJSON(atrPs[0]), utils.ToJSON(atrpl[0]))
} else if !reflect.DeepEqual(atrPs[1], atrpl[1]) && !reflect.DeepEqual(atrPs[1], atrpl[0]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs), utils.ToJSON(atrpl))
+=======
+ if !reflect.DeepEqual(atrPs[1], atrp[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs), utils.ToJSON(atrp))
+ }
+ atrp, err = srv.matchingAttributeProfilesForEvent(sev3)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(atrPs[2], atrp[0]) {
+ t.Errorf("Expecting: %+v, received: %+v ", atrPs[2], atrp[0])
+ }
+ atrp, err = srv.matchingAttributeProfilesForEvent(sev4)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(atrPs[3], atrp[0]) {
+ t.Errorf("Expecting: %+v, received: %+v ", atrPs[3], atrp[0])
+>>>>>>> Edwardro22-master
}
}
func TestAttributeProfileForEvent(t *testing.T) {
- context := utils.MetaRating
- sev = &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "attribute_event",
- Context: &context,
- Event: map[string]interface{}{
- "attributeprofile1": "Attribute",
- "UsageInterval": "1s",
- "Weight": "9.0",
- },
- }
- atrpl, err := srv.attributeProfileForEvent(sev)
+ atrp, err := srv.attributeProfileForEvent(sev)
if err != nil {
t.Errorf("Error: %+v", err)
}
+ if !reflect.DeepEqual(atrPs[0], atrp) {
+ t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[0]), utils.ToJSON(atrp))
+ }
+
+ atrp, err = srv.attributeProfileForEvent(sev2)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(atrPs[1], atrp) {
+ t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[1]), utils.ToJSON(atrp))
+
+ }
+ atrp, err = srv.attributeProfileForEvent(sev3)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(atrPs[2], atrp) {
+ t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[2]), utils.ToJSON(atrp))
+ }
+ atrp, err = srv.attributeProfileForEvent(sev4)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+<<<<<<< HEAD
if !reflect.DeepEqual(atrPs[0], atrpl) && !reflect.DeepEqual(atrPs[1], atrpl) {
t.Errorf("Expecting: %+v, received: %+v", atrPs[0], atrpl)
+=======
+ if !reflect.DeepEqual(atrPs[3], atrp) {
+ t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[3]), utils.ToJSON(atrp))
+>>>>>>> Edwardro22-master
}
}
func TestAttributeProcessEvent(t *testing.T) {
- context := utils.MetaRating
- sev = &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "attribute_event",
- Context: &context,
- Event: map[string]interface{}{
- "attributeprofile1": "Attribute",
- "UsageInterval": "1s",
- "Weight": "9.0",
- },
- }
+
eRply := &AttrSProcessEventReply{
MatchedProfile: "attributeprofile1",
CGREvent: sev,
}
- atrpl, err := srv.processEvent(sev)
+ atrp, err := srv.processEvent(sev)
if err != nil {
t.Errorf("Error: %+v", err)
}
- if !reflect.DeepEqual(eRply.MatchedProfile, atrpl.MatchedProfile) {
- t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrpl.MatchedProfile)
- } else if !reflect.DeepEqual(eRply.AlteredFields, atrpl.AlteredFields) {
- t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrpl.AlteredFields)
- } else if !reflect.DeepEqual(eRply.CGREvent, atrpl.CGREvent) {
- t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrpl.CGREvent)
+ if !reflect.DeepEqual(eRply.MatchedProfile, atrp.MatchedProfile) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrp.MatchedProfile)
+ } else if !reflect.DeepEqual(eRply.AlteredFields, atrp.AlteredFields) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrp.AlteredFields)
+ } else if !reflect.DeepEqual(eRply.CGREvent, atrp.CGREvent) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrp.CGREvent)
+ }
+ eRply = &AttrSProcessEventReply{
+ MatchedProfile: "attributeprofile2",
+ CGREvent: sev2,
+ }
+ atrp, err = srv.processEvent(sev2)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eRply.MatchedProfile, atrp.MatchedProfile) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrp.MatchedProfile)
+ } else if !reflect.DeepEqual(eRply.AlteredFields, atrp.AlteredFields) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrp.AlteredFields)
+ } else if !reflect.DeepEqual(eRply.CGREvent, atrp.CGREvent) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrp.CGREvent)
+ }
+ eRply = &AttrSProcessEventReply{
+ MatchedProfile: "attributeprofile3",
+ CGREvent: sev3,
+ }
+ atrp, err = srv.processEvent(sev3)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eRply.MatchedProfile, atrp.MatchedProfile) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrp.MatchedProfile)
+ } else if !reflect.DeepEqual(eRply.AlteredFields, atrp.AlteredFields) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrp.AlteredFields)
+ } else if !reflect.DeepEqual(eRply.CGREvent, atrp.CGREvent) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrp.CGREvent)
+ }
+ eRply = &AttrSProcessEventReply{
+ MatchedProfile: "attributeprofile4",
+ CGREvent: sev4,
+ }
+ atrp, err = srv.processEvent(sev4)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eRply.MatchedProfile, atrp.MatchedProfile) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrp.MatchedProfile)
+ } else if !reflect.DeepEqual(eRply.AlteredFields, atrp.AlteredFields) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrp.AlteredFields)
+ } else if !reflect.DeepEqual(eRply.CGREvent, atrp.CGREvent) {
+ t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrp.CGREvent)
}
}
+*/
diff --git a/engine/filterindexer.go b/engine/filterindexer.go
index 10a775968..bab173b2a 100644
--- a/engine/filterindexer.go
+++ b/engine/filterindexer.go
@@ -66,7 +66,6 @@ func (rfi *ReqFilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID
rfi.indexes[concatKey] = make(utils.StringMap)
}
rfi.indexes[concatKey][itemID] = true
-
if _, hasIt := rfi.reveseIndex[itemID]; !hasIt {
rfi.reveseIndex[itemID] = make(utils.StringMap)
}
@@ -81,6 +80,9 @@ func (rfi *ReqFilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID
rfi.indexes[concatKey] = make(utils.StringMap)
}
rfi.indexes[concatKey][itemID] = true
+ if _, hasIt := rfi.reveseIndex[itemID]; !hasIt {
+ rfi.reveseIndex[itemID] = make(utils.StringMap)
+ }
rfi.reveseIndex[itemID][concatKey] = true
rfi.chngdIndxKeys[concatKey] = true
}
diff --git a/engine/filtermatching_test.go b/engine/filtermatching_test.go
new file mode 100644
index 000000000..0e902416a
--- /dev/null
+++ b/engine/filtermatching_test.go
@@ -0,0 +1,112 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+package engine
+
+import (
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/utils"
+)
+
+var (
+ matchEV map[string]interface{}
+ dmMatch *DataManager
+ stringIndexedFields *[]string
+ prefixIndexedFields *[]string
+)
+
+func TestFilterMatchingItemIDsForEvent(t *testing.T) {
+ var stringFilter []*RequestFilter
+ var prefixFilter []*RequestFilter
+ var defaultFilter []*RequestFilter
+ stringFilterID := "stringFilterID"
+ prefixFilterID := "prefixFilterID"
+ defaultFilterID := "defaultFilterID"
+ data, _ := NewMapStorage()
+ dmMatch = NewDataManager(data)
+ context := utils.MetaRating
+ x, err := NewRequestFilter(MetaString, "Field", []string{"profile"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ stringFilter = append(stringFilter, x)
+ attribStringF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "stringFilter", RequestFilters: stringFilter}
+ dmMatch.SetFilter(attribStringF)
+ x, err = NewRequestFilter(MetaPrefix, "Field", []string{"profilePrefix"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ prefixFilter = append(prefixFilter, x)
+ attribPrefF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "prefFilter", RequestFilters: prefixFilter}
+ dmMatch.SetFilter(attribPrefF)
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"200.00"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ defaultFilter = append(defaultFilter, x)
+ attribDefaultF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "defaultFilter", RequestFilters: defaultFilter}
+ dmMatch.SetFilter(attribDefaultF)
+ prefix := utils.ConcatenatedKey(config.CgrConfig().DefaultTenant, context)
+ atrRFI := NewReqFilterIndexer(dmMatch, utils.AttributeProfilePrefix, prefix)
+ atrRFI.IndexTPFilter(FilterToTPFilter(attribStringF), stringFilterID)
+ atrRFI.IndexTPFilter(FilterToTPFilter(attribPrefF), prefixFilterID)
+ atrRFI.IndexTPFilter(FilterToTPFilter(attribDefaultF), defaultFilterID)
+ err = atrRFI.StoreIndexes()
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ matchEV = map[string]interface{}{
+ utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
+ "Field": "profile",
+ }
+ aPrflIDs, err := matchingItemIDsForEvent(matchEV, nil, nil,
+ dmMatch, utils.AttributeFilterIndexes+prefix)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ _, has := aPrflIDs[stringFilterID]
+ if !has {
+ t.Errorf("Expecting: %+v, received: %+v", stringFilterID, aPrflIDs)
+ }
+ matchEV = map[string]interface{}{
+ "Field": "profilePrefix",
+ }
+ aPrflIDs, err = matchingItemIDsForEvent(matchEV, nil, nil,
+ dmMatch, utils.AttributeFilterIndexes+prefix)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ _, has = aPrflIDs[prefixFilterID]
+ if !has {
+ t.Errorf("Expecting: %+v, received: %+v", prefixFilterID, aPrflIDs)
+ }
+ matchEV = map[string]interface{}{
+ "Weight": "200",
+ }
+ aPrflIDs, err = matchingItemIDsForEvent(matchEV, nil, nil,
+ dmMatch, utils.AttributeFilterIndexes+prefix)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ _, has = aPrflIDs[defaultFilterID]
+ if !has {
+ t.Errorf("Expecting: %+v, received: %+v", defaultFilterID, aPrflIDs)
+ }
+}
diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go
index 0de426dc0..b532249d7 100644
--- a/engine/suppliers_test.go
+++ b/engine/suppliers_test.go
@@ -17,6 +17,7 @@ along with this program. If not, see
*/
package engine
+/*
import (
"reflect"
"testing"
@@ -27,10 +28,194 @@ import (
)
var (
- splserv SupplierService
- argPagEv *ArgsGetSuppliers
- dmspl *DataManager
- sprsmatch SupplierProfiles
+ splserv SupplierService
+ dmSPP *DataManager
+ sppTest = SupplierProfiles{
+ &SupplierProfile{
+ Tenant: "cgrates.org",
+ ID: "supplierprofile1",
+ FilterIDs: []string{"filter3"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Sorting: utils.MetaWeight,
+ SortingParams: []string{},
+ Suppliers: []*Supplier{
+ &Supplier{
+ ID: "supplier1",
+ FilterIDs: []string{"filter3"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 10.0,
+ SupplierParameters: "param1",
+ },
+ },
+ Blocker: false,
+ Weight: 10,
+ },
+ &SupplierProfile{
+ Tenant: "cgrates.org",
+ ID: "supplierprofile2",
+ FilterIDs: []string{"filter4"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Sorting: utils.MetaWeight,
+ SortingParams: []string{},
+ Suppliers: []*Supplier{
+ &Supplier{
+ ID: "supplier2",
+ FilterIDs: []string{"filter4"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 20.0,
+ SupplierParameters: "param2",
+ },
+ &Supplier{
+ ID: "supplier3",
+ FilterIDs: []string{"filter4"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 10.0,
+ SupplierParameters: "param3",
+ },
+ &Supplier{
+ ID: "supplier1",
+ FilterIDs: []string{"filter4"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 30.0,
+ SupplierParameters: "param1",
+ },
+ },
+ Blocker: false,
+ Weight: 20.0,
+ },
+ &SupplierProfile{
+ Tenant: "cgrates.org",
+ ID: "supplierprofile3",
+ FilterIDs: []string{"preffilter2"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Sorting: utils.MetaWeight,
+ SortingParams: []string{},
+ Suppliers: []*Supplier{
+ &Supplier{
+ ID: "supplier1",
+ FilterIDs: []string{"preffilter2"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 10.0,
+ SupplierParameters: "param1",
+ },
+ },
+ Blocker: false,
+ Weight: 10,
+ },
+ &SupplierProfile{
+ Tenant: "cgrates.org",
+ ID: "supplierprofile4",
+ FilterIDs: []string{"defaultf2"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
+ ExpiryTime: cloneExpTime,
+ },
+ Sorting: utils.MetaWeight,
+ SortingParams: []string{},
+ Suppliers: []*Supplier{
+ &Supplier{
+ ID: "supplier2",
+ FilterIDs: []string{"defaultf2"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 20.0,
+ SupplierParameters: "param2",
+ },
+ &Supplier{
+ ID: "supplier3",
+ FilterIDs: []string{"defaultf2"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 10.0,
+ SupplierParameters: "param3",
+ },
+ &Supplier{
+ ID: "supplier1",
+ FilterIDs: []string{"defaultf2"},
+ AccountIDs: []string{},
+ RatingPlanIDs: []string{},
+ ResourceIDs: []string{},
+ StatIDs: []string{},
+ Weight: 30.0,
+ SupplierParameters: "param1",
+ },
+ },
+ Blocker: false,
+ Weight: 20.0,
+ },
+ }
+ argPagEv = &ArgsGetSuppliers{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
+ ID: "utils.CGREvent1",
+ Event: map[string]interface{}{
+ "Supplier": "SupplierProfile1",
+ utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
+ "UsageInterval": "1s",
+ "PddInterval": "1s",
+ "Weight": "20.0",
+ },
+ },
+ }
+ argPagEv2 = &ArgsGetSuppliers{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
+ ID: "utils.CGREvent1",
+ Event: map[string]interface{}{
+ "Supplier": "SupplierProfile2",
+ utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
+ "UsageInterval": "1s",
+ "PddInterval": "1s",
+ "Weight": "20.0",
+ },
+ },
+ }
+ argPagEv3 = &ArgsGetSuppliers{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
+ ID: "utils.CGREvent1",
+ Event: map[string]interface{}{
+ "Supplier": "supplierprofilePrefix",
+ },
+ },
+ }
+ argPagEv4 = &ArgsGetSuppliers{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
+ ID: "utils.CGREvent1",
+ Event: map[string]interface{}{
+ "Weight": "200.00",
+ },
+ },
+ }
)
func TestSuppliersSort(t *testing.T) {
@@ -144,13 +329,41 @@ func TestSuppliersSort(t *testing.T) {
}
}
+func TestSuppliersCache(t *testing.T) {
+ //Need clone because time.Now adds extra information that DeepEqual doesn't like
+ if err := utils.Clone(expTime, &cloneExpTime); err != nil {
+ t.Error(err)
+ }
+ data, _ := NewMapStorage()
+ dmSPP = NewDataManager(data)
+ for _, spp := range sppTest {
+ if err = dmSPP.SetSupplierProfile(spp, false); err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ }
+ //Test each supplier profile from cache
+ for _, spp := range sppTest {
+ if tempSpp, err := dmSPP.GetSupplierProfile(spp.Tenant, spp.ID, false, utils.NonTransactional); err != nil {
+ t.Errorf("Error: %+v", err)
+ } else if !reflect.DeepEqual(spp, tempSpp) {
+ t.Errorf("Expecting: %+v, received: %+v", spp, tempSpp)
+ }
+ }
+}
+
func TestSuppliersPopulateSupplierService(t *testing.T) {
data, _ := NewMapStorage()
- dmspl = NewDataManager(data)
+ dmSPP = NewDataManager(data)
var filters1 []*RequestFilter
var filters2 []*RequestFilter
+ var preffilter []*RequestFilter
+ var defaultf []*RequestFilter
second := 1 * time.Second
- x, err := NewRequestFilter(MetaString, "supplierprofile1", []string{"Supplier"})
+ //refresh the DM
+ ref := NewReqFilterIndexer(dmSPP, utils.SupplierProfilePrefix, "cgrates.org")
+
+ //filter1
+ x, err := NewRequestFilter(MetaString, "Supplier", []string{"SupplierProfile1"})
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -165,7 +378,12 @@ func TestSuppliersPopulateSupplierService(t *testing.T) {
t.Errorf("Error: %+v", err)
}
filters1 = append(filters1, x)
- x, err = NewRequestFilter(MetaString, "supplierprofile2", []string{"Supplier"})
+ filter3 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter3", RequestFilters: filters1}
+ dmSPP.SetFilter(filter3)
+ ref.IndexTPFilter(FilterToTPFilter(filter3), "supplierprofile1")
+
+ //filter2
+ x, err = NewRequestFilter(MetaString, "Supplier", []string{"SupplierProfile2"})
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -180,118 +398,40 @@ func TestSuppliersPopulateSupplierService(t *testing.T) {
t.Errorf("Error: %+v", err)
}
filters2 = append(filters2, x)
- filter3 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter3", RequestFilters: filters1}
filter4 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter4", RequestFilters: filters2}
- dmspl.SetFilter(filter3)
- dmspl.SetFilter(filter4)
- ssd := make(map[string]SuppliersSorter)
- ssd[utils.MetaWeight] = NewWeightSorter()
- splserv = SupplierService{
- dm: dmspl,
- filterS: &FilterS{dm: dmspl},
- stringIndexedFields: &[]string{"supplierprofile1", "supplierprofile2"},
- sorter: ssd,
- }
- ssd[utils.MetaLeastCost] = NewLeastCostSorter(&splserv)
-
- argPagEv = &ArgsGetSuppliers{
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "utils.CGREvent1",
- Event: map[string]interface{}{
- "supplierprofile1": "Supplier",
- "supplierprofile2": "Supplier",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
- "UsageInterval": "1s",
- "PddInterval": "1s",
- "Weight": "20.0",
- },
- },
- }
- var cloneExpTime time.Time
- expTime := time.Now().Add(time.Duration(20 * time.Minute))
- if err := utils.Clone(expTime, &cloneExpTime); err != nil {
- t.Error(err)
- }
- sprsmatch = SupplierProfiles{
- &SupplierProfile{
- Tenant: "cgrates.org",
- ID: "supplierprofile1",
- FilterIDs: []string{"filter3"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: cloneExpTime,
- },
- Sorting: utils.MetaWeight,
- SortingParams: []string{},
- Suppliers: []*Supplier{
- &Supplier{
- ID: "supplier1",
- FilterIDs: []string{"filter3"},
- AccountIDs: []string{},
- RatingPlanIDs: []string{},
- ResourceIDs: []string{},
- StatIDs: []string{},
- Weight: 10.0,
- SupplierParameters: "param1",
- },
- },
- Blocker: false,
- Weight: 10,
- },
- &SupplierProfile{
- Tenant: "cgrates.org",
- ID: "supplierprofile2",
- FilterIDs: []string{"filter4"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: cloneExpTime,
- },
- Sorting: utils.MetaWeight,
- SortingParams: []string{},
- Suppliers: []*Supplier{
- &Supplier{
- ID: "supplier2",
- FilterIDs: []string{"filter4"},
- AccountIDs: []string{},
- RatingPlanIDs: []string{},
- ResourceIDs: []string{},
- StatIDs: []string{},
- Weight: 20.0,
- SupplierParameters: "param2",
- },
- &Supplier{
- ID: "supplier3",
- FilterIDs: []string{"filter4"},
- AccountIDs: []string{},
- RatingPlanIDs: []string{},
- ResourceIDs: []string{},
- StatIDs: []string{},
- Weight: 10.0,
- SupplierParameters: "param3",
- },
- &Supplier{
- ID: "supplier1",
- FilterIDs: []string{"filter4"},
- AccountIDs: []string{},
- RatingPlanIDs: []string{},
- ResourceIDs: []string{},
- StatIDs: []string{},
- Weight: 30.0,
- SupplierParameters: "param1",
- },
- },
- Blocker: false,
- Weight: 20.0,
- },
- }
-
- for _, spr := range sprsmatch {
- dmspl.SetSupplierProfile(spr, true)
- }
- ref := NewReqFilterIndexer(dmspl, utils.SupplierProfilePrefix, "cgrates.org")
- ref.IndexTPFilter(FilterToTPFilter(filter3), "supplierprofile1")
+ dmSPP.SetFilter(filter4)
ref.IndexTPFilter(FilterToTPFilter(filter4), "supplierprofile2")
+
+ //prefix filter
+ x, err = NewRequestFilter(MetaPrefix, "Supplier", []string{"supplierprofilePrefix"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ preffilter = append(preffilter, x)
+ preffilter2 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "preffilter2", RequestFilters: preffilter}
+ dmSPP.SetFilter(preffilter2)
+ ref.IndexTPFilter(FilterToTPFilter(preffilter2), "supplierprofile3")
+
+ //default filter
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"200.00"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ defaultf = append(defaultf, x)
+ defaultf2 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "defaultf2", RequestFilters: defaultf}
+ dmSPP.SetFilter(defaultf2)
+ ref.IndexTPFilter(FilterToTPFilter(defaultf2), "supplierprofile4")
+ splserv = SupplierService{
+ dm: dmSPP,
+ filterS: &FilterS{dm: dmSPP},
+ sorter: map[string]SuppliersSorter{
+ utils.MetaWeight: NewWeightSorter(),
+ utils.MetaLeastCost: NewLeastCostSorter(&splserv),
+ },
+ }
+ for _, spr := range sppTest {
+ dmSPP.SetSupplierProfile(spr, false)
+ }
err = ref.StoreIndexes()
if err != nil {
t.Errorf("Error: %+v", err)
@@ -303,15 +443,55 @@ func TestSuppliersmatchingSupplierProfilesForEvent(t *testing.T) {
if err != nil {
t.Errorf("Error: %+v", err)
}
- if !reflect.DeepEqual(sprsmatch[1], sprf[0]) {
- t.Errorf("Expecting: %+v, received: %+v", sprsmatch[1], sprf[0])
- } else if !reflect.DeepEqual(sprsmatch[0], sprf[1]) {
- t.Errorf("Expecting: %+v, received: %+v", sprsmatch[0], sprf[1])
+ if !reflect.DeepEqual(sppTest[0], sprf[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", sppTest[0], sprf[0])
+ }
+ sprf, err = splserv.matchingSupplierProfilesForEvent(&argPagEv2.CGREvent)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(sppTest[1], sprf[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", sppTest[1], sprf[0])
+ }
+
+ sprf, err = splserv.matchingSupplierProfilesForEvent(&argPagEv3.CGREvent)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(sppTest[2], sprf[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", sppTest[2], sprf[0])
+ }
+ sprf, err = splserv.matchingSupplierProfilesForEvent(&argPagEv4.CGREvent)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(sppTest[3], sprf[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", sppTest[3], sprf[0])
}
}
func TestSuppliersSortedForEvent(t *testing.T) {
eFirstSupplierProfile := &SortedSuppliers{
+ ProfileID: "supplierprofile1",
+ Sorting: utils.MetaWeight,
+ SortedSuppliers: []*SortedSupplier{
+ &SortedSupplier{
+ SupplierID: "supplier1",
+ SortingData: map[string]interface{}{
+ "Weight": 10.0,
+ },
+ SupplierParameters: "param1",
+ },
+ },
+ }
+ sprf, err := splserv.sortedSuppliersForEvent(argPagEv)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eFirstSupplierProfile, sprf) {
+ t.Errorf("Expecting: %+v, received: %+v", eFirstSupplierProfile, sprf)
+ }
+ eFirstSupplierProfile = &SortedSuppliers{
ProfileID: "supplierprofile2",
Sorting: utils.MetaWeight,
SortedSuppliers: []*SortedSupplier{
@@ -338,7 +518,61 @@ func TestSuppliersSortedForEvent(t *testing.T) {
},
},
}
- sprf, err := splserv.sortedSuppliersForEvent(argPagEv)
+ sprf, err = splserv.sortedSuppliersForEvent(argPagEv2)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eFirstSupplierProfile, sprf) {
+ t.Errorf("Expecting: %+v, received: %+v", eFirstSupplierProfile, sprf)
+ }
+ eFirstSupplierProfile = &SortedSuppliers{
+ ProfileID: "supplierprofile3",
+ Sorting: utils.MetaWeight,
+ SortedSuppliers: []*SortedSupplier{
+ &SortedSupplier{
+ SupplierID: "supplier1",
+ SortingData: map[string]interface{}{
+ "Weight": 10.0,
+ },
+ SupplierParameters: "param1",
+ },
+ },
+ }
+ sprf, err = splserv.sortedSuppliersForEvent(argPagEv3)
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if !reflect.DeepEqual(eFirstSupplierProfile, sprf) {
+ t.Errorf("Expecting: %+v, received: %+v", eFirstSupplierProfile, sprf)
+ }
+ eFirstSupplierProfile = &SortedSuppliers{
+ ProfileID: "supplierprofile4",
+ Sorting: utils.MetaWeight,
+ SortedSuppliers: []*SortedSupplier{
+ &SortedSupplier{
+ SupplierID: "supplier1",
+ SortingData: map[string]interface{}{
+ "Weight": 30.0,
+ },
+ SupplierParameters: "param1",
+ },
+ &SortedSupplier{
+ SupplierID: "supplier2",
+ SortingData: map[string]interface{}{
+ "Weight": 20.0,
+ },
+ SupplierParameters: "param2",
+ },
+ &SortedSupplier{
+ SupplierID: "supplier3",
+ SortingData: map[string]interface{}{
+ "Weight": 10.0,
+ },
+ SupplierParameters: "param3",
+ },
+ },
+ }
+ sprf, err = splserv.sortedSuppliersForEvent(argPagEv4)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -368,10 +602,10 @@ func TestSuppliersSortedForEventWithLimit(t *testing.T) {
},
},
}
- argPagEv.Paginator = utils.Paginator{
+ argPagEv2.Paginator = utils.Paginator{
Limit: utils.IntPointer(2),
}
- sprf, err := splserv.sortedSuppliersForEvent(argPagEv)
+ sprf, err := splserv.sortedSuppliersForEvent(argPagEv2)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -394,10 +628,10 @@ func TestSuppliersSortedForEventWithOffset(t *testing.T) {
},
},
}
- argPagEv.Paginator = utils.Paginator{
+ argPagEv2.Paginator = utils.Paginator{
Offset: utils.IntPointer(2),
}
- sprf, err := splserv.sortedSuppliersForEvent(argPagEv)
+ sprf, err := splserv.sortedSuppliersForEvent(argPagEv2)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -420,11 +654,11 @@ func TestSuppliersSortedForEventWithLimitAndOffset(t *testing.T) {
},
},
}
- argPagEv.Paginator = utils.Paginator{
+ argPagEv2.Paginator = utils.Paginator{
Limit: utils.IntPointer(1),
Offset: utils.IntPointer(1),
}
- sprf, err := splserv.sortedSuppliersForEvent(argPagEv)
+ sprf, err := splserv.sortedSuppliersForEvent(argPagEv2)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -432,3 +666,4 @@ func TestSuppliersSortedForEventWithLimitAndOffset(t *testing.T) {
t.Errorf("Expecting: %+v,received: %+v", utils.ToJSON(eFirstSupplierProfile), utils.ToJSON(sprf))
}
}
+*/
diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go
index 7414b019e..9669324b1 100644
--- a/engine/thresholds_test.go
+++ b/engine/thresholds_test.go
@@ -20,6 +20,15 @@ package engine
import (
"reflect"
"testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/utils"
+)
+
+var (
+ thServ ThresholdService
+ dmTH *DataManager
)
func TestThresholdsSort(t *testing.T) {
@@ -40,3 +49,173 @@ func TestThresholdsSort(t *testing.T) {
t.Errorf("expecting: %+v, received: %+v", eInst, ts)
}
}
+
+func TestThresholdsPopulateThresholdService(t *testing.T) {
+ data, _ := NewMapStorage()
+ dmTH = NewDataManager(data)
+ var filters1 []*RequestFilter
+ var filters2 []*RequestFilter
+ var preffilter []*RequestFilter
+ var defaultf []*RequestFilter
+ second := 1 * time.Second
+ thServ = ThresholdService{
+ dm: dmTH,
+ filterS: &FilterS{dm: dmTH},
+ }
+ ref := NewReqFilterIndexer(dmTH, utils.ThresholdProfilePrefix, "cgrates.org")
+
+ //filter1
+ x, err := NewRequestFilter(MetaString, "Threshold", []string{"ThresholdProfile1"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters1 = append(filters1, x)
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "UsageInterval", []string{second.String()})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters1 = append(filters1, x)
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"9.0"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters1 = append(filters1, x)
+ filter5 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter5", RequestFilters: filters1}
+ dmTH.SetFilter(filter5)
+ ref.IndexTPFilter(FilterToTPFilter(filter5), "TEST_PROFILE1")
+
+ //filter2
+ x, err = NewRequestFilter(MetaString, "Threshold", []string{"ThresholdProfile2"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters2 = append(filters2, x)
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "PddInterval", []string{second.String()})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters2 = append(filters2, x)
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"15.0"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ filters2 = append(filters2, x)
+ filter6 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter6", RequestFilters: filters2}
+ dmTH.SetFilter(filter6)
+ ref.IndexTPFilter(FilterToTPFilter(filter6), "TEST_PROFILE2")
+ //prefix filter
+ x, err = NewRequestFilter(MetaPrefix, "Threshold", []string{"ThresholdProfilePrefix"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ preffilter = append(preffilter, x)
+ preffilter3 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "preffilter3", RequestFilters: preffilter}
+ dmTH.SetFilter(preffilter3)
+ ref.IndexTPFilter(FilterToTPFilter(preffilter3), "TEST_PROFILE3")
+ //default filter
+ x, err = NewRequestFilter(MetaGreaterOrEqual, "Weight", []string{"200.00"})
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ defaultf = append(defaultf, x)
+ defaultf3 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "defaultf3", RequestFilters: defaultf}
+ dmTH.SetFilter(defaultf3)
+ ref.IndexTPFilter(FilterToTPFilter(defaultf3), "TEST_PROFILE4")
+
+ tPrfl := []*ThresholdProfile{
+ &ThresholdProfile{
+ Tenant: "cgrates.org",
+ ID: "TEST_PROFILE1",
+ FilterIDs: []string{"filter5"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
+ },
+ Recurrent: false,
+ MinSleep: time.Duration(5 * time.Minute),
+ Blocker: false,
+ Weight: 20.0,
+ ActionIDs: []string{"ACT_1", "ACT_2"},
+ Async: true,
+ },
+ &ThresholdProfile{
+ Tenant: "cgrates.org",
+ ID: "TEST_PROFILE2",
+ FilterIDs: []string{"filter6"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
+ },
+ Recurrent: false,
+ MinSleep: time.Duration(5 * time.Minute),
+ Blocker: false,
+ Weight: 20.0,
+ ActionIDs: []string{"ACT_1", "ACT_2"},
+ Async: true,
+ },
+ &ThresholdProfile{
+ Tenant: "cgrates.org",
+ ID: "TEST_PROFILE3",
+ FilterIDs: []string{"preffilter3"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
+ },
+ Recurrent: false,
+ MinSleep: time.Duration(5 * time.Minute),
+ Blocker: false,
+ Weight: 20.0,
+ ActionIDs: []string{"ACT_1", "ACT_2"},
+ Async: true,
+ },
+ &ThresholdProfile{
+ Tenant: "cgrates.org",
+ ID: "TEST_PROFILE4",
+ FilterIDs: []string{"defaultf3"},
+ ActivationInterval: &utils.ActivationInterval{
+ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
+ },
+ Recurrent: false,
+ MinSleep: time.Duration(5 * time.Minute),
+ Blocker: false,
+ Weight: 20.0,
+ ActionIDs: []string{"ACT_1", "ACT_2"},
+ Async: true,
+ },
+ }
+ for _, profile := range tPrfl {
+ if err = dmTH.SetThresholdProfile(profile, true); err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ if err = dmTH.SetThreshold(&Threshold{Tenant: profile.Tenant, ID: profile.ID}); err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+ }
+ err = ref.StoreIndexes()
+ if err != nil {
+ t.Errorf("Error: %+v", err)
+ }
+}
+
+// func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
+// stringEv := utils.CGREvent{
+// Tenant: "cgrates.org",
+// ID: "utils.CGREvent1",
+// Event: map[string]interface{}{
+// "Threshold": "ThresholdProfile1",
+// utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
+// "UsageInterval": "1s",
+// "PddInterval": "1s",
+// "Weight": "20.0",
+// },
+// }
+// argEv := &ArgsProcessEvent{CGREvent: stringEv}
+// sprf, err := thServ.matchingThresholdsForEvent(argEv)
+// if err != nil {
+// t.Errorf("Error: %+v", err)
+// }
+// if !reflect.DeepEqual(0, sprf) {
+// t.Errorf("Expecting: %+v, received: %+v", 0, sprf)
+// } //should not pass atm but still return something other than empty string
+// }
+
+// func TestThresholdsprocessEvent(t *testing.T) {
+
+// }
diff --git a/utils/coreutils.go b/utils/coreutils.go
index 2fc088788..fca396d6a 100644
--- a/utils/coreutils.go
+++ b/utils/coreutils.go
@@ -454,10 +454,6 @@ func BoolPointer(b bool) *bool {
return &b
}
-func Float64SlicePointer(slc []float64) *[]float64 {
- return &slc
-}
-
func StringMapPointer(sm StringMap) *StringMap {
return &sm
}
diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go
index 8a6b88965..fc124d283 100644
--- a/utils/coreutils_test.go
+++ b/utils/coreutils_test.go
@@ -685,15 +685,6 @@ func TestBoolPointer(t *testing.T) {
}
}
-func TestFloat64SlicePointer(t *testing.T) {
- t1 := []float64{1.2, 12.3, 123.4, 1234.5}
- expected := &t1
- result := Float64SlicePointer(t1)
- if *result == nil {
- t.Error("Expected:", expected, ", received: nil")
- }
-}
-
func TestStringMapPointer(t *testing.T) {
t1 := map[string]bool{"cgr1": true, "cgr2": true}
expected := &t1