diff --git a/src/test/java/org/datadog/jmxfetch/TestInstance.java b/src/test/java/org/datadog/jmxfetch/TestInstance.java index bd59493a6..fcf303415 100644 --- a/src/test/java/org/datadog/jmxfetch/TestInstance.java +++ b/src/test/java/org/datadog/jmxfetch/TestInstance.java @@ -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> 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()); + } } diff --git a/src/test/resources/jmx_refresh_beans.yaml b/src/test/resources/jmx_refresh_beans.yaml new file mode 100644 index 000000000..cf892dca6 --- /dev/null +++ b/src/test/resources/jmx_refresh_beans.yaml @@ -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