From 3128d29d4605c25a495b55e4476acb1543afdf96 Mon Sep 17 00:00:00 2001 From: jasper-zhang Date: Thu, 11 Jan 2018 19:35:09 +0800 Subject: [PATCH] add unit test --- pom.xml | 6 +++ .../kafka/KafkaInfluxDBMetricsReporter.java | 2 +- .../KafkaInfluxDBMetricsReporterTest.java | 38 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporterTest.java diff --git a/pom.xml b/pom.xml index 9a692b2..03c510e 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,12 @@ influxdb-java 2.7 + + junit + junit + 4.12 + test + diff --git a/src/main/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporter.java b/src/main/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporter.java index bb41f78..3218e0f 100644 --- a/src/main/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporter.java +++ b/src/main/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporter.java @@ -50,7 +50,7 @@ public synchronized void startReporter(long pollingPeriodSecs) { if (initialized && !running) { reporter.start(pollingPeriodSecs, TimeUnit.SECONDS); running = true; - LOG.info("Started Kafka Graphite metrics reporter with polling period {} seconds", pollingPeriodSecs); + LOG.info("Started Kafka InfluxDB metrics reporter with polling period {} seconds", pollingPeriodSecs); } } diff --git a/src/test/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporterTest.java b/src/test/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporterTest.java new file mode 100644 index 0000000..3070e71 --- /dev/null +++ b/src/test/java/com/github/jasper/kafka/KafkaInfluxDBMetricsReporterTest.java @@ -0,0 +1,38 @@ +package com.github.jasper.kafka; + +import kafka.utils.VerifiableProperties; + +import java.util.Properties; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class KafkaInfluxDBMetricsReporterTest { + + @Test + public void initWithoutPropertiesSet() { + KafkaInfluxDBMetricsReporter reporter = new KafkaInfluxDBMetricsReporter(); + reporter.init(new VerifiableProperties()); + } + + @Test + public void initStartStopWithPropertiesSet() { + KafkaInfluxDBMetricsReporter reporter = new KafkaInfluxDBMetricsReporter(); + Properties properties = new Properties(); + properties.setProperty("kafka.graphite.metrics.reporter.enabled", "true"); + + reporter.init(new VerifiableProperties(properties)); + + reporter.startReporter(1L); + reporter.stopReporter(); + } + + + @Test + public void getMBeanName() { + KafkaInfluxDBMetricsReporter reporter = new KafkaInfluxDBMetricsReporter(); + assertEquals("kafka:type=com.github.jasper.kafka.KafkaInfluxDBMetricsReporter", reporter.getMBeanName()); + + } +}