diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index 3f2b01e57..bb0cb2b37 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -55,30 +55,34 @@ var sTestsFilterIndexesSV1 = []func(t *testing.T){ testV1FIdxComputeThresholdsIndexes, testV1FIdxSetSecondThresholdProfile, testV1FIdxSecondComputeThresholdsIndexes, + testV1FIdxRemoveThresholdProfile, //to add testV1TSGetThresholdsAfterRestart, // testV1FIdxSetThresholdProfile, // testV1FIdxUpdateThresholdProfile, - // testV1FIdxRemoveThresholdProfile, testV1FIdxSetStatQueueProfileIndexes, testV1FIdxComputeStatQueueProfileIndexes, testV1FIdxSetSecondStatQueueProfileIndexes, testV1FIdxSecondComputeStatQueueProfileIndexes, + testV1FIdxRemoveStatQueueProfile, testV1FIdxSetResourceProfileIndexes, testV1FIdxComputeResourceProfileIndexes, testV1FIdxSetSecondResourceProfileIndexes, testV1FIdxSecondComputeResourceProfileIndexes, + testV1FIdxRemoveResourceProfile, testV1FIdxSetSupplierProfileIndexes, testV1FIdxComputeSupplierProfileIndexes, testV1FIdxSetSecondSupplierProfileIndexes, testV1FIdxSecondComputeSupplierProfileIndexes, + testV1FIdxRemoveSupplierProfile, testV1FIdxSetAttributeProfileIndexes, testV1FIdxComputeAttributeProfileIndexes, testV1FIdxSetSecondAttributeProfileIndexes, testV1FIdxSecondComputeAttributeProfileIndexes, + testV1FIdxRemoveAttributeProfile, testV1FIdxStopEngine, } @@ -241,7 +245,10 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { nil); err != utils.ErrNotFound { t.Error(err) } - + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.ThresholdProfilePrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } } func testV1FIdxComputeThresholdsIndexes(t *testing.T) { @@ -343,10 +350,11 @@ func testV1FIdxSetSecondThresholdProfile(t *testing.T) { tenant, true)); err != nil { t.Error(err) } - if indexes, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.ThresholdProfilePrefix, tenant, false), + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.ThresholdProfilePrefix, tenant, false), nil); err != utils.ErrNotFound { t.Error(err) } + } func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) { @@ -385,6 +393,57 @@ func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) { } } +func testV1FIdxRemoveThresholdProfile(t *testing.T) { + var resp string + tenant := "cgrates.org" + emptySlice := []string{} + var reply2 string + if err := tFIdxRpc.Call(utils.ApierV1ComputeFilterIndexes, utils.ArgsComputeFilterIndexes{ + Tenant: "cgrates.org", + ThresholdIDs: nil, + AttributeIDs: &emptySlice, + ResourceIDs: &emptySlice, + StatIDs: &emptySlice, + SupplierIDs: &emptySlice, + }, &reply2); err != nil { + t.Error(err) + } + if reply2 != utils.OK { + t.Errorf("Error: %+v", reply2) + } + if err := tFIdxRpc.Call("ApierV1.RemThresholdProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.RemThresholdProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + var sqp *engine.ThresholdProfile + if err := tFIdxRpc.Call("ApierV1.GetThresholdProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &sqp); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if err := tFIdxRpc.Call("ApierV1.GetThresholdProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &sqp); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.ThresholdProfilePrefix, tenant, false), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.ThresholdProfilePrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } +} + /* func testV1FIdxGetThresholdsAfterRestart(t *testing.T) { time.Sleep(time.Second) @@ -501,23 +560,8 @@ func testV1FIdxUpdateThresholdProfile(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", tPrfl, reply) } } - -func testV1FIdxRemoveThresholdProfile(t *testing.T) { - var resp string - if err := tFIdxRpc.Call("ApierV1.RemThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil { - t.Error(err) - } else if resp != utils.OK { - t.Error("Unexpected reply returned", resp) - } - var sqp *engine.ThresholdProfile - if err := tFIdxRpc.Call("ApierV1.GetThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || - err.Error() != utils.ErrNotFound.Error() { - t.Error(err) - } -} */ + //StatQueueProfile func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { tenant := "cgrates.org" @@ -750,6 +794,55 @@ func testV1FIdxSecondComputeStatQueueProfileIndexes(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expectedRevIDX, utils.ToJSON(indexes)) } } +func testV1FIdxRemoveStatQueueProfile(t *testing.T) { + var resp string + tenant := "cgrates.org" + emptySlice := []string{} + var reply2 string + if err := tFIdxRpc.Call(utils.ApierV1ComputeFilterIndexes, utils.ArgsComputeFilterIndexes{ + Tenant: "cgrates.org", + ThresholdIDs: &emptySlice, + AttributeIDs: &emptySlice, + ResourceIDs: &emptySlice, + StatIDs: nil, + SupplierIDs: &emptySlice, + }, &reply2); err != nil { + t.Error(err) + } + if reply2 != utils.OK { + t.Errorf("Error: %+v", reply2) + } + if err := tFIdxRpc.Call("ApierV1.RemStatQueueProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.RemStatQueueProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.GetStatQueueProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if err := tFIdxRpc.Call("ApierV1.GetStatQueueProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE2"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.ResourceProfilesPrefix, tenant, false), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.ResourceProfilesPrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } +} //ResourceProfile func testV1FIdxSetResourceProfileIndexes(t *testing.T) { @@ -960,6 +1053,54 @@ func testV1FIdxSecondComputeResourceProfileIndexes(t *testing.T) { } } +func testV1FIdxRemoveResourceProfile(t *testing.T) { + var resp string + tenant := "cgrates.org" + emptySlice := []string{} + var reply2 string + if err := tFIdxRpc.Call(utils.ApierV1ComputeFilterIndexes, utils.ArgsComputeFilterIndexes{ + Tenant: "cgrates.org", + ThresholdIDs: &emptySlice, + AttributeIDs: &emptySlice, + ResourceIDs: nil, + StatIDs: &emptySlice, + SupplierIDs: &emptySlice, + }, &reply2); err != nil { + t.Error(err) + } + if reply2 != utils.OK { + t.Errorf("Error: %+v", reply2) + } + if err := tFIdxRpc.Call("ApierV1.RemResourceProfile", + &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.RemResourceProfile", + &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.GetResourceProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"}, + &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if err := tFIdxRpc.Call("ApierV1.GetResourceProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG2"}, + &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.ResourceProfilesPrefix, tenant, false), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.ResourceProfilesPrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } +} + //SupplierProfile func testV1FIdxSetSupplierProfileIndexes(t *testing.T) { tenant := "cgrates.org" @@ -1181,6 +1322,56 @@ func testV1FIdxSecondComputeSupplierProfileIndexes(t *testing.T) { } } +func testV1FIdxRemoveSupplierProfile(t *testing.T) { + var resp string + tenant := "cgrates.org" + emptySlice := []string{} + var reply2 string + if err := tFIdxRpc.Call(utils.ApierV1ComputeFilterIndexes, utils.ArgsComputeFilterIndexes{ + Tenant: "cgrates.org", + ThresholdIDs: &emptySlice, + AttributeIDs: &emptySlice, + ResourceIDs: &emptySlice, + StatIDs: &emptySlice, + SupplierIDs: nil, + }, &reply2); err != nil { + t.Error(err) + } + if reply2 != utils.OK { + t.Errorf("Error: %+v", reply2) + } + if err := tFIdxRpc.Call("ApierV1.RemSupplierProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.RemSupplierProfile", + &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if err := tFIdxRpc.Call("ApierV1.GetSupplierProfile", + &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE2"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.SupplierProfilePrefix, tenant, false), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.SupplierProfilePrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } +} + //AttributeProfile func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { tenant := "cgrates.org" @@ -1408,6 +1599,54 @@ func testV1FIdxSecondComputeAttributeProfileIndexes(t *testing.T) { } } +func testV1FIdxRemoveAttributeProfile(t *testing.T) { + var resp string + tenant := "cgrates.org" + emptySlice := []string{} + var reply2 string + if err := tFIdxRpc.Call(utils.ApierV1ComputeFilterIndexes, utils.ArgsComputeFilterIndexes{ + Tenant: "cgrates.org", + ThresholdIDs: &emptySlice, + AttributeIDs: nil, + ResourceIDs: &emptySlice, + StatIDs: &emptySlice, + SupplierIDs: &emptySlice, + }, &reply2); err != nil { + t.Error(err) + } + if reply2 != utils.OK { + t.Errorf("Error: %+v", reply2) + } + if err := tFIdxRpc.Call("ApierV1.RemAttributeProfile", + &utils.TenantID{Tenant: tenant, ID: "ApierTest"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.RemAttributeProfile", + &utils.TenantID{Tenant: tenant, ID: "ApierTest2"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } + if err := tFIdxRpc.Call("ApierV1.GetAttributeProfile", &utils.TenantID{Tenant: tenant, ID: "ApierTest2"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if err := tFIdxRpc.Call("ApierV1.GetAttributeProfile", &utils.TenantID{Tenant: tenant, ID: "ApierTest"}, &reply2); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + if _, err = onStor.GetFilterIndexes(engine.GetDBIndexKey(utils.AttributeProfilePrefix, tenant, false), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } + if _, err = onStor.GetFilterReverseIndexes(engine.GetDBIndexKey(utils.AttributeProfilePrefix, tenant, true), + nil); err != nil && err != utils.ErrNotFound { + t.Error(err) + } +} + // 1.set threshold in datadb fara sa faca indexuri // 2.fac querri la index sa fiu sigur ca is 0 // 3.compile indexes all diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index cff276399..15ca2a9cf 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -2218,7 +2218,7 @@ func testOnStorITCRUDResourceProfile(t *testing.T) { // if err = onStor.DataDB().SelectDatabase(onStorCfg); err != nil { // t.Error(err) // } - if err := onStor.RemoveResourceProfile(rL.Tenant, rL.ID, utils.NonTransactional); err != nil { + if err := onStor.RemoveResourceProfile(rL.Tenant, rL.ID, utils.NonTransactional, false); err != nil { t.Error(err) } if _, rcvErr := onStor.GetResourceProfile(rL.Tenant, rL.ID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { @@ -2375,7 +2375,7 @@ func testOnStorITCRUDStatQueueProfile(t *testing.T) { if _, ok := cache.Get(utils.StatQueueProfilePrefix + sq.ID); ok != false { t.Error("Should not be in cache") } - if err := onStor.RemoveStatQueueProfile(sq.Tenant, sq.ID, utils.NonTransactional); err != nil { + if err := onStor.RemoveStatQueueProfile(sq.Tenant, sq.ID, utils.NonTransactional, false); err != nil { t.Error(err) } if _, ok := cache.Get(utils.StatQueueProfilePrefix + sq.ID); ok != false { @@ -2478,7 +2478,7 @@ func testOnStorITCRUDThresholdProfile(t *testing.T) { } else if !reflect.DeepEqual(th, rcv) { t.Errorf("Expecting: %v, received: %v", th, rcv) } - if err := onStor.RemoveThresholdProfile(th.Tenant, th.ID, utils.NonTransactional); err != nil { + if err := onStor.RemoveThresholdProfile(th.Tenant, th.ID, utils.NonTransactional, false); err != nil { t.Error(err) } if _, rcvErr := onStor.GetThresholdProfile(th.Tenant, th.ID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { @@ -2598,7 +2598,7 @@ func testOnStorITCRUDSupplierProfile(t *testing.T) { } else if !reflect.DeepEqual(splProfile, rcv) { t.Errorf("Expecting: %v, received: %v", splProfile, rcv) } - if err := onStor.RemoveSupplierProfile(splProfile.Tenant, splProfile.ID, utils.NonTransactional); err != nil { + if err := onStor.RemoveSupplierProfile(splProfile.Tenant, splProfile.ID, utils.NonTransactional, false); err != nil { t.Error(err) } if _, rcvErr := onStor.GetSupplierProfile("cgrates.org", "SPRF_1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { @@ -2642,7 +2642,7 @@ func testOnStorITCRUDAttributeProfile(t *testing.T) { } else if !reflect.DeepEqual(attrProfile, rcv) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) } - if err := onStor.RemoveAttributeProfile(attrProfile.Tenant, attrProfile.ID, utils.NonTransactional); err != nil { + if err := onStor.RemoveAttributeProfile(attrProfile.Tenant, attrProfile.ID, utils.NonTransactional, false); err != nil { t.Error(err) } if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index ec7543c6b..d5d41376e 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1969,10 +1969,10 @@ func (ms *MongoStorage) SetFilterIndexesDrv(dbKey string, indexes map[string]uti return } -func (ms *MongoStorage) RemoveFilterIndexesDrv(id string) (err error) { +func (ms *MongoStorage) RemoveFilterIndexesDrv(dbKey string) (err error) { session, col := ms.conn(colRFI) defer session.Close() - err = col.Remove(bson.M{"key": id}) + err = col.Remove(bson.M{"key": dbKey}) if err == mgo.ErrNotFound { err = nil } diff --git a/migrator/migrator_it_test.go b/migrator/migrator_it_test.go index 5a44e7e79..b65021812 100644 --- a/migrator/migrator_it_test.go +++ b/migrator/migrator_it_test.go @@ -2485,9 +2485,15 @@ func testMigratorTpRatingPlans(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].TPid, result[0].TPid) } else if !reflect.DeepEqual(tpRatingPlan[0].ID, result[0].ID) { t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].ID, result[0].ID) - } else if !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[0]) { + } else if !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[0]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[1]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[0]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[1]) { t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[0]) - } else if !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[1]) { + } else if !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[0]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[1]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[0]) && + !reflect.DeepEqual(tpRatingPlan[0].RatingPlanBindings[0], result[0].RatingPlanBindings[1]) { t.Errorf("Expecting: %+v, received: %+v", tpRatingPlan[0].RatingPlanBindings[1], result[0].RatingPlanBindings[1]) }