From 220fc862d0ec662619fb934ba14cbdace7ea9571 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Mon, 13 Jul 2015 18:16:29 -0700 Subject: [PATCH] Fix bad pom being generated (fix #22) The tracing-api test artifact was being consumed by caffeine and the tracing-async projects in order to share a test utility. Due to Gradle generating the Maven pom dependencies in a non-deterministic order, this resulted in Maven resolving the dependencies incorrectly. Instead of allowing both a test and compile scope, Maven ignored the compile scope and did not consume the transitive dependency in downstream projects. The utility class was moved to caffeine/test and the async usage was rewritted to be ad hoc. Verified the pom generated only includes the compile scoped dependency. --- caffeine/build.gradle | 1 - .../caffeine/profiler/ProfilerHook.java | 2 +- .../benmanes/caffeine/cache/Caffeine.java | 2 +- .../caffeine/ConcurrentLinkedStackTest.java | 1 + .../caffeine/SingleConsumerQueueTest.java | 1 + .../caffeine/cache/BoundedBufferTest.java | 2 +- .../caffeine/cache/BoundedLocalCacheTest.java | 2 +- .../benmanes/caffeine/cache/Stresser.java | 2 +- .../caffeine/cache/StripedBufferTest.java | 2 +- .../caffeine/cache/buffer/BufferTest.java | 2 +- .../cache/stats/StatsCounterTest.java | 2 +- .../caffeine/locks/NonReentrantLockTest.java | 2 +- .../testing}/ConcurrentTestHarness.java | 2 +- .../benmanes/caffeine/testing/Threads.java | 1 - gradle/publish.gradle | 2 +- guava/build.gradle | 2 -- .../benmanes/caffeine/PackageSanityTests.java | 9 +----- .../caffeine/guava/CaffeinatedGuavaTest.java | 17 ++++++++--- .../common/cache/CacheBuilderGwtTest.java | 1 - .../google/common/cache/CacheBuilderTest.java | 4 +-- .../common/cache/CacheExpirationTest.java | 5 ++-- .../google/common/cache/CacheLoadingTest.java | 23 ++++++++------- .../google/common/cache/CacheRefreshTest.java | 1 - .../com/google/common/cache/FakeTicker.java | 28 +++++++++++++++++++ simulator/build.gradle | 2 +- tracing/async/build.gradle | 1 - .../cache/tracing/async/AsyncTracerTest.java | 20 +++++++++++-- 27 files changed, 88 insertions(+), 51 deletions(-) rename {tracing/api/src/test/java/com/github/benmanes/caffeine => caffeine/src/test/java/com/github/benmanes/caffeine/testing}/ConcurrentTestHarness.java (99%) create mode 100644 guava/src/test/java/com/google/common/cache/FakeTicker.java diff --git a/caffeine/build.gradle b/caffeine/build.gradle index 4def9344f6..f734defc52 100644 --- a/caffeine/build.gradle +++ b/caffeine/build.gradle @@ -22,7 +22,6 @@ dependencies { compile project(':tracing:api') testCompile project(':simulator') - testCompile project(path: ':tracing:api', configuration: 'testArtifacts') testCompile libraries.guava testCompile test_libraries.awaitility testCompile test_libraries.guava_testlib diff --git a/caffeine/src/jmh/java/com/github/benmanes/caffeine/profiler/ProfilerHook.java b/caffeine/src/jmh/java/com/github/benmanes/caffeine/profiler/ProfilerHook.java index f6808ad9a0..8fff90657b 100644 --- a/caffeine/src/jmh/java/com/github/benmanes/caffeine/profiler/ProfilerHook.java +++ b/caffeine/src/jmh/java/com/github/benmanes/caffeine/profiler/ProfilerHook.java @@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.LongAdder; -import com.github.benmanes.caffeine.ConcurrentTestHarness; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.base.Stopwatch; /** diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java index 9c54dcbef1..4fffead595 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java @@ -666,7 +666,7 @@ RemovalListener getRemovalListener(boolean * Warning: any exception thrown by {@code writer} will be propagated to the {@code Cache} * user. *

- * This feature cannot be used in conjunction with {@link #buildAsync}. + * This feature cannot be used in conjunction with {@link #weakKeys()} or {@link #buildAsync}. * * @param writer a writer instance that caches should notify each time an entry is explicitly * created or modified, or removed for any reason diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/ConcurrentLinkedStackTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/ConcurrentLinkedStackTest.java index 29f4bcb62b..80da323a2a 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/ConcurrentLinkedStackTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/ConcurrentLinkedStackTest.java @@ -51,6 +51,7 @@ import com.github.benmanes.caffeine.ConcurrentLinkedStackTest.ValidatingStackListener; import com.github.benmanes.caffeine.base.UnsafeAccess; import com.github.benmanes.caffeine.testing.Awaits; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import com.google.common.testing.SerializableTester; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/SingleConsumerQueueTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/SingleConsumerQueueTest.java index 60c135f641..918f870d51 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/SingleConsumerQueueTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/SingleConsumerQueueTest.java @@ -47,6 +47,7 @@ import com.github.benmanes.caffeine.SingleConsumerQueue.LinearizableNode; import com.github.benmanes.caffeine.SingleConsumerQueueTest.ValidatingQueueListener; import com.github.benmanes.caffeine.testing.Awaits; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.testing.SerializableTester; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedBufferTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedBufferTest.java index 4e3f88d02f..59d558fc39 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedBufferTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedBufferTest.java @@ -26,7 +26,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; /** * The tests cases for the {@link BoundedBuffer}. diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java index 9e8b33ea9a..751dc2fcae 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java @@ -37,7 +37,6 @@ import org.testng.annotations.Listeners; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.Policy.Eviction; import com.github.benmanes.caffeine.cache.testing.CacheContext; import com.github.benmanes.caffeine.cache.testing.CacheProvider; @@ -52,6 +51,7 @@ import com.github.benmanes.caffeine.cache.testing.CacheValidationListener; import com.github.benmanes.caffeine.locks.NonReentrantLock; import com.github.benmanes.caffeine.testing.Awaits; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/Stresser.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/Stresser.java index 2429974a4f..7df5e26218 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/Stresser.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/Stresser.java @@ -25,9 +25,9 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.LongAdder; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.simulator.generator.IntegerGenerator; import com.github.benmanes.caffeine.cache.simulator.generator.ScrambledZipfianGenerator; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ThreadFactoryBuilder; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/StripedBufferTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/StripedBufferTest.java index a2a0076772..2e2332fe8f 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/StripedBufferTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/StripedBufferTest.java @@ -26,7 +26,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.base.MoreObjects; /** diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java index edd7cb1848..24db24a004 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/buffer/BufferTest.java @@ -24,8 +24,8 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.ReadBuffer; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; /** * The tests cases for a read buffer strategy. This validates an implementation approach which can diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/StatsCounterTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/StatsCounterTest.java index 13cf3a3cc0..7d68cab525 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/StatsCounterTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/StatsCounterTest.java @@ -20,7 +20,7 @@ import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; /** * @author ben.manes@gmail.com (Ben Manes) diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/locks/NonReentrantLockTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/locks/NonReentrantLockTest.java index 5c7a8f4c65..1bf941d2bf 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/locks/NonReentrantLockTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/locks/NonReentrantLockTest.java @@ -28,8 +28,8 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.testing.Awaits; +import com.github.benmanes.caffeine.testing.ConcurrentTestHarness; import com.google.common.testing.SerializableTester; /** diff --git a/tracing/api/src/test/java/com/github/benmanes/caffeine/ConcurrentTestHarness.java b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/ConcurrentTestHarness.java similarity index 99% rename from tracing/api/src/test/java/com/github/benmanes/caffeine/ConcurrentTestHarness.java rename to caffeine/src/test/java/com/github/benmanes/caffeine/testing/ConcurrentTestHarness.java index c3caf6e37a..248370f5f7 100644 --- a/tracing/api/src/test/java/com/github/benmanes/caffeine/ConcurrentTestHarness.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/ConcurrentTestHarness.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.benmanes.caffeine; +package com.github.benmanes.caffeine.testing; import java.util.ArrayList; import java.util.List; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/Threads.java b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/Threads.java index a18abc0cdf..6e81ba6c6d 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/Threads.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/Threads.java @@ -41,7 +41,6 @@ import org.testng.log4testng.Logger; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.MoreExecutors; diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 628e59e83c..9e164b0bcf 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -13,7 +13,7 @@ extraArchive.tests = true modifyPom { project { name 'Caffeine cache' - description 'Concurrent data-structures for Java' + description 'A high performance caching library for Java 8+' url 'https://github.com/ben-manes/caffeine' inceptionYear '2014' diff --git a/guava/build.gradle b/guava/build.gradle index 8e996019fa..e3e1722f8c 100644 --- a/guava/build.gradle +++ b/guava/build.gradle @@ -7,8 +7,6 @@ dependencies { compile project(":caffeine") compile libraries.guava - testCompile project(path: ':tracing:api', configuration: 'testArtifacts') - testCompile project(path: ":caffeine", configuration: "testArtifacts") testCompile test_libraries.junit testCompile test_libraries.guava_testlib testCompile test_libraries.truth diff --git a/guava/src/test/java/com/github/benmanes/caffeine/PackageSanityTests.java b/guava/src/test/java/com/github/benmanes/caffeine/PackageSanityTests.java index 7ff1513287..585e9f658a 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/PackageSanityTests.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/PackageSanityTests.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine; -import com.github.benmanes.caffeine.testing.Awaits; import com.google.common.testing.AbstractPackageSanityTests; /** @@ -28,13 +27,7 @@ public class PackageSanityTests extends AbstractPackageSanityTests { public PackageSanityTests() { publicApiOnly(); ignoreClasses(clazz -> - clazz == Awaits.class || clazz == SingleConsumerQueue.class || - clazz == ConcurrentLinkedStack.class || - clazz.getSimpleName().startsWith("Is") || - clazz.getSimpleName().contains("Test") || - clazz.getSimpleName().contains("Stresser") || - clazz.getSimpleName().contains("Generator") || - clazz.getSimpleName().contains("Benchmark")); + clazz == ConcurrentLinkedStack.class); } } diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java index 303e083a18..63e08feb43 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaTest.java @@ -17,10 +17,7 @@ import java.lang.reflect.Constructor; -import junit.framework.TestCase; - import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader; import com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache.CacheLoaderException; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -28,6 +25,8 @@ import com.google.common.testing.SerializableTester; import com.google.common.util.concurrent.MoreExecutors; +import junit.framework.TestCase; + /** * @author ben.manes@gmail.com (Ben Manes) */ @@ -35,7 +34,8 @@ public final class CaffeinatedGuavaTest extends TestCase { public void testSerializable() { SerializableTester.reserialize(CaffeinatedGuava.build(Caffeine.newBuilder())); - SerializableTester.reserialize(CaffeinatedGuava.build(Caffeine.newBuilder(), Loader.IDENTITY)); + SerializableTester.reserialize(CaffeinatedGuava.build( + Caffeine.newBuilder(), IdentityLoader.INSTANCE)); SerializableTester.reserialize(CaffeinatedGuava.build( Caffeine.newBuilder(), TestingCacheLoaders.identityLoader())); } @@ -81,4 +81,13 @@ public void testReload_throwable() { assertTrue(Thread.currentThread().isInterrupted()); } } + + enum IdentityLoader implements com.github.benmanes.caffeine.cache.CacheLoader { + INSTANCE; + + @Override + public Object load(Object key) { + return key; + } + } } diff --git a/guava/src/test/java/com/google/common/cache/CacheBuilderGwtTest.java b/guava/src/test/java/com/google/common/cache/CacheBuilderGwtTest.java index 7dfb99540c..97851826ad 100644 --- a/guava/src/test/java/com/google/common/cache/CacheBuilderGwtTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheBuilderGwtTest.java @@ -28,7 +28,6 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalListener; import com.github.benmanes.caffeine.cache.RemovalNotification; -import com.github.benmanes.caffeine.cache.testing.FakeTicker; import com.github.benmanes.caffeine.guava.CaffeinatedGuava; import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableList; diff --git a/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java b/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java index 119188a0d5..1761c1c4b4 100644 --- a/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java @@ -32,11 +32,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalListener; import com.github.benmanes.caffeine.cache.RemovalNotification; @@ -357,7 +357,7 @@ public void testRemovalNotification_clear() throws InterruptedException { final CountDownLatch computationStarted = new CountDownLatch(1); final CountDownLatch computationComplete = new CountDownLatch(1); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { computationStarted.countDown(); cache.getUnchecked("b"); computationComplete.countDown(); diff --git a/guava/src/test/java/com/google/common/cache/CacheExpirationTest.java b/guava/src/test/java/com/google/common/cache/CacheExpirationTest.java index d2b105e9a0..421de009bf 100644 --- a/guava/src/test/java/com/google/common/cache/CacheExpirationTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheExpirationTest.java @@ -25,12 +25,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.TestCase; - import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalListener; import com.github.benmanes.caffeine.cache.RemovalNotification; -import com.github.benmanes.caffeine.cache.testing.FakeTicker; import com.github.benmanes.caffeine.guava.CaffeinatedGuava; import com.google.common.cache.TestingCacheLoaders.IdentityLoader; import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; @@ -38,6 +35,8 @@ import com.google.common.util.concurrent.Callables; import com.google.common.util.concurrent.MoreExecutors; +import junit.framework.TestCase; + /** * Tests relating to cache expiration: make sure entries expire at the right times, make sure * expired entries don't show up, etc. diff --git a/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java b/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java index 59b0d06eab..7700b0b3d6 100644 --- a/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java @@ -30,17 +30,14 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.logging.Logger; -import junit.framework.TestCase; - -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.testing.FakeTicker; import com.github.benmanes.caffeine.guava.CaffeinatedGuava; import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.TestingCacheLoaders.IdentityLoader; @@ -58,6 +55,8 @@ import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.Uninterruptibles; +import junit.framework.TestCase; + /** * Tests relating to cache loading: concurrent loading, exceptions during loading, etc. * @@ -2089,11 +2088,11 @@ public String load(String key) { assertFalse(map.containsKey(getKey)); assertSame(refreshKey, map.get(refreshKey)); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.getUnchecked(getKey); getFinishedSignal.countDown(); }); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.refresh(refreshKey); getFinishedSignal.countDown(); }); @@ -2140,11 +2139,11 @@ public String load(String key) { ConcurrentMap map = cache.asMap(); map.put(refreshKey, refreshKey); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.getUnchecked(getKey); getFinishedSignal.countDown(); }); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.refresh(refreshKey); getFinishedSignal.countDown(); }); @@ -2192,11 +2191,11 @@ public String load(String key) { ConcurrentMap map = cache.asMap(); map.put(refreshKey, refreshKey); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.getUnchecked(getKey); getFinishedSignal.countDown(); }); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.refresh(refreshKey); getFinishedSignal.countDown(); }); @@ -2208,11 +2207,11 @@ public String load(String key) { assertFalse(map.containsKey(refreshKey)); // start new computations - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.getUnchecked(getKey); getFinishedSignal.countDown(); }); - ConcurrentTestHarness.execute(() -> { + ForkJoinPool.commonPool().execute(() -> { cache.refresh(refreshKey); getFinishedSignal.countDown(); }); diff --git a/guava/src/test/java/com/google/common/cache/CacheRefreshTest.java b/guava/src/test/java/com/google/common/cache/CacheRefreshTest.java index 224c5a8b2a..dda946298b 100644 --- a/guava/src/test/java/com/google/common/cache/CacheRefreshTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheRefreshTest.java @@ -19,7 +19,6 @@ import junit.framework.TestCase; import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.testing.FakeTicker; import com.github.benmanes.caffeine.guava.CaffeinatedGuava; import com.google.common.cache.TestingCacheLoaders.IncrementingLoader; import com.google.common.util.concurrent.MoreExecutors; diff --git a/guava/src/test/java/com/google/common/cache/FakeTicker.java b/guava/src/test/java/com/google/common/cache/FakeTicker.java new file mode 100644 index 0000000000..95280d6b2c --- /dev/null +++ b/guava/src/test/java/com/google/common/cache/FakeTicker.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.common.cache; + +import java.io.Serializable; + +import com.github.benmanes.caffeine.cache.Ticker; + +/** + * @author ben.manes@gmail.com (Ben Manes) + */ +final class FakeTicker extends com.google.common.testing.FakeTicker + implements Ticker, Serializable { + private static final long serialVersionUID = 1L; +} diff --git a/simulator/build.gradle b/simulator/build.gradle index da481beac4..2df1b962df 100644 --- a/simulator/build.gradle +++ b/simulator/build.gradle @@ -5,6 +5,7 @@ mainClassName = 'com.github.benmanes.caffeine.cache.simulator.Simulator' dependencies { compile project(':tracing:api') + compile project(':tracing:async') compile libraries.akka compile libraries.joor @@ -12,7 +13,6 @@ dependencies { compile libraries.flip_tables compile libraries.univocity_parsers - compile project(':tracing:async') testCompile test_libraries.jimfs testCompile test_libraries.testng testCompile test_libraries.awaitility diff --git a/tracing/async/build.gradle b/tracing/async/build.gradle index 8381e0f4d0..0f2e61f9f5 100644 --- a/tracing/async/build.gradle +++ b/tracing/async/build.gradle @@ -7,7 +7,6 @@ dependencies { testCompile test_libraries.jimfs testCompile test_libraries.testng testCompile test_libraries.awaitility - testCompile project(path: ':tracing:api', configuration: 'testArtifacts') } test { diff --git a/tracing/async/src/test/java/com/github/benmanes/caffeine/cache/tracing/async/AsyncTracerTest.java b/tracing/async/src/test/java/com/github/benmanes/caffeine/cache/tracing/async/AsyncTracerTest.java index 4d9e71caa9..f65897ba05 100644 --- a/tracing/async/src/test/java/com/github/benmanes/caffeine/cache/tracing/async/AsyncTracerTest.java +++ b/tracing/async/src/test/java/com/github/benmanes/caffeine/cache/tracing/async/AsyncTracerTest.java @@ -15,6 +15,7 @@ */ package com.github.benmanes.caffeine.cache.tracing.async; +import static com.jayway.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; @@ -26,12 +27,14 @@ import java.nio.file.Path; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.Phaser; +import java.util.concurrent.atomic.AtomicInteger; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.github.benmanes.caffeine.ConcurrentTestHarness; import com.github.benmanes.caffeine.cache.tracing.Tracer; import com.google.common.jimfs.Jimfs; import com.lmax.disruptor.util.DaemonThreadFactory; @@ -60,14 +63,25 @@ public void serviceLoader() { @Test(dataProvider = "tracer") public void publishEvents(AsyncTracer tracer, boolean plainText) throws Exception { - ConcurrentTestHarness.timeTasks(10, () -> { + int nThreads = 10; + Phaser phaser = new Phaser(nThreads); + AtomicInteger done = new AtomicInteger(); + + Runnable task = () -> { + phaser.arriveAndAwaitAdvance(); for (int i = 0; i < 100; i++) { tracer.register(Integer.toString(i)); tracer.recordRead(i, i); tracer.recordWrite(i, i, i); tracer.recordDelete(i, i); } - }); + done.incrementAndGet(); + }; + for (int i = 0; i < nThreads; i++) { + ForkJoinPool.commonPool().execute(task); + } + await().untilAtomic(done, is(nThreads)); + tracer.shutdown(); if (plainText) { assertThat(Files.lines(filePath).count(), is(4000L));