diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index ddb6f1de8..5caf237f3 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -197,7 +197,7 @@ public static int getLoopCounter() { return loopCounter; } - private void clearInstances(final Collection instances) { + protected void clearInstances(final Collection instances) { final List> cleanupInstanceTasks = new ArrayList<>(instances.size()); for (final Instance instance : instances) { diff --git a/src/test/java/org/datadog/jmxfetch/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java index e5cadcfac..554463d64 100644 --- a/src/test/java/org/datadog/jmxfetch/TestCommon.java +++ b/src/test/java/org/datadog/jmxfetch/TestCommon.java @@ -110,6 +110,16 @@ public void unregisterMBean() throws MBeanRegistrationException, InstanceNotFoun } } + /** + * Clear instances and their instance telemetry bean after execution of every test. + */ + @After + public void clearInstances() { + if (app != null) { + app.clearInstances(getInstances()); + } + } + /** Init JMXFetch with the given YAML configuration file. */ protected void initApplication(String yamlFileName, String autoDiscoveryPipeFile) throws FileNotFoundException, IOException { diff --git a/src/test/resources/jmx_counter_rate.yaml b/src/test/resources/jmx_counter_rate.yaml index ab58e7aad..4485994ee 100644 --- a/src/test/resources/jmx_counter_rate.yaml +++ b/src/test/resources/jmx_counter_rate.yaml @@ -3,7 +3,7 @@ init_config: instances: - process_name_regex: .*surefire.* refresh_beans: 4 - name: jmx_test_instance + name: jmx_test_instance1 conf: - include: domain: org.datadog.jmxfetch.test @@ -13,7 +13,7 @@ instances: alias: test.counter - process_name_regex: .*surefire.* refresh_beans: 4 - name: jmx_test_instance + name: jmx_test_instance2 conf: - include: domain: org.datadog.jmxfetch.test diff --git a/src/test/resources/jmx_sd_pipe.txt b/src/test/resources/jmx_sd_pipe.txt index be9ef7688..2c277e77b 100644 --- a/src/test/resources/jmx_sd_pipe.txt +++ b/src/test/resources/jmx_sd_pipe.txt @@ -4,7 +4,7 @@ init_config: instances: - process_name_regex: .*surefire.* - name: jmx_first_instance + name: jmx_first_instance1 cassandra_aliasing: true conf: - include: @@ -12,7 +12,7 @@ instances: attribute: - ShouldBe100 - process_name_regex: .*surefire.* - name: jmx_second_instance + name: jmx_second_instance2 conf: - include: bean: org.apache.cassandra.metrics:keyspace=MyKeySpace,type=ColumnFamily,scope=MyColumnFamily,name=PendingTasks @@ -25,7 +25,7 @@ init_config: instances: - process_name_regex: .*surefire.* - name: jmx_test_instance + name: jmx_test_instance3 conf: - include: bean: org.datadog.jmxfetch.test:type=SimpleTestJavaApp,scope=Co|olScope,host=localhost,component= diff --git a/src/test/resources/jmx_sd_pipe_longname.txt b/src/test/resources/jmx_sd_pipe_longname.txt index d1f58c2ee..f528209f0 100644 --- a/src/test/resources/jmx_sd_pipe_longname.txt +++ b/src/test/resources/jmx_sd_pipe_longname.txt @@ -4,7 +4,7 @@ init_config: instances: - process_name_regex: .*surefire.* - name: jmx_test_instance + name: jmx_test_instance1 conf: - include: bean: org.datadog.jmxfetch.test:type=SimpleTestJavaApp,scope=Co|olScope,host=localhost,component= @@ -25,7 +25,7 @@ init_config: instances: - process_name_regex: .*surefire.* - name: jmx_test_instance + name: jmx_test_instance2 conf: - include: bean: org.datadog.jmxfetch.test:type=SimpleTestJavaApp,scope=Co|olScope,host=localhost,component=