Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up instance telemetry bean in tests #485

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading