mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user