From 8318e45edbbcac3a18243bdf597f51c1d6198861 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 8 Jul 2016 17:26:38 +0300 Subject: [PATCH] multiple integration tests fixes --- apier/v1/apier.go | 2 ++ apier/v1/apier_local_test.go | 15 +++++++++------ apier/v1/smgenericv1_it_test.go | 3 ++- apier/v1/triggers.go | 3 --- apier/v2/apier.go | 2 +- engine/aliases.go | 5 ++--- engine/storage_map.go | 2 ++ engine/storage_mongo_datadb.go | 2 ++ engine/storage_redis.go | 4 +++- general_tests/acntacts_test.go | 4 ++-- general_tests/auth_test.go | 4 ++-- general_tests/costs1_test.go | 4 ++-- general_tests/datachrg1_test.go | 4 ++-- general_tests/ddazmbl1_test.go | 4 ++-- general_tests/ddazmbl2_test.go | 4 ++-- general_tests/ddazmbl3_test.go | 4 ++-- general_tests/rpcclient_it_test.go | 10 ++++------ general_tests/smschrg1_test.go | 4 ++-- general_tests/tut_smgeneric_it_test.go | 2 +- general_tests/tutorial_local_test.go | 2 +- utils/apitpdata.go | 1 + 21 files changed, 46 insertions(+), 39 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index e7a440998..07b204da4 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -838,10 +838,12 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach if err != nil { // Not really an error here since we only count in cache utils.Logger.Warning(fmt.Sprintf("ApierV1.GetCacheStats, error on GetLoadHistory: %s", err.Error())) } + cs.LastLoadID = utils.NOT_AVAILABLE cs.LastRatingLoadID = utils.NOT_AVAILABLE cs.LastAccountingLoadID = utils.NOT_AVAILABLE cs.LastLoadTime = utils.NOT_AVAILABLE } else { + cs.LastLoadID = loadHistInsts[0].LoadID cs.LastRatingLoadID = loadHistInsts[0].RatingLoadID cs.LastAccountingLoadID = loadHistInsts[0].AccountingLoadID cs.LastLoadTime = loadHistInsts[0].LoadTime.Format(time.RFC3339) diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go index 3324d3da5..9921bc4ab 100644 --- a/apier/v1/apier_local_test.go +++ b/apier/v1/apier_local_test.go @@ -826,9 +826,10 @@ func TestApierGetCacheStats(t *testing.T) { return } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 3, RatingPlans: 1, RatingProfiles: 2, Actions: 2, ActionPlans: 1, LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE} var args utils.AttrCacheStats - if err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { + err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) + expectedStats := &utils.CacheStats{Destinations: 3, RatingPlans: 1, RatingProfiles: 2, Actions: 2, ActionPlans: 1, LastLoadID: "ReloadCacheAPI", LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime} + if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling ApierV1.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats) @@ -1244,9 +1245,10 @@ func TestApierResetDataBeforeLoadFromFolder(t *testing.T) { t.Error("Calling ApierV1.ReloadCache got reply: ", reply) } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE} var args utils.AttrCacheStats - if err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { + err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) + expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime} + if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(rcvStats, expectedStats) { t.Errorf("Calling ApierV1.GetCacheStats received: %v, expected: %v", rcvStats, expectedStats) @@ -1759,9 +1761,10 @@ func TestApierGetCacheStats2(t *testing.T) { return } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE} var args utils.AttrCacheStats - if err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { + err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) + expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime} + if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling ApierV1.GetCacheStats expected: %v, received: %v", expectedStats, rcvStats) diff --git a/apier/v1/smgenericv1_it_test.go b/apier/v1/smgenericv1_it_test.go index b14feadc7..b9897379e 100644 --- a/apier/v1/smgenericv1_it_test.go +++ b/apier/v1/smgenericv1_it_test.go @@ -117,7 +117,8 @@ func TestSMGV1CacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastRatingLoadID: smgV1LoadInst.RatingLoadID, LastAccountingLoadID: smgV1LoadInst.AccountingLoadID, LastLoadTime: smgV1LoadInst.LoadTime.Format(time.RFC3339)} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, + LastLoadID: smgV1LoadInst.LoadID, LastRatingLoadID: smgV1LoadInst.RatingLoadID, LastAccountingLoadID: smgV1LoadInst.AccountingLoadID, LastLoadTime: smgV1LoadInst.LoadTime.Format(time.RFC3339)} var args utils.AttrCacheStats if err := smgV1Rpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/apier/v1/triggers.go b/apier/v1/triggers.go index ecfd90c76..ec8645ca5 100644 --- a/apier/v1/triggers.go +++ b/apier/v1/triggers.go @@ -1,8 +1,6 @@ package v1 import ( - "log" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -219,7 +217,6 @@ func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers, } else { return 0, err } - log.Print("HERE: ", account.ActionTriggers) for _, at := range account.ActionTriggers { if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) && (attr.GroupID == "" || at.ID == attr.GroupID) { diff --git a/apier/v2/apier.go b/apier/v2/apier.go index c6b0afdaa..e5f7aa796 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -259,7 +259,7 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, return err } } - loadHistList, err := self.AccountDb.GetLoadHistory(1, false) + loadHistList, err := self.AccountDb.GetLoadHistory(1, true) if err != nil { return err } diff --git a/engine/aliases.go b/engine/aliases.go index f220551a3..1aeff8059 100644 --- a/engine/aliases.go +++ b/engine/aliases.go @@ -289,9 +289,8 @@ func (am *AliasHandler) GetReverseAlias(attr *AttrReverseAlias, result *map[stri aliases := make(map[string][]*Alias) rKey := utils.REVERSE_ALIASES_PREFIX + attr.Alias + attr.Target + attr.Context if x, err := CacheGet(rKey); err == nil { - existingKeys := x.(map[interface{}]struct{}) - for iKey := range existingKeys { - key := iKey.(string) + existingKeys := x.(map[string]struct{}) + for key := range existingKeys { // get destination id elems := strings.Split(key, utils.CONCATENATED_KEY_SEP) var destID string diff --git a/engine/storage_map.go b/engine/storage_map.go index f7e4413df..b4f12aafd 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -227,6 +227,7 @@ func (ms *MapStorage) cacheRating(loadID string, dKeys, rpKeys, rpfKeys, lcrKeys utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } + ms.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(ms.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } @@ -305,6 +306,7 @@ func (ms *MapStorage) cacheAccounting(loadID string, alsKeys []string) error { utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } + ms.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(ms.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index ce2445064..4ea52887b 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -672,6 +672,7 @@ func (ms *MongoStorage) cacheRating(loadID string, dKeys, rpKeys, rpfKeys, lcrKe utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } + ms.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(ms.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } @@ -773,6 +774,7 @@ func (ms *MongoStorage) cacheAccounting(loadID string, alsKeys []string) (err er utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } + ms.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(ms.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index e69e3c8a5..c989301c4 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -346,7 +346,7 @@ func (rs *RedisStorage) cacheRating(loadID string, dKeys, rpKeys, rpfKeys, lcrKe utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } - + rs.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(rs.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } @@ -448,6 +448,8 @@ func (rs *RedisStorage) cacheAccounting(loadID string, alsKeys []string) (err er utils.Logger.Info(fmt.Sprintf("error saving load history: %v (%v)", loadHist, err)) return err } + + rs.GetLoadHistory(1, true) // to load last instance in cache return utils.SaveCacheFileInfo(rs.cacheDumpDir, &utils.CacheFileInfo{Encoding: utils.MSGPACK, LoadInfo: loadHist}) } diff --git a/general_tests/acntacts_test.go b/general_tests/acntacts_test.go index d470fe31d..48877790a 100644 --- a/general_tests/acntacts_test.go +++ b/general_tests/acntacts_test.go @@ -61,8 +61,8 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,,false,false,10` t.Fatal(err) } csvr.WriteToDatabase(false, false) - ratingDbAcntActs.CacheRatingAll() - acntDbAcntActs.CacheAccountingAll() + ratingDbAcntActs.CacheRatingAll("TestAcntActsLoadCsv") + acntDbAcntActs.CacheAccountingAll("TestAcntActsLoadCsv") expectAcnt := &engine.Account{ID: "cgrates.org:1"} if acnt, err := acntDbAcntActs.GetAccount("cgrates.org:1"); err != nil { t.Error(err) diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index 922089519..db0861224 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -74,8 +74,8 @@ RP_ANY,DR_ANY_1CNT,*any,10` } else if acnt == nil { t.Error("No account saved") } - ratingDbAuth.CacheRatingAll() - acntDbAuth.CacheAccountingAll() + ratingDbAuth.CacheRatingAll("TestAuthLoadCsv") + acntDbAuth.CacheAccountingAll("TestAuthLoadCsv") if cachedDests := engine.CacheCountEntries(utils.DESTINATION_PREFIX); cachedDests != 1 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/costs1_test.go b/general_tests/costs1_test.go index d6851ac8e..9ff8bd741 100644 --- a/general_tests/costs1_test.go +++ b/general_tests/costs1_test.go @@ -74,8 +74,8 @@ RP_SMS1,DR_SMS_1,ALWAYS,10` t.Fatal(err) } csvr.WriteToDatabase(false, false) - ratingDb.CacheRatingAll() - acntDb.CacheAccountingAll() + ratingDb.CacheRatingAll("TestCosts1LoadCsvTp") + acntDb.CacheAccountingAll("TestCosts1LoadCsvTp") if cachedRPlans := engine.CacheCountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 3 { t.Error("Wrong number of cached rating plans found", cachedRPlans) diff --git a/general_tests/datachrg1_test.go b/general_tests/datachrg1_test.go index 22e07aaad..bf4833b8f 100644 --- a/general_tests/datachrg1_test.go +++ b/general_tests/datachrg1_test.go @@ -61,8 +61,8 @@ RP_DATA1,DR_DATA_2,TM2,10` t.Fatal(err) } csvr.WriteToDatabase(false, false) - ratingDb.CacheRatingAll() - acntDb.CacheAccountingAll() + ratingDb.CacheRatingAll("TestLoadCsvTpDtChrg1") + acntDb.CacheAccountingAll("TestLoadCsvTpDtChrg1") if cachedRPlans := engine.CacheCountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 1 { t.Error("Wrong number of cached rating plans found", cachedRPlans) diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 8ec644e8a..8ec94423b 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -110,8 +110,8 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` t.Error("No account saved") } - ratingDb.CacheRatingAll() - acntDb.CacheAccountingAll() + ratingDb.CacheRatingAll("TestLoadCsvTp") + acntDb.CacheAccountingAll("TestLoadCsvTp") if cachedDests := engine.CacheCountEntries(utils.DESTINATION_PREFIX); cachedDests != 2 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index fcae6003b..248b9736a 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -109,8 +109,8 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` } else if acnt == nil { t.Error("No account saved") } - ratingDb2.CacheRatingAll() - acntDb2.CacheAccountingAll() + ratingDb2.CacheRatingAll("TestSetStorage2") + acntDb2.CacheAccountingAll("TestSetStorage2") if cachedDests := engine.CacheCountEntries(utils.DESTINATION_PREFIX); cachedDests != 2 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index 6ca54d439..44ddee30d 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -107,8 +107,8 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` } else if acnt == nil { t.Error("No account saved") } - ratingDb3.CacheRatingAll() - acntDb3.CacheAccountingAll() + ratingDb3.CacheRatingAll("TestSetStorage3") + acntDb3.CacheAccountingAll("TestSetStorage3") if cachedDests := engine.CacheCountEntries(utils.DESTINATION_PREFIX); cachedDests != 2 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/rpcclient_it_test.go b/general_tests/rpcclient_it_test.go index 6d002f17f..d84ea15cf 100644 --- a/general_tests/rpcclient_it_test.go +++ b/general_tests/rpcclient_it_test.go @@ -425,15 +425,13 @@ func TestRPCITStatusBcastCmd(t *testing.T) { } if err := rpcRAL1.Call("ApierV2.GetCacheStats", utils.AttrCacheStats{}, &stats); err != nil { t.Error(err) - } else if stats.LastRatingLoadID != loadInst.RatingLoadID || - stats.LastAccountingLoadID != loadInst.AccountingLoadID { - t.Errorf("Received unexpected stats: %+v", stats) + } else if stats.LastRatingLoadID != loadInst.RatingLoadID { + t.Errorf("Received unexpected stats: %+v vs %+v", stats, loadInst) } if err := rpcRAL2.Call("ApierV2.GetCacheStats", utils.AttrCacheStats{}, &stats); err != nil { t.Error(err) - } else if stats.LastRatingLoadID != loadInst.RatingLoadID || - stats.LastAccountingLoadID != loadInst.AccountingLoadID { - t.Errorf("Received unexpected stats: %+v", stats) + } else if stats.LastRatingLoadID != loadInst.RatingLoadID { + t.Errorf("Received unexpected stats: %+v vs %+v", stats, loadInst) } } diff --git a/general_tests/smschrg1_test.go b/general_tests/smschrg1_test.go index 759652608..4e525c3a8 100644 --- a/general_tests/smschrg1_test.go +++ b/general_tests/smschrg1_test.go @@ -57,8 +57,8 @@ func TestSMSLoadCsvTpSmsChrg1(t *testing.T) { t.Fatal(err) } csvr.WriteToDatabase(false, false) - ratingDb.CacheRatingAll() - acntDb.CacheAccountingAll() + ratingDb.CacheRatingAll("TestSMSLoadCsvTpSmsChrg1") + acntDb.CacheAccountingAll("TestSMSLoadCsvTpSmsChrg1") if cachedRPlans := engine.CacheCountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 1 { t.Error("Wrong number of cached rating plans found", cachedRPlans) diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index 111c68ab3..256a18317 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -115,7 +115,7 @@ func TestTutSMGCacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastRatingLoadID: smgLoadInst.RatingLoadID, LastAccountingLoadID: smgLoadInst.AccountingLoadID, LastLoadTime: smgLoadInst.LoadTime.Format(time.RFC3339)} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: smgLoadInst.RatingLoadID, LastAccountingLoadID: smgLoadInst.AccountingLoadID, LastLoadTime: smgLoadInst.LoadTime.Format(time.RFC3339)} var args utils.AttrCacheStats if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index 38851271f..9d93dc278 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -116,7 +116,7 @@ func TestTutLocalCacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastRatingLoadID: loadInst.RatingLoadID, LastAccountingLoadID: loadInst.AccountingLoadID, LastLoadTime: loadInst.LoadTime.Format(time.RFC3339)} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: loadInst.RatingLoadID, LastAccountingLoadID: loadInst.AccountingLoadID, LastLoadTime: loadInst.LoadTime.Format(time.RFC3339)} var args utils.AttrCacheStats if err := tutLocalRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index b72a38ee1..eaa84cb2d 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -588,6 +588,7 @@ type CacheStats struct { CdrStats int Users int Aliases int + LastLoadID string LastRatingLoadID string LastAccountingLoadID string LastLoadTime string