From f6d5978b7f3d78f886128e33417b122257bd8412 Mon Sep 17 00:00:00 2001 From: raymond zhao Date: Wed, 11 Oct 2023 17:06:33 -0400 Subject: [PATCH] Clean up instance telemetry bean in tests --- src/main/java/org/datadog/jmxfetch/App.java | 2 +- src/test/java/org/datadog/jmxfetch/TestCommon.java | 10 ++++++++++ src/test/resources/jmx_counter_rate.yaml | 4 ++-- src/test/resources/jmx_sd_pipe_longname.txt | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) 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_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=