diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go index 1f64d96c2..e0fe5a227 100644 --- a/apier/v1/replicate_it_test.go +++ b/apier/v1/replicate_it_test.go @@ -54,6 +54,7 @@ var ( testInternalReplicateITSetAccount, testInternalReplicateITActionTrigger, testInternalReplicateITThreshold, + testInternalReplicateITRateProfile, testInternalReplicateITLoadIds, testInternalReplicateITKillEngine, @@ -1347,6 +1348,85 @@ func testInternalReplicateITThreshold(t *testing.T) { } +func testInternalReplicateITRateProfile(t *testing.T) { + //set + rPrf := &RateProfileWithCache{ + RateProfileWithArgDispatcher: &engine.RateProfileWithArgDispatcher{ + RateProfile: &engine.RateProfile{ + Tenant: "cgrates.org", + ID: "RP1", + FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"}, + Weight: 0, + ConnectFee: 0.1, + RoundingMethod: "*up", + RoundingDecimals: 4, + MinCost: 0.1, + MaxCost: 0.6, + MaxCostStrategy: "*free", + Rates: map[string]*engine.Rate{ + "FIRST_GI": &engine.Rate{ + ID: "FIRST_GI", + FilterIDs: []string{"*gi:~*req.Usage:0"}, + Weight: 0, + Value: 0.12, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Minute), + Blocker: false, + }, + "SECOND_GI": &engine.Rate{ + ID: "SECOND_GI", + FilterIDs: []string{"*gi:~*req.Usage:1m"}, + Weight: 10, + Value: 0.06, + Unit: time.Duration(1 * time.Minute), + Increment: time.Duration(1 * time.Second), + Blocker: false, + }, + }, + }, + }, + } + + var result string + if err := internalRPC.Call(utils.APIerSv1SetRateProfile, rPrf, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + // check + var reply *engine.RateProfile + if err := engineOneRPC.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rPrf.RateProfileWithArgDispatcher.RateProfile, reply) { + t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply) + } + if err := engineTwoRPC.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rPrf.RateProfileWithArgDispatcher.RateProfile, reply) { + t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply) + } + //remove + if err := internalRPC.Call(utils.APIerSv1RemoveRateProfile, &utils.TenantIDWithCache{ + Tenant: rPrf.Tenant, ID: rPrf.ID}, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + //check again + if err := engineOneRPC.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v recived: %+v", utils.ErrNotFound, err) + } + if err := engineTwoRPC.Call(utils.APIerSv1GetRateProfile, + utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Expecting: %+v recived: %+v", utils.ErrNotFound, err) + } +} + func testInternalReplicateITLoadIds(t *testing.T) { // get LoadIDs var rcv1e1 map[string]int64 diff --git a/data/conf/samples/replication/internal/cgrates.json b/data/conf/samples/replication/internal/cgrates.json index d0c57d0ae..124d6fc93 100644 --- a/data/conf/samples/replication/internal/cgrates.json +++ b/data/conf/samples/replication/internal/cgrates.json @@ -64,6 +64,7 @@ "*dispatcher_profiles":{"remote":false,"replicate":true}, "*dispatcher_hosts":{"remote":false,"replicate":true}, "*filter_indexes" :{"remote":false,"replicate":true}, + "*rate_profiles":{"remote":false,"replicate":true}, "*load_ids":{"remote":false,"replicate":true}, }, }, diff --git a/data/conf/samples/replication/internal_gob/cgrates.json b/data/conf/samples/replication/internal_gob/cgrates.json index 1a5a4596a..c07908115 100644 --- a/data/conf/samples/replication/internal_gob/cgrates.json +++ b/data/conf/samples/replication/internal_gob/cgrates.json @@ -56,6 +56,7 @@ "*dispatcher_profiles":{"remote":true,"replicate":true}, "*dispatcher_hosts":{"remote":true,"replicate":true}, "*filter_indexes" :{"remote":true,"replicate":true}, + "*rate_profiles":{"remote":false,"replicate":true}, "*load_ids":{"remote":true,"replicate":true}, }, },