From 1fdd3ef6547cd6594a7e9cf302464555b02ea892 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 31 Jul 2015 16:54:59 +0300 Subject: [PATCH] flush users on reload --- engine/lcr_test.go | 16 ++++++++-------- engine/users.go | 11 +++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/engine/lcr_test.go b/engine/lcr_test.go index ad94fabe9..93fb2c6d4 100644 --- a/engine/lcr_test.go +++ b/engine/lcr_test.go @@ -215,11 +215,11 @@ func TestLcrGet(t *testing.T) { func TestLcrRequestAsCallDescriptor(t *testing.T) { sTime := time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC) callDur := time.Duration(1) * time.Minute - lcrReq := &LcrRequest{Account: "1001", StartTime: sTime.String()} + lcrReq := &LcrRequest{Account: "2001", StartTime: sTime.String()} if _, err := lcrReq.AsCallDescriptor(); err == nil || err != utils.ErrMandatoryIeMissing { t.Error("Unexpected error received: %v", err) } - lcrReq = &LcrRequest{Account: "1001", Destination: "1002", StartTime: sTime.String()} + lcrReq = &LcrRequest{Account: "2001", Destination: "2002", StartTime: sTime.String()} eCd := &CallDescriptor{ Direction: utils.OUT, Tenant: config.CgrConfig().DefaultTenant, @@ -412,7 +412,7 @@ func TestLCRCostSuppliersLoadAllRounded(t *testing.T) { Supplier: "*out:tenant12:call:dan12", supplierQueues: []*StatsQueue{ &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(100 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(200 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, @@ -452,7 +452,7 @@ func TestLCRCostSuppliersLoadAllRounded(t *testing.T) { }, }, &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{SetupTime: setupTime.Add(300 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{SetupTime: setupTime.Add(400 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, @@ -512,7 +512,7 @@ func TestLCRCostSuppliersLoadAllOver(t *testing.T) { Supplier: "*out:tenant12:call:dan12", supplierQueues: []*StatsQueue{ &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(100 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(200 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, @@ -552,7 +552,7 @@ func TestLCRCostSuppliersLoadAllOver(t *testing.T) { }, }, &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(300 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(400 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, @@ -612,7 +612,7 @@ func TestLCRCostSuppliersLoadAllOverMisingDefault(t *testing.T) { Supplier: "*out:tenant12:call:dan12", supplierQueues: []*StatsQueue{ &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(100 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(200 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, @@ -652,7 +652,7 @@ func TestLCRCostSuppliersLoadAllOverMisingDefault(t *testing.T) { }, }, &StatsQueue{ - Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(300 * time.Minute)}}, + Cdrs: []*QCdr{&QCdr{}, &QCdr{}, &QCdr{SetupTime: setupTime.Add(400 * time.Minute)}}, conf: &CdrStats{ QueueLength: 0, TimeWindow: 10 * time.Minute, diff --git a/engine/users.go b/engine/users.go index 3c3cc22ec..b8faf8b52 100644 --- a/engine/users.go +++ b/engine/users.go @@ -88,12 +88,23 @@ func newUserMap(accountingDb AccountingStorage, indexes []string) *UserMap { func (um *UserMap) ReloadUsers(in string, reply *string) error { um.mu.Lock() defer um.mu.Unlock() + + // backup old data + oldTable := um.table + oldIndex := um.index + um.table = make(map[string]map[string]string) + um.index = make(map[string]map[string]bool) + // load from rating db if ups, err := um.accountingDb.GetUsers(); err == nil { for _, up := range ups { um.table[up.GetId()] = up.Profile } } else { + // restore old data before return + um.table = oldTable + um.index = oldIndex + *reply = err.Error() return err }