@Test
public void kafkaReporterTagsTest() throws IOException {
MetricContext metricContext =
MetricContext.builder(this.getClass().getCanonicalName() + ".kafkaReporterTagsTest").build();
Counter counter = metricContext.counter("com.linkedin.example.counter");
Tag<?> tag1 = new Tag<>("tag1", "value1");
Tag<?> tag2 = new Tag<>("tag2", 2);
MockKafkaPusher pusher = new MockKafkaPusher();
KafkaReporter kafkaReporter =
getBuilder(pusher).withTags(Lists.newArrayList(tag1, tag2)).build("localhost:0000", "topic", new Properties());
counter.inc();
kafkaReporter.report(metricContext);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
MetricReport metricReport = nextReport(pusher.messageIterator());
Assert.assertEquals(4, metricReport.getTags().size());
Assert.assertTrue(metricReport.getTags().containsKey(tag1.getKey()));
Assert.assertEquals(metricReport.getTags().get(tag1.getKey()), tag1.getValue().toString());
Assert.assertTrue(metricReport.getTags().containsKey(tag2.getKey()));
Assert.assertEquals(metricReport.getTags().get(tag2.getKey()), tag2.getValue().toString());
}