From cdd63c2154dd1df586b0d9021150d594b0a5ee1f Mon Sep 17 00:00:00 2001 From: childe Date: Wed, 6 Mar 2019 11:16:02 +0800 Subject: [PATCH] stats & setBelongto --- filter/link_metric_test.go | 8 ++++---- filter/link_stats_metric_test.go | 33 ++++++++++++-------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/filter/link_metric_test.go b/filter/link_metric_test.go index 95b50e53..dd9e3e28 100644 --- a/filter/link_metric_test.go +++ b/filter/link_metric_test.go @@ -86,7 +86,7 @@ func TestLinkMetricFilter(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkMetricEvents(now) { @@ -222,7 +222,7 @@ func TestLinkMetricFilterWindowOffset(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkMetricEvents(now) { @@ -399,7 +399,7 @@ func TestLinkMetricFilterCumulativeMode(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkMetricEvents(now) { @@ -436,7 +436,7 @@ func TestLinkMetricFilterSeparateMode(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkMetricEvents(now) { diff --git a/filter/link_stats_metric_test.go b/filter/link_stats_metric_test.go index 3d59fbb3..f582137c 100644 --- a/filter/link_stats_metric_test.go +++ b/filter/link_stats_metric_test.go @@ -30,7 +30,7 @@ func TestLinkStatsMetricFilter(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkStatsMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkStatsMetricEvents(now) { @@ -98,13 +98,10 @@ func TestLinkStatsMetricFilter(t *testing.T) { if len(localhost_metric["200"].(map[interface{}]interface{})) != 1 { t.Errorf("%v", f.metricToEmit[ts]) } - if len(localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)) != 2 { - t.Errorf("%v", f.metricToEmit[ts]) - } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["count"] != 2 { + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).count != 2 { t.Errorf("_10->localhost->200->responseTime-count should be 2") } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["sum"] != 20.4 { + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).sum != 20.4 { t.Errorf("_10->localhost->200->responseTime-sum should be 20.4") } } @@ -129,7 +126,7 @@ func TestLinkStatsMetricFilterWindowOffset(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkStatsMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkStatsMetricEvents(now) { @@ -197,18 +194,15 @@ func TestLinkStatsMetricFilterWindowOffset(t *testing.T) { if len(localhost_metric["200"].(map[interface{}]interface{})) != 1 { t.Errorf("%v", f.metricToEmit[ts]) } - if len(localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)) != 2 { - t.Errorf("%v", f.metricToEmit[ts]) - } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["count"] != 2 { + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).count != 2 { t.Errorf("_10->localhost->200->responseTime-count should be 2") } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["sum"] != 20.4 { + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).sum != 20.4 { t.Errorf("_10->localhost->200->responseTime-sum should be 20.4") } } -func _testLinkStatsMetricFilterAccumulateMode(t *testing.T, f *LinkStatsMetricFilter, now int64, count, sum float64) { +func _testLinkStatsMetricFilterAccumulateMode(t *testing.T, f *LinkStatsMetricFilter, now int64, count int, sum float64) { if len(f.metricToEmit) != 4 { t.Error(f.metricToEmit) } @@ -257,13 +251,10 @@ func _testLinkStatsMetricFilterAccumulateMode(t *testing.T, f *LinkStatsMetricFi if len(localhost_metric["200"].(map[interface{}]interface{})) != 1 { t.Errorf("%v", f.metricToEmit[ts]) } - if len(localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)) != 2 { - t.Errorf("%v", f.metricToEmit[ts]) - } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["count"] != count { - t.Errorf("_10->localhost->200->responseTime-count should be %f", count) + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).count != count { + t.Errorf("_10->localhost->200->responseTime-count should be %d", count) } - if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(map[string]float64)["sum"] != sum { + if localhost_metric["200"].(map[interface{}]interface{})["responseTime"].(*stats).sum != sum { t.Errorf("_10->localhost->200->responseTime-sum should be %f", sum) } } @@ -288,7 +279,7 @@ func TestLinkStatsMetricFilterCumulativeMode(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkStatsMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkStatsMetricEvents(now) { @@ -325,7 +316,7 @@ func TestLinkStatsMetricFilterSeparateMode(t *testing.T) { config["drop_original_event"] = drop_original_event f = NewLinkStatsMetricFilter(config) - f.SetNexter(&NilNexter{}) + f.SetBelongTo(NewFilterBox(config)) now := time.Now().Unix() for _, event := range createLinkStatsMetricEvents(now) {