diff --git a/build.gradle b/build.gradle index 28b035452d..8f6510bfaa 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ allprojects { } } -subprojects { proj -> +subprojects { apply plugin: 'com.github.ethankhall.semantic-versioning' apply plugin: 'nebula.provided-base' apply plugin: 'net.ltgt.errorprone' @@ -64,6 +64,9 @@ subprojects { proj -> testCompile libraries.guava testCompile test_libraries.hamcrest testCompile test_libraries.awaitility + testCompile test_libraries.osgi_compile + + testRuntime test_libraries.osgi_runtime } configurations { @@ -74,6 +77,7 @@ subprojects { proj -> if (!it.name.startsWith('slow')) { rootProject.testReport.reportOn it } + it.dependsOn('jar') } task testJar(type: Jar, group: "Build") { diff --git a/caffeine/build.gradle b/caffeine/build.gradle index 3ab7ef8fb2..562fe282c4 100644 --- a/caffeine/build.gradle +++ b/caffeine/build.gradle @@ -21,6 +21,7 @@ plugins.withType(EclipsePlugin) { dependencies { testCompile libraries.ycsb testCompile libraries.guava + testCompile test_libraries.junit testCompile test_libraries.testng testCompile test_libraries.jctools testCompile test_libraries.mockito @@ -52,8 +53,7 @@ dependencies { jar.manifest { name 'com.github.ben-manes.caffeine' instruction 'Import-Package', - 'sun.misc.*', - 'resolution:=optional' + 'sun.misc.*;resolution:=optional' instruction 'Export-Package', 'com.github.benmanes.caffeine', 'com.github.benmanes.caffeine.base', diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/OSGiTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/OSGiTest.java new file mode 100644 index 0000000000..3168a7ba2e --- /dev/null +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/OSGiTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2015 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.benmanes.caffeine; + +import static org.junit.Assert.assertEquals; +import static org.ops4j.pax.exam.CoreOptions.bundle; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; +import static org.ops4j.pax.exam.CoreOptions.options; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerMethod; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; + +/** + * @author ben.manes@gmail.com (Ben Manes) + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerMethod.class) +public final class OSGiTest { + + @Configuration + public Option[] config() { + return options( + junitBundles(), + bundle("file:" + System.getProperty("caffeine.osgi.jar"))); + } + + @Test + public void sanity() { + LoadingCache cache = Caffeine.newBuilder().build(k -> -k); + assertEquals(-1, cache.get(1).intValue()); + } +} diff --git a/caffeine/testing.gradle b/caffeine/testing.gradle index 47aec188c0..dcd3b64d2e 100644 --- a/caffeine/testing.gradle +++ b/caffeine/testing.gradle @@ -2,6 +2,7 @@ * The configuration to break cache tests into independant tasks. */ test { + useTestNG() exclude 'com/github/benmanes/caffeine/cache/**' } @@ -23,6 +24,7 @@ testNames.each { testName -> def labels = testType.split('And').collect { it[0].toLowerCase() + it.substring(1) } task "${testName}"(type: Test) { + it.useTestNG() group = 'Cache tests' description = 'Runs ' + labels.join(' with ') + implementation + ' and ' + (hasStats ? 'stats ' : 'no stats ') + @@ -48,25 +50,34 @@ testNames.each { testName -> task isolatedTests(type: Test, group: 'Cache tests') { description = 'Tests that must be run in isolation' + useTestNG() if (!System.env.'CI') { tasks.test.dependsOn(it) } } +task osgiTests(type: Test, group: 'Cache tests', description: 'Isolated OSGi tests') { + useJUnit() + tasks.test.dependsOn(it) + systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path +} + tasks.withType(Test) { - useTestNG() - if (name.startsWith('slow')) { - maxParallelForks = 2 - options.includeGroups = ['slow'] - } else if (name.startsWith('isolated')) { - options.includeGroups = ['isolated'] - } else { - options { - excludeGroups = ['slow', 'isolated'] - parallel = 'methods' - threadCount = 6 + if (options instanceof TestNGOptions) { + if (name.startsWith('slow')) { + maxParallelForks = 2 + options.includeGroups = ['slow'] + } else if (name.startsWith('isolated')) { + options.includeGroups = ['isolated'] + } else { + options { + excludeGroups = ['slow', 'isolated'] + parallel = 'methods' + threadCount = 6 + } } } + // ensure tasks don't overwrite the default report directories used by the 'test' task reports.html.destination = "${buildDir}/reports/${name}" reports.junitXml.destination = "${buildDir}/reports/${name}/results" diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 74ba26c51b..c5024e3852 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -36,7 +36,7 @@ ext { jsr305: '3.0.1', stream: '2.9.0', univocity_parsers: '1.5.6', - ycsb: '0.5.0-RC1', + ycsb: '0.5.0-RC2', ] test_versions = [ awaitility: '1.6.5', @@ -47,6 +47,7 @@ ext { jimfs: '1.0', junit: '4.12', mockito: '2.0.31-beta', + pax_exam: '4.6.0', testng: '6.9.9', truth: '0.24', ] @@ -56,12 +57,12 @@ ext { ehcache2: '2.10.1-55', ehcache3: '3.0.0.m3', high_scale_lib: '1.0.6', - infinispan: '8.1.0.Alpha2', - jackrabbit: '1.3.9', + infinispan: '8.1.0.Beta1', + jackrabbit: '1.3.10', jamm: '0.3.1', java_object_layout: '0.3.2', koloboke: '0.6.8', - slf4j: '1.7.12', + slf4j: '1.7.13', tcache: '0.4.0', ] plugin_versions = [ @@ -110,6 +111,15 @@ ext { mockito: dependencies.create("org.mockito:mockito-core:${test_versions.mockito}") { exclude group: 'org.hamcrest' }, + osgi_compile: [ + "org.apache.felix:org.apache.felix.framework:5.4.0", + "org.ops4j.pax.exam:pax-exam-junit4:${test_versions.pax_exam}", + ], + osgi_runtime: [ + "org.ops4j.pax.exam:pax-exam-container-native:${test_versions.pax_exam}", + "org.ops4j.pax.exam:pax-exam-link-mvn:${test_versions.pax_exam}", + "org.ops4j.pax.url:pax-url-aether:2.4.3", + ], testng: [ dependencies.create("org.testng:testng:${test_versions.testng}") { exclude group: 'junit' diff --git a/guava/build.gradle b/guava/build.gradle index 64949b7f4a..1cdbc2b98e 100644 --- a/guava/build.gradle +++ b/guava/build.gradle @@ -8,19 +8,27 @@ dependencies { compile libraries.guava testCompile test_libraries.junit - testCompile test_libraries.guava_testlib testCompile test_libraries.truth testCompile test_libraries.easymock + testCompile test_libraries.guava_testlib } + jar.manifest { name 'com.github.ben-manes.caffeine.guava' instruction 'Import-Package', + 'com.google.common.cache', 'com.github.benmanes.caffeine.cache', 'com.github.benmanes.caffeine.cache.stats' instruction 'Export-Package', - 'com.github.benmanes.caffeine.guava.*' + 'com.github.benmanes.caffeine.guava' } tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') } + +test { + systemProperty 'guava.osgi.version', versions.guava + systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path + systemProperty 'caffeine-guava.osgi.jar', project(':guava').jar.archivePath.path +} diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/OSGiTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/OSGiTest.java new file mode 100644 index 0000000000..f33ebf7798 --- /dev/null +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/OSGiTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2015 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.benmanes.caffeine.guava; + +import static org.junit.Assert.assertEquals; +import static org.ops4j.pax.exam.CoreOptions.bundle; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerMethod; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; + +/** + * @author ben.manes@gmail.com (Ben Manes) + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerMethod.class) +public final class OSGiTest { + + @Configuration + public Option[] config() { + return options( + junitBundles(), + bundle("file:" + System.getProperty("caffeine.osgi.jar")), + bundle("file:" + System.getProperty("caffeine-guava.osgi.jar")), + mavenBundle("com.google.guava", "guava", System.getProperty("guava.osgi.version"))); + } + + @Test + public void sanity() { + CacheLoader loader = new CacheLoader() { + @Override public Integer load(Integer key) { + return -key; + } + }; + LoadingCache cache = CaffeinatedGuava.build(Caffeine.newBuilder(), loader); + assertEquals(-1, cache.getUnchecked(1).intValue()); + } +} diff --git a/jcache/build.gradle b/jcache/build.gradle index e18dd9fa45..1667be502a 100644 --- a/jcache/build.gradle +++ b/jcache/build.gradle @@ -27,10 +27,18 @@ dependencies { jar.manifest { name 'com.github.ben-manes.caffeine.jcache' instruction 'Import-Package', + 'javax.cache.*', + 'com.typesafe.config', 'com.github.benmanes.caffeine.cache', 'com.github.benmanes.caffeine.cache.stats' instruction 'Export-Package', - 'com.github.benmanes.caffeine.jcache.*' + 'com.github.benmanes.caffeine.jcache.spi', + 'com.github.benmanes.caffeine.jcache.copy', + 'com.github.benmanes.caffeine.jcache.configuration' + instruction 'Require-Capability', + 'osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"' + instruction 'Provide-Capability', + 'osgi.serviceloader;osgi.serviceloader=com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider' } tasks.withType(Javadoc) { @@ -65,3 +73,12 @@ task testCompatibilityKit(type: Test, group: 'Build', description: 'Runs the JCa systemProperty 'javax.management.builder.initial', "${pkg}.management.JCacheMBeanServerBuilder" } test.dependsOn(testCompatibilityKit) + +task osgiTests(type: Test, group: 'Build', description: 'Isolated OSGi tests') { + useJUnit() + tasks.test.dependsOn(it) + systemProperty 'config.osgi.version', versions.config + systemProperty 'jcache.osgi.version', versions.jcache + systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path + systemProperty 'caffeine-jcache.osgi.jar', project(':jcache').jar.archivePath.path +} diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java new file mode 100644 index 0000000000..db874f83c7 --- /dev/null +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/OSGiTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.benmanes.caffeine.jcache; + +import static org.junit.Assert.assertNull; +import static org.ops4j.pax.exam.CoreOptions.bundle; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; + +import javax.cache.Cache; +import javax.cache.Caching; +import javax.cache.spi.CachingProvider; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerMethod; + +/** + * @author ben.manes@gmail.com (Ben Manes) + */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerMethod.class) +public final class OSGiTest { + + @Configuration + public Option[] config() { + return options( + junitBundles(), + bundle("file:" + System.getProperty("caffeine.osgi.jar")), + bundle("file:" + System.getProperty("caffeine-jcache.osgi.jar")), + mavenBundle("com.typesafe", "config", System.getProperty("config.osgi.version")), + mavenBundle("javax.cache", "cache-api", System.getProperty("jcache.osgi.version"))); + } + + @Test + @Ignore("Requires jsr107 cache-api v1.0.1 (see https://github.com/jsr107/jsr107spec/issues/326)") + public void sanity() { + CachingProvider cachingProvider = Caching.getCachingProvider( + "com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider", + getClass().getClassLoader()); + Cache cache = cachingProvider.getCacheManager() + .getCache("test-cache", Integer.class, Integer.class); + assertNull(cache.get(1)); + } +} diff --git a/simulator/build.gradle b/simulator/build.gradle index 4ba088dae6..62ebfd818a 100644 --- a/simulator/build.gradle +++ b/simulator/build.gradle @@ -28,14 +28,6 @@ test { useTestNG() } -jar.manifest { - name 'com.github.ben-manes.caffeine.simulator' - instruction 'Import-Package', - 'com.github.benmanes.caffeine.cache.*' - instruction 'Export-Package', - 'com.github.benmanes.caffeine.cache.simulator.*' -} - tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') }