diff --git a/cmd/cgr-loader/rates.go b/cmd/cgr-loader/rates.go index eb180698d..a26a2d8c3 100644 --- a/cmd/cgr-loader/rates.go +++ b/cmd/cgr-loader/rates.go @@ -163,6 +163,7 @@ func loadRatingProfiles() { continue } tenant, tor, direction, subject, fallbacksubject := record[0], record[1], record[2], record[3], record[4] + fmt.Sprintf("%s:%s:%s:%s:%s", direction, tenant, tor, subject) at, err := time.Parse(time.RFC3339, record[6]) if err != nil { log.Printf("Cannot parse activation time from %v", record[5]) @@ -189,8 +190,9 @@ func loadRatingProfiles() { for _, p := range d.Prefixes { //destinations // Search for a CallDescriptor with the same key var cd *timespans.CallDescriptor + key := fmt.Sprintf("%s:%s:%s:%s:%s", direction, tenant, tor, subject, p) for _, c := range ratingProfiles[p] { - if c.GetKey() == r.DestinationsTag { + if c.GetKey() == key { cd = c } } diff --git a/data/RatingProfiles.csv b/data/RatingProfiles.csv index 55e042598..8db032214 100644 --- a/data/RatingProfiles.csv +++ b/data/RatingProfiles.csv @@ -1,4 +1,5 @@ Tenant,TOR,Direction,Subject,RatesFallbackSubject,RatesTimingTag,ActivationTime -CUSTOMER_1,0,OUT,rif:from:tm,danb,STANDARD,2012-01-01T00:00:00Z +CUSTOMER_1,0,OUT,rif:from:tm,danb,PREMIUM,2012-01-01T00:00:00Z +CUSTOMER_1,0,OUT,rif:from:tm,danb,STANDARD,2012-02-28T00:00:00Z CUSTOMER_2,0,OUT,danb:87.139.12.167,danb,STANDARD,2012-01-01T00:00:00Z CUSTOMER_1,0,OUT,danb,,PREMIUM,2012-01-01T00:00:00Z \ No newline at end of file diff --git a/timespans/activationperiod_test.go b/timespans/activationperiod_test.go index 3904ffaf1..7ee0edbd0 100644 --- a/timespans/activationperiod_test.go +++ b/timespans/activationperiod_test.go @@ -32,12 +32,18 @@ func init() { } func TestApRestoreRedis(t *testing.T) { - cd := &CallDescriptor{Tenant: "vdf", - Subject: "rif", - Destination: "0257"} + cd := &CallDescriptor{ + Direction: "OUT", + TOR: "0", + Tenant: "CUSTOMER_1", + Subject: "rif:from:tm", + Destination: "49"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 2 { - t.Error("Error restoring activation periods: ", cd.ActivationPeriods) + if len(cd.ActivationPeriods) != 4 { + for _, ap := range cd.ActivationPeriods { + t.Log(ap) + } + t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } @@ -80,26 +86,26 @@ func TestApStoreRestoreBlank(t *testing.T) { } func TestFallbackDirect(t *testing.T) { - cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745"} + cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "41"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 1 { - t.Error("Error restoring activation periods: ", cd.ActivationPeriods) + if len(cd.ActivationPeriods) != 3 { + t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } func TestFallbackWithBackTrace(t *testing.T) { - cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745121"} + cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "4123"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 1 { - t.Error("Error restoring activation periods: ", cd.ActivationPeriods) + if len(cd.ActivationPeriods) != 3 { + t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } func TestFallbackDefault(t *testing.T) { - cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "00000"} + cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "0000"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 1 { - t.Error("Error restoring activation periods: ", cd.ActivationPeriods) + if len(cd.ActivationPeriods) != 3 { + t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } @@ -107,7 +113,7 @@ func TestFallbackNoInfiniteLoop(t *testing.T) { cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0721"} cd.SearchStorageForPrefix() if len(cd.ActivationPeriods) != 0 { - t.Error("Error restoring activation periods: ", cd.ActivationPeriods) + t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } diff --git a/timespans/calldesc.go b/timespans/calldesc.go index 5ff7529d4..17cc4216b 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -96,7 +96,7 @@ Restores the activation periods for the specified prefix from storage. */ func (cd *CallDescriptor) SearchStorageForPrefix() (destPrefix string, err error) { cd.ActivationPeriods = make([]*ActivationPeriod, 0) - base := fmt.Sprintf("%s:%s:%s:%s:", cd.Destination, cd.Tenant, cd.TOR, cd.Subject) + base := fmt.Sprintf("%s:%s:%s:%s:", cd.Direction, cd.Tenant, cd.TOR, cd.Subject) destPrefix = cd.Destination key := base + destPrefix values, err := cd.getActivationPeriodsOrFallback(key, base, destPrefix, 1) @@ -123,7 +123,7 @@ func (cd *CallDescriptor) getActivationPeriodsOrFallback(key, base, destPrefix s recursionDepth++ return cd.getActivationPeriodsOrFallback(key, base, destPrefix, recursionDepth) } - //get for a smaller prefix if the orignal one was not found + //get for a smaller prefix if the orignal one was not found for i := len(cd.Destination); err != nil || fallbackKey != ""; { if fallbackKey != "" { base = fallbackKey + ":"