Skip to content

Commit

Permalink
minor touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Nov 4, 2024
1 parent ed1f4cd commit 4f94cf6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 32 deletions.
14 changes: 9 additions & 5 deletions caffeine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sourceSets {
}

val compileJavaPoetJava by tasks.existing
val javaAgent: Configuration by configurations.creating
val jammAgent: Configuration by configurations.creating
val collections4Sources: Configuration by configurations.creating
val javaPoetImplementation: Configuration = configurations["javaPoetImplementation"]

Expand All @@ -48,15 +48,18 @@ dependencies {
classifier = "tests"
}
}
testImplementation(sourceSets["codeGen"].output)
testImplementation(libs.eclipse.collections.testutils)

collections4Sources(libs.commons.collections4) {
artifact {
classifier = "test-sources"
}
}
testImplementation(sourceSets["codeGen"].output)
testImplementation(libs.eclipse.collections.testutils)

javaAgent(libs.jamm)
jammAgent(libs.jamm) {
isTransitive = false
}

jmh(libs.jamm)
jmh(libs.tcache)
Expand All @@ -73,6 +76,7 @@ dependencies {
javaPoetImplementation(libs.javapoet)
javaPoetImplementation(libs.commons.lang3)
javaPoetImplementation(libs.google.java.format)

}

val compileCodeGenJava by tasks.existing(JavaCompile::class) {
Expand Down Expand Up @@ -264,7 +268,7 @@ tasks.register<JavaExec>("memoryOverhead") {
"--add-opens", "java.base/java.lang.ref=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"-javaagent:${configurations["javaAgent"].singleFile}")
"-javaagent:${jammAgent.asPath}")
}

tasks.register<Stress>("stress") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ public void ticker() {
Ticker ticker = new FakeTicker()::read;
var builder = Caffeine.newBuilder().ticker(ticker);
assertThat(builder.ticker).isSameInstanceAs(ticker);
assertThat(builder.getTicker()).isSameInstanceAs(Ticker.disabledTicker());
assertThat(builder.build()).isNotNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,21 @@ private Set<List<Object>> combinations() {
var keys = filterTypes(options.keys(), cacheSpec.keys());
var values = filterTypes(options.values(), cacheSpec.values());
var statistics = filterTypes(options.stats(), cacheSpec.stats());
var expiry = Sets.immutableEnumSet(Arrays.asList(cacheSpec.expiry()));
var computations = filterTypes(options.compute(), cacheSpec.compute());
var loaders = Sets.immutableEnumSet(Arrays.asList(cacheSpec.loader()));
var weigher = Sets.immutableEnumSet(Arrays.asList(cacheSpec.weigher()));
var executor = Sets.immutableEnumSet(Arrays.asList(cacheSpec.executor()));
var scheduler = Sets.immutableEnumSet(Arrays.asList(cacheSpec.scheduler()));
var population = Sets.immutableEnumSet(Arrays.asList(cacheSpec.population()));
var maximumSize = Sets.immutableEnumSet(Arrays.asList(cacheSpec.maximumSize()));
var implementations = filterTypes(options.implementation(), cacheSpec.implementation());
var initialCapacity = Sets.immutableEnumSet(Arrays.asList(cacheSpec.initialCapacity()));
var removalListener = Sets.immutableEnumSet(Arrays.asList(cacheSpec.removalListener()));
var evictionListener = Sets.immutableEnumSet(Arrays.asList(cacheSpec.evictionListener()));
var expireAfterWrite = Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterWrite()));
var expireAfterAccess = Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterAccess()));
var refreshAfterWrite = Sets.immutableEnumSet(Arrays.asList(cacheSpec.refreshAfterWrite()));

