Skip to content

Commit 03514e6

Browse files
committed
Fix OSGi manifests; add tests (fixes #33)
1 parent a8c3630 commit 03514e6

File tree

10 files changed

+250
-29
lines changed

10 files changed

+250
-29
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ allprojects {
3434
}
3535
}
3636

37-
subprojects { proj ->
37+
subprojects {
3838
apply plugin: 'com.github.ethankhall.semantic-versioning'
3939
apply plugin: 'nebula.provided-base'
4040
apply plugin: 'net.ltgt.errorprone'
@@ -64,6 +64,9 @@ subprojects { proj ->
6464
testCompile libraries.guava
6565
testCompile test_libraries.hamcrest
6666
testCompile test_libraries.awaitility
67+
testCompile test_libraries.osgi_compile
68+
69+
testRuntime test_libraries.osgi_runtime
6770
}
6871

6972
configurations {
@@ -74,6 +77,7 @@ subprojects { proj ->
7477
if (!it.name.startsWith('slow')) {
7578
rootProject.testReport.reportOn it
7679
}
80+
it.dependsOn('jar')
7781
}
7882

7983
task testJar(type: Jar, group: "Build") {

caffeine/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ plugins.withType(EclipsePlugin) {
2121
dependencies {
2222
testCompile libraries.ycsb
2323
testCompile libraries.guava
24+
testCompile test_libraries.junit
2425
testCompile test_libraries.testng
2526
testCompile test_libraries.jctools
2627
testCompile test_libraries.mockito
@@ -52,8 +53,7 @@ dependencies {
5253
jar.manifest {
5354
name 'com.github.ben-manes.caffeine'
5455
instruction 'Import-Package',
55-
'sun.misc.*',
56-
'resolution:=optional'
56+
'sun.misc.*;resolution:=optional'
5757
instruction 'Export-Package',
5858
'com.github.benmanes.caffeine',
5959
'com.github.benmanes.caffeine.base',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2015 Ben Manes. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.benmanes.caffeine;
17+
18+
import static org.junit.Assert.assertEquals;
19+
import static org.ops4j.pax.exam.CoreOptions.bundle;
20+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
21+
import static org.ops4j.pax.exam.CoreOptions.options;
22+
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.ops4j.pax.exam.Configuration;
26+
import org.ops4j.pax.exam.Option;
27+
import org.ops4j.pax.exam.junit.PaxExam;
28+
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
29+
import org.ops4j.pax.exam.spi.reactors.PerMethod;
30+
31+
import com.github.benmanes.caffeine.cache.Caffeine;
32+
import com.github.benmanes.caffeine.cache.LoadingCache;
33+
34+
/**
35+
* @author [email protected] (Ben Manes)
36+
*/
37+
@RunWith(PaxExam.class)
38+
@ExamReactorStrategy(PerMethod.class)
39+
public final class OSGiTest {
40+
41+
@Configuration
42+
public Option[] config() {
43+
return options(
44+
junitBundles(),
45+
bundle("file:" + System.getProperty("caffeine.osgi.jar")));
46+
}
47+
48+
@Test
49+
public void sanity() {
50+
LoadingCache<Integer, Integer> cache = Caffeine.newBuilder().build(k -> -k);
51+
assertEquals(-1, cache.get(1).intValue());
52+
}
53+
}

caffeine/testing.gradle

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* The configuration to break cache tests into independant tasks.
33
*/
44
test {
5+
useTestNG()
56
exclude 'com/github/benmanes/caffeine/cache/**'
67
}
78

@@ -23,6 +24,7 @@ testNames.each { testName ->
2324
def labels = testType.split('And').collect { it[0].toLowerCase() + it.substring(1) }
2425

2526
task "${testName}"(type: Test) {
27+
it.useTestNG()
2628
group = 'Cache tests'
2729
description = 'Runs ' + labels.join(' with ') +
2830
implementation + ' and ' + (hasStats ? 'stats ' : 'no stats ') +
@@ -48,25 +50,34 @@ testNames.each { testName ->
4850
task isolatedTests(type: Test, group: 'Cache tests') {
4951
description = 'Tests that must be run in isolation'
5052

53+
useTestNG()
5154
if (!System.env.'CI') {
5255
tasks.test.dependsOn(it)
5356
}
5457
}
5558

59+
task osgiTests(type: Test, group: 'Cache tests', description: 'Isolated OSGi tests') {
60+
useJUnit()
61+
tasks.test.dependsOn(it)
62+
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
63+
}
64+
5665
tasks.withType(Test) {
57-
useTestNG()
58-
if (name.startsWith('slow')) {
59-
maxParallelForks = 2
60-
options.includeGroups = ['slow']
61-
} else if (name.startsWith('isolated')) {
62-
options.includeGroups = ['isolated']
63-
} else {
64-
options {
65-
excludeGroups = ['slow', 'isolated']
66-
parallel = 'methods'
67-
threadCount = 6
66+
if (options instanceof TestNGOptions) {
67+
if (name.startsWith('slow')) {
68+
maxParallelForks = 2
69+
options.includeGroups = ['slow']
70+
} else if (name.startsWith('isolated')) {
71+
options.includeGroups = ['isolated']
72+
} else {
73+
options {
74+
excludeGroups = ['slow', 'isolated']
75+
parallel = 'methods'
76+
threadCount = 6
77+
}
6878
}
6979
}
80+
7081
// ensure tasks don't overwrite the default report directories used by the 'test' task
7182
reports.html.destination = "${buildDir}/reports/${name}"
7283
reports.junitXml.destination = "${buildDir}/reports/${name}/results"

gradle/dependencies.gradle

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ext {
3636
jsr305: '3.0.1',
3737
stream: '2.9.0',
3838
univocity_parsers: '1.5.6',
39-
ycsb: '0.5.0-RC1',
39+
ycsb: '0.5.0-RC2',
4040
]
4141
test_versions = [
4242
awaitility: '1.6.5',
@@ -47,6 +47,7 @@ ext {
4747
jimfs: '1.0',
4848
junit: '4.12',
4949
mockito: '2.0.31-beta',
50+
pax_exam: '4.6.0',
5051
testng: '6.9.9',
5152
truth: '0.24',
5253
]
@@ -56,12 +57,12 @@ ext {
5657
ehcache2: '2.10.1-55',
5758
ehcache3: '3.0.0.m3',
5859
high_scale_lib: '1.0.6',
59-
infinispan: '8.1.0.Alpha2',
60-
jackrabbit: '1.3.9',
60+
infinispan: '8.1.0.Beta1',
61+
jackrabbit: '1.3.10',
6162
jamm: '0.3.1',
6263
java_object_layout: '0.3.2',
6364
koloboke: '0.6.8',
64-
slf4j: '1.7.12',
65+
slf4j: '1.7.13',
6566
tcache: '0.4.0',
6667
]
6768
plugin_versions = [
@@ -110,6 +111,15 @@ ext {
110111
mockito: dependencies.create("org.mockito:mockito-core:${test_versions.mockito}") {
111112
exclude group: 'org.hamcrest'
112113
},
114+
osgi_compile: [
115+
"org.apache.felix:org.apache.felix.framework:5.4.0",
116+
"org.ops4j.pax.exam:pax-exam-junit4:${test_versions.pax_exam}",
117+
],
118+
osgi_runtime: [
119+
"org.ops4j.pax.exam:pax-exam-container-native:${test_versions.pax_exam}",
120+
"org.ops4j.pax.exam:pax-exam-link-mvn:${test_versions.pax_exam}",
121+
"org.ops4j.pax.url:pax-url-aether:2.4.3",
122+
],
113123
testng: [
114124
dependencies.create("org.testng:testng:${test_versions.testng}") {
115125
exclude group: 'junit'

guava/build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ dependencies {
88
compile libraries.guava
99

1010
testCompile test_libraries.junit
11-
testCompile test_libraries.guava_testlib
1211
testCompile test_libraries.truth
1312
testCompile test_libraries.easymock
13+
testCompile test_libraries.guava_testlib
1414
}
15+
1516
jar.manifest {
1617
name 'com.github.ben-manes.caffeine.guava'
1718
instruction 'Import-Package',
19+
'com.google.common.cache',
1820
'com.github.benmanes.caffeine.cache',
1921
'com.github.benmanes.caffeine.cache.stats'
2022
instruction 'Export-Package',
21-
'com.github.benmanes.caffeine.guava.*'
23+
'com.github.benmanes.caffeine.guava'
2224
}
2325

2426
tasks.withType(Javadoc) {
2527
options.addStringOption('Xdoclint:none', '-quiet')
2628
}
29+
30+
test {
31+
systemProperty 'guava.osgi.version', versions.guava
32+
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
33+
systemProperty 'caffeine-guava.osgi.jar', project(':guava').jar.archivePath.path
34+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2015 Ben Manes. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.benmanes.caffeine.guava;
17+
18+
import static org.junit.Assert.assertEquals;
19+
import static org.ops4j.pax.exam.CoreOptions.bundle;
20+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
21+
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
22+
import static org.ops4j.pax.exam.CoreOptions.options;
23+
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.ops4j.pax.exam.Configuration;
27+
import org.ops4j.pax.exam.Option;
28+
import org.ops4j.pax.exam.junit.PaxExam;
29+
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
30+
import org.ops4j.pax.exam.spi.reactors.PerMethod;
31+
32+
import com.github.benmanes.caffeine.cache.Caffeine;
33+
import com.google.common.cache.CacheLoader;
34+
import com.google.common.cache.LoadingCache;
35+
36+
/**
37+
* @author [email protected] (Ben Manes)
38+
*/
39+
@RunWith(PaxExam.class)
40+
@ExamReactorStrategy(PerMethod.class)
41+
public final class OSGiTest {
42+
43+
@Configuration
44+
public Option[] config() {
45+
return options(
46+
junitBundles(),
47+
bundle("file:" + System.getProperty("caffeine.osgi.jar")),
48+
bundle("file:" + System.getProperty("caffeine-guava.osgi.jar")),
49+
mavenBundle("com.google.guava", "guava", System.getProperty("guava.osgi.version")));
50+
}
51+
52+
@Test
53+
public void sanity() {
54+
CacheLoader<Integer, Integer> loader = new CacheLoader<Integer, Integer>() {
55+
@Override public Integer load(Integer key) {
56+
return -key;
57+
}
58+
};
59+
LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder(), loader);
60+
assertEquals(-1, cache.getUnchecked(1).intValue());
61+
}
62+
}

jcache/build.gradle

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ dependencies {
2727
jar.manifest {
2828
name 'com.github.ben-manes.caffeine.jcache'
2929
instruction 'Import-Package',
30+
'javax.cache.*',
31+
'com.typesafe.config',
3032
'com.github.benmanes.caffeine.cache',
3133
'com.github.benmanes.caffeine.cache.stats'
3234
instruction 'Export-Package',
33-
'com.github.benmanes.caffeine.jcache.*'
35+
'com.github.benmanes.caffeine.jcache.spi',
36+
'com.github.benmanes.caffeine.jcache.copy',
37+
'com.github.benmanes.caffeine.jcache.configuration'
38+
instruction 'Require-Capability',
39+
'osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"'
40+
instruction 'Provide-Capability',
41+
'osgi.serviceloader;osgi.serviceloader=com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider'
3442
}
3543

3644
tasks.withType(Javadoc) {
@@ -65,3 +73,12 @@ task testCompatibilityKit(type: Test, group: 'Build', description: 'Runs the JCa
6573
systemProperty 'javax.management.builder.initial', "${pkg}.management.JCacheMBeanServerBuilder"
6674
}
6775
test.dependsOn(testCompatibilityKit)
76+
77+
task osgiTests(type: Test, group: 'Build', description: 'Isolated OSGi tests') {
78+
useJUnit()
79+
tasks.test.dependsOn(it)
80+
systemProperty 'config.osgi.version', versions.config
81+
systemProperty 'jcache.osgi.version', versions.jcache
82+
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
83+
systemProperty 'caffeine-jcache.osgi.jar', project(':jcache').jar.archivePath.path
84+
}

0 commit comments

Comments
 (0)