Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,7 +59,7 @@ public void reportsGaugeValues() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Gauges ----------------------------------------------------------------------",
"gauge",
Expand All @@ -76,7 +82,7 @@ public void reportsCounterValues() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Counters --------------------------------------------------------------------",
"test.counter",
Expand Down Expand Up @@ -113,7 +119,7 @@ public void reportsHistogramValues() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Histograms ------------------------------------------------------------------",
"test.histogram",
Expand Down Expand Up @@ -150,7 +156,7 @@ public void reportsMeterValues() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Meters ----------------------------------------------------------------------",
"test.meter",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -250,7 +256,7 @@ public void reportMeterWithDisabledAttributes() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Meters ----------------------------------------------------------------------",
"test.meter",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -366,7 +372,7 @@ public void reportHistogramWithDisabledAttributes() throws Exception {

assertThat(consoleOutput())
.isEqualTo(lines(
"3/17/13 6:04:36 PM =============================================================",
dateHeader,
"",
"-- Histograms ------------------------------------------------------------------",
"test.histogram",
Expand Down
31 changes: 31 additions & 0 deletions metrics-jcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@
Uses the CacheStatisticsMXBean provided statistics.
</description>

<profiles>
<profile>
<id>jdk9</id>
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-modules java.xml.bind</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codahale.metrics.jvm;

import com.sun.management.UnixOperatingSystemMXBean;
import org.junit.Test;

import javax.management.ObjectName;
Expand All @@ -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;
Expand All @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@
</dependencies>

<profiles>
<profile>
<id>jdk9</id>
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-sign-artifacts</id>
<activation>
Expand Down