Skip to content

Commit

Permalink
run isolatedTests on ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jul 5, 2021
1 parent 13af13c commit 0f1692d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ run() {
}

run "./gradlew check"
run "./gradlew :caffeine:isolatedTests"
run "./gradlew :caffeine:slowGuavaTest"
run "./gradlew :caffeine:slowCaffeineTest"
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@

import static com.github.benmanes.caffeine.testing.ConcurrentTestHarness.DAEMON_FACTORY;
import static com.github.benmanes.caffeine.testing.ConcurrentTestHarness.timeTasks;
import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset;
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.is;

import java.time.Duration;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.testing.RemovalListeners;
import com.github.benmanes.caffeine.cache.testing.RemovalListeners.ConsumingRemovalListener;
import com.github.benmanes.caffeine.cache.testing.RemovalNotification;
import com.google.common.collect.Multiset;

import site.ycsb.generator.NumberGenerator;
import site.ycsb.generator.ScrambledZipfianGenerator;
Expand All @@ -52,19 +47,23 @@
public final class Issue412Test {
private static final int NUM_THREADS = 5;

private ConsumingRemovalListener<Integer, Boolean> listener;
private Cache<Integer, Boolean> cache;
private ExecutorService executor;
private AtomicBoolean collected;
private Integer[] ints;
private Random random;

@BeforeMethod
public void before() {
executor = Executors.newCachedThreadPool(DAEMON_FACTORY);
listener = RemovalListeners.consuming();
collected = new AtomicBoolean();
cache = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofNanos(10))
.removalListener(listener)
.removalListener((k, v, cause) -> {
if (cause == RemovalCause.COLLECTED) {
collected.set(true);
}
})
.executor(executor)
.build();
ints = generateSequence();
Expand All @@ -75,11 +74,7 @@ public void before() {
public void expire_remove() {
timeTasks(NUM_THREADS, this::addRemoveAndExpire);
shutdownAndAwaitTermination(executor, 1, TimeUnit.MINUTES);

Multiset<RemovalCause> causes = listener.removed().stream()
.map(RemovalNotification::getCause)
.collect(toImmutableMultiset());
assertThat(causes, not(hasItem(RemovalCause.COLLECTED)));
assertThat(collected.get(), is(false));
}

private void addRemoveAndExpire() {
Expand Down
2 changes: 0 additions & 2 deletions caffeine/testing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ testNames.each { testName ->

task isolatedTests(type: Test, group: 'Cache tests') {
description = 'Tests that must be run in isolation'

useTestNG()
it.onlyIf { !System.env.'CI' }
}

task osgiTests(type: Test, group: 'Cache tests', description: 'Isolated OSGi tests') {
Expand Down

0 comments on commit 0f1692d

Please sign in to comment.