Skip to content

Commit

Permalink
add openjdk's collection test suite
Browse files Browse the repository at this point in the history
The relevant tests were extracted with minimal modifications to allow
for them to be run on Java 11, by a non-main test harness, to add and
only run the Caffeine implementations, and to fix issues with stateful
statics that are modified within the tests.
  • Loading branch information
ben-manes committed Jan 4, 2025
1 parent d2e530a commit 8f06a21
Show file tree
Hide file tree
Showing 43 changed files with 7,828 additions and 31 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ workflows:
- caffeine:strongKeysAndSoftValuesSyncCaffeineTest
- caffeine:weakKeysAndWeakValuesSyncCaffeineTest
- caffeine:weakKeysAndSoftValuesSyncCaffeineTest
- caffeine:standaloneTest
- caffeine:lincheckTest
- caffeine:isolatedTest
- caffeine:junitTest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
github.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: actionlint
uses: reviewdog/action-actionlint@08ef4afa963243489a457cca426f705ce4e0d1a5 # v1.60.0
uses: reviewdog/action-actionlint@534eb894142bcf31616e5436cbe4214641c58101 # v1.61.0
env:
SHELLCHECK_OPTS: -e SC2001 -e SC2035 -e SC2046 -e SC2061 -e SC2086 -e SC2156
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
- caffeine:strongKeysAndSoftValuesSyncCaffeineTest
- caffeine:weakKeysAndWeakValuesSyncCaffeineTest
- caffeine:weakKeysAndSoftValuesSyncCaffeineTest
- caffeine:standaloneTest
- caffeine:lincheckTest
- caffeine:isolatedTest
- caffeine:junitTest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
objects.githubusercontent.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Typos
uses: crate-ci/typos@9d890159570d5018df91fedfa40b4730cd4a81b1 # v1.28.4
uses: crate-ci/typos@c8fd3764afbf5eaf6e53d2e6571c835db2c8fa5f # v1.29.0
40 changes: 24 additions & 16 deletions caffeine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ tasks.named<JavaCompile>("compileJmhJava").configure {
}
}

tasks.test.configure {
val standaloneTest = tasks.register<Test>("standaloneTest") {
group = "Verification"
description = "Tests that are not part of an explicit suite"
exclude("com/github/benmanes/caffeine/cache/**")
dependsOn(junitTest)

useTestNG {
threadCount = max(6, Runtime.getRuntime().availableProcessors() - 1)
jvmArgs("-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled")
excludeGroups("slow", "isolated", "lincheck")
parallel = "methods"
}
}

tasks.register<Test>("isolatedTest") {
val isolatedTest = tasks.register<Test>("isolatedTest") {
group = "Verification"
description = "Tests that must be run in isolation"
useTestNG {
Expand All @@ -182,7 +181,7 @@ tasks.register<Test>("isolatedTest") {
}
}

tasks.register<Test>("lincheckTest") {
val lincheckTest = tasks.register<Test>("lincheckTest") {
group = "Verification"
description = "Tests that assert linearizability"
enabled = !isEarlyAccess()
Expand All @@ -194,30 +193,39 @@ tasks.register<Test>("lincheckTest") {
}
}

tasks.register<Test>("fuzzTest") {
val fuzzTest = tasks.register<Test>("fuzzTest") {
group = "Verification"
description = "Fuzz tests"
include("com/github/benmanes/caffeine/fuzz/**")

forkEvery = 1
failFast = true
useJUnitPlatform()
testLogging.events("started")
environment("JAZZER_FUZZ", "1")
include("com/github/benmanes/caffeine/fuzz/**")
testLogging.events("started")
useJUnitPlatform()
failFast = true
forkEvery = 1
}

val junitTest = tasks.register<Test>("junitTest") {
group = "Verification"
description = "JUnit tests"
exclude("com/github/benmanes/caffeine/fuzz/**")

val jar by tasks.existing(Jar::class)
dependsOn(jar)

useJUnit()
failFast = true
maxHeapSize = "2g"
exclude("com/github/benmanes/caffeine/fuzz/**")
systemProperty("caffeine.osgi.jar", relativePath(jar.get().archiveFile.get().asFile.path))
maxHeapSize = "2g"
failFast = true
useJUnit()
}

tasks.test.configure {
exclude("com/github/benmanes/caffeine/**")
dependsOn(standaloneTest)
dependsOn(isolatedTest)
dependsOn(lincheckTest)
dependsOn(junitTest)
dependsOn(fuzzTest)
}

tasks.jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,16 @@ public Iterator<K> iterator() {
public Spliterator<K> spliterator() {
return new KeySpliterator<>(cache);
}

@Override
public Object[] toArray() {
return cache.collectKeys() ? super.toArray() : cache.data.keySet().toArray();
}

@Override
public <T> T[] toArray(T[] array) {
return cache.collectKeys() ? super.toArray(array) : cache.data.keySet().toArray(array);
}
}

/** An adapter to safely externalize the key iterator. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,16 @@ public Iterator<K> iterator() {
public Spliterator<K> spliterator() {
return cache.data.keySet().spliterator();
}

@Override
public Object[] toArray() {
return cache.data.keySet().toArray();
}

@Override
public <T> T[] toArray(T[] array) {
return cache.data.keySet().toArray(array);
}
}

/** An adapter to safely externalize the key iterator. */
Expand Down Expand Up @@ -804,6 +814,16 @@ public Iterator<V> iterator() {
public Spliterator<V> spliterator() {
return cache.data.values().spliterator();
}

@Override
public Object[] toArray() {
return cache.data.values().toArray();
}

@Override
public <T> T[] toArray(T[] array) {
return cache.data.values().toArray(array);
}
}

/** An adapter to safely externalize the value iterator. */
Expand Down Expand Up @@ -939,6 +959,16 @@ public Iterator<Entry<K, V>> iterator() {
public Spliterator<Entry<K, V>> spliterator() {
return new EntrySpliterator<>(cache);
}

@Override
public Object[] toArray() {
return cache.data.entrySet().toArray();
}

@Override
public <T> T[] toArray(T[] array) {
return cache.data.entrySet().toArray(array);
}
}

/** An adapter to safely externalize the entry iterator. */
Expand Down
Loading

0 comments on commit 8f06a21

Please sign in to comment.