From 25fde9c11da5d1e23d819a1c968edf8df9c7b0f0 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Tue, 18 Apr 2017 01:13:12 +0900 Subject: [PATCH] Suppress tests currently untestable under Java 9 (when building on Java 9). --- pom.xml | 14 ++- .../zaxxer/hikari/osgi/OSGiBundleTest.java | 118 +++++++++++------- .../java/com/zaxxer/hikari/pool/TestElf.java | 4 + .../com/zaxxer/hikari/pool/TestMetrics.java | 46 ++++--- .../util/TomcatConcurrentBagLeakTest.java | 9 ++ 5 files changed, 117 insertions(+), 74 deletions(-) diff --git a/pom.xml b/pom.xml index 136bc3f0..52ab9944 100644 --- a/pom.xml +++ b/pom.xml @@ -192,6 +192,12 @@ ${pax.exam.version} test + + org.ops4j.pax.exam + pax-exam-link-assembly + ${pax.exam.version} + test + org.ops4j.pax.exam pax-exam-link-mvn @@ -362,10 +368,14 @@ 2.19.1 - ${surefireArgLine} + ${surefireArgLine} + --add-opens java.base/java.net=ALL-UNNAMED + --add-opens java.base/java.security=ALL-UNNAMED + --add-exports java.base/sun.net.www.protocol.http=ALL-UNNAMED + --add-exports java.base/sun.net.www.protocol.https=ALL-UNNAMED ${skip.unit.tests} - false + true diff --git a/src/test/java/com/zaxxer/hikari/osgi/OSGiBundleTest.java b/src/test/java/com/zaxxer/hikari/osgi/OSGiBundleTest.java index 761a8024..a41b9165 100644 --- a/src/test/java/com/zaxxer/hikari/osgi/OSGiBundleTest.java +++ b/src/test/java/com/zaxxer/hikari/osgi/OSGiBundleTest.java @@ -17,6 +17,10 @@ package com.zaxxer.hikari.osgi; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.InitializationError; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -24,9 +28,9 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import javax.inject.Inject; - import java.io.File; +import static com.zaxxer.hikari.pool.TestElf.isJava9; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.ops4j.pax.exam.CoreOptions.*; @@ -34,58 +38,76 @@ import static org.ops4j.pax.exam.CoreOptions.*; /** * @author lburgazzoli */ -@RunWith(PaxExam.class) +@RunWith(OSGiBundleTest.ConditionalPaxExam.class) public class OSGiBundleTest { - @Inject - BundleContext context; + @Test + public void checkInject() + { + assertNotNull(context); + } + + @Test + public void checkBundle() + { + Boolean bundleFound = false; + Boolean bundleActive = false; - @Configuration - public Option[] config() - { - return options( - systemProperty("org.osgi.framework.storage.clean").value("true"), - systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"), - mavenBundle("org.slf4j","slf4j-api","1.7.5"), - mavenBundle("org.slf4j","slf4j-simple","1.7.5").noStart(), - mavenBundle("org.javassist", "javassist", "3.19.0-GA"), - new File("target/classes").exists() - ? bundle("reference:file:target/classes") - : bundle("reference:file:../target/classes"), - junitBundles(), - cleanCaches() - ); - } + Bundle[] bundles = context.getBundles(); + for (Bundle bundle : bundles) { + if (bundle != null) { + if (bundle.getSymbolicName().equals("com.zaxxer.HikariCP")) { + bundleFound = true; + if (bundle.getState() == Bundle.ACTIVE) { + bundleActive = true; + } + } + } + } - @Test - public void checkInject() - { - assertNotNull(context); - } + assertTrue(bundleFound); + assertTrue(bundleActive); + } - @Test - public void checkBundle() - { - Boolean bundleFound = false; - Boolean bundleActive = false; + @Inject + BundleContext context; - Bundle[] bundles = context.getBundles(); - for(Bundle bundle : bundles) - { - if(bundle != null) - { - if(bundle.getSymbolicName().equals("com.zaxxer.HikariCP")) - { - bundleFound = true; - if(bundle.getState() == Bundle.ACTIVE) - { - bundleActive = true; - } - } - } - } + @Configuration + public Option[] config() + { + return options( + systemProperty("org.osgi.framework.storage.clean").value("true"), + systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"), + mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), + mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(), + new File("target/classes").exists() + ? bundle("reference:file:target/classes") + : bundle("reference:file:../target/classes"), + junitBundles(), + cleanCaches() + ); + } + + public static class ConditionalPaxExam extends PaxExam + { + public ConditionalPaxExam(Class klass) throws InitializationError { + super(klass); + } + + @Override + public void run(RunNotifier notifier) { + if (!isJava9()) { + super.run(notifier); + } + } + + @Override + public void filter(Filter filter) throws NoTestsRemainException { + if (isJava9()) { + throw new NoTestsRemainException(); + } - assertTrue(bundleFound); - assertTrue(bundleActive); - } + super.filter(filter); + } + } } diff --git a/src/test/java/com/zaxxer/hikari/pool/TestElf.java b/src/test/java/com/zaxxer/hikari/pool/TestElf.java index a04a43a8..7ec29255 100644 --- a/src/test/java/com/zaxxer/hikari/pool/TestElf.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestElf.java @@ -44,6 +44,10 @@ public final class TestElf // default constructor } + public static boolean isJava9() { + return System.getProperty("java.version").startsWith("9"); + } + public static HikariPool getPool(HikariDataSource ds) { try { diff --git a/src/test/java/com/zaxxer/hikari/pool/TestMetrics.java b/src/test/java/com/zaxxer/hikari/pool/TestMetrics.java index fcba58ec..775bb494 100644 --- a/src/test/java/com/zaxxer/hikari/pool/TestMetrics.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestMetrics.java @@ -44,8 +44,6 @@ import com.zaxxer.hikari.metrics.MetricsTrackerFactory; import com.zaxxer.hikari.metrics.dropwizard.CodahaleMetricsTrackerFactory; import com.zaxxer.hikari.util.UtilityElf; -import shaded.org.codehaus.plexus.interpolation.os.Os; - /** * Test HikariCP/CodaHale metrics integration. * @@ -85,7 +83,7 @@ public class TestMetrics @Test public void testMetricUsage() throws SQLException { - assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); + assumeFalse(System.getProperty("os.name").contains("Windows")); MetricRegistry metricRegistry = new MetricRegistry(); HikariConfig config = newHikariConfig(); @@ -156,19 +154,19 @@ public class TestMetrics try (HikariDataSource ds = newHikariDataSource()) { ds.setMaximumPoolSize(1); ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); - + MetricRegistry metricRegistry = new MetricRegistry(); HealthCheckRegistry healthRegistry = new HealthCheckRegistry(); - + try { try (Connection connection = ds.getConnection()) { // close immediately } - + // After the pool as started, we can only set them once... ds.setMetricRegistry(metricRegistry); ds.setHealthCheckRegistry(healthRegistry); - + // and never again... ds.setMetricRegistry(metricRegistry); fail("Should not have been allowed to set registry after pool started"); @@ -192,19 +190,19 @@ public class TestMetrics try (HikariDataSource ds = newHikariDataSource()) { ds.setMaximumPoolSize(1); ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); - + MetricRegistry metricRegistry = new MetricRegistry(); HealthCheckRegistry healthRegistry = new HealthCheckRegistry(); - + ds.setMetricRegistry(metricRegistry); ds.setHealthCheckRegistry(healthRegistry); - + // before the pool is started, we can set it any number of times... ds.setMetricRegistry(metricRegistry); ds.setHealthCheckRegistry(healthRegistry); - + try (Connection connection = ds.getConnection()) { - + // after the pool is started, we cannot set it any more ds.setMetricRegistry(metricRegistry); fail("Should not have been allowed to set registry after pool started"); @@ -221,15 +219,15 @@ public class TestMetrics try (HikariDataSource ds = newHikariDataSource()) { ds.setMaximumPoolSize(1); ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); - + MetricRegistry metricRegistry = new MetricRegistry(); MetricsTrackerFactory metricsTrackerFactory = new CodahaleMetricsTrackerFactory(metricRegistry); - + try (Connection connection = ds.getConnection()) { - + // After the pool as started, we can only set them once... ds.setMetricsTrackerFactory(metricsTrackerFactory); - + // and never again... ds.setMetricsTrackerFactory(metricsTrackerFactory); fail("Should not have been allowed to set metricsTrackerFactory after pool started"); @@ -254,16 +252,16 @@ public class TestMetrics try (HikariDataSource ds = newHikariDataSource()) { ds.setMaximumPoolSize(1); ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); - + MetricRegistry metricRegistry = new MetricRegistry(); - + // before the pool is started, we can set it any number of times using either setter ds.setMetricRegistry(metricRegistry); ds.setMetricRegistry(metricRegistry); ds.setMetricRegistry(metricRegistry); - + try (Connection connection = ds.getConnection()) { - + // after the pool is started, we cannot set it any more ds.setMetricRegistry(metricRegistry); fail("Should not have been allowed to set registry after pool started"); @@ -280,17 +278,17 @@ public class TestMetrics try (HikariDataSource ds = newHikariDataSource()) { ds.setMaximumPoolSize(1); ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); - + MetricRegistry metricRegistry = new MetricRegistry(); MetricsTrackerFactory metricsTrackerFactory = new CodahaleMetricsTrackerFactory(metricRegistry); - + // before the pool is started, we can set it any number of times using either setter ds.setMetricsTrackerFactory(metricsTrackerFactory); ds.setMetricsTrackerFactory(metricsTrackerFactory); ds.setMetricsTrackerFactory(metricsTrackerFactory); - + try (Connection connection = ds.getConnection()) { - + // after the pool is started, we cannot set it any more ds.setMetricsTrackerFactory(metricsTrackerFactory); fail("Should not have been allowed to set registry factory after pool started"); diff --git a/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java b/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java index 06957b2e..83551fbc 100644 --- a/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java +++ b/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java @@ -16,9 +16,11 @@ package com.zaxxer.hikari.util; +import static com.zaxxer.hikari.pool.TestElf.isJava9; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assume.assumeTrue; import java.io.DataInputStream; import java.io.IOException; @@ -28,6 +30,9 @@ import java.lang.reflect.Method; import java.net.URL; import java.util.concurrent.CompletableFuture; +import com.zaxxer.hikari.pool.TestElf; +import org.junit.Assume; +import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; @@ -45,6 +50,8 @@ public class TomcatConcurrentBagLeakTest @Test public void testConcurrentBagForLeaks() throws Exception { + assumeTrue(!isJava9()); + ClassLoader cl = new FauxWebClassLoader(); Class clazz = cl.loadClass(this.getClass().getName() + "$FauxWebContext"); Object fauxWebContext = clazz.newInstance(); @@ -60,6 +67,8 @@ public class TomcatConcurrentBagLeakTest @Test public void testConcurrentBagForLeaks2() throws Exception { + assumeTrue(!isJava9()); + ClassLoader cl = this.getClass().getClassLoader(); Class clazz = cl.loadClass(this.getClass().getName() + "$FauxWebContext"); Object fauxWebContext = clazz.newInstance();