diff --git a/.travis.yml b/.travis.yml index 1182cd2036..120e3c25ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,20 @@ install: echo "I trust Maven." # don't just run the tests, also run error-prone script: mvn verify -jdk: - - oraclejdk8 +matrix: + include: + - os: linux + jdk: oraclejdk8 + addons: + apt: + packages: + - oracle-java8-installer + - os: linux + jdk: oraclejdk9 + addons: + apt: + packages: + - oracle-java9-installer notifications: email: diff --git a/metrics-core/src/test/java/com/codahale/metrics/ConsoleReporterTest.java b/metrics-core/src/test/java/com/codahale/metrics/ConsoleReporterTest.java index 24cbb29707..19bbae9759 100644 --- a/metrics-core/src/test/java/com/codahale/metrics/ConsoleReporterTest.java +++ b/metrics-core/src/test/java/com/codahale/metrics/ConsoleReporterTest.java @@ -35,10 +35,16 @@ public class ConsoleReporterTest { .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(); + private String dateHeader; @Before public void setUp() throws Exception { when(clock.getTime()).thenReturn(1363568676000L); + // JDK9 has changed the java.text.DateFormat API implementation according to Unicode. + // See http://mail.openjdk.java.net/pipermail/jdk9-dev/2017-April/005732.html + dateHeader = System.getProperty("java.version").startsWith("1.8") ? + "3/17/13 6:04:36 PM =============================================================" : + "3/17/13, 6:04:36 PM ============================================================"; } @Test @@ -53,7 +59,7 @@ public void reportsGaugeValues() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Gauges ----------------------------------------------------------------------", "gauge", @@ -76,7 +82,7 @@ public void reportsCounterValues() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Counters --------------------------------------------------------------------", "test.counter", @@ -113,7 +119,7 @@ public void reportsHistogramValues() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Histograms ------------------------------------------------------------------", "test.histogram", @@ -150,7 +156,7 @@ public void reportsMeterValues() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Meters ----------------------------------------------------------------------", "test.meter", @@ -196,7 +202,7 @@ public void reportsTimerValues() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Timers ----------------------------------------------------------------------", "test.another.timer", @@ -250,7 +256,7 @@ public void reportMeterWithDisabledAttributes() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Meters ----------------------------------------------------------------------", "test.meter", @@ -306,7 +312,7 @@ public void reportTimerWithDisabledAttributes() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Timers ----------------------------------------------------------------------", "test.another.timer", @@ -366,7 +372,7 @@ public void reportHistogramWithDisabledAttributes() throws Exception { assertThat(consoleOutput()) .isEqualTo(lines( - "3/17/13 6:04:36 PM =============================================================", + dateHeader, "", "-- Histograms ------------------------------------------------------------------", "test.histogram", diff --git a/metrics-jcache/pom.xml b/metrics-jcache/pom.xml index e23313c057..a441a6779f 100644 --- a/metrics-jcache/pom.xml +++ b/metrics-jcache/pom.xml @@ -16,6 +16,37 @@ Uses the CacheStatisticsMXBean provided statistics. + + + jdk9 + + 9 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 9 + 9 + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + + --add-modules java.xml.bind + + + + + + + io.dropwizard.metrics diff --git a/metrics-jvm/src/main/java/com/codahale/metrics/jvm/FileDescriptorRatioGauge.java b/metrics-jvm/src/main/java/com/codahale/metrics/jvm/FileDescriptorRatioGauge.java index 53f9851a7f..066a2d01cb 100644 --- a/metrics-jvm/src/main/java/com/codahale/metrics/jvm/FileDescriptorRatioGauge.java +++ b/metrics-jvm/src/main/java/com/codahale/metrics/jvm/FileDescriptorRatioGauge.java @@ -1,11 +1,10 @@ package com.codahale.metrics.jvm; import com.codahale.metrics.RatioGauge; +import com.sun.management.UnixOperatingSystemMXBean; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; /** * A gauge for the ratio of used to total file descriptors. @@ -31,17 +30,11 @@ public FileDescriptorRatioGauge(OperatingSystemMXBean os) { @Override protected Ratio getRatio() { - try { - return Ratio.of(invoke("getOpenFileDescriptorCount"), - invoke("getMaxFileDescriptorCount")); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + if (os instanceof UnixOperatingSystemMXBean) { + final UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os; + return Ratio.of(unixOs.getOpenFileDescriptorCount(), unixOs.getMaxFileDescriptorCount()); + } else { return Ratio.of(Double.NaN, Double.NaN); } } - - private long invoke(String name) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - final Method method = os.getClass().getDeclaredMethod(name); - method.setAccessible(true); - return (Long) method.invoke(os); - } } diff --git a/metrics-jvm/src/test/java/com/codahale/metrics/jvm/FileDescriptorRatioGaugeTest.java b/metrics-jvm/src/test/java/com/codahale/metrics/jvm/FileDescriptorRatioGaugeTest.java index e756d70040..fcf82a5922 100644 --- a/metrics-jvm/src/test/java/com/codahale/metrics/jvm/FileDescriptorRatioGaugeTest.java +++ b/metrics-jvm/src/test/java/com/codahale/metrics/jvm/FileDescriptorRatioGaugeTest.java @@ -1,5 +1,6 @@ package com.codahale.metrics.jvm; +import com.sun.management.UnixOperatingSystemMXBean; import org.junit.Test; import javax.management.ObjectName; @@ -12,7 +13,7 @@ @SuppressWarnings("UnusedDeclaration") public class FileDescriptorRatioGaugeTest { - private final OperatingSystemMXBean os = new OperatingSystemMXBean() { + private final OperatingSystemMXBean os = new UnixOperatingSystemMXBean() { @Override public String getName() { return null; @@ -38,16 +39,56 @@ public double getSystemLoadAverage() { return 0; } - // these duplicate methods from UnixOperatingSystem - - private long getOpenFileDescriptorCount() { + @Override + public long getOpenFileDescriptorCount() { return 10; } - private long getMaxFileDescriptorCount() { + @Override + public long getMaxFileDescriptorCount() { return 100; } + @Override + public long getCommittedVirtualMemorySize() { + return 0; + } + + @Override + public long getTotalSwapSpaceSize() { + return 0; + } + + @Override + public long getFreeSwapSpaceSize() { + return 0; + } + + @Override + public long getProcessCpuTime() { + return 0; + } + + @Override + public long getFreePhysicalMemorySize() { + return 0; + } + + @Override + public long getTotalPhysicalMemorySize() { + return 0; + } + + @Override + public double getSystemCpuLoad() { + return 0; + } + + @Override + public double getProcessCpuLoad() { + return 0; + } + // overridden on Java 1.7; random crap on Java 1.6 @Override public ObjectName getObjectName() { diff --git a/pom.xml b/pom.xml index 78dc7d2982..54f5c26ef2 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,27 @@ + + jdk9 + + 9 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 9 + 9 + true + true + + + + + release-sign-artifacts