From 7cf9beb5b7b3e80b70f2bb59249d6d967e943fc4 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 9 Nov 2015 16:16:48 +0200 Subject: [PATCH 1/4] merge tests --- engine/callcost_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/engine/callcost_test.go b/engine/callcost_test.go index 46448e90a..c9ce24f01 100644 --- a/engine/callcost_test.go +++ b/engine/callcost_test.go @@ -33,20 +33,23 @@ func TestSingleResultMerge(t *testing.T) { if cc1.Cost != 61 { t.Errorf("expected 61 was %v", cc1.Cost) } - /*t1 = time.Date(2012, time.February, 2, 17, 1, 0, 0, time.UTC) + t1 = time.Date(2012, time.February, 2, 17, 1, 0, 0, time.UTC) t2 = time.Date(2012, time.February, 2, 17, 2, 0, 0, time.UTC) - cd = &CallDescriptor{Direction: utils.OUT, TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2} + cd = &CallDescriptor{Direction: utils.OUT, Category: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2} cc2, _ := cd.GetCost() - if cc2.Cost != 60 { + if cc2.Cost != 61 { t.Errorf("expected 60 was %v", cc2.Cost) } cc1.Merge(cc2) - if len(cc1.Timespans) != 1 || cc1.Timespans[0].GetDuration().Seconds() != 120 { - t.Error("wrong resulted timespan: ", len(cc1.Timespans)) + if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 60 || cc1.Timespans[1].GetDuration().Seconds() != 60 { + for _, ts := range cc1.Timespans { + t.Logf("TS: %+v", ts) + } + t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds()) } - if cc1.Cost != 120 { + if cc1.Cost != 122 { t.Errorf("Exdpected 120 was %v", cc1.Cost) - }*/ + } } func TestMultipleResultMerge(t *testing.T) { @@ -73,7 +76,7 @@ func TestMultipleResultMerge(t *testing.T) { } cc1.Merge(cc2) if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 60 { - t.Error("wrong resulted timespan: ", len(cc1.Timespans)) + t.Error("wrong resulted timespans: ", len(cc1.Timespans)) } if cc1.Cost != 91 { t.Errorf("Exdpected 91 was %v", cc1.Cost) From d871a37ffa89229e1add9a38eaaae18501881112 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 9 Nov 2015 17:52:37 +0200 Subject: [PATCH 2/4] test for counters fixes #199, fixes #213 --- engine/account_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/engine/account_test.go b/engine/account_test.go index e579232c8..1cd5046a5 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -19,6 +19,7 @@ along with this program. If not, see package engine import ( + "log" "testing" "time" @@ -936,6 +937,35 @@ func TestAccountExecuteTriggeredActionsOrder(t *testing.T) { } } +func TestAccountExecuteTriggeredDayWeek(t *testing.T) { + ub := &Account{ + Id: "TEST_UB", + BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}, Directions: utils.StringMap{utils.OUT: true}}, &Balance{Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}}, + ActionTriggers: ActionTriggers{ + &ActionTrigger{Id: "day_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, + &ActionTrigger{Id: "week_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 100, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, + }, + } + ub.InitCounters() + if len(ub.UnitCounters) != 1 || len(ub.UnitCounters[0].Balances) != 2 { + log.Print("Error initializing counters: ", ub.UnitCounters[0].Balances[0]) + } + + ub.countUnits(1, utils.MONETARY, &CallCost{Direction: utils.OUT}, nil) + if ub.UnitCounters[0].Balances[0].Value != 1 || + ub.UnitCounters[0].Balances[1].Value != 1 { + t.Error("Error incrementing both counters", ub.UnitCounters[0].Balances[0].Value, ub.UnitCounters[0].Balances[1].Value) + } + + // we can reset them + resetCountersAction(ub, nil, &Action{BalanceType: utils.MONETARY, Balance: &Balance{Id: "day_trigger"}}, nil) + if ub.UnitCounters[0].Balances[0].Value != 0 || + ub.UnitCounters[0].Balances[1].Value != 1 { + t.Error("Error reseting both counters", ub.UnitCounters[0].Balances[0].Value, ub.UnitCounters[0].Balances[1].Value) + } + +} + func TestCleanExpired(t *testing.T) { ub := &Account{ Id: "TEST_UB_OREDER", From 39e34453a2cf100fe3dc0d07b3f08f00810b9218 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 9 Nov 2015 19:00:09 +0200 Subject: [PATCH 3/4] added *min/*max ddc triggers fixes #266 --- engine/action_trigger.go | 2 +- engine/stats_queue.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/action_trigger.go b/engine/action_trigger.go index 7ab63c864..72cc86441 100644 --- a/engine/action_trigger.go +++ b/engine/action_trigger.go @@ -32,7 +32,7 @@ import ( type ActionTrigger struct { Id string // for visual identification ThresholdType string //*min_counter, *max_counter, *min_balance, *max_balance - // stats: *min_asr, *max_asr, *min_acd, *max_acd, *min_tcd, *max_tcd, *min_acc, *max_acc, *min_tcc, *max_tcc + // stats: *min_asr, *max_asr, *min_acd, *max_acd, *min_tcd, *max_tcd, *min_acc, *max_acc, *min_tcc, *max_tcc, *min_ddc, *max_ddc ThresholdValue float64 Recurrent bool // reset eexcuted flag each run MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers diff --git a/engine/stats_queue.go b/engine/stats_queue.go index bbadfb200..c9bd1619f 100644 --- a/engine/stats_queue.go +++ b/engine/stats_queue.go @@ -48,6 +48,8 @@ var METRIC_TRIGGER_MAP = map[string]string{ "*max_acc": ACC, "*min_tcc": TCC, "*max_tcc": TCC, + "*min_ddc": DDC, + "*max_ddc": DDC, } // Simplified cdr structure containing only the necessary info From 0c451c8044295d5db7484aa67fc27059a8f76bf4 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 6 Nov 2015 16:18:56 +0200 Subject: [PATCH 4/4] longer threshold type in db --- data/storage/mysql/create_tariffplan_tables.sql | 2 +- data/storage/postgres/create_tariffplan_tables.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 4e368e8d9..facb3f7b9 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -197,7 +197,7 @@ CREATE TABLE `tp_action_triggers` ( `tpid` varchar(64) NOT NULL, `tag` varchar(64) NOT NULL, `unique_id` varchar(64) NOT NULL, - `threshold_type` char(12) NOT NULL, + `threshold_type` char(64) NOT NULL, `threshold_value` DECIMAL(20,4) NOT NULL, `recurrent` BOOLEAN NOT NULL, `min_sleep` varchar(16) NOT NULL, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 241e9f2e4..1722ff74b 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -192,7 +192,7 @@ CREATE TABLE tp_action_triggers ( tpid VARCHAR(64) NOT NULL, tag VARCHAR(64) NOT NULL, unique_id VARCHAR(64) NOT NULL, - threshold_type char(12) NOT NULL, + threshold_type char(64) NOT NULL, threshold_value NUMERIC(20,4) NOT NULL, recurrent BOOLEAN NOT NULL, min_sleep VARCHAR(16) NOT NULL,