Search in sources :

Example 1 with MockDataPointIterator

use of com.srotya.sidewinder.core.storage.MockDataPointIterator in project sidewinder by srotya.

the class TestGrafanaStreamingOutput method testJsonValidity.

@Test
public void testJsonValidity() throws WebApplicationException, IOException {
    GrafanaOutputv2 out1 = new GrafanaOutputv2("targetname1", false);
    out1.setPointsIterator(new MockDataPointIterator(Arrays.asList(new DataPoint(1L, 2L), new DataPoint(3L, 4L))));
    GrafanaStreamingOutput output = new GrafanaStreamingOutput(Arrays.asList(Arrays.asList(out1).iterator()));
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    output.write(os);
    String payload = new String(os.toByteArray());
    JsonArray ary = new Gson().fromJson(payload, JsonArray.class);
    assertEquals(1, ary.size());
    assertEquals(2, ary.get(0).getAsJsonObject().get("datapoints").getAsJsonArray().size());
    out1.setPointsIterator(new MockDataPointIterator(Arrays.asList(new DataPoint(1L, 2L), new DataPoint(3L, 4L))));
    GrafanaOutputv2 out2 = new GrafanaOutputv2("targetname2", false);
    out2.setPointsIterator(new MockDataPointIterator(Arrays.asList(new DataPoint(1L, 2L), new DataPoint(3L, 4L))));
    GrafanaOutputv2 out3 = new GrafanaOutputv2("targetname2", false);
    out3.setPointsIterator(new MockDataPointIterator(Arrays.asList(new DataPoint(1L, 2L))));
    GrafanaOutputv2 out4 = new GrafanaOutputv2("targetname2", false);
    out4.setPointsIterator(new MockDataPointIterator(Arrays.asList(new DataPoint(1L, 2L), new DataPoint(3L, 4L))));
    output = new GrafanaStreamingOutput(Arrays.asList(Arrays.asList(out1, out2).iterator(), Arrays.asList(out3, out4).iterator()));
    os = new ByteArrayOutputStream();
    output.write(os);
    payload = new String(os.toByteArray());
    ary = new Gson().fromJson(payload, JsonArray.class);
    assertEquals(4, ary.size());
    assertEquals(2, ary.get(0).getAsJsonObject().get("datapoints").getAsJsonArray().size());
    assertEquals(2, ary.get(1).getAsJsonObject().get("datapoints").getAsJsonArray().size());
    assertEquals(1, ary.get(2).getAsJsonObject().get("datapoints").getAsJsonArray().size());
}
Also used : JsonArray(com.google.gson.JsonArray) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) GrafanaOutputv2(com.srotya.sidewinder.core.api.grafana.GrafanaOutputv2) MockDataPointIterator(com.srotya.sidewinder.core.storage.MockDataPointIterator) Gson(com.google.gson.Gson) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 GrafanaOutputv2 (com.srotya.sidewinder.core.api.grafana.GrafanaOutputv2)1 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)1 MockDataPointIterator (com.srotya.sidewinder.core.storage.MockDataPointIterator)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.Test)1