if (isAsyncOnly) {
values = values.contains(ReferenceType.STRONG)
Expand All @@ -119,26 +131,11 @@ private Set<List<Object>> combinations() {
if (computations.isEmpty() || implementations.isEmpty() || keys.isEmpty() || values.isEmpty()) {
return ImmutableSet.of();
}
return Sets.cartesianProduct(
Sets.immutableEnumSet(Arrays.asList(cacheSpec.initialCapacity())),
Sets.immutableEnumSet(statistics),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.weigher())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.maximumSize())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.expiry())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterAccess())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterWrite())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.refreshAfterWrite())),
Sets.immutableEnumSet(keys),
Sets.immutableEnumSet(values),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.executor())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.scheduler())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.removalListener())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.evictionListener())),
Sets.immutableEnumSet(Arrays.asList(cacheSpec.population())),
asyncLoader,
Sets.immutableEnumSet(computations),
Sets.immutableEnumSet(loaders),
Sets.immutableEnumSet(implementations));

return Sets.cartesianProduct(initialCapacity, statistics, weigher, maximumSize, expiry,
expireAfterAccess, expireAfterWrite, refreshAfterWrite, keys, values, executor, scheduler,
removalListener, evictionListener, population, asyncLoader, computations, loaders,
implementations);
}

/** Returns the set of options filtered if a specific type is specified. */
Expand Down
5 changes: 5 additions & 0 deletions gradle/config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@
<Method name="activate"/>
<Bug pattern="UPM_UNCALLED_PRIVATE_METHOD"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.jcache.CacheFactory$Builder"/>
<Method name="newLoadingCacheProxy"/>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.jcache.CacheProxy"/>
<Method name="postProcess"/>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ eclipse-collections = "12.0.0.M3"
ehcache3 = "3.10.8"
errorprone = "2.35.1"
errorprone-plugin = "4.1.0"
errorprone-support = "0.19.0"
errorprone-support = "0.19.1"
expiring-map = "0.5.11"
fast-filter = "1.0.2"
fastutil = "8.5.15"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
`java-library`
}

val mockitoAgent: Configuration by configurations.creating

dependencies {
testImplementation(libs.guava)
testImplementation(libs.guice)
Expand All @@ -25,13 +27,18 @@ dependencies {
testRuntimeOnly(libs.junit5.launcher)
testRuntimeOnly(libs.bundles.junit.engines)
testRuntimeOnly(libs.bundles.osgi.test.runtime)

mockitoAgent(libs.mockito) {
isTransitive = false
}
}

tasks.withType<Test>().configureEach {
inputs.property("javaVendor", java.toolchain.vendor.get().toString())

// Use --debug-jvm to remotely attach to the test task
jvmArgs("-XX:SoftRefLRUPolicyMSPerMB=0", "-XX:+EnableDynamicAgentLoading", "-Xshare:off")
jvmArgs("-javaagent:${mockitoAgent.asPath}")
jvmArgs(defaultJvmArgs())
if (isCI()) {
reports.junitXml.includeSystemOutLog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,8 @@ private CacheProxy<K, V> newCacheProxy() {

/** Creates a cache that reads through on a cache miss. */
private CacheProxy<K, V> newLoadingCacheProxy() {
var factory = config.getCacheLoaderFactory();
if (factory == null) {
throw new IllegalStateException();
}

CacheLoader<K, V> cacheLoader = factory.create();
@SuppressWarnings("NullAway")
CacheLoader<K, V> cacheLoader = config.getCacheLoaderFactory().create();
var adapter = new JCacheLoaderAdapter<>(
cacheLoader, dispatcher, expiryPolicy, ticker, statistics);
var cache = new LoadingCacheProxy<>(cacheName, executor, cacheManager, config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,13 @@ public void disabled() {
DisabledCacheWriter.get().deleteAll(null);
}

@Test
public void hasCacheWriter() {
var noWriter = new CaffeineConfiguration<>(jcacheConfiguration)
.setCacheWriterFactory(null);
assertThat(noWriter.hasCacheWriter()).isFalse();
assertThat(jcacheConfiguration.hasCacheWriter()).isTrue();
}

interface CloseableCacheWriter extends CacheWriter<Integer, Integer>, Closeable {}
}

0 comments on commit 4f94cf6

Please sign in to comment.