diff --git a/cmd/cgr-loader/rates.go b/cmd/cgr-loader/rates.go index a26a2d8c3..f8383f75a 100644 --- a/cmd/cgr-loader/rates.go +++ b/cmd/cgr-loader/rates.go @@ -187,7 +187,9 @@ func loadRatingProfiles() { for _, d := range destinations { if d.Id == r.DestinationsTag { ap.AddInterval(rt.GetInterval(r)) + log.Print(d) for _, p := range d.Prefixes { //destinations + log.Print("P: ", p) // 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) @@ -206,7 +208,19 @@ func loadRatingProfiles() { } ratingProfiles[p] = append(ratingProfiles[p], cd) } - cd.ActivationPeriods = append(cd.ActivationPeriods, ap) + // check the activation periods for the same activation time + foundAp := false + for _, actPer := range cd.ActivationPeriods { + if actPer.ActivationTime == ap.ActivationTime { + actPer.AddInterval(ap.Intervals...) + foundAp = true + break + } + } + // if not found then add a new actvation time + if !foundAp { + cd.ActivationPeriods = append(cd.ActivationPeriods, ap) + } if fallbacksubject != "" && ratingProfiles[p].getKey(fmt.Sprintf("%s:%s:%s:%s:%s", direction, tenant, tor, subject, timespans.FallbackDestination)) == nil { cd = ×pans.CallDescriptor{ diff --git a/timespans/activationperiod_test.go b/timespans/activationperiod_test.go index 7ee0edbd0..0dbc3c53a 100644 --- a/timespans/activationperiod_test.go +++ b/timespans/activationperiod_test.go @@ -88,7 +88,7 @@ func TestApStoreRestoreBlank(t *testing.T) { func TestFallbackDirect(t *testing.T) { cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "41"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 3 { + if len(cd.ActivationPeriods) != 1 { t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } @@ -96,15 +96,15 @@ func TestFallbackDirect(t *testing.T) { func TestFallbackWithBackTrace(t *testing.T) { cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "4123"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 3 { + if len(cd.ActivationPeriods) != 1 { t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } func TestFallbackDefault(t *testing.T) { - cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "0000"} + cd := &CallDescriptor{TOR: "0", Direction: "OUT", Tenant: "CUSTOMER_2", Subject: "danb:87.139.12.167", Destination: "4123"} cd.SearchStorageForPrefix() - if len(cd.ActivationPeriods) != 3 { + if len(cd.ActivationPeriods) != 1 { t.Error("Error restoring activation periods: ", len(cd.ActivationPeriods)) } } diff --git a/timespans/dateseries_test.go b/timespans/dateseries_test.go index 5b9e09afb..f705e4455 100644 --- a/timespans/dateseries_test.go +++ b/timespans/dateseries_test.go @@ -28,8 +28,8 @@ import ( func TestMonthStoreRestore(t *testing.T) { m := Months{5, 6, 7, 8} r, _ := json.Marshal(m) - if string(r) != "5,6,7,8," { - t.Errorf("Error serializing months: %v", r) + if string(r) != "[5,6,7,8]" { + t.Errorf("Error serializing months: %v", string(r)) } o := Months{} json.Unmarshal(r, &o) @@ -41,8 +41,8 @@ func TestMonthStoreRestore(t *testing.T) { func TestMonthDayStoreRestore(t *testing.T) { md := MonthDays{24, 25, 26} r, _ := json.Marshal(md) - if string(r) != "24,25,26," { - t.Errorf("Error serializing month days: %v", r) + if string(r) != "[24,25,26]" { + t.Errorf("Error serializing month days: %v", string(r)) } o := MonthDays{} json.Unmarshal(r, &o) @@ -54,8 +54,8 @@ func TestMonthDayStoreRestore(t *testing.T) { func TestWeekDayStoreRestore(t *testing.T) { wd := WeekDays{time.Saturday, time.Sunday} r, _ := json.Marshal(wd) - if string(r) != "6,0," { - t.Errorf("Error serializing week days: %v", r) + if string(r) != "[6,0]" { + t.Errorf("Error serializing week days: %v", string(r)) } o := WeekDays{} json.Unmarshal(r, &o) diff --git a/timespans/destinations_test.go b/timespans/destinations_test.go index 78ee924ce..7913d1bc0 100644 --- a/timespans/destinations_test.go +++ b/timespans/destinations_test.go @@ -35,7 +35,7 @@ func TestDestinationStoreRestore(t *testing.T) { d1 := &Destination{Id: "nat"} json.Unmarshal(s, d1) s1, _ := json.Marshal(d1) - if reflect.DeepEqual(s1, s) { + if string(s1) != string(s) { t.Errorf("Expected %q was %q", s, s1) } } diff --git a/timespans/minute_buckets_test.go b/timespans/minute_buckets_test.go index 7d54a2e76..8095ee78e 100644 --- a/timespans/minute_buckets_test.go +++ b/timespans/minute_buckets_test.go @@ -23,33 +23,19 @@ import ( ) func TestGetDestination(t *testing.T) { - mb := &MinuteBucket{DestinationId: "nationale"} + mb := &MinuteBucket{DestinationId: "nat"} d := mb.getDestination() - if d == nil || d.Id != "nationale" || len(d.Prefixes) != 4 { + if d == nil || d.Id != "nat" || len(d.Prefixes) != 3 { t.Error("Got wrong destination: ", d) } } func TestMultipleGetDestination(t *testing.T) { - mb := &MinuteBucket{DestinationId: "nationale"} + mb := &MinuteBucket{DestinationId: "nat"} d := mb.getDestination() d = mb.getDestination() d = mb.getDestination() - if d == nil || d.Id != "nationale" || len(d.Prefixes) != 4 { - t.Error("Got wrong destination: ", d) - } - mb = &MinuteBucket{DestinationId: "retea"} - d = mb.getDestination() - d = mb.getDestination() - d = mb.getDestination() - if d == nil || d.Id != "retea" || len(d.Prefixes) != 2 { - t.Error("Got wrong destination: ", d) - } - mb = &MinuteBucket{DestinationId: "mobil"} - d = mb.getDestination() - d = mb.getDestination() - d = mb.getDestination() - if d == nil || d.Id != "mobil" || len(d.Prefixes) != 2 { + if d == nil || d.Id != "nat" || len(d.Prefixes) != 3 { t.Error("Got wrong destination: ", d) } }