multiple integration tests fixes

This commit is contained in:
Radu Ioan Fericean
2016-07-08 17:26:38 +03:00
parent ed65235587
commit 8318e45edb
21 changed files with 46 additions and 39 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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())

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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

View File

@@ -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})
}

View File

@@ -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})
}

View File

@@ -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})
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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)

View File

@@ -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())

View File

@@ -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())

View File

@@ -588,6 +588,7 @@ type CacheStats struct {
CdrStats int
Users int
Aliases int
LastLoadID string
LastRatingLoadID string
LastAccountingLoadID string
LastLoadTime string