From bf2464f82ef78ac976a3c1330aced6ba26d89fbd Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Mon, 24 Feb 2020 00:18:37 +0100 Subject: [PATCH] Tweak GitHub build workflow (#1542) * Use official setup-java GitHub action * Run build with GitHub workflow on pull requests * Use actions/checkout@v2 * Try speeding up Maven builds by tuning JVM parameters * Add cache to GitHub workflow * Remove building old branches * Remove build with Java 13 Java 13 removed support for emitting Java 6 bytecode. https://www.oracle.com/technetwork/java/javase/12-relnote-issues-5211422.html#JDK-8028563 --- .github/workflows/maven.yml | 30 ++++++++++++------- .../collectd/CollectdReporterTest.java | 21 ++++++------- .../codahale/metrics/collectd/Receiver.java | 2 +- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index def0b69b65..464f7bf4aa 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,11 +1,12 @@ name: Java CI on: + pull_request: + branches: + - 4.1-maintenance + - 4.1-development + - 5.0-development push: branches: - - 3.0-maintenance - - 3.1-maintenance - - 3.2-maintenance - - 4.0-maintenance - 4.1-maintenance - 4.1-development - 5.0-development @@ -14,17 +15,26 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - java_version: [1.8, 11] - os: [ubuntu-latest, macOS-latest] + java_version: [8, 11] + os: + - ubuntu-latest + env: + JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Set up JDK uses: actions/setup-java@v1 with: java-version: ${{ matrix.java_version }} + - uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- - name: Print Java and Maven versions - run: ./mvnw -B -s .github/settings.xml -v + run: ./mvnw -B -ff -s .github/settings.xml -v - name: Build with Maven - run: ./mvnw -B -s .github/settings.xml install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true + run: ./mvnw -B -ff -s .github/settings.xml install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true - name: Run tests - run: ./mvnw -B -s .github/settings.xml verify + run: ./mvnw -B -ff -s .github/settings.xml verify diff --git a/metrics-collectd/src/test/java/com/codahale/metrics/collectd/CollectdReporterTest.java b/metrics-collectd/src/test/java/com/codahale/metrics/collectd/CollectdReporterTest.java index 2d4bae7eaa..c89ee7b9eb 100644 --- a/metrics-collectd/src/test/java/com/codahale/metrics/collectd/CollectdReporterTest.java +++ b/metrics-collectd/src/test/java/com/codahale/metrics/collectd/CollectdReporterTest.java @@ -1,7 +1,6 @@ package com.codahale.metrics.collectd; import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; import com.codahale.metrics.Meter; import com.codahale.metrics.MetricAttribute; @@ -13,8 +12,10 @@ import org.junit.ClassRule; import org.junit.Test; +import java.util.Collections; import java.util.EnumSet; import java.util.List; +import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; @@ -70,7 +71,7 @@ public void reportsDoubleGauges() throws Exception { private void reportsGauges(T value) throws Exception { reporter.report( - map("gauge", (Gauge) () -> value), + map("gauge", () -> value), map(), map(), map(), @@ -82,7 +83,7 @@ private void reportsGauges(T value) throws Exception { @Test public void reportsBooleanGauges() throws Exception { reporter.report( - map("gauge", (Gauge) () -> true), + map("gauge", () -> true), map(), map(), map(), @@ -91,7 +92,7 @@ public void reportsBooleanGauges() throws Exception { assertThat(nextValues(receiver)).containsExactly(1d); reporter.report( - map("gauge", (Gauge) () -> false), + map("gauge", () -> false), map(), map(), map(), @@ -103,7 +104,7 @@ public void reportsBooleanGauges() throws Exception { @Test public void doesNotReportStringGauges() throws Exception { reporter.report( - map("unsupported", (Gauge) () -> "value"), + map("unsupported", () -> "value"), map(), map(), map(), @@ -267,17 +268,17 @@ public void sanitizesMetricName() throws Exception { } private SortedMap map() { - return new TreeMap<>(); + return Collections.emptySortedMap(); } private SortedMap map(String name, T metric) { - final SortedMap map = map(); - map.put(name, metric); - return map; + final Map map = Collections.singletonMap(name, metric); + return new TreeMap<>(map); } private List nextValues(Receiver receiver) throws Exception { - return receiver.next().getValues(); + final ValueList valueList = receiver.next(); + return valueList == null ? Collections.emptyList() : valueList.getValues(); } } diff --git a/metrics-collectd/src/test/java/com/codahale/metrics/collectd/Receiver.java b/metrics-collectd/src/test/java/com/codahale/metrics/collectd/Receiver.java index 996340fd12..7f38e151fd 100644 --- a/metrics-collectd/src/test/java/com/codahale/metrics/collectd/Receiver.java +++ b/metrics-collectd/src/test/java/com/codahale/metrics/collectd/Receiver.java @@ -45,7 +45,7 @@ public void dispatch(Notification notification) { } public ValueList next() throws InterruptedException { - return queue.poll(1, TimeUnit.SECONDS); + return queue.poll(2, TimeUnit.SECONDS); } @Override