@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()); }
@Override public void write(OutputStream os) throws IOException, WebApplicationException { os = new BufferedOutputStream(os, 8192); os.write('['); if (targets.size() > 0) { serializeEntry(os, 0); for (int i = 1; i < targets.size(); i++) { os.write(','); serializeEntry(os, i); } } os.write(']'); os.close(); }
GrafanaStreamingOutput implements StreamingOutput { @Override public void write(OutputStream os) throws IOException, WebApplicationException { os = new BufferedOutputStream(os, 8192); os.write('['); if (targets.size() > 0) { serializeEntry(os, 0); for (int i = 1; i < targets.size(); i++) { os.write(','); serializeEntry(os, i); } } os.write(']'); os.close(); } }
GrafanaStreamingOutput implements StreamingOutput { @Override public void write(OutputStream os) throws IOException, WebApplicationException { os = new BufferedOutputStream(os, 8192); os.write('['); if (targets.size() > 0) { serializeEntry(os, 0); for (int i = 1; i < targets.size(); i++) { os.write(','); serializeEntry(os, i); } } os.write(']'); os.close(); } GrafanaStreamingOutput(List<Iterator<GrafanaOutputv2>> output); }
GrafanaStreamingOutput implements StreamingOutput { @Override public void write(OutputStream os) throws IOException, WebApplicationException { os = new BufferedOutputStream(os, 8192); os.write('['); if (targets.size() > 0) { serializeEntry(os, 0); for (int i = 1; i < targets.size(); i++) { os.write(','); serializeEntry(os, i); } } os.write(']'); os.close(); } GrafanaStreamingOutput(List<Iterator<GrafanaOutputv2>> output); @Override void write(OutputStream os); }
GrafanaStreamingOutput implements StreamingOutput { @Override public void write(OutputStream os) throws IOException, WebApplicationException { os = new BufferedOutputStream(os, 8192); os.write('['); if (targets.size() > 0) { serializeEntry(os, 0); for (int i = 1; i < targets.size(); i++) { os.write(','); serializeEntry(os, i); } } os.write(']'); os.close(); } GrafanaStreamingOutput(List<Iterator<GrafanaOutputv2>> output); @Override void write(OutputStream os);  }