From db6a62db3ca3ae589aceb511f63a0aad1d1f2072 Mon Sep 17 00:00:00 2001 From: Ian Bucad Date: Fri, 29 Jan 2021 16:10:19 +1100 Subject: [PATCH 1/2] test bean refresh --- .../org/datadog/jmxfetch/TestInstance.java | 48 +++++++++++++++++++ src/test/resources/jmx_refresh_beans.yaml | 14 ++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/resources/jmx_refresh_beans.yaml diff --git a/src/test/java/org/datadog/jmxfetch/TestInstance.java b/src/test/java/org/datadog/jmxfetch/TestInstance.java index bd59493a6..5f7cf5af2 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(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()); + } } diff --git a/src/test/resources/jmx_refresh_beans.yaml b/src/test/resources/jmx_refresh_beans.yaml new file mode 100644 index 000000000..3440b5458 --- /dev/null +++ b/src/test/resources/jmx_refresh_beans.yaml @@ -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 From 66f77d8d5190d4ccb7043f4da5734abcb19ea466 Mon Sep 17 00:00:00 2001 From: Ian Bucad Date: Mon, 1 Feb 2021 12:47:44 +1100 Subject: [PATCH 2/2] reduce sleep time --- src/test/java/org/datadog/jmxfetch/TestInstance.java | 6 +++--- src/test/resources/jmx_refresh_beans.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/datadog/jmxfetch/TestInstance.java b/src/test/java/org/datadog/jmxfetch/TestInstance.java index 5f7cf5af2..fcf303415 100644 --- a/src/test/java/org/datadog/jmxfetch/TestInstance.java +++ b/src/test/java/org/datadog/jmxfetch/TestInstance.java @@ -164,7 +164,7 @@ public void testRefreshBeans() throws Exception { // We register an additional mbean registerMBean(testApp, "org.datadog.jmxfetch.test:iteration=one"); log.info("sleeping before the next collection"); - Thread.sleep(5000); + Thread.sleep(1500); // We run a second collection. refresh_beans_initial should be due. run(); @@ -176,7 +176,7 @@ public void testRefreshBeans() throws Exception { // We register additional mbean registerMBean(testApp, "org.datadog.jmxfetch.test:iteration=two"); log.info("sleeping before the next collection"); - Thread.sleep(5000); + Thread.sleep(1500); // We run a third collection. No change expected; refresh_beans not due. run(); @@ -186,7 +186,7 @@ public void testRefreshBeans() throws Exception { assertEquals(15, metrics.size()); log.info("sleeping before the next collection"); - Thread.sleep(5000); + Thread.sleep(1500); // We run the last collection. refresh_beans should be due. run(); diff --git a/src/test/resources/jmx_refresh_beans.yaml b/src/test/resources/jmx_refresh_beans.yaml index 3440b5458..cf892dca6 100644 --- a/src/test/resources/jmx_refresh_beans.yaml +++ b/src/test/resources/jmx_refresh_beans.yaml @@ -2,9 +2,9 @@ init_config: instances: - process_name_regex: .*surefire.* - min_collection_interval: 5 - refresh_beans_initial: 5 - refresh_beans: 10 + min_collection_interval: 1 + refresh_beans_initial: 1 + refresh_beans: 3 name: jmx_test_instance conf: - include: