From 13ebb50f70b53bb220457257a2e1640ed1685c0a Mon Sep 17 00:00:00 2001 From: linghengqian Date: Sat, 9 Sep 2023 20:17:11 +0800 Subject: [PATCH] Add support for `com.github.ben-manes.caffeine:caffeine:2.9.3` --- .../caffeine/2.9.3/index.json | 3 + .../caffeine/2.9.3/reflect-config.json | 203 ++++++++++++++++++ .../caffeine/index.json | 7 + .../caffeine/2.9.3/.gitignore | 4 + .../caffeine/2.9.3/build.gradle | 35 +++ .../caffeine/2.9.3/gradle.properties | 2 + .../caffeine/2.9.3/settings.gradle | 13 ++ .../caffeine/CaffeineTest.java | 74 +++++++ .../caffeine/EvictionTest.java | 62 ++++++ .../caffeine/PolicyTest.java | 37 ++++ .../caffeine/PopulationTest.java | 68 ++++++ .../caffeine/RemovalTest.java | 47 ++++ .../caffeine/2.9.3/user-code-filter.json | 10 + tests/src/index.json | 6 + 14 files changed, 571 insertions(+) create mode 100644 metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/index.json create mode 100644 metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/reflect-config.json create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/.gitignore create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/build.gradle create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/gradle.properties create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/settings.gradle create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/user-code-filter.json diff --git a/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/index.json b/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/index.json new file mode 100644 index 000000000..768b5502a --- /dev/null +++ b/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/index.json @@ -0,0 +1,3 @@ +[ + "reflect-config.json" +] diff --git a/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/reflect-config.json b/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/reflect-config.json new file mode 100644 index 000000000..e376150a0 --- /dev/null +++ b/metadata/com.github.ben-manes.caffeine/caffeine/2.9.3/reflect-config.json @@ -0,0 +1,203 @@ +[ +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BBHeader$ReadAndWriteCounterRef"}, + "name":"com.github.benmanes.caffeine.cache.BBHeader$ReadAndWriteCounterRef", + "fields":[{"name":"writeCounter"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BBHeader$ReadCounterRef"}, + "name":"com.github.benmanes.caffeine.cache.BBHeader$ReadCounterRef", + "fields":[{"name":"readCounter"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BLCHeader$DrainStatusRef"}, + "name":"com.github.benmanes.caffeine.cache.BLCHeader$DrainStatusRef", + "fields":[{"name":"drainStatus"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueue"}, + "name":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueColdProducerFields", + "fields":[{"name":"producerLimit"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueue"}, + "name":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueConsumerFields", + "fields":[{"name":"consumerIndex"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueue"}, + "name":"com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueProducerFields", + "fields":[{"name":"producerIndex"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.Caffeine"}, + "name":"com.github.benmanes.caffeine.cache.CacheLoader", + "methods":[{"name":"asyncLoadAll","parameterTypes":["java.lang.Iterable","java.util.concurrent.Executor"] }, {"name":"loadAll","parameterTypes":["java.lang.Iterable"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.LocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.CacheLoader", + "methods":[{"name":"loadAll","parameterTypes":["java.lang.Iterable"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.FW"}, + "name":"com.github.benmanes.caffeine.cache.FW", + "fields":[{"name":"value"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.WI"}, + "name":"com.github.benmanes.caffeine.cache.FW", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PD"}, + "name":"com.github.benmanes.caffeine.cache.PD", + "fields":[{"name":"value"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PS"}, + "name":"com.github.benmanes.caffeine.cache.PS", + "fields":[{"name":"key"}, {"name":"value"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PSA"}, + "name":"com.github.benmanes.caffeine.cache.PSA", + "fields":[{"name":"accessTime"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSA"}, + "name":"com.github.benmanes.caffeine.cache.PSA", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSSMS"}, + "name":"com.github.benmanes.caffeine.cache.PSMS", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSMW"}, + "name":"com.github.benmanes.caffeine.cache.PSMW", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PSR"}, + "name":"com.github.benmanes.caffeine.cache.PSR", + "fields":[{"name":"writeTime"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSMSR"}, + "name":"com.github.benmanes.caffeine.cache.PSRMS", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PSW"}, + "name":"com.github.benmanes.caffeine.cache.PSW", + "fields":[{"name":"writeTime"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSA"}, + "name":"com.github.benmanes.caffeine.cache.PSW", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSW"}, + "name":"com.github.benmanes.caffeine.cache.PSW", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SSSMW"}, + "name":"com.github.benmanes.caffeine.cache.PSWMW", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PW"}, + "name":"com.github.benmanes.caffeine.cache.PW", + "fields":[{"name":"value"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache"}, + "name":"com.github.benmanes.caffeine.cache.SI", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSA", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSMS", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSMSR", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.LocalCacheFactory"}, + "name":"com.github.benmanes.caffeine.cache.SSMSW", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSMW", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache"}, + "name":"com.github.benmanes.caffeine.cache.SSSMS", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSSMWW", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.SSW", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.StripedBuffer"}, + "name":"com.github.benmanes.caffeine.cache.StripedBuffer", + "fields":[{"name":"tableBusy"}] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"}, + "name":"com.github.benmanes.caffeine.cache.WI", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.StripedBuffer"}, + "name":"java.lang.Thread", + "fields":[{"name":"threadLocalRandomProbe"}] +}, + +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.UnsafeAccess"}, + "name":"sun.misc.Unsafe", + "fields":[{"name":"theUnsafe"}] +},{ +"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.NodeFactory"}, +"name":"com.github.benmanes.caffeine.cache.PSWMS", +"methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache"}, + "name":"com.github.benmanes.caffeine.cache.SI", + "methods":[{"name":"","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.AsyncCacheLoader","boolean"] }] +}, +{ + "condition":{"typeReachable":"com.github.benmanes.caffeine.cache.NodeFactory"}, + "name":"com.github.benmanes.caffeine.cache.PD", + "fields":[{"name":"value"}], + "methods":[{"name":"","parameterTypes":[] }] +},{ +"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.NodeFactory"}, +"name":"com.github.benmanes.caffeine.cache.PW", +"fields":[{"name":"value"}], +"methods":[{"name":"","parameterTypes":[] }] +} +] diff --git a/metadata/com.github.ben-manes.caffeine/caffeine/index.json b/metadata/com.github.ben-manes.caffeine/caffeine/index.json index d18c4708f..36073d36b 100644 --- a/metadata/com.github.ben-manes.caffeine/caffeine/index.json +++ b/metadata/com.github.ben-manes.caffeine/caffeine/index.json @@ -6,5 +6,12 @@ "tested-versions": [ "3.1.2" ] + }, + { + "metadata-version": "2.9.3", + "module": "com.github.ben-manes.caffeine:caffeine", + "tested-versions": [ + "2.9.3" + ] } ] diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/.gitignore b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/.gitignore new file mode 100644 index 000000000..c98c7875b --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/.gitignore @@ -0,0 +1,4 @@ +gradlew.bat +gradlew +gradle/ +build/ diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/build.gradle b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/build.gradle new file mode 100644 index 000000000..09614f064 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/build.gradle @@ -0,0 +1,35 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ + +plugins { + id "org.graalvm.internal.tck" +} + +String libraryVersion = tck.testedLibraryVersion.get() + +dependencies { + testImplementation "com.github.ben-manes.caffeine:caffeine:$libraryVersion" + testImplementation 'org.assertj:assertj-core:3.22.0' + testImplementation 'org.awaitility:awaitility:4.2.0' + testImplementation 'com.google.guava:guava-testlib:32.1.2-jre' +} + +graalvmNative { + agent { + defaultMode = "conditional" + modes { + conditional { + userCodeFilterPath = "user-code-filter.json" + } + } + metadataCopy { + mergeWithExisting = true + inputTaskNames.add("test") + outputDirectories.add("src/test/resources/META-INF/native-image/com.github.ben-manes.caffeine/caffeine") + } + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/gradle.properties b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/gradle.properties new file mode 100644 index 000000000..185d7f50a --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/gradle.properties @@ -0,0 +1,2 @@ +library.version = 2.9.3 +metadata.dir = com.github.ben-manes.caffeine/caffeine/2.9.3/ diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/settings.gradle b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/settings.gradle new file mode 100644 index 000000000..d58cd0cda --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + def tckPath = Objects.requireNonNullElse( + System.getenv("GVM_TCK_TCKDIR"), + "../../../../tck-build-logic" + ) + includeBuild(tckPath) +} + +plugins { + id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT" +} + +rootProject.name = 'com.github.ben-manes.caffeine.caffeine_tests' diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java new file mode 100644 index 000000000..2e24fdb92 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java @@ -0,0 +1,74 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package com_github_ben_manes_caffeine.caffeine; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.CaffeineSpec; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.Scheduler; +import com.google.common.testing.FakeTicker; +import org.junit.jupiter.api.Test; + +import java.lang.ref.Cleaner; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CaffeineTest { + @Test + void testRefresh() { + LoadingCache graphs = Caffeine.newBuilder().maximumSize(10_000).refreshAfterWrite(1, TimeUnit.MINUTES) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(graphs.get("Hello")).isEqualTo("World"); + assertThat(graphs.getAll(List.of("Hi", "Aloha"))).isEqualTo(Map.of("Hi", "Universe", "Aloha", "Universe")); + } + + @Test + void testStatistics() { + Cache graphs = Caffeine.newBuilder().maximumSize(10_000).recordStats().build(); + graphs.put("Hello", "World"); + assertThat(graphs.getIfPresent("Hello")).isEqualTo("World"); + } + + @Test + void testSpecification() { + CaffeineSpec spec = CaffeineSpec.parse("maximumWeight=1000, expireAfterWrite=10m, recordStats"); + LoadingCache graphs = Caffeine.from(spec).weigher((String key, String graph) -> graph.length()) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(graphs.get("Hello")).isEqualTo("World"); + } + + @Test + void testCleanup() { + LoadingCache firstGraphs = Caffeine.newBuilder().scheduler(Scheduler.systemScheduler()).expireAfterWrite(10, TimeUnit.MINUTES) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + firstGraphs.put("Hello", "World"); + assertThat(firstGraphs.getIfPresent("Hello")).isEqualTo("World"); + Cache secondGraphs = Caffeine.newBuilder().weakValues().build(); + Cleaner cleaner = Cleaner.create(); + cleaner.register("World", secondGraphs::cleanUp); + secondGraphs.put("Hello", "World"); + assertThat(secondGraphs.getIfPresent("Hello")).isEqualTo("World"); + } + + @Test + void testTesting() { + FakeTicker ticker = new FakeTicker(); + Cache cache = Caffeine.newBuilder() + .expireAfterWrite(10, TimeUnit.MINUTES) + .executor(Runnable::run) + .ticker(ticker::read) + .maximumSize(10) + .build(); + cache.put("Hello", "World"); + ticker.advance(30, TimeUnit.MINUTES); + assertThat(cache.getIfPresent("Hello")).isNull(); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java new file mode 100644 index 000000000..bbe1d5e0a --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java @@ -0,0 +1,62 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package com_github_ben_manes_caffeine.caffeine; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.Expiry; +import com.github.benmanes.caffeine.cache.LoadingCache; +import org.junit.jupiter.api.Test; + +import java.time.ZonedDateTime; +import java.util.concurrent.TimeUnit; + +import static java.time.temporal.ChronoUnit.MILLIS; +import static org.assertj.core.api.Assertions.assertThat; + +public class EvictionTest { + @Test + void testSizeBased() { + LoadingCache firstGraphs = Caffeine.newBuilder().maximumSize(10_000).build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(firstGraphs.get("Hello")).isEqualTo("World"); + LoadingCache secondGraphs = Caffeine.newBuilder().maximumWeight(10_000).weigher((String key, String graph) -> graph.length()) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(secondGraphs.get("Hello")).isEqualTo("World"); + } + + @Test + void testTimeBased() { + LoadingCache firstGraphs = Caffeine.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(firstGraphs.get("Hello")).isEqualTo("World"); + LoadingCache secondGraphs = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(secondGraphs.get("Hello")).isEqualTo("World"); + LoadingCache thirdGraphs = Caffeine.newBuilder().expireAfter(new Expiry() { + public long expireAfterCreate(String key, String graph, long currentTime) { + long seconds = ZonedDateTime.now().plusHours(5).minus(System.currentTimeMillis(), MILLIS).toEpochSecond(); + return TimeUnit.SECONDS.toNanos(seconds); + } + + public long expireAfterUpdate(String key, String graph, long currentTime, long currentDuration) { + return currentDuration; + } + + public long expireAfterRead(String key, String graph, long currentTime, long currentDuration) { + return currentDuration; + } + }).build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(thirdGraphs.get("Hello")).isEqualTo("World"); + } + + @Test + void testReferenceBased() { + LoadingCache firstGraphs = Caffeine.newBuilder().weakKeys().weakValues().build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(firstGraphs.get("Hello")).isEqualTo("World"); + LoadingCache secondGraphs = Caffeine.newBuilder().softValues().build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(secondGraphs.get("Hello")).isEqualTo("World"); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java new file mode 100644 index 000000000..c0c063412 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java @@ -0,0 +1,37 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package com_github_ben_manes_caffeine.caffeine; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PolicyTest { + @Test + void testSizeBased() { + Cache cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).build(); + cache.policy().eviction().ifPresent(eviction -> eviction.setMaximum(2 * eviction.getMaximum())); + cache.put("Hello", "World"); + assertThat(cache.getIfPresent("Hello")).isEqualTo("World"); + } + + @Test + void testTimeBased() { + Cache cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).build(); + cache.policy().expireAfterAccess().ifPresent(eviction -> eviction.setExpiresAfter(Duration.ofMinutes(5))); + cache.policy().expireAfterWrite().ifPresent(eviction -> eviction.setExpiresAfter(Duration.ofMinutes(5))); + cache.policy().expireVariably().ifPresent(eviction -> eviction.setExpiresAfter("Hello", Duration.ofMinutes(5))); + cache.policy().refreshAfterWrite().ifPresent(refresh -> refresh.setExpiresAfter(Duration.ofMinutes(5))); + cache.put("Hello", "World"); + assertThat(cache.getIfPresent("Hello")).isEqualTo("World"); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java new file mode 100644 index 000000000..1e0a99b74 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java @@ -0,0 +1,68 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package com_github_ben_manes_caffeine.caffeine; + +import com.github.benmanes.caffeine.cache.AsyncCache; +import com.github.benmanes.caffeine.cache.AsyncLoadingCache; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulationTest { + @Test + void testManual() { + Cache cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).build(); + assertThat(cache.getIfPresent("Hello")).isNull(); + assertThat(cache.get("Hello", k -> "World")).isEqualTo("World"); + cache.put("Hello", "World"); + assertThat(cache.getIfPresent("Hello")).isEqualTo("World"); + cache.invalidate("Hello"); + assertThat(cache.getIfPresent("Hello")).isNull(); + } + + @Test + void testLoading() { + LoadingCache cache = Caffeine.newBuilder().maximumSize(10_000).expireAfterWrite(10, TimeUnit.MINUTES) + .build(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(cache.get("Hello")).isEqualTo("World"); + assertThat(cache.getAll(List.of("Hi", "Aloha"))).isEqualTo(Map.of("Hi", "Universe", "Aloha", "Universe")); + } + + @SuppressWarnings("DataFlowIssue") + @Test + void testAsynchronousManual() throws ExecutionException, InterruptedException { + AsyncCache cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).buildAsync(); + assertThat(cache.getIfPresent("Hello")).isNull(); + assertThat(cache.get("Hello", k -> "World").get()).isEqualTo("World"); + cache.put("Hello", CompletableFuture.supplyAsync(() -> "World")); + assertThat(cache.getIfPresent("Hello").get()).isEqualTo("World"); + cache.synchronous().invalidate("Hello"); + assertThat(cache.getIfPresent("Hello")).isNull(); + } + + @Test + void testAsynchronouslyLoading() throws ExecutionException, InterruptedException { + AsyncLoadingCache firstCache = Caffeine.newBuilder().maximumSize(10_000).expireAfterWrite(10, TimeUnit.MINUTES) + .buildAsync((key, executor) -> + key.equals("Hello") ? CompletableFuture.supplyAsync(() -> "World") : CompletableFuture.supplyAsync(() -> "Universe")); + assertThat(firstCache.get("Hello").get()).isEqualTo("World"); + assertThat(firstCache.getAll(List.of("Hi", "Aloha")).get()).isEqualTo(Map.of("Hi", "Universe", "Aloha", "Universe")); + AsyncLoadingCache secondCache = Caffeine.newBuilder().maximumSize(10_000).expireAfterWrite(10, TimeUnit.MINUTES) + .buildAsync(key -> key.equals("Hello") ? "World" : "Universe"); + assertThat(secondCache.get("Hello").get()).isEqualTo("World"); + assertThat(secondCache.getAll(List.of("Hi", "Aloha")).get()).isEqualTo(Map.of("Hi", "Universe", "Aloha", "Universe")); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java new file mode 100644 index 000000000..8bb19d16e --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java @@ -0,0 +1,47 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package com_github_ben_manes_caffeine.caffeine; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.RemovalCause; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RemovalTest { + @Test + void testExplicitRemovals() { + Cache cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).build(); + cache.putAll(Map.of("Hello", "World", "Hi", "Universe", "Aloha", "Universe")); + assertThat(cache.getAll(List.of("Hello", "Hi", "Aloha"), key -> null)) + .isEqualTo(Map.of("Hello", "World", "Hi", "Universe", "Aloha", "Universe")); + cache.invalidate("Hello"); + assertThat(cache.getIfPresent("Hello")).isNull(); + cache.invalidateAll(List.of("Hi", "Aloha")); + Stream.of("Hi", "Aloha").forEach(s -> assertThat(cache.getIfPresent(s)).isNull()); + cache.invalidateAll(); + Stream.of("Hello", "Hi", "Aloha").forEach(s -> assertThat(cache.getIfPresent(s)).isNull()); + } + + @Test + void testRemovalListeners() { + Cache graphs = Caffeine.newBuilder() + .evictionListener((String key, String graph, RemovalCause cause) -> System.out.printf("Key %s was evicted (%s)%n", key, cause)) + .removalListener((String key, String graph, RemovalCause cause) -> System.out.printf("Key %s was removed (%s)%n", key, cause)) + .build(); + graphs.put("Hello", "World"); + assertThat(graphs.getIfPresent("Hello")).isEqualTo("World"); + graphs.invalidate("Hello"); + assertThat(graphs.getIfPresent("Hello")).isNull(); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/user-code-filter.json b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/user-code-filter.json new file mode 100644 index 000000000..f6a552f04 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/2.9.3/user-code-filter.json @@ -0,0 +1,10 @@ +{ + "rules": [ + { + "excludeClasses": "**" + }, + { + "includeClasses": "com.github.benmanes.caffeine.cache.**" + } + ] +} diff --git a/tests/src/index.json b/tests/src/index.json index b0e687e5e..ba4578878 100644 --- a/tests/src/index.json +++ b/tests/src/index.json @@ -34,6 +34,12 @@ "name" : "com.fasterxml.jackson.core:jackson-databind", "versions" : [ "2.15.2" ] } ] +}, { + "test-project-path" : "com.github.ben-manes.caffeine/caffeine/2.9.3", + "libraries" : [ { + "name" : "com.github.ben-manes.caffeine:caffeine", + "versions" : [ "2.9.3" ] + } ] }, { "test-project-path" : "com.github.ben-manes.caffeine/caffeine/3.1.2", "libraries" : [ {