From 6574ae14fce4cf61572d6461272da79bc99dc79e Mon Sep 17 00:00:00 2001 From: linghengqian Date: Thu, 19 Jan 2023 19:37:06 +0800 Subject: [PATCH] Add support for `com.github.ben-manes.caffeine:caffeine:3.1.2` --- .../caffeine/3.1.2/index.json | 3 + .../caffeine/3.1.2/reflect-config.json | 608 ++++++++++++++++++ .../caffeine/index.json | 10 + metadata/index.json | 4 + .../caffeine/3.1.2/.gitignore | 4 + .../caffeine/3.1.2/build.gradle | 36 ++ .../caffeine/3.1.2/gradle.properties | 2 + .../caffeine/3.1.2/settings.gradle | 13 + .../caffeine/CaffeineTest.java | 88 +++ .../caffeine/ComputeTest.java | 97 +++ .../caffeine/EvictionTest.java | 62 ++ .../caffeine/PolicyTest.java | 37 ++ .../caffeine/PopulationTest.java | 68 ++ .../caffeine/RemovalTest.java | 47 ++ .../caffeine/WriteBehindCacheWriter.java | 60 ++ .../caffeine/3.1.2/user-code-filter.json | 10 + tests/src/index.json | 11 + 17 files changed, 1160 insertions(+) create mode 100644 metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/index.json create mode 100644 metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/reflect-config.json create mode 100644 metadata/com.github.ben-manes.caffeine/caffeine/index.json create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/.gitignore create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/build.gradle create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/gradle.properties create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/settings.gradle create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/ComputeTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/WriteBehindCacheWriter.java create mode 100644 tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/user-code-filter.json diff --git a/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/index.json b/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/index.json new file mode 100644 index 000000000..768b5502a --- /dev/null +++ b/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/index.json @@ -0,0 +1,3 @@ +[ + "reflect-config.json" +] diff --git a/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/reflect-config.json b/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/reflect-config.json new file mode 100644 index 000000000..90c9aa70b --- /dev/null +++ b/metadata/com.github.ben-manes.caffeine/caffeine/3.1.2/reflect-config.json @@ -0,0 +1,608 @@ +[ + { + "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$ReadAndWriteCounterRef" + }, + "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.BoundedLocalCache" + }, + "name": "com.github.benmanes.caffeine.cache.BoundedLocalCache", + "fields": [ + { + "name": "refreshes" + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.Caffeine" + }, + "name": "com.github.benmanes.caffeine.cache.CacheLoader", + "methods": [ + { + "name": "asyncLoadAll", + "parameterTypes": [ + "java.util.Set", + "java.util.concurrent.Executor" + ] + }, + { + "name": "loadAll", + "parameterTypes": [ + "java.util.Set" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.LocalLoadingCache" + }, + "name": "com.github.benmanes.caffeine.cache.CacheLoader", + "methods": [ + { + "name": "loadAll", + "parameterTypes": [ + "java.util.Set" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.FS" + }, + "name": "com.github.benmanes.caffeine.cache.FS", + "fields": [ + { + "name": "key" + }, + { + "name": "value" + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.WS" + }, + "name": "com.github.benmanes.caffeine.cache.FS", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "boolean" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalAsyncCache" + }, + "name": "com.github.benmanes.caffeine.cache.SSMSW", + "methods": [ + { + "name": "", + "parameterTypes": [ + "com.github.benmanes.caffeine.cache.Caffeine", + "com.github.benmanes.caffeine.cache.AsyncCacheLoader", + "boolean" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalAsyncLoadingCache" + }, + "name": "com.github.benmanes.caffeine.cache.SSMSW", + "methods": [ + { + "name": "", + "parameterTypes": [ + "com.github.benmanes.caffeine.cache.Caffeine", + "com.github.benmanes.caffeine.cache.AsyncCacheLoader", + "boolean" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache" + }, + "name": "com.github.benmanes.caffeine.cache.SSMSW", + "methods": [ + { + "name": "", + "parameterTypes": [ + "com.github.benmanes.caffeine.cache.Caffeine", + "com.github.benmanes.caffeine.cache.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.AsyncCacheLoader", + "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.UnboundedLocalCache" + }, + "name": "com.github.benmanes.caffeine.cache.UnboundedLocalCache", + "fields": [ + { + "name": "refreshes" + } + ] + }, + { + "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.AsyncCacheLoader", + "boolean" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache" + }, + "name": "com.github.benmanes.caffeine.cache.WS", + "methods": [ + { + "name": "", + "parameterTypes": [ + "com.github.benmanes.caffeine.cache.Caffeine", + "com.github.benmanes.caffeine.cache.AsyncCacheLoader", + "boolean" + ] + } + ] + }, + { + "condition": { + "typeReachable": "com.github.benmanes.caffeine.cache.Caffeine" + }, + "name": "com.github.benmanes.caffeine.cache.WS", + "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.PSWMS", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "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 new file mode 100644 index 000000000..d18c4708f --- /dev/null +++ b/metadata/com.github.ben-manes.caffeine/caffeine/index.json @@ -0,0 +1,10 @@ +[ + { + "latest": true, + "metadata-version": "3.1.2", + "module": "com.github.ben-manes.caffeine:caffeine", + "tested-versions": [ + "3.1.2" + ] + } +] diff --git a/metadata/index.json b/metadata/index.json index c383c24fe..614f03c0d 100644 --- a/metadata/index.json +++ b/metadata/index.json @@ -86,6 +86,10 @@ "directory": "com.zaxxer/HikariCP", "module": "com.zaxxer:HikariCP" }, + { + "directory": "com.github.ben-manes.caffeine/caffeine", + "module": "com.github.ben-manes.caffeine:caffeine" + }, { "directory": "org.jetbrains.kotlin/kotlin-reflect", "module": "org.jetbrains.kotlin:kotlin-reflect" diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/.gitignore b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/.gitignore new file mode 100644 index 000000000..c98c7875b --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/.gitignore @@ -0,0 +1,4 @@ +gradlew.bat +gradlew +gradle/ +build/ diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/build.gradle b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/build.gradle new file mode 100644 index 000000000..b1f007932 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/build.gradle @@ -0,0 +1,36 @@ +/* + * 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 'io.reactivex.rxjava3:rxjava:3.1.6' + testImplementation 'org.awaitility:awaitility:4.2.0' + testImplementation 'com.google.guava:guava-testlib:31.1-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/3.1.2/gradle.properties b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/gradle.properties new file mode 100644 index 000000000..94e1cea02 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/gradle.properties @@ -0,0 +1,2 @@ +library.version = 3.1.2 +metadata.dir = com.github.ben-manes.caffeine/caffeine/3.1.2/ diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/settings.gradle b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/settings.gradle new file mode 100644 index 000000000..d58cd0cda --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java new file mode 100644 index 000000000..76a14914d --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/CaffeineTest.java @@ -0,0 +1,88 @@ +/* + * 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.Interner; +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")); + } + + @SuppressWarnings("StringEquality") + @Test + void testInterner() { + Interner firstInterner = Interner.newStrongInterner(); + String s1 = firstInterner.intern("value"); + String s2 = firstInterner.intern("value"); + assertThat(s1 == s2).isTrue(); + LoadingCache graphs = Caffeine.newBuilder().weakKeys().build(key -> key.equals("Hello") ? "World" : "Universe"); + Interner secondInterner = Interner.newWeakInterner(); + String canonical = secondInterner.intern("Hello"); + assertThat(graphs.get(canonical)).isEqualTo("World"); + } + + @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/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/ComputeTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/ComputeTest.java new file mode 100644 index 000000000..9e00c926d --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/ComputeTest.java @@ -0,0 +1,97 @@ +/* + * 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.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BinaryOperator; +import java.util.stream.LongStream; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ComputeTest { + @Test + public void givenCacheUpdate_writeBehindIsCalled() { + AtomicBoolean writerCalled = new AtomicBoolean(false); + var writer = new WriteBehindCacheWriter.Builder() + .bufferTime(1, TimeUnit.SECONDS) + .coalesce(BinaryOperator.maxBy(ZonedDateTime::compareTo)) + .writeAction(entries -> writerCalled.set(true)) + .build(); + Cache cache = Caffeine.newBuilder().build(); + cache.asMap().computeIfAbsent(1L, key -> { + var value = ZonedDateTime.now(); + writer.write(key, value); + return value; + }); + Awaitility.await().untilTrue(writerCalled); + } + + @Test + public void givenCacheUpdateOnMultipleKeys_writeBehindIsCalled() { + AtomicBoolean writerCalled = new AtomicBoolean(false); + AtomicInteger numberOfEntries = new AtomicInteger(0); + var writer = new WriteBehindCacheWriter.Builder() + .bufferTime(1, TimeUnit.SECONDS) + .coalesce(BinaryOperator.maxBy(ZonedDateTime::compareTo)) + .writeAction(entries -> { + numberOfEntries.set(entries.size()); + writerCalled.set(true); + }).build(); + Cache cache = Caffeine.newBuilder().build(); + LongStream.rangeClosed(1L, 3L).forEach(i -> cache.asMap().computeIfAbsent(i, key -> { + var value = ZonedDateTime.now(); + writer.write(key, value); + return value; + })); + Awaitility.await().untilTrue(writerCalled); + assertThat(numberOfEntries.intValue()).isEqualTo(3); + } + + @Test + public void givenMultipleCacheUpdatesOnSameKey_writeBehindIsCalledWithMostRecentTime() { + AtomicBoolean writerCalled = new AtomicBoolean(false); + AtomicInteger numberOfEntries = new AtomicInteger(0); + AtomicReference timeInWriteBehind = new AtomicReference<>(); + var writer = new WriteBehindCacheWriter.Builder() + .bufferTime(1, TimeUnit.SECONDS) + .coalesce(BinaryOperator.maxBy(ZonedDateTime::compareTo)) + .writeAction(entries -> { + if (entries.isEmpty()) { + return; + } + numberOfEntries.set(entries.size()); + ZonedDateTime zonedDateTime = entries.values().iterator().next(); + timeInWriteBehind.set(zonedDateTime); + writerCalled.set(true); + }).build(); + Cache cache = Caffeine.newBuilder().build(); + var values = List.of( + ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 0, ZoneId.systemDefault()), + ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 100, ZoneId.systemDefault()), + ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 300, ZoneId.systemDefault()), + ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 500, ZoneId.systemDefault())); + values.forEach(value -> cache.asMap().compute(1L, (key, oldValue) -> { + writer.write(key, value); + return value; + })); + var mostRecentTime = values.get(values.size() - 1); + Awaitility.await().untilTrue(writerCalled); + assertThat(numberOfEntries.intValue()).isEqualTo(1); + assertThat(timeInWriteBehind.get()).isEqualTo(mostRecentTime); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/EvictionTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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/3.1.2/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/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/PolicyTest.java new file mode 100644 index 000000000..242161be3 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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.setRefreshesAfter(Duration.ofMinutes(5))); + cache.put("Hello", "World"); + assertThat(cache.getIfPresent("Hello")).isEqualTo("World"); + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/PopulationTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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/3.1.2/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/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/RemovalTest.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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/3.1.2/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/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/WriteBehindCacheWriter.java b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/WriteBehindCacheWriter.java new file mode 100644 index 000000000..3fb33a06d --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/src/test/java/com_github_ben_manes_caffeine/caffeine/WriteBehindCacheWriter.java @@ -0,0 +1,60 @@ +/* + * 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 io.reactivex.rxjava3.subjects.PublishSubject; + +import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; +import java.util.function.BinaryOperator; +import java.util.function.Consumer; + +import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.toMap; + +@SuppressWarnings("ResultOfMethodCallIgnored") +public final class WriteBehindCacheWriter { + private final PublishSubject> subject; + + private WriteBehindCacheWriter(Builder builder) { + subject = PublishSubject.create(); + subject.buffer(builder.bufferTimeNanos, TimeUnit.NANOSECONDS) + .map(entries -> entries.stream().collect(toMap(Entry::getKey, Entry::getValue, builder.coalescer))) + .subscribe(builder.writeAction::accept); + } + + public void write(K key, V value) { + subject.onNext(new SimpleImmutableEntry<>(key, value)); + } + + public static final class Builder { + private Consumer> writeAction; + private BinaryOperator coalescer; + private long bufferTimeNanos; + + public Builder bufferTime(long duration, TimeUnit unit) { + this.bufferTimeNanos = TimeUnit.NANOSECONDS.convert(duration, unit); + return this; + } + + public Builder writeAction(Consumer> writeAction) { + this.writeAction = requireNonNull(writeAction); + return this; + } + + public Builder coalesce(BinaryOperator coalescer) { + this.coalescer = requireNonNull(coalescer); + return this; + } + + public WriteBehindCacheWriter build() { + return new WriteBehindCacheWriter<>(this); + } + } +} diff --git a/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/user-code-filter.json b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/user-code-filter.json new file mode 100644 index 000000000..f6a552f04 --- /dev/null +++ b/tests/src/com.github.ben-manes.caffeine/caffeine/3.1.2/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 a418dcc61..097858348 100644 --- a/tests/src/index.json +++ b/tests/src/index.json @@ -208,6 +208,17 @@ } ] }, + { + "test-project-path": "com.github.ben-manes.caffeine/caffeine/3.1.2", + "libraries": [ + { + "name": "com.github.ben-manes.caffeine:caffeine", + "versions": [ + "3.1.2" + ] + } + ] + }, { "test-project-path": "org.jetbrains.kotlin/kotlin-reflect/1.7.10", "libraries": [