mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
replaced storageGetter with dataStorage
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user