Skip to content

Commit

Permalink
Fix OSGi manifests; add tests (fixes #33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Nov 13, 2015
1 parent a8c3630 commit 03514e6
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 29 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand All @@ -74,6 +77,7 @@ subprojects { proj ->
if (!it.name.startsWith('slow')) {
rootProject.testReport.reportOn it
}
it.dependsOn('jar')
}

task testJar(type: Jar, group: "Build") {
Expand Down
4 changes: 2 additions & 2 deletions caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
53 changes: 53 additions & 0 deletions caffeine/src/test/java/com/github/benmanes/caffeine/OSGiTest.java
Original file line number Diff line number Diff line change
@@ -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 [email protected] (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<Integer, Integer> cache = Caffeine.newBuilder().build(k -> -k);
assertEquals(-1, cache.get(1).intValue());
}
}
33 changes: 22 additions & 11 deletions caffeine/testing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* The configuration to break cache tests into independant tasks.
*/
test {
useTestNG()
exclude 'com/github/benmanes/caffeine/cache/**'
}

Expand All @@ -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 ') +
Expand All @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
]
Expand All @@ -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 = [
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 10 additions & 2 deletions guava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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 [email protected] (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<Integer, Integer> loader = new CacheLoader<Integer, Integer>() {
@Override public Integer load(Integer key) {
return -key;
}
};
LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder(), loader);
assertEquals(-1, cache.getUnchecked(1).intValue());
}
}
19 changes: 18 additions & 1 deletion jcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 03514e6

Please sign in to comment.