From 4638bad4d13efd4bbe611fa4d01b6085ebdbe97f Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 17 Dec 2013 22:37:51 +0200 Subject: [PATCH] replaced storageGetter with dataStorage --- engine/calldesc.go | 16 ++++++++-------- engine/calldesc_test.go | 2 +- engine/destinations_test.go | 16 ++++++++-------- engine/loader_csv_test.go | 4 ++-- engine/ratingplan_test.go | 4 ++-- engine/ratingprofile.go | 2 +- engine/responder.go | 2 +- engine/storage_test.go | 16 ++++++++-------- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index ab3adfa84..433859d6d 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -38,14 +38,14 @@ func init() { } DEBUG := true if DEBUG { - storageGetter, _ = NewMapStorage() + dataStorage, _ = NewMapStorage() accountingStorage, _ = NewMapStorage() } else { - //storageGetter, _ = NewMongoStorage(db_server, "27017", "cgrates_test", "", "") - storageGetter, _ = NewRedisStorage("127.0.0.1:6379", 11, "", utils.MSGPACK) + //dataStorage, _ = NewMongoStorage(db_server, "27017", "cgrates_test", "", "") + dataStorage, _ = NewRedisStorage("127.0.0.1:6379", 11, "", utils.MSGPACK) accountingStorage, _ = NewRedisStorage("127.0.0.1:6379", 12, "", utils.MSGPACK) } - storageLogger = storageGetter.(LogStorage) + storageLogger = dataStorage.(LogStorage) } const ( @@ -55,7 +55,7 @@ const ( var ( Logger utils.LoggerInterface - storageGetter DataStorage + dataStorage DataStorage accountingStorage AccountingStorage storageLogger LogStorage debitPeriod = 10 * time.Second @@ -67,7 +67,7 @@ var ( // Exported method to set the storage getter. func SetDataStorage(sg DataStorage) { - storageGetter = sg + dataStorage = sg } func SetAccountingStorage(ag AccountingStorage) { @@ -172,7 +172,7 @@ func (cd *CallDescriptor) getRatingPlansForPrefix(key string, recursionDepth int err = errors.New("Max fallback recursion depth reached!" + key) return } - rpf, err := storageGetter.GetRatingProfile(key, false) + rpf, err := dataStorage.GetRatingProfile(key, false) if err != nil || rpf == nil { return err } @@ -581,7 +581,7 @@ func (cd *CallDescriptor) AddRecievedCallSeconds() (err error) { func (cd *CallDescriptor) FlushCache() (err error) { cache2go.XFlush() cache2go.Flush() - storageGetter.PreCache(nil, nil, nil, nil) + dataStorage.PreCache(nil, nil, nil, nil) return nil } diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 67ac4d216..84a90f1c5 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -342,7 +342,7 @@ func BenchmarkStorageGetting(b *testing.B) { cd := &CallDescriptor{Direction: "*out", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2} b.StartTimer() for i := 0; i < b.N; i++ { - storageGetter.GetRatingProfile(cd.GetKey(cd.Subject), false) + dataStorage.GetRatingProfile(cd.GetKey(cd.Subject), false) } } diff --git a/engine/destinations_test.go b/engine/destinations_test.go index be1f8df29..eefeec7a5 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -39,11 +39,11 @@ func TestDestinationStoreRestore(t *testing.T) { func TestDestinationStorageStore(t *testing.T) { nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} - err := storageGetter.SetDestination(nationale) + err := dataStorage.SetDestination(nationale) if err != nil { t.Error("Error storing destination: ", err) } - result, err := storageGetter.GetDestination(nationale.Id) + result, err := dataStorage.GetDestination(nationale.Id) if nationale.containsPrefix("0257") == 0 || nationale.containsPrefix("0256") == 0 || nationale.containsPrefix("0723") == 0 { t.Errorf("Expected %q was %q", nationale, result) } @@ -74,28 +74,28 @@ func TestDestinationContainsPrefixWrong(t *testing.T) { } func TestDestinationGetExists(t *testing.T) { - d, err := storageGetter.GetDestination("NAT") + d, err := dataStorage.GetDestination("NAT") if err != nil || d == nil { t.Error("Could not get destination: ", d) } } func TestDestinationGetExistsCache(t *testing.T) { - storageGetter.GetDestination("NAT") + dataStorage.GetDestination("NAT") if _, err := cache2go.GetCached(DESTINATION_PREFIX + "0256"); err != nil { t.Error("Destination not cached:", err) } } func TestDestinationGetNotExists(t *testing.T) { - d, err := storageGetter.GetDestination("not existing") + d, err := dataStorage.GetDestination("not existing") if d != nil { t.Error("Got false destination: ", d, err) } } func TestDestinationGetNotExistsCache(t *testing.T) { - storageGetter.GetDestination("not existing") + dataStorage.GetDestination("not existing") if d, err := cache2go.GetCached("not existing"); err == nil { t.Error("Bad destination cached: ", d) } @@ -106,7 +106,7 @@ func TestDestinationGetNotExistsCache(t *testing.T) { func BenchmarkDestinationStorageStoreRestore(b *testing.B) { nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} for i := 0; i < b.N; i++ { - storageGetter.SetDestination(nationale) - storageGetter.GetDestination(nationale.Id) + dataStorage.SetDestination(nationale) + dataStorage.GetDestination(nationale.Id) } } diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 9d13893a4..9cefaab11 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -129,7 +129,7 @@ vdf,minitsboy,*out,MORE_MINUTES,STANDARD_TRIGGER var csvr *CSVReader func init() { - csvr = NewStringCSVReader(storageGetter, accountingStorage, ',', destinations, timings, rates, destinationRates, destinationRateTimings, ratingProfiles, actions, actionTimings, actionTriggers, accountActions) + csvr = NewStringCSVReader(dataStorage, accountingStorage, ',', destinations, timings, rates, destinationRates, destinationRateTimings, ratingProfiles, actions, actionTimings, actionTriggers, accountActions) csvr.LoadDestinations() csvr.LoadTimings() csvr.LoadRates() @@ -141,7 +141,7 @@ func init() { csvr.LoadActionTriggers() csvr.LoadAccountActions() csvr.WriteToDatabase(false, false) - storageGetter.PreCache(nil, nil, nil, nil) + dataStorage.PreCache(nil, nil, nil, nil) } func TestLoadDestinations(t *testing.T) { diff --git a/engine/ratingplan_test.go b/engine/ratingplan_test.go index 4c4b179b9..3b7fa2747 100644 --- a/engine/ratingplan_test.go +++ b/engine/ratingplan_test.go @@ -269,9 +269,9 @@ func BenchmarkRatingPlanRestore(b *testing.B) { EndTime: "15:00:00"}} rp := &RatingPlan{Id: "test"} rp.AddRateInterval("NAT", i) - storageGetter.SetRatingPlan(rp) + dataStorage.SetRatingPlan(rp) b.ResetTimer() for i := 0; i < b.N; i++ { - storageGetter.GetRatingPlan(rp.Id, true) + dataStorage.GetRatingPlan(rp.Id, true) } } diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index ba80c1cd1..869c55ed1 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -106,7 +106,7 @@ func (ris RatingInfos) Sort() { func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error) { var ris RatingInfos for index, rpa := range rp.RatingPlanActivations.GetActiveForCall(cd) { - rpl, err := storageGetter.GetRatingPlan(rpa.RatingPlanId, false) + rpl, err := dataStorage.GetRatingPlan(rpa.RatingPlanId, false) if err != nil || rpl == nil { Logger.Err(fmt.Sprintf("Error checking destination: %v", err)) continue diff --git a/engine/responder.go b/engine/responder.go index d3cf90b9b..548be6c21 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -183,7 +183,7 @@ func (rs *Responder) Shutdown(arg string, reply *string) (err error) { if rs.Bal != nil { rs.Bal.Shutdown("Responder.Shutdown") } - storageGetter.(Storage).Close() + dataStorage.(Storage).Close() defer func() { rs.ExitChan <- true }() *reply = "Done!" return diff --git a/engine/storage_test.go b/engine/storage_test.go index 63adb5c72..1e2d10958 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -72,7 +72,7 @@ func TestMsgpackTime(t *testing.T) { } func TestStorageDestinationContainsPrefixShort(t *testing.T) { - dest, err := storageGetter.GetDestination("NAT") + dest, err := dataStorage.GetDestination("NAT") precision := dest.containsPrefix("0723") if err != nil || precision != 4 { t.Error("Error finding prefix: ", err, precision) @@ -80,7 +80,7 @@ func TestStorageDestinationContainsPrefixShort(t *testing.T) { } func TestStorageDestinationContainsPrefixLong(t *testing.T) { - dest, err := storageGetter.GetDestination("NAT") + dest, err := dataStorage.GetDestination("NAT") precision := dest.containsPrefix("0723045326") if err != nil || precision != 4 { t.Error("Error finding prefix: ", err, precision) @@ -88,7 +88,7 @@ func TestStorageDestinationContainsPrefixLong(t *testing.T) { } func TestStorageDestinationContainsPrefixNotExisting(t *testing.T) { - dest, err := storageGetter.GetDestination("NAT") + dest, err := dataStorage.GetDestination("NAT") precision := dest.containsPrefix("072") if err != nil || precision != 0 { t.Error("Error finding prefix: ", err, precision) @@ -96,11 +96,11 @@ func TestStorageDestinationContainsPrefixNotExisting(t *testing.T) { } func TestPreCacheRefresh(t *testing.T) { - storageGetter.SetDestination(&Destination{"T11", []string{"0"}}) - storageGetter.GetDestination("T11") - storageGetter.SetDestination(&Destination{"T11", []string{"1"}}) - storageGetter.PreCache(nil, nil, nil, nil) - d, err := storageGetter.GetDestination("T11") + dataStorage.SetDestination(&Destination{"T11", []string{"0"}}) + dataStorage.GetDestination("T11") + dataStorage.SetDestination(&Destination{"T11", []string{"1"}}) + dataStorage.PreCache(nil, nil, nil, nil) + d, err := dataStorage.GetDestination("T11") p := d.containsPrefix("1") if err != nil || p == 0 { t.Error("Error refreshing cache:", d)