mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 15:48:44 +05:00
Updated statmetrics test && added comments
This commit is contained in:
committed by
Dan Christian Bogos
parent
b99d87c262
commit
f258a289f4
@@ -963,6 +963,13 @@ func testV1STSProcessStatsOneEvent(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expectedMetrics, metrics) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
|
||||
}
|
||||
var statQueue engine.StatQueue
|
||||
if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatQueueOne"}}, &statQueue); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(statQueue.SQItems) != 0 {
|
||||
t.Errorf("Expected 0, Received %v", len(statQueue.SQItems))
|
||||
}
|
||||
}
|
||||
|
||||
func testV1STSStatsPing(t *testing.T) {
|
||||
|
||||
@@ -166,6 +166,7 @@ func (asr *StatASR) AddEvent(evID string, ev utils.DataProvider) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// AddOneEvent aggregates the metric value without storing the events
|
||||
func (asr *StatASR) AddOneEvent(ev utils.DataProvider) (err error) {
|
||||
var answered int
|
||||
if answered, err = asr.getFieldVal(ev); err != nil {
|
||||
@@ -179,6 +180,7 @@ func (asr *StatASR) AddOneEvent(ev utils.DataProvider) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// RemEvent deletes a stored event and decrements statistics of the metric for recalculation
|
||||
func (asr *StatASR) RemEvent(evID string) (err error) {
|
||||
val, has := asr.Events[evID]
|
||||
if !has {
|
||||
|
||||
@@ -328,7 +328,6 @@ func TestASRAddOneEvent(t *testing.T) {
|
||||
Event: map[string]any{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1"}
|
||||
asr.AddOneEvent(utils.MapStorage{utils.MetaReq: ev.Event})
|
||||
asr.AddOneEvent(utils.MapStorage{utils.MetaReq: ev2.Event})
|
||||
if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" {
|
||||
@@ -338,12 +337,7 @@ func TestASRAddOneEvent(t *testing.T) {
|
||||
if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "33.33333%" {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
}
|
||||
asr.AddOneEvent(utils.MapStorage{utils.MetaReq: ev4.Event})
|
||||
if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "25%" {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
}
|
||||
asr.RemEvent(ev4.ID)
|
||||
asr.RemEvent(ev2.ID)
|
||||
asr.AddOneEvent(utils.MapStorage{utils.MetaReq: ev2.Event})
|
||||
if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "25%" {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
}
|
||||
@@ -722,10 +716,7 @@ func TestACDAddOneEvent(t *testing.T) {
|
||||
if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" {
|
||||
t.Errorf("wrong acd value: %s", strVal)
|
||||
}
|
||||
acd.RemEvent(ev2.ID)
|
||||
if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" {
|
||||
t.Errorf("wrong acd value: %s", strVal)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestTCDGetStringValue(t *testing.T) {
|
||||
@@ -1071,10 +1062,6 @@ func TestTCDAddOneEvent(t *testing.T) {
|
||||
if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "5m0s" {
|
||||
t.Errorf("wrong tcd value: %s", strVal)
|
||||
}
|
||||
tcd.RemEvent(ev2.ID)
|
||||
if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "5m0s" {
|
||||
t.Errorf("wrong tcd value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestACCGetStringValue(t *testing.T) {
|
||||
@@ -1370,10 +1357,6 @@ func TestACCAddOneEvent(t *testing.T) {
|
||||
if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" {
|
||||
t.Errorf("wrong acc value: %s", strVal)
|
||||
}
|
||||
acc.RemEvent(ev2.ID)
|
||||
if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" {
|
||||
t.Errorf("wrong acc value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTCCGetStringValue(t *testing.T) {
|
||||
@@ -1674,10 +1657,6 @@ func TestTCCAddOneEvent(t *testing.T) {
|
||||
if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" {
|
||||
t.Errorf("wrong tcc value: %s", strVal)
|
||||
}
|
||||
tcc.RemEvent(ev2.ID)
|
||||
if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" {
|
||||
t.Errorf("wrong tcc value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPDDGetStringValue(t *testing.T) {
|
||||
@@ -2041,10 +2020,6 @@ func TestPDDAddOneEvent(t *testing.T) {
|
||||
if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" {
|
||||
t.Errorf("wrong pdd value: %s", strVal)
|
||||
}
|
||||
pdd.RemEvent(ev2.ID)
|
||||
if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" {
|
||||
t.Errorf("wrong pdd value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDDCGetStringValue(t *testing.T) {
|
||||
@@ -2281,10 +2256,6 @@ func TestDDCAddOneEvent(t *testing.T) {
|
||||
if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" {
|
||||
t.Errorf("wrong statDistinct value: %s", strVal)
|
||||
}
|
||||
statDistinct.RemEvent(ev.ID)
|
||||
if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" {
|
||||
t.Errorf("wrong statDistinct value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatSumGetFloat64Value(t *testing.T) {
|
||||
@@ -2585,10 +2556,6 @@ func TestStatSumAddOneEvent(t *testing.T) {
|
||||
if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" {
|
||||
t.Errorf("wrong statSum value: %s", strVal)
|
||||
}
|
||||
statSum.RemEvent(ev2.ID)
|
||||
if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" {
|
||||
t.Errorf("wrong statSum value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatAverageGetFloat64Value(t *testing.T) {
|
||||
@@ -2888,10 +2855,6 @@ func TestStatAverageAddOneEvent(t *testing.T) {
|
||||
if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" {
|
||||
t.Errorf("wrong statAvg value: %s", strVal)
|
||||
}
|
||||
statAvg.RemEvent(ev2.ID)
|
||||
if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" {
|
||||
t.Errorf("wrong statAvg value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatDistinctGetFloat64Value(t *testing.T) {
|
||||
@@ -3098,7 +3061,7 @@ func TestStatDistinctGetCompressFactor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatDistinct(t *testing.T) {
|
||||
func TestStatDistinctAddOneEvent(t *testing.T) {
|
||||
statDistinct, _ := NewStatDistinct(2, "~*req.Cost", []string{})
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]any{"Cost": "20"}}
|
||||
@@ -3116,10 +3079,6 @@ func TestStatDistinct(t *testing.T) {
|
||||
if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" {
|
||||
t.Errorf("wrong statDistinct value: %s", strVal)
|
||||
}
|
||||
statDistinct.RemEvent(ev.ID)
|
||||
if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" {
|
||||
t.Errorf("wrong statDistinct value: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
var jMarshaler JSONMarshaler
|
||||
|
||||
Reference in New Issue
Block a user