mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
small fix
This commit is contained in:
@@ -88,6 +88,7 @@ var sTestsOnStorIT = []func(t *testing.T){
|
||||
testOnStorITCRUDHistory,
|
||||
testOnStorITCRUDStructVersion,
|
||||
testOnStorITCRUDSQStoredMetrics,
|
||||
testOnStorITCRUDStatsQueue,
|
||||
}
|
||||
|
||||
func TestOnStorITRedisConnect(t *testing.T) {
|
||||
@@ -1844,7 +1845,7 @@ func testOnStorITCRUDStatsQueue(t *testing.T) {
|
||||
timeTTL := time.Duration(0 * time.Second)
|
||||
sq := &StatsQueue{
|
||||
ID: "test",
|
||||
ActivationInterval: &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC)},
|
||||
ActivationInterval: &utils.ActivationInterval{},
|
||||
Filters: []*RequestFilter{},
|
||||
QueueLength: 2,
|
||||
TTL: &timeTTL,
|
||||
@@ -1852,12 +1853,17 @@ func testOnStorITCRUDStatsQueue(t *testing.T) {
|
||||
Store: true,
|
||||
Thresholds: []string{},
|
||||
}
|
||||
if _, rcvErr := onStor.GetStatsQueue(sq.ID, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetStatsQueue(sq.ID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.SetStatsQueue(sq); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetStatsQueue(sq.ID, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(sq, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", sq, rcv)
|
||||
}
|
||||
if rcv, err := onStor.GetStatsQueue(sq.ID, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(sq, rcv) {
|
||||
@@ -1866,6 +1872,9 @@ func testOnStorITCRUDStatsQueue(t *testing.T) {
|
||||
if err := onStor.RemStatsQueue(sq.ID, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, rcvErr := onStor.GetStatsQueue(sq.ID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if _, rcvErr := onStor.GetStatsQueue(sq.ID, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
|
||||
@@ -2011,6 +2011,7 @@ func (ms *MongoStorage) MatchReqFilterIndex(dbKey, fieldValKey string) (itemIDs
|
||||
|
||||
// GetStatsQueue retrieves a StatsQueue from dataDB/cache
|
||||
func (ms *MongoStorage) GetStatsQueue(sqID string, skipCache bool, transactionID string) (sq *StatsQueue, err error) {
|
||||
var rez *StatsQueue
|
||||
cacheKey := utils.StatsQueuePrefix + sqID
|
||||
if !skipCache {
|
||||
if x, ok := cache.Get(cacheKey); ok {
|
||||
@@ -2023,13 +2024,14 @@ func (ms *MongoStorage) GetStatsQueue(sqID string, skipCache bool, transactionID
|
||||
session, col := ms.conn(utils.StatsQueuePrefix)
|
||||
defer session.Close()
|
||||
cCommit := cacheCommit(transactionID)
|
||||
if err = col.Find(bson.M{"id": sqID}).One(&sq); err != nil {
|
||||
if err = col.Find(bson.M{"id": sqID}).One(&rez); err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
cache.Set(cacheKey, nil, cCommit, transactionID)
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
sq = rez
|
||||
cache.Set(cacheKey, sq, cCommit, transactionID)
|
||||
return
|
||||
}
|
||||
@@ -2044,15 +2046,8 @@ func (ms *MongoStorage) SetStatsQueue(sq *StatsQueue) (err error) {
|
||||
|
||||
// RemStatsQueue removes a StatsQueue from dataDB/cache
|
||||
func (ms *MongoStorage) RemStatsQueue(sqID string, transactionID string) (err error) {
|
||||
session, col := ms.conn(utils.SQStoredMetricsPrefix)
|
||||
session, col := ms.conn(utils.StatsQueuePrefix)
|
||||
key := utils.StatsQueuePrefix + sqID
|
||||
_, err = ms.GetStatsQueue(sqID, false, transactionID)
|
||||
if err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
err = col.Remove(bson.M{"id": sqID})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1589,7 +1589,7 @@ func (rs *RedisStorage) GetStatsQueue(sqID string, skipCache bool, transactionID
|
||||
if err = rs.ms.Unmarshal(values, &sq); err != nil {
|
||||
return
|
||||
}
|
||||
cache.Set(key, &sq, cacheCommit(transactionID), transactionID)
|
||||
cache.Set(key, sq, cacheCommit(transactionID), transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user