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 17, 2023
1 parent 93e6f90 commit 513e7c0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public TaskStatusHandler invoke(
}
}

protected void clearAllInstances() {
this.clearInstances(this.instances);
}

/**
* Builds an {@link ExecutorService} of the specified fixed size. Threads will be created
* and executed as daemons if {@link AppConfig#isDaemon()} is true. Defaults to false.
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testRegexpAliasing() throws Exception {
List<String> tags =
Arrays.asList(
"jmx_domain:org.datadog.jmxfetch.test",
"instance:jmx_test_instance",
"instance:jmx_test_instance1",
"foo:Bar",
"qux:Baz");

Expand Down Expand Up @@ -963,7 +963,7 @@ public void testServiceDiscovery() throws Exception {
List<String> tags = Arrays.asList(
"type:SimpleTestJavaApp",
"scope:CoolScope",
"instance:jmx_test_instance",
"instance:jmx_test_instance2",
"jmx_domain:org.datadog.jmxfetch.test",
"bean_host:localhost",
"component"
Expand Down Expand Up @@ -998,7 +998,7 @@ public void testServiceDiscovery() throws Exception {
tags =
Arrays.asList(
"jmx_domain:org.datadog.jmxfetch.test",
"instance:jmx_test_instance",
"instance:jmx_test_instance1",
"foo:Bar",
"qux:Baz");

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.clearAllInstances();
}
}

/** Init JMXFetch with the given YAML configuration file. */
protected void initApplication(String yamlFileName, String autoDiscoveryPipeFile)
throws FileNotFoundException, IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/jmx_alias_match.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ init_config:

instances:
- process_name_regex: .*surefire.*
name: jmx_test_instance
name: jmx_test_instance1
conf:
- include:
domain: org.datadog.jmxfetch.test
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
2 changes: 1 addition & 1 deletion src/test/resources/jmx_sd_pipe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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_instance2
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_instance3
conf:
- include:
bean: org.datadog.jmxfetch.test:type=SimpleTestJavaApp,scope=Co|olScope,host=localhost,component=
Expand Down

0 comments on commit 513e7c0

Please sign in to comment.