Skip to content

Commit

Permalink
Fix bad pom being generated (fix #22)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ben-manes committed Jul 14, 2015
1 parent ba81c36 commit 220fc86
Show file tree
Hide file tree
Showing 27 changed files with 88 additions and 51 deletions.
1 change: 0 additions & 1 deletion caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ <K1 extends K, V1 extends V> RemovalListener<K1, V1> getRemovalListener(boolean
* <b>Warning:</b> any exception thrown by {@code writer} will be propagated to the {@code Cache}
* user.
* <p>
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.testng.annotations.Test;

import com.github.benmanes.caffeine.ConcurrentTestHarness;
import com.github.benmanes.caffeine.testing.ConcurrentTestHarness;

/**
* @author [email protected] (Ben Manes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 0 additions & 2 deletions guava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.benmanes.caffeine;

import com.github.benmanes.caffeine.testing.Awaits;
import com.google.common.testing.AbstractPackageSanityTests;

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@

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;
import com.google.common.cache.TestingCacheLoaders;
import com.google.common.testing.SerializableTester;
import com.google.common.util.concurrent.MoreExecutors;

import junit.framework.TestCase;

/**
* @author [email protected] (Ben Manes)
*/
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()));
}
Expand Down Expand Up @@ -81,4 +81,13 @@ public void testReload_throwable() {
assertTrue(Thread.currentThread().isInterrupted());
}
}

enum IdentityLoader implements com.github.benmanes.caffeine.cache.CacheLoader<Object, Object> {
INSTANCE;

@Override
public Object load(Object key) {
return key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
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;
import com.google.common.collect.Iterators;
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.
Expand Down
23 changes: 11 additions & 12 deletions guava/src/test/java/com/google/common/cache/CacheLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -2140,11 +2139,11 @@ public String load(String key) {
ConcurrentMap<String,String> 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();
});
Expand Down Expand Up @@ -2192,11 +2191,11 @@ public String load(String key) {
ConcurrentMap<String,String> 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();
});
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions guava/src/test/java/com/google/common/cache/FakeTicker.java
Original file line number Diff line number Diff line change
@@ -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 [email protected] (Ben Manes)
*/
final class FakeTicker extends com.google.common.testing.FakeTicker
implements Ticker, Serializable {
private static final long serialVersionUID = 1L;
}
Loading

0 comments on commit 220fc86

Please sign in to comment.