diff --git a/.travis.yml b/.travis.yml index 969c98a5..3096c49d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,6 @@ language: java + +jdk: + - oraclejdk8 + script: mvn verify diff --git a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentIT.java b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentIT.java index 9bb29a11..17052c07 100644 --- a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentIT.java +++ b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/JavaAgentIT.java @@ -14,7 +14,6 @@ import java.util.Collections; import java.util.List; -import org.junit.Assert; import org.junit.Test; public class JavaAgentIT { @@ -113,97 +112,4 @@ private String resolveRelativePathToResource(String resource) { final File workingDir = new File(new File(".").getAbsolutePath()); return "." + configwk.replace(workingDir.getParentFile().getAbsolutePath(), ""); } - - /** - * Test that the agent string argument is parsed properly. We expect the agent argument in one of these forms... - *
-     * {@code :}
-     * 
- *
-     * {@code ::}
-     * 
- * Since the ':' character is part of the spec for this arg, Windows-style paths could cause an issue with parsing. - * See https://github.com/prometheus/jmx_exporter/issues/312. - */ - @Test - public void testAgentStringParsing() { - final String DEFAULT_HOST = "0.0.0.0"; - - JavaAgent.Config config = JavaAgent.parseConfig("8080:config.yaml", DEFAULT_HOST); - Assert.assertEquals(DEFAULT_HOST, config.host); - Assert.assertEquals("config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - config = JavaAgent.parseConfig("8080:/unix/path/config.yaml", DEFAULT_HOST); - Assert.assertEquals(DEFAULT_HOST, config.host); - Assert.assertEquals("/unix/path/config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - config = JavaAgent.parseConfig("google.com:8080:/unix/path/config.yaml", DEFAULT_HOST); - Assert.assertEquals("google.com", config.host); - Assert.assertEquals("/unix/path/config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - config = JavaAgent.parseConfig("127.0.0.1:8080:/unix/path/config.yaml", DEFAULT_HOST); - Assert.assertEquals("127.0.0.1", config.host); - Assert.assertEquals("/unix/path/config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - config = JavaAgent.parseConfig("8080:\\Windows\\Local\\Drive\\Path\\config.yaml", DEFAULT_HOST); - Assert.assertEquals(DEFAULT_HOST, config.host); - Assert.assertEquals("\\Windows\\Local\\Drive\\Path\\config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - // the following check was previously failing to parse the file correctly - config = JavaAgent.parseConfig("8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); - Assert.assertEquals(DEFAULT_HOST, config.host); - Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - // the following check was previously failing to parse the file correctly - config = JavaAgent.parseConfig("google.com:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); - Assert.assertEquals("google.com", config.host); - Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - // the following check was previously failing to parse the file correctly - config = JavaAgent.parseConfig("127.0.0.1:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); - Assert.assertEquals("127.0.0.1", config.host); - Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); - Assert.assertEquals(8080, config.port); - } - - /** - * If someone is specifying an ipv6 address and a host name, this should be rejected. - */ - @Test(expected = IllegalArgumentException.class) - public void testRejectInvalidInput() { - JavaAgent.parseConfig("[2001:0db8:0000:0042:0000:8a2e:0370:7334]:localhost:8080:config.yaml", "0.0.0.0"); - } - - /** - * Similarly to the test above, two host names - */ - @Test(expected = IllegalArgumentException.class) - public void testRejectInvalidInput2() { - JavaAgent.parseConfig("127.0.0.1:localhost:8080:config.yaml", "0.0.0.0"); - } - - /** - * Exercise the existing Ipv6 parsing logic. The current logic leaves the brackets on the host. - */ - @Test - public void testIpv6AddressParsing() { - final String DEFAULT_HOST = "0.0.0.0"; - - JavaAgent.Config config = JavaAgent.parseConfig("[1:2:3:4]:8080:config.yaml", DEFAULT_HOST); - Assert.assertEquals("[1:2:3:4]", config.host); - Assert.assertEquals("config.yaml", config.file); - Assert.assertEquals(8080, config.port); - - config = JavaAgent.parseConfig("[2001:0db8:0000:0042:0000:8a2e:0370:7334]:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); - Assert.assertEquals("[2001:0db8:0000:0042:0000:8a2e:0370:7334]", config.host); - Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); - Assert.assertEquals(8080, config.port); - } } diff --git a/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/TestJavaAgent.java b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/TestJavaAgent.java new file mode 100644 index 00000000..085ea240 --- /dev/null +++ b/jmx_prometheus_javaagent/src/test/java/io/prometheus/jmx/TestJavaAgent.java @@ -0,0 +1,99 @@ +package io.prometheus.jmx; + +import org.junit.Assert; +import org.junit.Test; + +public class TestJavaAgent { + /** + * Test that the agent string argument is parsed properly. We expect the agent argument in one of these forms... + *
+     * {@code :}
+     * 
+ *
+     * {@code ::}
+     * 
+ * Since the ':' character is part of the spec for this arg, Windows-style paths could cause an issue with parsing. + * See https://github.com/prometheus/jmx_exporter/issues/312. + */ + @Test + public void testAgentStringParsing() { + final String DEFAULT_HOST = "0.0.0.0"; + + JavaAgent.Config config = JavaAgent.parseConfig("8080:config.yaml", DEFAULT_HOST); + Assert.assertEquals(DEFAULT_HOST, config.host); + Assert.assertEquals("config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + config = JavaAgent.parseConfig("8080:/unix/path/config.yaml", DEFAULT_HOST); + Assert.assertEquals(DEFAULT_HOST, config.host); + Assert.assertEquals("/unix/path/config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + config = JavaAgent.parseConfig("google.com:8080:/unix/path/config.yaml", DEFAULT_HOST); + Assert.assertEquals("google.com", config.host); + Assert.assertEquals("/unix/path/config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + config = JavaAgent.parseConfig("127.0.0.1:8080:/unix/path/config.yaml", DEFAULT_HOST); + Assert.assertEquals("127.0.0.1", config.host); + Assert.assertEquals("/unix/path/config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + config = JavaAgent.parseConfig("8080:\\Windows\\Local\\Drive\\Path\\config.yaml", DEFAULT_HOST); + Assert.assertEquals(DEFAULT_HOST, config.host); + Assert.assertEquals("\\Windows\\Local\\Drive\\Path\\config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + // the following check was previously failing to parse the file correctly + config = JavaAgent.parseConfig("8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); + Assert.assertEquals(DEFAULT_HOST, config.host); + Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + // the following check was previously failing to parse the file correctly + config = JavaAgent.parseConfig("google.com:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); + Assert.assertEquals("google.com", config.host); + Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + // the following check was previously failing to parse the file correctly + config = JavaAgent.parseConfig("127.0.0.1:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); + Assert.assertEquals("127.0.0.1", config.host); + Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); + Assert.assertEquals(8080, config.port); + } + + /** + * If someone is specifying an ipv6 address and a host name, this should be rejected. + */ + @Test(expected = IllegalArgumentException.class) + public void testRejectInvalidInput() { + JavaAgent.parseConfig("[2001:0db8:0000:0042:0000:8a2e:0370:7334]:localhost:8080:config.yaml", "0.0.0.0"); + } + + /** + * Similarly to the test above, two host names + */ + @Test(expected = IllegalArgumentException.class) + public void testRejectInvalidInput2() { + JavaAgent.parseConfig("127.0.0.1:localhost:8080:config.yaml", "0.0.0.0"); + } + + /** + * Exercise the existing Ipv6 parsing logic. The current logic leaves the brackets on the host. + */ + @Test + public void testIpv6AddressParsing() { + final String DEFAULT_HOST = "0.0.0.0"; + + JavaAgent.Config config = JavaAgent.parseConfig("[1:2:3:4]:8080:config.yaml", DEFAULT_HOST); + Assert.assertEquals("[1:2:3:4]", config.host); + Assert.assertEquals("config.yaml", config.file); + Assert.assertEquals(8080, config.port); + + config = JavaAgent.parseConfig("[2001:0db8:0000:0042:0000:8a2e:0370:7334]:8080:C:\\Windows\\Path\\config.yaml", DEFAULT_HOST); + Assert.assertEquals("[2001:0db8:0000:0042:0000:8a2e:0370:7334]", config.host); + Assert.assertEquals("C:\\Windows\\Path\\config.yaml", config.file); + Assert.assertEquals(8080, config.port); + } +}