@Test public void metricsAreFormattedCorrectly() throws IOException { StringWriter writer = new StringWriter(); SensuWriter2 sensuWriter = new SensuWriter2(new GraphiteWriter2(ImmutableList.<String>of(), null), new JsonFactory()); sensuWriter.write(writer, ServerFixtures.dummyServer(), QueryFixtures.dummyQuery(), ResultFixtures.dummyResults()); String lineSep = System.lineSeparator(); assertThat(writer.toString()).isEqualTo( "{" + lineSep + " \"name\" : \"jmxtrans\"," + lineSep + " \"type\" : \"metric\"," + lineSep + " \"handler\" : \"graphite\"," + lineSep + " \"output\" : \"host_example_net_4321.MemoryAlias.ObjectPendingFinalizationCount 10 0\\n\"" + lineSep + "}"); }
@Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); StringWriter temporaryWriter = new StringWriter() ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("name", "jmxtrans"); g.writeStringField("type", "metric"); g.writeStringField("handler", "graphite"); graphiteWriter.write(temporaryWriter, server, query, results); g.writeStringField("output", temporaryWriter.toString()); g.writeEndObject(); g.flush(); } }
SensuWriter2 implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); StringWriter temporaryWriter = new StringWriter() ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("name", "jmxtrans"); g.writeStringField("type", "metric"); g.writeStringField("handler", "graphite"); graphiteWriter.write(temporaryWriter, server, query, results); g.writeStringField("output", temporaryWriter.toString()); g.writeEndObject(); g.flush(); } } }
SensuWriter2 implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); StringWriter temporaryWriter = new StringWriter() ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("name", "jmxtrans"); g.writeStringField("type", "metric"); g.writeStringField("handler", "graphite"); graphiteWriter.write(temporaryWriter, server, query, results); g.writeStringField("output", temporaryWriter.toString()); g.writeEndObject(); g.flush(); } } SensuWriter2(@Nonnull GraphiteWriter2 graphiteWriter, @Nonnull JsonFactory jsonFactory); }
SensuWriter2 implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); StringWriter temporaryWriter = new StringWriter() ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("name", "jmxtrans"); g.writeStringField("type", "metric"); g.writeStringField("handler", "graphite"); graphiteWriter.write(temporaryWriter, server, query, results); g.writeStringField("output", temporaryWriter.toString()); g.writeEndObject(); g.flush(); } } SensuWriter2(@Nonnull GraphiteWriter2 graphiteWriter, @Nonnull JsonFactory jsonFactory); @Override void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results); }
SensuWriter2 implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); StringWriter temporaryWriter = new StringWriter() ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("name", "jmxtrans"); g.writeStringField("type", "metric"); g.writeStringField("handler", "graphite"); graphiteWriter.write(temporaryWriter, server, query, results); g.writeStringField("output", temporaryWriter.toString()); g.writeEndObject(); g.flush(); } } SensuWriter2(@Nonnull GraphiteWriter2 graphiteWriter, @Nonnull JsonFactory jsonFactory); @Override void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results);  }