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

Add tests for refresh_beans and refresh_beans_initial #351

Merged
merged 2 commits into from
Feb 5, 2021
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
48 changes: 48 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,52 @@ public void testLoadMetricConfigResources() throws Exception {

assertEquals(2, configurationList.size());
}

/** Tests refresh_beans_initial and the following refresh_beans */
@Test
public void testRefreshBeans() throws Exception {
SimpleTestJavaApp testApp = new SimpleTestJavaApp();
initApplication("jmx_refresh_beans.yaml");

// We do a first collection
run();
List<Map<String, Object>> metrics = getMetrics();

// 13 metrics from java.lang
assertEquals(13, metrics.size());

// We register an additional mbean
registerMBean(testApp, "org.datadog.jmxfetch.test:iteration=one");
log.info("sleeping before the next collection");
Thread.sleep(1500);

// We run a second collection. refresh_beans_initial should be due.
run();
metrics = getMetrics();

// 15 = 13 metrics from java.lang + 2 iteration=one
assertEquals(15, metrics.size());

// We register additional mbean
registerMBean(testApp, "org.datadog.jmxfetch.test:iteration=two");
log.info("sleeping before the next collection");
Thread.sleep(1500);

// We run a third collection. No change expected; refresh_beans not due.
run();
metrics = getMetrics();

// 15 = 13 metrics from java.lang + 2 iteration=one
assertEquals(15, metrics.size());

log.info("sleeping before the next collection");
Thread.sleep(1500);

// We run the last collection. refresh_beans should be due.
run();
metrics = getMetrics();

// 17 = 13 metrics from java.lang + 2 iteration=one + 2 iteration=two
assertEquals(17, metrics.size());
}
}
14 changes: 14 additions & 0 deletions src/test/resources/jmx_refresh_beans.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
init_config:

instances:
- process_name_regex: .*surefire.*
min_collection_interval: 1
refresh_beans_initial: 1
refresh_beans: 3
name: jmx_test_instance
conf:
- include:
domain: org.datadog.jmxfetch.test
attribute:
- ShouldBe100
- ShouldBe1000