Skip to content

Commit 73f40d3

Browse files
committed
Use JUnitPlatform as a test runner when possible
This simplifies the builds by letting a single test task run against various engines. However, we cannot yet do this for the core library as the JUnit5 scanner and runner inefficiently handle large suites.
1 parent 149b6a4 commit 73f40d3

19 files changed

Lines changed: 95 additions & 108 deletions

File tree

build.gradle

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ subprojects {
6060

6161
dependencies {
6262
testImplementation libraries.guava
63+
testImplementation testLibraries.junit
6364
testImplementation testLibraries.truth
65+
testImplementation testLibraries.testng
6466
testImplementation testLibraries.mockito
6567
testImplementation testLibraries.hamcrest
6668
testImplementation testLibraries.awaitility
6769
testImplementation testLibraries.osgiCompile
6870
testImplementation platforms.collect { platform(it) }
6971

7072
testRuntimeOnly testLibraries.osgiRuntime
73+
testRuntimeOnly testLibraries.junitEngines
7174

7275
restrictions.each { module, version ->
7376
constraints.testImplementation(module).version { require version }
@@ -110,11 +113,17 @@ def isNonStable = { String version ->
110113
def regex = /^[0-9,.v-]+(-r)?$/
111114
return (!stableKeyword || unstableKeyword) && !(version ==~ regex)
112115
}
113-
dependencyUpdates {
114-
rejectVersionIf {
115-
isNonStable(it.candidate.version) && it.candidate.group in [
116-
'javax.json.bind', 'org.jetbrains.kotlin'
117-
]
116+
tasks.named("dependencyUpdates").configure {
117+
resolutionStrategy {
118+
componentSelection {
119+
all {
120+
def unstable = ['javax.json.bind', 'org.jetbrains.kotlin']
121+
if (isNonStable(it.candidate.version) && it.candidate.group in unstable) {
122+
reject('release candidate')
123+
}
124+
}
125+
force libraries.coherence
126+
}
118127
}
119128
}
120129

caffeine/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ dependencies {
3939
testImplementation libraries.guava
4040
testImplementation libraries.picocli
4141
testImplementation libraries.fastutil
42-
testImplementation testLibraries.junit
43-
testImplementation testLibraries.testng
4442
testImplementation testLibraries.jctools
4543
testImplementation testLibraries.lincheck
4644
testImplementation libraries.commonsLang3

caffeine/src/jmh/java/com/github/benmanes/caffeine/SlotLookupBenchmark.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SlotLookupBenchmark {
5959
long[] array;
6060

6161
@Setup
62+
@SuppressWarnings("deprecation")
6263
public void setupThreadLocal() {
6364
threadLocal = ThreadLocal.withInitial(() -> {
6465
for (int i = 0; i < ARENA_SIZE; i++) {
@@ -88,6 +89,7 @@ public int threadLocal() {
8889
@Benchmark
8990
public int threadIdHash() {
9091
// Emulates finding the arena slot by hashing the thread id
92+
@SuppressWarnings("deprecation")
9193
long hash = mix64(Thread.currentThread().getId());
9294
return selectSlot(Long.hashCode(hash));
9395
}

caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ final class FrequencySketch<E> {
4444
* uniformly distributed in order to minimize collisions. In that configuration the memory
4545
* accesses are not predictable and lack spatial locality, which may cause the pipeline to need to
4646
* wait for four memory loads. Instead the items are uniformly distributed to blocks and each
47-
* counter is selected uniformly from 16 byte segments. While the runtime memory layout may result
48-
* in the blocks not being cache aligned, the L2 spatial prefetcher tries to load aligned pairs of
49-
* cache lines so the typical cost is only one memory access.
47+
* counter is selected uniformly from a distinct 16 byte segment. While the runtime memory layout
48+
* may result in the blocks not being cache aligned, the L2 spatial prefetcher tries to load
49+
* aligned pairs of cache lines so the typical cost is only one memory access.
5050
*
5151
* The frequency of all entries is aged periodically using a sampling window based on the maximum
5252
* number of entries in the cache. This is referred to as the reset operation by TinyLfu and keeps

caffeine/src/main/java/com/github/benmanes/caffeine/cache/StripedBuffer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ final boolean casTableBusy() {
116116

117117
@Override
118118
public int offer(E e) {
119+
@SuppressWarnings("deprecation")
119120
long z = mix64(Thread.currentThread().getId());
120121
int increment = ((int) (z >>> 32)) | 1;
121122
int h = (int) z;

caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public void increment_distinct(FrequencySketch<Integer> sketch) {
9393
assertThat(sketch.frequency(item + 2)).isEqualTo(0);
9494
}
9595

96+
@Test(dataProvider = "sketch")
97+
public void increment_zero(FrequencySketch<Integer> sketch) {
98+
sketch.increment(0);
99+
assertThat(sketch.frequency(0)).isEqualTo(1);
100+
}
101+
96102
@Test
97103
public void reset() {
98104
boolean reset = false;

caffeine/src/test/java/com/github/benmanes/caffeine/jsr166/JSR166TestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ void assertThreadBlocks(Thread thread, Thread.State expected) {
11981198
/**
11991199
* Returns the thread's blocker's class name, if any, else null.
12001200
*/
1201+
@SuppressWarnings("deprecation")
12011202
String blockerClassName(Thread thread) {
12021203
ThreadInfo threadInfo; LockInfo lockInfo;
12031204
if ((threadInfo = THREAD_MXBEAN.getThreadInfo(thread.getId(), 0)) != null

gradle/dependencies.gradle

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ext {
3838
errorprone: '2.15.0',
3939
expiringMap: '0.5.10',
4040
fastfilter: '1.0.2',
41-
fastutil: '8.5.8',
41+
fastutil: '8.5.9',
4242
flipTables: '1.1.0',
4343
googleJavaFormat: '1.15.0',
4444
guava: '31.1-jre',
@@ -56,7 +56,7 @@ ext {
5656
ohc: '0.6.1',
5757
osgiComponentAnnotations: '1.5.0',
5858
picocli: '4.6.3',
59-
slf4j: '2.0.2',
59+
slf4j: '2.0.3',
6060
tcache: '2.0.1',
6161
stream: '2.9.8',
6262
univocityParsers: '2.9.1',
@@ -72,7 +72,9 @@ ext {
7272
hamcrest: '2.2',
7373
jcacheTck: '1.1.1',
7474
jctools: '4.0.1',
75-
junit: '4.13.2',
75+
junit4: '4.13.2',
76+
junit5: '5.9.1',
77+
junitTestNG: '1.0.4',
7678
lincheck: '2.14.1',
7779
mockito: '4.8.0',
7880
paxExam: '4.13.5',
@@ -97,7 +99,7 @@ ext {
9799
jmhReport: '0.9.0',
98100
nexusPublish: '1.1.0',
99101
nullaway: '1.3.0',
100-
pmd: '6.49.0',
102+
pmd: '6.50.0',
101103
semanticVersioning: '1.1.0',
102104
snyke: '0.4',
103105
sonarqube: '3.4.0.2513',
@@ -107,6 +109,10 @@ ext {
107109
stats: '0.47.0',
108110
versions: '0.42.0',
109111
]
112+
platformVerrsions = [
113+
asm: '9.3',
114+
kotlin: '1.7.20',
115+
]
110116
annotationProcessorVersions = [
111117
autoValue: '1.9',
112118
autoValueBuilder: '2.9.3',
@@ -181,7 +187,14 @@ ext {
181187
jcacheTckTests: "javax.cache:cache-tests:${testVersions.jcacheTck}:tests",
182188
jcacheTckTestSources: "javax.cache:cache-tests:${testVersions.jcacheTck}:test-sources",
183189
jctools: "org.jctools:jctools-core:${testVersions.jctools}",
184-
junit: "junit:junit:${testVersions.junit}",
190+
junit: [
191+
"junit:junit:${testVersions.junit4}",
192+
"org.junit.jupiter:junit-jupiter:${testVersions.junit5}",
193+
],
194+
junitEngines: [
195+
"org.junit.vintage:junit-vintage-engine:${testVersions.junit5}",
196+
"org.junit.support:testng-engine:${testVersions.junitTestNG}",
197+
],
185198
lincheck: "org.jetbrains.kotlinx:lincheck-jvm:${testVersions.lincheck}",
186199
mockito: "org.mockito:mockito-core:${testVersions.mockito}",
187200
osgiCompile: "org.ops4j.pax.exam:pax-exam-junit4:${testVersions.paxExam}",
@@ -201,7 +214,6 @@ ext {
201214
testng: [
202215
"org.testng:testng:${testVersions.testng}",
203216
"com.google.inject:guice:${testVersions.guice}",
204-
'org.ow2.asm:asm:9.3',
205217
],
206218
truth: [
207219
"com.google.truth:truth:${testVersions.truth}",
@@ -242,7 +254,9 @@ ext {
242254
],
243255
]
244256
platforms = [
245-
'org.jetbrains.kotlin:kotlin-bom:1.7.10'
257+
"org.jetbrains.kotlin:kotlin-bom:${platformVerrsions.kotlin}",
258+
"org.junit:junit-bom:${testVersions.junit5}",
259+
"org.ow2.asm:asm-bom:${platformVerrsions.asm}",
246260
]
247261
restrictions = [
248262
'org.jsoup:jsoup': '1.15.3',

guava/build.gradle

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

1010
testImplementation libraries.slf4jNop
11-
testImplementation testLibraries.junit
12-
testImplementation testLibraries.truth
1311
testImplementation testLibraries.jctools
1412
testImplementation testLibraries.guavaTestLib
13+
14+
testRuntimeOnly testLibraries.junitEngines
1515
}
1616

1717
tasks.named('compileJava').configure {
@@ -36,25 +36,13 @@ tasks.withType(Javadoc).configureEach {
3636
}
3737

3838
tasks.named('test').configure {
39-
useJUnit {
40-
excludeCategories 'com.github.benmanes.caffeine.guava.OSGiTests'
41-
}
42-
}
43-
44-
def osgiTest = tasks.register('osgiTest', Test) {
45-
group = 'Cache tests'
46-
description = 'Isolated OSGi tests'
47-
48-
useJUnit {
49-
includeCategories 'com.github.benmanes.caffeine.guava.OSGiTests'
50-
}
51-
}
52-
tasks.named('test').configure {
53-
dependsOn(osgiTest)
39+
useJUnitPlatform()
5440
}
5541

5642
tasks.withType(Test) {
57-
systemProperty 'guava.osgi.version', versions.guava
58-
systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
59-
systemProperty 'caffeine-guava.osgi.jar', project(':guava').jar.archivePath.path
43+
systemProperties [
44+
'guava.osgi.version': versions.guava,
45+
'caffeine.osgi.jar': project(':caffeine').jar.archivePath.path,
46+
'caffeine-guava.osgi.jar': project(':guava').jar.archivePath.path,
47+
]
6048
}

guava/src/test/java/com/github/benmanes/caffeine/guava/OSGiTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import static org.ops4j.pax.exam.CoreOptions.options;
2323

2424
import org.junit.Test;
25-
import org.junit.experimental.categories.Categories.IncludeCategory;
26-
import org.junit.experimental.categories.Category;
2725
import org.junit.runner.RunWith;
2826
import org.ops4j.pax.exam.Configuration;
2927
import org.ops4j.pax.exam.Option;
@@ -39,7 +37,6 @@
3937
* @author ben.manes@gmail.com (Ben Manes)
4038
*/
4139
@RunWith(PaxExam.class)
42-
@IncludeCategory(OSGiTests.class)
4340
@ExamReactorStrategy(PerMethod.class)
4441
public final class OSGiTest {
4542

@@ -54,7 +51,6 @@ public Option[] config() {
5451
}
5552

5653
@Test
57-
@Category(OSGiTests.class)
5854
public void sanity() {
5955
CacheLoader<Integer, Integer> loader = new CacheLoader<Integer, Integer>() {
6056
@Override public Integer load(Integer key) {

0 commit comments

Comments
 (0)