Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
update test code
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverneverer committed Jun 5, 2020
1 parent 21ef387 commit 2421673
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class MetricsPool {

private final MetricRegistry registry = new MetricRegistry();
public static MetricsReporter reporter;
private static PegasusCollector collector;
public static PegasusCollector collector;

public MetricsPool(String host, String tags, int reportStepSec, String type) {
metricType = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public void before() {
public void genJsonsFromMeter() throws Exception {
String host = "simple-test-host.bj";
String tags = "what=you,like=another";
MetricsPool pool = new MetricsPool(host, tags, 20);
Falcon falcon = new Falcon(host, tags, 20, r);
Meter m = r.meter("TestName");

m.mark(1);
m.mark(1);

StringBuilder builder = new StringBuilder();
pool.genJsonsFromMeter("TestName", m, builder);
falcon.genJsonsFromMeter("TestName", m, builder);

JSONArray array = new JSONArray("[" + builder.toString() + "]");
Assert.assertEquals(1, array.length());
Expand All @@ -54,12 +54,12 @@ public void genJsonsFromMeter() throws Exception {
public void genJsonFromHistogram() throws Exception {
String host = "simple-test-host.bj";
String tags = "what=you,like=another";
MetricsPool pool = new MetricsPool(host, tags, 20);
Falcon falcon = new Falcon(host, tags, 20, r);
Histogram h = r.histogram("TestHist");
for (int i = 0; i < 1000000; ++i) h.update((long) i);

StringBuilder builder = new StringBuilder();
pool.genJsonsFromHistogram("TestHist", h, builder);
falcon.genJsonsFromHistogram("TestHist", h, builder);

JSONArray array = new JSONArray("[" + builder.toString() + "]");
Assert.assertEquals(2, array.length());
Expand All @@ -79,7 +79,7 @@ public void genJsonFromHistogram() throws Exception {

@Test
public void oneMetricToJson() throws Exception {
MetricsPool.FalconMetric metric = new MetricsPool.FalconMetric();
Falcon.FalconMetric metric = new Falcon.FalconMetric();
metric.endpoint = "1.2.3.4";
metric.metric = "simple_metric";
metric.timestamp = 12343455L;
Expand All @@ -89,7 +89,7 @@ public void oneMetricToJson() throws Exception {
metric.tags = "cluster=onebox,app=new";

StringBuilder builder = new StringBuilder();
MetricsPool.oneMetricToJson(metric, builder);
Falcon.oneMetricToJson(metric, builder);

JSONObject obj = new JSONObject(builder.toString());
Assert.assertEquals(metric.endpoint, obj.getString("endpoint"));
Expand All @@ -102,7 +102,7 @@ public void oneMetricToJson() throws Exception {

builder.setLength(0);
metric.tags = "";
MetricsPool.oneMetricToJson(metric, builder);
Falcon.oneMetricToJson(metric, builder);
obj = new JSONObject(builder.toString());
Assert.assertEquals(metric.endpoint, obj.getString("endpoint"));
Assert.assertEquals(metric.metric, obj.getString("metric"));
Expand All @@ -117,7 +117,7 @@ public void oneMetricToJson() throws Exception {
public void metricsToJson() throws Exception {
String host = "simple-test-host.bj";
String tags = "what=you,like=another";
MetricsPool pool = new MetricsPool(host, tags, 20);
MetricsPool pool = new MetricsPool(host, tags, 20, "falcon");

pool.setMeter("aaa@temp", 1);
pool.setMeter("aaa", 2);
Expand All @@ -127,7 +127,7 @@ public void metricsToJson() throws Exception {
pool.setHistorgram("ccc@temp", i);
}

JSONArray array = new JSONArray(pool.metricsToJson());
JSONArray array = new JSONArray(MetricsPool.collector.updateMetric());
Assert.assertEquals(6, array.length());
for (int i = 0; i < array.length(); ++i) {
JSONObject j = array.getJSONObject(i);
Expand Down

0 comments on commit 2421673

Please sign in to comment.