Skip to content

Commit

Permalink
Clean up instance telemetry bean in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rayz committed Oct 11, 2023
1 parent 93e6f90 commit f6d5978
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static int getLoopCounter() {
return loopCounter;
}

private void clearInstances(final Collection<Instance> instances) {
protected void clearInstances(final Collection<Instance> instances) {
final List<InstanceTask<Void>> cleanupInstanceTasks =
new ArrayList<>(instances.size());
for (final Instance instance : instances) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/jmx_counter_rate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/jmx_sd_pipe_longname.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down

0 comments on commit f6d5978

Please sign in to comment.