use of com.srotya.sidewinder.core.api.grafana.GrafanaOutputv2 in project sidewinder by srotya.
the class GrafanaStreamingOutput method serializeOutput.
private boolean serializeOutput(OutputStream os, Iterator<GrafanaOutputv2> itr) throws IOException {
GrafanaOutputv2 gOutput = itr.next();
if (gOutput.getPointsIterator() != null) {
DataPointIterator pointsIterator = gOutput.getPointsIterator();
if (pointsIterator.hasNext()) {
os.write(("{\"target\":\"" + gOutput.getTarget() + "\",\"datapoints\":[").getBytes());
serializePoint(os, pointsIterator, gOutput);
while (pointsIterator.hasNext()) {
os.write(',');
serializePoint(os, pointsIterator, gOutput);
}
os.write(']');
os.write('}');
return true;
} else {
return false;
}
} else {
return false;
}
}
use of com.srotya.sidewinder.core.api.grafana.GrafanaOutputv2 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());
}
Aggregations