From 43bdcb367c583599bbbe007956c65f7b7fc75a3e Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Tue, 24 Jan 2017 16:03:21 +0200 Subject: [PATCH 1/4] small fix --- engine/onstor_it_test.go | 36 ++++++++++++++++++++++++------------ engine/storage_map.go | 12 +++++++----- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 645043323..6db28f09a 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -37,6 +37,7 @@ var ( rdsITdb *RedisStorage mgoITdb *MongoStorage onStor DataDB + dbnames string ) // subtests to be executed for each confDIR @@ -66,8 +67,8 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITPushPop, testOnStorITCRUDRatingPlan, testOnStorITCRUDRatingProfile, - testOnStorITCRUDDestination, - testOnStorITCRUDReverseDestination, + testOnStorITCRUDDestinations, + testOnStorITCRUDReverseDestinations, testOnStorITCRUDLCR, testOnStorITCRUDCdrStats, testOnStorITCRUDActions, @@ -92,6 +93,14 @@ func TestOnStorITRedisConnect(t *testing.T) { if err != nil { t.Fatal("Could not connect to Redis", err.Error()) } + dbnames = cfg.DataDbName +} + +func TestOnStorITRedis(t *testing.T) { + onStor = rdsITdb + for _, stest := range sTestsOnStorIT { + t.Run("TestOnStorITRedis", stest) + } } func TestOnStorITMongoConnect(t *testing.T) { @@ -104,15 +113,8 @@ func TestOnStorITMongoConnect(t *testing.T) { utils.StorDB, nil, mgoITCfg.CacheConfig, mgoITCfg.LoadHistorySize); err != nil { t.Fatal(err) } + dbnames = mgoITCfg.StorDBName } - -func TestOnStorITRedis(t *testing.T) { - onStor = rdsITdb - for _, stest := range sTestsOnStorIT { - t.Run("TestOnStorITRedis", stest) - } -} - func TestOnStorITMongo(t *testing.T) { onStor = mgoITdb for _, stest := range sTestsOnStorIT { @@ -253,6 +255,7 @@ func testOnStorITCacheDestinations(t *testing.T) { if err := onStor.SetDestination(dst, utils.NonTransactional); err != nil { t.Error(err) } + if _, hasIt := cache.Get(utils.DESTINATION_PREFIX + dst.Id); hasIt { t.Error("Already in cache") } @@ -265,11 +268,20 @@ func testOnStorITCacheDestinations(t *testing.T) { if err := onStor.CacheDataFromDB(utils.DESTINATION_PREFIX, []string{dst.Id}, false); err != nil { t.Error(err) } + if err = onStor.SelectDatabase("13"); err != nil { + t.Error(err) + } + if _, rcvErr := onStor.GetReverseDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } if itm, hasIt := cache.Get(utils.DESTINATION_PREFIX + dst.Id); !hasIt { t.Error("Did not cache") } else if !reflect.DeepEqual(dst, itm.(*Destination)) { t.Error("Wrong item in the cache") } + if err = onStor.SelectDatabase(dbnames); err != nil { + t.Error(err) + } } func testOnStorITCacheReverseDestinations(t *testing.T) { @@ -913,7 +925,7 @@ func testOnStorITCRUDRatingProfile(t *testing.T) { } } -func testOnStorITCRUDDestination(t *testing.T) { +func testOnStorITCRUDDestinations(t *testing.T) { dst := &Destination{Id: "CRUDDestination2", Prefixes: []string{"+491", "+492", "+493"}} if _, rcvErr := onStor.GetDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { t.Error(rcvErr) @@ -934,7 +946,7 @@ func testOnStorITCRUDDestination(t *testing.T) { } } -func testOnStorITCRUDReverseDestination(t *testing.T) { +func testOnStorITCRUDReverseDestinations(t *testing.T) { dst := &Destination{Id: "CRUDReverseDestination", Prefixes: []string{"+494", "+495", "+496"}} dst2 := &Destination{Id: "CRUDReverseDestination2", Prefixes: []string{"+497", "+498", "+499"}} if _, rcvErr := onStor.GetReverseDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { diff --git a/engine/storage_map.go b/engine/storage_map.go index 015a3723c..254e4856c 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1028,15 +1028,17 @@ func (ms *MapStorage) GetAccountActionPlans(acntID string, skipCache bool, trans key := utils.AccountActionPlansPrefix + acntID var values []byte if !skipCache { - if ap, ok := cache.Get(key); !ok { - return nil, utils.ErrNotFound - } else { - return ap.([]string), nil + if x, ok := cache.Get(key); ok { + if x == nil { + return nil, utils.ErrNotFound + } + return x.([]string), nil } } if _, ok := ms.dict[key]; !ok { cache.Set(key, nil, cacheCommit(transactionID), transactionID) - return nil, utils.ErrNotFound + err = utils.ErrNotFound + return nil, err } if err = ms.ms.Unmarshal(values, &apIDs); err != nil { From de61a73796995ac5c0e637c81958763bd318aebe Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Wed, 25 Jan 2017 17:33:56 +0200 Subject: [PATCH 2/4] Testing GetFromCache --- engine/onstor_it_test.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 6db28f09a..b25993f1b 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -268,20 +268,11 @@ func testOnStorITCacheDestinations(t *testing.T) { if err := onStor.CacheDataFromDB(utils.DESTINATION_PREFIX, []string{dst.Id}, false); err != nil { t.Error(err) } - if err = onStor.SelectDatabase("13"); err != nil { - t.Error(err) - } - if _, rcvErr := onStor.GetReverseDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { - t.Error(rcvErr) - } if itm, hasIt := cache.Get(utils.DESTINATION_PREFIX + dst.Id); !hasIt { t.Error("Did not cache") } else if !reflect.DeepEqual(dst, itm.(*Destination)) { t.Error("Wrong item in the cache") } - if err = onStor.SelectDatabase(dbnames); err != nil { - t.Error(err) - } } func testOnStorITCacheReverseDestinations(t *testing.T) { @@ -893,6 +884,22 @@ func testOnStorITCRUDRatingPlan(t *testing.T) { } else if !reflect.DeepEqual(rp, rcv) { t.Errorf("Expecting: %v, received: %v", rp, rcv) } + // FixMe + //if err = onStor.SelectDatabase("13"); err != nil { + // t.Error(err) + // } + // if _, rcvErr := onStor.GetRatingPlan(rp.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { + // t.Error(rcvErr) + // } + // + // if rcv, err := onStor.GetRatingPlan(rp.Id, false, utils.NonTransactional); err != nil { + // t.Error(err) + // } else if !reflect.DeepEqual(rp, rcv) { + // t.Errorf("Expecting: %v, received: %v", rp, rcv) + // } + // if err = onStor.SelectDatabase(dbnames); err != nil { + // t.Error(err) + // } } func testOnStorITCRUDRatingProfile(t *testing.T) { From 122f0b89abe6b8262377794c6e325a0a6ea83679 Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Wed, 25 Jan 2017 17:59:13 +0200 Subject: [PATCH 3/4] Small Fix --- engine/onstor_it_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index b25993f1b..4c62520d3 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -34,10 +34,10 @@ import ( ) var ( - rdsITdb *RedisStorage - mgoITdb *MongoStorage - onStor DataDB - dbnames string + rdsITdb *RedisStorage + mgoITdb *MongoStorage + onStor DataDB + OnStorCfg string ) // subtests to be executed for each confDIR @@ -93,7 +93,7 @@ func TestOnStorITRedisConnect(t *testing.T) { if err != nil { t.Fatal("Could not connect to Redis", err.Error()) } - dbnames = cfg.DataDbName + OnStorCfg = cfg.DataDbName } func TestOnStorITRedis(t *testing.T) { @@ -113,7 +113,7 @@ func TestOnStorITMongoConnect(t *testing.T) { utils.StorDB, nil, mgoITCfg.CacheConfig, mgoITCfg.LoadHistorySize); err != nil { t.Fatal(err) } - dbnames = mgoITCfg.StorDBName + OnStorCfg = mgoITCfg.StorDBName } func TestOnStorITMongo(t *testing.T) { onStor = mgoITdb @@ -885,19 +885,19 @@ func testOnStorITCRUDRatingPlan(t *testing.T) { t.Errorf("Expecting: %v, received: %v", rp, rcv) } // FixMe - //if err = onStor.SelectDatabase("13"); err != nil { + // if err = onStor.SelectDatabase("13"); err != nil { // t.Error(err) // } // if _, rcvErr := onStor.GetRatingPlan(rp.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { // t.Error(rcvErr) // } // - // if rcv, err := onStor.GetRatingPlan(rp.Id, false, utils.NonTransactional); err != nil { - // t.Error(err) - // } else if !reflect.DeepEqual(rp, rcv) { - // t.Errorf("Expecting: %v, received: %v", rp, rcv) - // } - // if err = onStor.SelectDatabase(dbnames); err != nil { + if rcv, err := onStor.GetRatingPlan(rp.Id, false, utils.NonTransactional); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(rp, rcv) { + t.Errorf("Expecting: %v, received: %v", rp, rcv) + } + // if err = onStor.SelectDatabase(OnStorCfg); err != nil { // t.Error(err) // } } From 86f28bcdd509e1ef9ac052850bb71ea45c37c178 Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Wed, 25 Jan 2017 18:05:59 +0200 Subject: [PATCH 4/4] Small Fix --- engine/onstor_it_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 4c62520d3..12bf51ab0 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -37,7 +37,7 @@ var ( rdsITdb *RedisStorage mgoITdb *MongoStorage onStor DataDB - OnStorCfg string + onStorCfg string ) // subtests to be executed for each confDIR @@ -93,7 +93,7 @@ func TestOnStorITRedisConnect(t *testing.T) { if err != nil { t.Fatal("Could not connect to Redis", err.Error()) } - OnStorCfg = cfg.DataDbName + onStorCfg = cfg.DataDbName } func TestOnStorITRedis(t *testing.T) { @@ -113,7 +113,7 @@ func TestOnStorITMongoConnect(t *testing.T) { utils.StorDB, nil, mgoITCfg.CacheConfig, mgoITCfg.LoadHistorySize); err != nil { t.Fatal(err) } - OnStorCfg = mgoITCfg.StorDBName + onStorCfg = mgoITCfg.StorDBName } func TestOnStorITMongo(t *testing.T) { onStor = mgoITdb @@ -897,7 +897,7 @@ func testOnStorITCRUDRatingPlan(t *testing.T) { } else if !reflect.DeepEqual(rp, rcv) { t.Errorf("Expecting: %v, received: %v", rp, rcv) } - // if err = onStor.SelectDatabase(OnStorCfg); err != nil { + // if err = onStor.SelectDatabase(onStorCfg); err != nil { // t.Error(err) // } }