Skip to content

Commit

Permalink
test bean refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
ian28223 committed Jan 29, 2021
1 parent 7866ef6 commit db6a62d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
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(5000);

// 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(5000);

// 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(5000);

// 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: 5
refresh_beans_initial: 5
refresh_beans: 10
name: jmx_test_instance
conf:
- include:
domain: org.datadog.jmxfetch.test
attribute:
- ShouldBe100
- ShouldBe1000

0 comments on commit db6a62d

Please sign in to comment.