mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
cache refactoring for save and load
This commit is contained in:
@@ -21,7 +21,6 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
|
||||
"testing"
|
||||
@@ -83,7 +82,7 @@ func TestDestinationGetExists(t *testing.T) {
|
||||
|
||||
func TestDestinationGetExistsCache(t *testing.T) {
|
||||
ratingStorage.GetDestination("NAT")
|
||||
if _, err := cache2go.Get(utils.DESTINATION_PREFIX + "0256"); err != nil {
|
||||
if _, err := CacheGet(utils.DESTINATION_PREFIX + "0256"); err != nil {
|
||||
t.Error("Destination not cached:", err)
|
||||
}
|
||||
}
|
||||
@@ -97,7 +96,7 @@ func TestDestinationGetNotExists(t *testing.T) {
|
||||
|
||||
func TestDestinationGetNotExistsCache(t *testing.T) {
|
||||
ratingStorage.GetDestination("not existing")
|
||||
if d, err := cache2go.Get("not existing"); err == nil {
|
||||
if d, err := CacheGet("not existing"); err == nil {
|
||||
t.Error("Bad destination cached: ", d)
|
||||
}
|
||||
}
|
||||
@@ -128,17 +127,17 @@ func TestNonCachedDestWrongPrefix(t *testing.T) {
|
||||
|
||||
func TestCleanStalePrefixes(t *testing.T) {
|
||||
x := struct{}{}
|
||||
cache2go.Cache(utils.DESTINATION_PREFIX+"1", map[interface{}]struct{}{"D1": x, "D2": x})
|
||||
cache2go.Cache(utils.DESTINATION_PREFIX+"2", map[interface{}]struct{}{"D1": x})
|
||||
cache2go.Cache(utils.DESTINATION_PREFIX+"3", map[interface{}]struct{}{"D2": x})
|
||||
CacheSet(utils.DESTINATION_PREFIX+"1", map[string]struct{}{"D1": x, "D2": x})
|
||||
CacheSet(utils.DESTINATION_PREFIX+"2", map[string]struct{}{"D1": x})
|
||||
CacheSet(utils.DESTINATION_PREFIX+"3", map[string]struct{}{"D2": x})
|
||||
CleanStalePrefixes([]string{"D1"})
|
||||
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
|
||||
if r, err := CacheGet(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[string]struct{})) != 1 {
|
||||
t.Error("Error cleaning stale destination ids", r)
|
||||
}
|
||||
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "2"); err == nil {
|
||||
if r, err := CacheGet(utils.DESTINATION_PREFIX + "2"); err == nil {
|
||||
t.Error("Error removing stale prefix: ", r)
|
||||
}
|
||||
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
|
||||
if r, err := CacheGet(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[string]struct{})) != 1 {
|
||||
t.Error("Error performing stale cleaning: ", r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user