diff --git a/pom.xml b/pom.xml
index 18cd989b3..3b1ab826d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -200,7 +200,13 @@
org.testcontainers
testcontainers
- 1.18.0
+ 1.19.3
+ test
+
+
+ org.hamcrest
+ hamcrest-library
+ 1.3
test
diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java
index 1cc3b91f9..9da8de750 100644
--- a/src/main/java/org/datadog/jmxfetch/Instance.java
+++ b/src/main/java/org/datadog/jmxfetch/Instance.java
@@ -16,7 +16,6 @@
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
diff --git a/src/test/java/org/datadog/jmxfetch/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java
index edb8bde68..49fb77a12 100644
--- a/src/test/java/org/datadog/jmxfetch/TestCommon.java
+++ b/src/test/java/org/datadog/jmxfetch/TestCommon.java
@@ -1,9 +1,5 @@
package org.datadog.jmxfetch;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -19,11 +15,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
@@ -31,12 +24,15 @@
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
+
+import org.junit.After;
+import org.junit.BeforeClass;
+
import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.util.CustomLogger;
+import org.datadog.jmxfetch.util.MetricsAssert;
import org.datadog.jmxfetch.util.LogLevel;
-import org.junit.After;
-import org.junit.BeforeClass;
final class ConfigUtil {
public static Path writeConfigYamlToTemp(String content, String yamlName) throws IOException {
@@ -261,49 +257,7 @@ public void assertMetric(
List additionalTags,
int countTags,
String metricType) {
- List tags = new ArrayList(commonTags);
- tags.addAll(additionalTags);
-
- for (Map m : metrics) {
- String mName = (String) (m.get("name"));
- Double mValue = (Double) (m.get("value"));
- Set mTags = new HashSet(Arrays.asList((String[]) (m.get("tags"))));
-
- if (mName.equals(name)) {
-
- if (!value.equals(-1)) {
- assertEquals((Double) value.doubleValue(), mValue);
- } else if (!lowerBound.equals(-1) || !upperBound.equals(-1)) {
- assertTrue(mValue > (Double) lowerBound.doubleValue());
- assertTrue(mValue < (Double) upperBound.doubleValue());
- }
-
- if (countTags != -1) {
- assertEquals(countTags, mTags.size());
- }
- for (String t : tags) {
- assertThat(mTags, hasItem(t));
- }
-
- if (metricType != null) {
- assertEquals(metricType, m.get("type"));
- }
- // Brand the metric
- m.put("tested", true);
-
- return;
- }
- }
- fail(
- "Metric assertion failed (name: "
- + name
- + ", value: "
- + value
- + ", tags: "
- + tags
- + ", #tags: "
- + countTags
- + ").");
+ MetricsAssert.assertMetric(name, value, lowerBound, upperBound, commonTags, additionalTags, countTags, metricType, this.metrics);
}
public void assertMetric(
diff --git a/src/test/java/org/datadog/jmxfetch/TestGCMetrics.java b/src/test/java/org/datadog/jmxfetch/TestGCMetrics.java
new file mode 100644
index 000000000..fdb5f4d45
--- /dev/null
+++ b/src/test/java/org/datadog/jmxfetch/TestGCMetrics.java
@@ -0,0 +1,214 @@
+package org.datadog.jmxfetch;
+
+import static org.datadog.jmxfetch.util.MetricsAssert.*;
+import static org.datadog.jmxfetch.util.server.JDKImage.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.junit.Test;
+
+import org.datadog.jmxfetch.reporter.ConsoleReporter;
+import org.datadog.jmxfetch.util.MetricsAssert;
+import org.datadog.jmxfetch.util.server.MisbehavingJMXServer;
+import org.datadog.jmxfetch.util.server.SimpleAppContainer;
+
+@Slf4j
+public class TestGCMetrics extends TestCommon {
+
+ @Test
+ public void testJMXDirectBasic() throws Exception {
+ try (final SimpleAppContainer container = new SimpleAppContainer()) {
+ container.start();
+ final String ipAddress = container.getIp();
+ final String remoteJmxServiceUrl = String.format(
+ "service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", ipAddress, container.getRMIPort());
+ final JMXServiceURL jmxUrl = new JMXServiceURL(remoteJmxServiceUrl);
+ final JMXConnector conn = JMXConnectorFactory.connect(jmxUrl);
+ final MBeanServerConnection mBeanServerConnection = conn.getMBeanServerConnection();
+ assertDomainPresent("java.lang", mBeanServerConnection);
+ }
+ }
+
+ @Test
+ public void testDefaultOldGC() throws IOException {
+ try (final MisbehavingJMXServer server = new MisbehavingJMXServer.Builder().build()) {
+ final List