Internal change

RELNOTES=n/a
PiperOrigin-RevId: 347710478
This commit is contained in:
Google Java Core Libraries 2020-12-15 18:56:08 -05:00 committed by Colin Decker
parent 4ce1869ed7
commit 2b55799273
228 changed files with 1158 additions and 847 deletions

View File

@ -125,4 +125,3 @@ flavor.
[using Guava in your build]: https://github.com/google/guava/wiki/UseGuavaInYourBuild
[repackage]: https://github.com/google/guava/wiki/UseGuavaInYourBuild#what-if-i-want-to-use-beta-apis-from-a-library-that-people-use-as-a-dependency

View File

@ -29,7 +29,6 @@ import junit.framework.AssertionFailedError;
* serialization tests require more setup. This no-op behavior allows test authors to intersperse
* {@code SerializableTester} calls with other, GWT-compatible tests.
*
*
* @author Mike Bostock
* @since 10.0
*/

View File

@ -151,7 +151,7 @@ public class FakeTickerTest extends TestCase {
final CountDownLatch startLatch = new CountDownLatch(numberOfThreads);
final CountDownLatch doneLatch = new CountDownLatch(numberOfThreads);
for (int i = numberOfThreads; i > 0; i--) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
executorService.submit(
new Callable<Void>() {

View File

@ -16,6 +16,7 @@
package com.google.common.testing;
/** Test nulls for the entire package. */
public class PackageSanityTests extends AbstractPackageSanityTests {}

View File

@ -29,7 +29,6 @@ import java.util.Random;
/**
* Benchmark for the {@link CharMatcher} class.
*
*
* @author David Beaumont
* @author Kevin Bourrillion
* @author David Richter

View File

@ -252,7 +252,7 @@ public class ExecutionListBenchmark {
final AtomicInteger integer = new AtomicInteger();
// Execute a bunch of tasks to ensure that our threads are allocated and hot
for (int i = 0; i < NUM_THREADS * 10; i++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
executorService.submit(
new Runnable() {
@ -334,10 +334,10 @@ public class ExecutionListBenchmark {
list = impl.newExecutionList();
listenerLatch = new CountDownLatch(numListeners * NUM_THREADS);
for (int j = 0; j < NUM_THREADS; j++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = executorService.submit(addTask);
}
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = executorService.submit(executeTask);
returnValue += (int) listenerLatch.getCount();
listenerLatch.await();
@ -360,10 +360,10 @@ public class ExecutionListBenchmark {
for (int i = 0; i < reps; i++) {
list = impl.newExecutionList();
listenerLatch = new CountDownLatch(numListeners * NUM_THREADS);
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = executorService.submit(executeTask);
for (int j = 0; j < NUM_THREADS; j++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError1 = executorService.submit(addTask);
}
returnValue += (int) listenerLatch.getCount();

View File

@ -171,6 +171,7 @@ public class AbstractIteratorTest extends TestCase {
}
}
@GwtIncompatible // weak references
public void testFreesNextReference() {
Iterator<Object> itr =

View File

@ -32,7 +32,6 @@ import java.lang.annotation.Target;
* Google-internal Android suite generators. Note that those generators also suppress any test
* annotated with MediumTest or LargeTest.
*
*
* <p>Why use a custom annotation instead of {@code android.test.suitebuilder.annotation.Suppress}?
* I'm not completely sure that this is the right choice, but it has various advantages:
*

View File

@ -79,6 +79,7 @@ public class EnumsTest extends TestCase {
assertThat(Enums.getIfPresent(TestEnum.class, "WOMBAT")).isAbsent();
}
@GwtIncompatible // weak references
public void testGetIfPresent_doesNotPreventClassUnloading() throws Exception {
WeakReference<?> shadowLoaderReference = doTestClassUnloading();

View File

@ -47,6 +47,7 @@ import junit.framework.TestCase;
* @author Eamonn McManus
*/
public class FinalizableReferenceQueueClassLoaderUnloadingTest extends TestCase {
/*

View File

@ -40,6 +40,7 @@ public class FinalizableReferenceQueueTest extends TestCase {
frq = null;
}
public void testFinalizeReferentCalled() {
final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());
@ -71,6 +72,7 @@ public class FinalizableReferenceQueueTest extends TestCase {
*/
private WeakReference<ReferenceQueue<Object>> queueReference;
public void testThatFinalizerStops() {
weaklyReferenceQueue();
GcFinalization.awaitClear(queueReference);

View File

@ -500,7 +500,7 @@ public class CacheBuilderTest extends TestCase {
final CountDownLatch tasksFinished = new CountDownLatch(nTasks);
for (int i = 0; i < nTasks; i++) {
final String s = "a" + i;
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {
@ -595,7 +595,7 @@ public class CacheBuilderTest extends TestCase {
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
for (int i = 0; i < nTasks; i++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {

View File

@ -79,7 +79,7 @@ public class CacheLoaderTest extends TestCase {
assertEquals(0, loadAllCount.get());
baseLoader.load(new Object());
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object());
baseLoader.loadAll(ImmutableList.of(new Object()));
assertEquals(1, loadCount.get());
@ -90,7 +90,7 @@ public class CacheLoaderTest extends TestCase {
CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor);
asyncReloader.load(new Object());
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError1 = asyncReloader.reload(new Object(), new Object());
asyncReloader.loadAll(ImmutableList.of(new Object()));
assertEquals(2, loadCount.get());

View File

@ -1766,6 +1766,7 @@ public class CacheLoadingTest extends TestCase {
assertEquals(0, removalListener.getCount());
}
public void testReloadAfterValueReclamation() throws InterruptedException, ExecutionException {
CountingLoader countingLoader = new CountingLoader();
LoadingCache<Object, Object> cache =
@ -1940,6 +1941,7 @@ public class CacheLoadingTest extends TestCase {
}
}
public void testConcurrentLoading() throws InterruptedException {
testConcurrentLoading(CacheBuilder.newBuilder());
}
@ -1952,6 +1954,7 @@ public class CacheLoadingTest extends TestCase {
testConcurrentLoadingCheckedException(builder);
}
public void testConcurrentExpirationLoading() throws InterruptedException {
testConcurrentLoading(CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS));
}
@ -2181,6 +2184,7 @@ public class CacheLoadingTest extends TestCase {
return resultList;
}
public void testAsMapDuringLoading() throws InterruptedException, ExecutionException {
final CountDownLatch getStartedSignal = new CountDownLatch(2);
final CountDownLatch letGetFinishSignal = new CountDownLatch(1);
@ -2239,6 +2243,7 @@ public class CacheLoadingTest extends TestCase {
assertEquals(refreshKey + suffix, map.get(refreshKey));
}
public void testInvalidateDuringLoading() throws InterruptedException, ExecutionException {
// computation starts; invalidate() is called on the key being computed, computation finishes
final CountDownLatch computationStarted = new CountDownLatch(2);
@ -2295,6 +2300,7 @@ public class CacheLoadingTest extends TestCase {
assertEquals(2, cache.size());
}
public void testInvalidateAndReloadDuringLoading()
throws InterruptedException, ExecutionException {
// computation starts; clear() is called, computation finishes
@ -2367,6 +2373,7 @@ public class CacheLoadingTest extends TestCase {
assertEquals(refreshKey + suffix, map.get(refreshKey));
}
public void testExpandDuringLoading() throws InterruptedException {
final int count = 3;
final AtomicInteger callCount = new AtomicInteger();

View File

@ -47,6 +47,7 @@ public class EmptyCachesTest extends TestCase {
}
}
public void testInvalidate_empty() {
for (LoadingCache<Object, Object> cache : caches()) {
cache.getUnchecked("a");
@ -68,6 +69,7 @@ public class EmptyCachesTest extends TestCase {
}
}
public void testEquals_null() {
for (LoadingCache<Object, Object> cache : caches()) {
assertFalse(cache.equals(null));
@ -137,6 +139,7 @@ public class EmptyCachesTest extends TestCase {
}
}
public void testKeySet_clear() {
for (LoadingCache<Object, Object> cache : caches()) {
warmUp(cache, 0, 100);
@ -211,6 +214,7 @@ public class EmptyCachesTest extends TestCase {
}
}
public void testValues_clear() {
for (LoadingCache<Object, Object> cache : caches()) {
warmUp(cache, 0, 100);
@ -285,6 +289,7 @@ public class EmptyCachesTest extends TestCase {
}
}
public void testEntrySet_clear() {
for (LoadingCache<Object, Object> cache : caches()) {
warmUp(cache, 0, 100);

View File

@ -97,6 +97,7 @@ public class LocalCacheTest extends TestCase {
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(LocalCacheTest.class);
@ -700,6 +701,7 @@ public class LocalCacheTest extends TestCase {
assertEquals(1, map.size());
}
public void testCopyEntry_computing() {
final CountDownLatch startSignal = new CountDownLatch(1);
final CountDownLatch computingSignal = new CountDownLatch(1);
@ -801,6 +803,7 @@ public class LocalCacheTest extends TestCase {
checkLogged(e);
}
public void testRemovalListener_replaced_computing() {
final CountDownLatch startSignal = new CountDownLatch(1);
final CountDownLatch computingSignal = new CountDownLatch(1);

View File

@ -157,7 +157,7 @@ public class LocalLoadingCacheTest extends TestCase {
assertThat(map).containsEntry(three, one);
assertThat(map).containsEntry(one, two);
// TODO(cgruber): Confirm with fry@ that this is a reasonable substitute.
// TODO(user): Confirm with fry@ that this is a reasonable substitute.
// Set<Entry<Object, Object>> entries = map.entrySet();
// assertThat(entries).containsExactly(
// Maps.immutableEntry(three, one), Maps.immutableEntry(one, two));
@ -293,6 +293,7 @@ public class LocalLoadingCacheTest extends TestCase {
assertFalse(segment.recencyQueue.isEmpty());
}
public void testRecursiveComputation() throws InterruptedException {
final AtomicReference<LoadingCache<Integer, String>> cacheRef = new AtomicReference<>();
CacheLoader<Integer, String> recursiveLoader =

View File

@ -187,6 +187,7 @@ public class PopulatedCachesTest extends TestCase {
}
}
public void testKeySet_populated() {
for (LoadingCache<Object, Object> cache : caches()) {
Set<Object> keys = cache.asMap().keySet();
@ -237,6 +238,7 @@ public class PopulatedCachesTest extends TestCase {
}
}
public void testEntrySet_populated() {
for (LoadingCache<Object, Object> cache : caches()) {
Set<Entry<Object, Object>> entries = cache.asMap().entrySet();

View File

@ -137,6 +137,7 @@ public class AbstractIteratorTest extends TestCase {
}
}
@GwtIncompatible // weak references
public void testFreesNextReference() {
Iterator<Object> itr =

View File

@ -208,6 +208,7 @@ public class ImmutableRangeMapTest extends TestCase {
}
}
public void testSubRangeMap() {
for (Range<Integer> range1 : RANGES) {
for (Range<Integer> range2 : RANGES) {

View File

@ -84,6 +84,7 @@ public class InternersTest extends TestCase {
assertEquals(concurrencyLevel, internerImpl.map.concurrencyLevel);
}
public void testWeak_afterGC() throws InterruptedException {
Integer canonical = new Integer(5);
Integer not = new Integer(5);

View File

@ -101,15 +101,15 @@ public class QueuesTest extends TestCase {
private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedException {
for (boolean interruptibly : new boolean[] {true, false}) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 20));
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError1 = threadPool.submit(new Producer(q, 20));
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError2 = threadPool.submit(new Producer(q, 20));
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError3 = threadPool.submit(new Producer(q, 20));
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError4 = threadPool.submit(new Producer(q, 20));
List<Object> buf = newArrayList();
@ -182,7 +182,7 @@ public class QueuesTest extends TestCase {
}
private void testNegativeMaxElements(BlockingQueue<Object> q) throws InterruptedException {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 1));
List<Object> buf = newArrayList();
@ -201,7 +201,7 @@ public class QueuesTest extends TestCase {
}
private void testDrain_throws(BlockingQueue<Object> q) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread()));
try {
Queues.drain(q, ImmutableList.of(), 100, MAX_VALUE, NANOSECONDS);
@ -218,7 +218,7 @@ public class QueuesTest extends TestCase {
private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue<Object> q) {
final Thread mainThread = currentThread();
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Callable<Void>() {
@ -275,7 +275,7 @@ public class QueuesTest extends TestCase {
}
// but does the wait actually occurs?
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread()));
try {
// if waiting works, this should get stuck
@ -291,7 +291,7 @@ public class QueuesTest extends TestCase {
assertEquals(0, Queues.drainUninterruptibly(q, ImmutableList.of(), 0, 10, MILLISECONDS));
// but does the wait actually occurs?
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread()));
Stopwatch timer = Stopwatch.createStarted();

View File

@ -539,6 +539,7 @@ public class TreeRangeMapTest extends TestCase {
rangeMap.asMapOfRanges());
}
public void testSubRangeMapExhaustive() {
for (Range<Integer> range1 : RANGES) {
for (Range<Integer> range2 : RANGES) {

View File

@ -271,6 +271,7 @@ public class TreeRangeSetTest extends AbstractRangeSetTest {
return expected;
}
public void testSubRangeSet() {
for (Range<Integer> range1 : QUERY_RANGES) {
for (Range<Integer> range2 : QUERY_RANGES) {
@ -309,6 +310,7 @@ public class TreeRangeSetTest extends AbstractRangeSetTest {
}
}
public void testSubRangeSetOfComplement() {
for (Range<Integer> range1 : QUERY_RANGES) {
for (Range<Integer> range2 : QUERY_RANGES) {
@ -324,6 +326,7 @@ public class TreeRangeSetTest extends AbstractRangeSetTest {
}
}
public void testComplementOfSubRangeSet() {
for (Range<Integer> range1 : QUERY_RANGES) {
for (Range<Integer> range2 : QUERY_RANGES) {

View File

@ -785,6 +785,7 @@ public abstract class AbstractNetworkTest {
assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
}
@Test
public void concurrentIteration() throws Exception {
addEdge(1, 2, "foo");

View File

@ -380,6 +380,7 @@ public final class ValueGraphTest {
.inOrder();
}
@Test
public void concurrentIteration() throws Exception {
graph = ValueGraphBuilder.directed().build();

View File

@ -519,6 +519,7 @@ public class BloomFilterTest extends TestCase {
assertEquals(BloomFilterStrategies.MURMUR128_MITZ_64, BloomFilterStrategies.values()[1]);
}
public void testNoRaceConditions() throws Exception {
final BloomFilter<Integer> bloomFilter =
BloomFilter.create(Funnels.integerFunnel(), 15_000_000, 0.01);

View File

@ -16,6 +16,7 @@
package com.google.common.hash;
/**
* An enum that contains all of the known hash functions.
*

View File

View File

@ -51,6 +51,7 @@ public class ByteStreamsTest extends IoTestCase {
assertThat(out.toByteArray()).isEqualTo(expected);
}
public void testCopyFileChannel() throws IOException {
final int chunkSize = 14407; // Random prime, unlikely to match any internal chunk size
ByteArrayOutputStream out = new ByteArrayOutputStream();

View File

@ -16,6 +16,7 @@
package com.google.common.io;
import com.google.common.testing.GcFinalization;
import java.io.File;
import java.io.IOException;
@ -29,6 +30,7 @@ import java.util.Arrays;
*/
public class FileBackedOutputStreamTest extends IoTestCase {
public void testThreshold() throws Exception {
testThreshold(0, 100, true, false);
testThreshold(10, 100, true, false);
@ -76,6 +78,7 @@ public class FileBackedOutputStreamTest extends IoTestCase {
}
}
public void testFinalizeDeletesFile() throws Exception {
byte[] data = newPreFilledByteArray(100);
FileBackedOutputStream out = new FileBackedOutputStream(0, true);
@ -99,6 +102,7 @@ public class FileBackedOutputStreamTest extends IoTestCase {
});
}
public void testThreshold_resetOnFinalize() throws Exception {
testThreshold(0, 100, true, true);
testThreshold(10, 100, true, true);

View File

@ -16,7 +16,6 @@
package com.google.common.io;
import static com.google.common.io.Files.touch;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Charsets;

View File

@ -747,6 +747,7 @@ public class LongMathTest extends TestCase {
}
}
@GwtIncompatible // Slow
public void testBinomial_exhaustiveNotOverflowing() {
// Tests all of the inputs to LongMath.binomial that won't cause it to overflow, that weren't
@ -783,6 +784,7 @@ public class LongMathTest extends TestCase {
}
}
@GwtIncompatible // far too slow
public void testSqrtOfPerfectSquareAsDoubleIsPerfect() {
// This takes just over a minute on my machine.

View File

@ -16,6 +16,7 @@
package com.google.common.net;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Ascii;

View File

@ -169,6 +169,7 @@ public class ClassPathTest extends TestCase {
.isEqualTo(new File("/C:\\\u20320 \u22909"));
}
@AndroidIncompatible // Android forbids null parent ClassLoader
// https://github.com/google/guava/issues/2152
public void testJarFileWithSpaces() throws Exception {
@ -177,6 +178,7 @@ public class ClassPathTest extends TestCase {
assertThat(ClassPath.from(classloader).getTopLevelClasses()).isNotEmpty();
}
public void testScan_classPathCycle() throws IOException {
File jarFile = File.createTempFile("with_circular_class_path", ".jar");
try {
@ -190,6 +192,7 @@ public class ClassPathTest extends TestCase {
}
}
public void testScanFromFile_fileNotExists() throws IOException {
ClassLoader classLoader = ClassPathTest.class.getClassLoader();
assertThat(
@ -198,6 +201,7 @@ public class ClassPathTest extends TestCase {
.isEmpty();
}
public void testScanFromFile_notJarFile() throws IOException {
ClassLoader classLoader = ClassPathTest.class.getClassLoader();
File notJar = File.createTempFile("not_a_jar", "txt");
@ -347,6 +351,7 @@ public class ClassPathTest extends TestCase {
// Test that ResourceInfo.urls() returns identical content to ClassLoader.getResources()
public void testGetClassPathUrls() throws Exception {
String oldPathSeparator = PATH_SEPARATOR.value();
String oldClassPath = JAVA_CLASS_PATH.value();
@ -387,12 +392,14 @@ public class ClassPathTest extends TestCase {
private static class Nested {}
public void testNulls() throws IOException {
new NullPointerTester().testAllPublicStaticMethods(ClassPath.class);
new NullPointerTester()
.testAllPublicInstanceMethods(ClassPath.from(getClass().getClassLoader()));
}
public void testLocationsFrom_idempotentScan() throws IOException {
ImmutableSet<ClassPath.LocationInfo> locations =
ClassPath.locationsFrom(getClass().getClassLoader());
@ -422,11 +429,13 @@ public class ClassPathTest extends TestCase {
.testEquals();
}
public void testScanAllResources() throws IOException {
assertThat(scanResourceNames(ClassLoader.getSystemClassLoader()))
.contains("com/google/common/reflect/ClassPathTest.class");
}
public void testExistsThrowsSecurityException() throws IOException, URISyntaxException {
SecurityManager oldSecurityManager = System.getSecurityManager();
try {

View File

@ -68,6 +68,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
thrownByExecutionThread);
}
public void testServiceStartStop() throws Exception {
WaitOnRunService service = new WaitOnRunService();
assertFalse(service.startUpCalled);
@ -84,6 +85,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
executionThread.join();
}
public void testServiceStopIdempotence() throws Exception {
WaitOnRunService service = new WaitOnRunService();
@ -100,6 +102,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
executionThread.join();
}
public void testServiceExitingOnItsOwn() throws Exception {
WaitOnRunService service = new WaitOnRunService();
service.expectedShutdownState = Service.State.RUNNING;
@ -170,6 +173,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
}
}
public void testServiceThrowOnStartUp() throws Exception {
ThrowOnStartUpService service = new ThrowOnStartUpService();
assertFalse(service.startUpCalled);
@ -208,6 +212,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
}
}
public void testServiceThrowOnRun() throws Exception {
ThrowOnRunService service = new ThrowOnRunService();
@ -224,6 +229,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
assertEquals(Service.State.FAILED, service.state());
}
public void testServiceThrowOnRunAndThenAgainOnShutDown() throws Exception {
ThrowOnRunService service = new ThrowOnRunService();
service.throwOnShutDown = true;
@ -265,6 +271,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
}
}
public void testServiceThrowOnShutDown() throws Exception {
ThrowOnShutDown service = new ThrowOnShutDown();
@ -324,6 +331,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
protected void run() throws Exception {}
}
public void testStopWhileStarting_runNotCalled() throws Exception {
final CountDownLatch started = new CountDownLatch(1);
FakeService service =
@ -353,6 +361,7 @@ public class AbstractExecutionThreadServiceTest extends TestCase {
assertEquals(0, service.shutdownCalled);
}
public void testDefaultService() throws InterruptedException {
WaitOnRunService service = new WaitOnRunService();
service.startAsync().awaitRunning();

View File

@ -579,7 +579,7 @@ public class AbstractFutureTest extends TestCase {
final AbstractFuture<String> future = new AbstractFuture<String>() {};
currentFuture.set(future);
for (Callable<?> task : allTasks) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = executor.submit(task);
}
awaitUnchecked(barrier);
@ -798,7 +798,7 @@ public class AbstractFutureTest extends TestCase {
final AbstractFuture<String> future = new AbstractFuture<String>() {};
currentFuture.set(future);
for (Callable<?> task : allTasks) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = executor.submit(task);
}
awaitUnchecked(barrier);

View File

@ -420,6 +420,7 @@ public class AbstractScheduledServiceTest extends TestCase {
assertTrue(called);
}
public void testFixedDelayScheduleFarFuturePotentiallyOverflowingScheduleIsNeverReached()
throws Exception {
TestAbstractScheduledCustomService service =
@ -440,6 +441,7 @@ public class AbstractScheduledServiceTest extends TestCase {
service.awaitTerminated();
}
public void testCustomSchedulerFarFuturePotentiallyOverflowingScheduleIsNeverReached()
throws Exception {
TestAbstractScheduledCustomService service =
@ -475,6 +477,7 @@ public class AbstractScheduledServiceTest extends TestCase {
}
}
public void testCustomSchedule_startStop() throws Exception {
final CyclicBarrier firstBarrier = new CyclicBarrier(2);
final CyclicBarrier secondBarrier = new CyclicBarrier(2);
@ -505,6 +508,7 @@ public class AbstractScheduledServiceTest extends TestCase {
future.cancel(false);
}
public void testCustomSchedulerServiceStop() throws Exception {
TestAbstractScheduledCustomService service = new TestAbstractScheduledCustomService();
service.startAsync().awaitRunning();
@ -518,6 +522,7 @@ public class AbstractScheduledServiceTest extends TestCase {
assertEquals(1, service.numIterations.get());
}
public void testCustomScheduler_deadlock() throws InterruptedException, BrokenBarrierException {
final CyclicBarrier inGetNextSchedule = new CyclicBarrier(2);
// This will flakily deadlock, so run it multiple times to increase the flake likelihood
@ -548,6 +553,7 @@ public class AbstractScheduledServiceTest extends TestCase {
}
}
public void testBig() throws Exception {
TestAbstractScheduledCustomService service =
new TestAbstractScheduledCustomService() {
@ -607,6 +613,7 @@ public class AbstractScheduledServiceTest extends TestCase {
}
}
public void testCustomSchedulerFailure() throws Exception {
TestFailingCustomScheduledService service = new TestFailingCustomScheduledService();
service.startAsync().awaitRunning();

View File

@ -330,6 +330,7 @@ public class AbstractServiceTest extends TestCase {
}
}
public void testAwaitTerminated() throws Exception {
final NoOpService service = new NoOpService();
Thread waiter =
@ -347,6 +348,7 @@ public class AbstractServiceTest extends TestCase {
assertFalse(waiter.isAlive());
}
public void testAwaitTerminated_FailedService() throws Exception {
final ManualSwitchedService service = new ManualSwitchedService();
final AtomicReference<Throwable> exception = Atomics.newReference();
@ -374,6 +376,7 @@ public class AbstractServiceTest extends TestCase {
assertThat(exception.get()).hasCauseThat().isEqualTo(EXCEPTION);
}
public void testThreadedServiceStartAndWaitStopAndWait() throws Throwable {
ThreadedService service = new ThreadedService();
RecordingListener listener = RecordingListener.record(service);
@ -391,6 +394,7 @@ public class AbstractServiceTest extends TestCase {
listener.getStateHistory());
}
public void testThreadedServiceStopIdempotence() throws Throwable {
ThreadedService service = new ThreadedService();
@ -406,6 +410,7 @@ public class AbstractServiceTest extends TestCase {
throwIfSet(thrownByExecutionThread);
}
public void testThreadedServiceStopIdempotenceAfterWait() throws Throwable {
ThreadedService service = new ThreadedService();
@ -423,6 +428,7 @@ public class AbstractServiceTest extends TestCase {
throwIfSet(thrownByExecutionThread);
}
public void testThreadedServiceStopIdempotenceDoubleWait() throws Throwable {
ThreadedService service = new ThreadedService();
@ -655,6 +661,7 @@ public class AbstractServiceTest extends TestCase {
}
}
public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
final StartFailingService service = new StartFailingService();
service.startAsync();
@ -674,6 +681,7 @@ public class AbstractServiceTest extends TestCase {
assertFalse(thread + " is deadlocked", thread.isAlive());
}
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(
@ -688,6 +696,7 @@ public class AbstractServiceTest extends TestCase {
service.stopAsync();
}
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
final NoOpThreadedService service = new NoOpThreadedService();
service.addListener(

View File

@ -13,6 +13,7 @@
package com.google.common.util.concurrent;
/** Unit test for {@link AtomicDouble}. */
public class AtomicDoubleTest extends JSR166TestCase {

View File

@ -47,7 +47,7 @@ public class AtomicLongMapBasherTest extends TestCase {
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
for (int i = 0; i < nTasks; i++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {

View File

@ -16,6 +16,7 @@
package com.google.common.util.concurrent;
import com.google.common.base.Joiner;
import com.google.common.util.concurrent.CycleDetectingLockFactory.Policies;
import com.google.common.util.concurrent.CycleDetectingLockFactory.Policy;
@ -441,6 +442,7 @@ public class CycleDetectingLockFactoryTest extends TestCase {
lockD.lock();
}
public void testReentrantLock_tryLock() throws Exception {
LockingThread thread = new LockingThread(lockA);
thread.start();
@ -452,6 +454,7 @@ public class CycleDetectingLockFactoryTest extends TestCase {
assertTrue(lockA.tryLock());
}
public void testReentrantWriteLock_tryLock() throws Exception {
LockingThread thread = new LockingThread(writeLockA);
thread.start();
@ -465,6 +468,7 @@ public class CycleDetectingLockFactoryTest extends TestCase {
assertTrue(readLockA.tryLock());
}
public void testReentrantReadLock_tryLock() throws Exception {
LockingThread thread = new LockingThread(readLockA);
thread.start();

View File

@ -36,6 +36,7 @@ public class ExecutionListTest extends TestCase {
private final ExecutionList list = new ExecutionList();
public void testRunOnPopulatedList() throws Exception {
Executor exec = Executors.newCachedThreadPool();
CountDownLatch countDownLatch = new CountDownLatch(3);
@ -66,6 +67,7 @@ public class ExecutionListTest extends TestCase {
assertEquals(1, runCalled.get());
}
public void testExecute_idempotentConcurrently() throws InterruptedException {
final CountDownLatch okayToRun = new CountDownLatch(1);
final AtomicInteger runCalled = new AtomicInteger();
@ -101,6 +103,7 @@ public class ExecutionListTest extends TestCase {
assertEquals(1, runCalled.get());
}
public void testAddAfterRun() throws Exception {
// Run the previous test
testRunOnPopulatedList();

View File

@ -88,6 +88,7 @@ public class ExecutionSequencerTest extends TestCase {
assertThat(thirdCallable.called).isTrue();
}
public void testCancellationMultipleThreads() throws Exception {
final BlockingCallable blockingCallable = new BlockingCallable();
ListenableFuture<Void> unused = serializer.submit(blockingCallable, executor);
@ -115,6 +116,7 @@ public class ExecutionSequencerTest extends TestCase {
assertThat(getDone(future2)).isFalse();
}
public void testSecondTaskWaitsForFirstEvenIfCancelled() throws Exception {
final BlockingCallable blockingCallable = new BlockingCallable();
ListenableFuture<Void> future1 = serializer.submit(blockingCallable, executor);

View File

@ -132,6 +132,7 @@ public class FluentFutureTest extends TestCase {
assertThat(f.get()).isEqualTo(2);
}
@GwtIncompatible // withTimeout
public void testWithTimeout() throws Exception {
ScheduledExecutorService executor = newScheduledThreadPool(1);

View File

@ -353,6 +353,7 @@ public class FuturesGetCheckedTest extends TestCase {
public static final class WillBeUnloadedException extends Exception {}
public void testGetChecked_classUnloading() throws Exception {
WeakReference<?> classUsedByGetChecked = doTestClassUnloading();
GcFinalization.awaitClear(classUsedByGetChecked);

View File

@ -3375,11 +3375,13 @@ public class FuturesTest extends TestCase {
: pseudoTimedGetUninterruptibly(future, 2500, MILLISECONDS);
}
@GwtIncompatible // threads
public void testAllAsList_extensive() throws InterruptedException {
runExtensiveMergerTest(Merger.allMerger);
}
@GwtIncompatible // threads
public void testSuccessfulAsList_extensive() throws InterruptedException {
runExtensiveMergerTest(Merger.successMerger);

View File

@ -131,6 +131,7 @@ public class FuturesTransformAsyncTest extends AbstractChainedListenableFutureTe
}
}
public void testFutureCancellableBeforeFunctionCompletion() throws Exception {
// Set the result in a separate thread since this test runs the function
// (which will block) in the same thread.

View File

@ -16,6 +16,7 @@
package com.google.common.util.concurrent;
/**
* Tests for {@link Monitor}'s interruptible methods.
*

View File

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import junit.framework.TestCase;
public final class InterruptibleTaskTest extends TestCase {
// Regression test for a deadlock where a task could be stuck busy waiting for the task to

View File

@ -100,6 +100,7 @@ public class JdkFutureAdaptersTest extends TestCase {
assertTrue(listenableFuture.isDone());
}
public void testListenInPoolThreadUsesGivenExecutor() throws Exception {
ExecutorService executorService =
newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build());
@ -124,6 +125,7 @@ public class JdkFutureAdaptersTest extends TestCase {
assertTrue(listenableFuture.isDone());
}
public void testListenInPoolThreadCustomExecutorInterrupted() throws Exception {
final CountDownLatch submitSuccessful = new CountDownLatch(1);
ExecutorService executorService =
@ -233,6 +235,7 @@ public class JdkFutureAdaptersTest extends TestCase {
}
}
@SuppressWarnings("IsInstanceIncompatibleType") // intentional.
public void testListenInPoolThreadRunsListenerAfterRuntimeException() throws Exception {
RuntimeExceptionThrowingFuture<String> input = new RuntimeExceptionThrowingFuture<>();

View File

@ -80,6 +80,7 @@ public class ListenableFutureTaskTest extends TestCase {
super.tearDown();
}
public void testListenerDoesNotRunUntilTaskCompletes() throws Exception {
// Test default state of not started.
@ -105,6 +106,7 @@ public class ListenableFutureTaskTest extends TestCase {
assertFalse(task.isCancelled());
}
public void testListenerCalledOnException() throws Exception {
throwException = true;
@ -140,6 +142,7 @@ public class ListenableFutureTaskTest extends TestCase {
assertEquals(1, runLatch.getCount());
}
public void testListenerCalledOnCancelFromRunning() throws Exception {
exec.execute(task);
runLatch.await();

View File

@ -129,6 +129,7 @@ public class ListenerCallQueueTest extends TestCase {
logHandler.getStoredLogRecords().get(0).getMessage());
}
public void testEnqueueAndDispatch_multithreaded() throws InterruptedException {
Object listener = new Object();
ExecutorService service = Executors.newFixedThreadPool(4);
@ -152,6 +153,7 @@ public class ListenerCallQueueTest extends TestCase {
}
}
public void testEnqueueAndDispatch_multithreaded_withThrowingRunnable()
throws InterruptedException {
Object listener = new Object();

View File

@ -88,6 +88,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
public void run() {}
};
public void testDirectExecutorServiceServiceInThreadExecution() throws Exception {
final ListeningExecutorService executor = newDirectExecutorService();
final ThreadLocal<Integer> threadLocalCount =
@ -167,6 +168,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertEquals(10, threadLocalCount.get().intValue());
}
public void testDirectExecutorServiceServiceTermination() throws Exception {
final ExecutorService executor = newDirectExecutorService();
final CyclicBarrier barrier = new CyclicBarrier(2);
@ -352,6 +354,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(delegate).execute(task);
}
public void testListeningDecorator_scheduleSuccess() throws Exception {
final CountDownLatch completed = new CountDownLatch(1);
ScheduledThreadPoolExecutor delegate =
@ -377,6 +380,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertEquals(0, delegate.getQueue().size());
}
public void testListeningDecorator_scheduleFailure() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
ListeningScheduledExecutorService service = listeningDecorator(delegate);
@ -387,6 +391,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertEquals(0, delegate.getQueue().size());
}
public void testListeningDecorator_schedulePeriodic() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
ListeningScheduledExecutorService service = listeningDecorator(delegate);
@ -407,6 +412,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertEquals(0, delegate.getQueue().size());
}
public void testListeningDecorator_cancelled() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
BlockingQueue<?> delegateQueue = delegate.getQueue();
@ -560,6 +566,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
}
}
public void testAddDelayedShutdownHook_success() throws InterruptedException {
TestApplication application = new TestApplication();
ExecutorService service = mock(ExecutorService.class);
@ -571,6 +578,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
shutdownFirst.verify(service).awaitTermination(2, TimeUnit.SECONDS);
}
public void testAddDelayedShutdownHook_interrupted() throws InterruptedException {
TestApplication application = new TestApplication();
ExecutorService service = mock(ExecutorService.class);
@ -580,6 +588,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(service).shutdown();
}
public void testGetExitingExecutorService_executorSetToUseDaemonThreads() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor =
@ -588,6 +597,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}
public void testGetExitingExecutorService_executorDelegatesToOriginal() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
@ -597,6 +607,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(executor).execute(EMPTY_RUNNABLE);
}
public void testGetExitingExecutorService_shutdownHookRegistered() throws InterruptedException {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
@ -607,6 +618,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(executor).shutdown();
}
public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() {
TestApplication application = new TestApplication();
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
@ -614,6 +626,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}
public void testGetExitingScheduledExecutorService_executorDelegatesToOriginal() {
TestApplication application = new TestApplication();
ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class);
@ -623,6 +636,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(executor).execute(EMPTY_RUNNABLE);
}
public void testGetScheduledExitingExecutorService_shutdownHookRegistered()
throws InterruptedException {
TestApplication application = new TestApplication();
@ -655,6 +669,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
assertEquals(oldName, Thread.currentThread().getName());
}
public void testExecutors_nullCheck() throws Exception {
new ClassSanityTester()
.setDefault(RateLimiter.class, RateLimiter.create(1.0))
@ -684,12 +699,14 @@ public class MoreExecutorsTest extends JSR166TestCase {
/* Half of a 1-second timeout in nanoseconds */
private static final long HALF_SECOND_NANOS = NANOSECONDS.convert(1L, SECONDS) / 2;
public void testShutdownAndAwaitTermination_immediateShutdown() throws Exception {
ExecutorService service = Executors.newSingleThreadExecutor();
assertTrue(shutdownAndAwaitTermination(service, 1L, SECONDS));
assertTrue(service.isTerminated());
}
public void testShutdownAndAwaitTermination_immediateShutdownInternal() throws Exception {
ExecutorService service = mock(ExecutorService.class);
when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)).thenReturn(true);
@ -699,6 +716,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(service).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS);
}
public void testShutdownAndAwaitTermination_forcedShutDownInternal() throws Exception {
ExecutorService service = mock(ExecutorService.class);
when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS))
@ -711,6 +729,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(service).shutdownNow();
}
public void testShutdownAndAwaitTermination_nonTerminationInternal() throws Exception {
ExecutorService service = mock(ExecutorService.class);
when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS))
@ -722,6 +741,7 @@ public class MoreExecutorsTest extends JSR166TestCase {
verify(service).shutdownNow();
}
public void testShutdownAndAwaitTermination_interruptedInternal() throws Exception {
final ExecutorService service = mock(ExecutorService.class);
when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS))

View File

@ -274,6 +274,7 @@ public class SequentialExecutorTest extends TestCase {
assertEquals(1, numCalls.get());
}
public void testTaskThrowsError() throws Exception {
class MyError extends Error {}
final CyclicBarrier barrier = new CyclicBarrier(2);
@ -312,6 +313,7 @@ public class SequentialExecutorTest extends TestCase {
}
}
public void testRejectedExecutionThrownWithMultipleCalls() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final SettableFuture<?> future = SettableFuture.create();

View File

@ -119,6 +119,7 @@ public class ServiceManagerTest extends TestCase {
}
}
public void testServiceStartupTimes() {
Service a = new NoOpDelayedService(150);
Service b = new NoOpDelayedService(353);
@ -132,6 +133,7 @@ public class ServiceManagerTest extends TestCase {
assertTrue(startupTimes.get(b) >= 353);
}
public void testServiceStartupTimes_selfStartingServices() {
// This tests to ensure that:
// 1. service times are accurate when the service is started by the manager
@ -167,6 +169,7 @@ public class ServiceManagerTest extends TestCase {
assertThat(startupTimes.get(b)).isNotNull();
}
public void testServiceStartStop() {
Service a = new NoOpService();
Service b = new NoOpService();
@ -188,6 +191,7 @@ public class ServiceManagerTest extends TestCase {
assertTrue(listener.failedServices.isEmpty());
}
public void testFailStart() throws Exception {
Service a = new NoOpService();
Service b = new FailStartService();
@ -215,6 +219,7 @@ public class ServiceManagerTest extends TestCase {
assertTrue(listener.stoppedCalled);
}
public void testFailRun() throws Exception {
Service a = new NoOpService();
Service b = new FailRunService();
@ -237,6 +242,7 @@ public class ServiceManagerTest extends TestCase {
assertTrue(listener.stoppedCalled);
}
public void testFailStop() throws Exception {
Service a = new NoOpService();
Service b = new FailStopService();
@ -265,6 +271,7 @@ public class ServiceManagerTest extends TestCase {
assertThat(toString).contains("FailStartService");
}
public void testTimeouts() throws Exception {
Service a = new NoOpDelayedService(50);
ServiceManager manager = new ServiceManager(asList(a));

View File

@ -51,16 +51,19 @@ public class SettableFutureTest extends TestCase {
}
}
public void testSetValue() throws Exception {
assertTrue(future.set("value"));
tester.testCompletedFuture("value");
}
public void testSetFailure() throws Exception {
assertTrue(future.setException(new Exception("failure")));
tester.testFailedFuture("failure");
}
public void testSetFailureNull() throws Exception {
try {
future.setException(null);
@ -72,6 +75,7 @@ public class SettableFutureTest extends TestCase {
tester.testFailedFuture("failure");
}
public void testCancel() throws Exception {
assertTrue(future.cancel(true));
tester.testCancelledFuture();

View File

@ -129,6 +129,7 @@ public class StripedTest extends TestCase {
assertTrue(Striped.lazyWeakLock(256).size() == 256);
}
public void testWeakImplementations() {
for (Striped<?> striped : weakImplementations()) {
WeakReference<Object> weakRef = new WeakReference<>(striped.get(new Object()));
@ -136,6 +137,7 @@ public class StripedTest extends TestCase {
}
}
public void testWeakReadWrite() {
Striped<ReadWriteLock> striped = Striped.lazyWeakReadWriteLock(1000);
Object key = new Object();
@ -148,6 +150,7 @@ public class StripedTest extends TestCase {
readLock.unlock();
}
public void testStrongImplementations() {
for (Striped<?> striped : strongImplementations()) {
WeakReference<Object> weakRef = new WeakReference<>(striped.get(new Object()));

View File

@ -56,6 +56,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
builder = new ThreadFactoryBuilder();
}
public void testThreadFactoryBuilder_defaults() throws InterruptedException {
ThreadFactory threadFactory = builder.build();
Thread thread = threadFactory.newThread(monitoredRunnable);
@ -92,6 +93,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
assertThat(thread.getName()).matches("^pool-\\d+-thread-" + threadId + "$");
}
public void testNameFormatWithPercentS_custom() {
String format = "super-duper-thread-%s";
ThreadFactory factory = builder.setNameFormat(format).build();
@ -100,6 +102,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
}
}
public void testNameFormatWithPercentD_custom() {
String format = "super-duper-thread-%d";
ThreadFactory factory = builder.setNameFormat(format).build();
@ -108,18 +111,21 @@ public class ThreadFactoryBuilderTest extends TestCase {
}
}
public void testDaemon_false() {
ThreadFactory factory = builder.setDaemon(false).build();
Thread thread = factory.newThread(monitoredRunnable);
assertFalse(thread.isDaemon());
}
public void testDaemon_true() {
ThreadFactory factory = builder.setDaemon(true).build();
Thread thread = factory.newThread(monitoredRunnable);
assertTrue(thread.isDaemon());
}
public void testPriority_custom() {
for (int i = Thread.MIN_PRIORITY; i <= Thread.MAX_PRIORITY; i++) {
ThreadFactory factory = builder.setPriority(i).build();
@ -144,6 +150,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
}
}
public void testUncaughtExceptionHandler_custom() {
assertEquals(
UNCAUGHT_EXCEPTION_HANDLER,
@ -154,6 +161,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
.getUncaughtExceptionHandler());
}
public void testBuildMutateBuild() {
ThreadFactory factory1 = builder.setPriority(1).build();
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
@ -169,6 +177,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
unused = builder.build(); // this is *also* allowed
}
public void testBuildMutate() {
ThreadFactory factory1 = builder.setPriority(1).build();
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
@ -177,6 +186,7 @@ public class ThreadFactoryBuilderTest extends TestCase {
assertEquals(1, factory1.newThread(monitoredRunnable).getPriority());
}
public void testThreadFactory() throws InterruptedException {
final String THREAD_NAME = "ludicrous speed";
final int THREAD_PRIORITY = 1;

View File

@ -16,6 +16,7 @@
package com.google.common.util.concurrent;
import com.google.common.annotations.GwtCompatible;
import com.google.common.util.concurrent.AbstractFuture.TrustedFuture;

View File

@ -116,6 +116,7 @@ public class UninterruptibleFutureTest extends TestCase {
assertTrue(sleeper.completed);
}
public void testMakeUninterruptible_timeoutPreservedThroughInterruption()
throws ExecutionException {
@ -154,26 +155,32 @@ public class UninterruptibleFutureTest extends TestCase {
}
}
public void testMakeUninterruptible_untimed_uninterrupted() throws Exception {
runUntimedInterruptsTest(0);
}
public void testMakeUninterruptible_untimed_interrupted() throws Exception {
runUntimedInterruptsTest(1);
}
public void testMakeUninterruptible_untimed_multiplyInterrupted() throws Exception {
runUntimedInterruptsTest(38);
}
public void testMakeUninterruptible_timed_uninterrupted() throws Exception {
runTimedInterruptsTest(0);
}
public void testMakeUninterruptible_timed_interrupted() throws Exception {
runTimedInterruptsTest(1);
}
public void testMakeUninterruptible_timed_multiplyInterrupted() throws Exception {
runTimedInterruptsTest(38);
}
@ -228,6 +235,7 @@ public class UninterruptibleFutureTest extends TestCase {
}
}
public void testMakeUninterruptible_timedGetZeroTimeoutAttempted()
throws TimeoutException, ExecutionException {
SettableFuture<String> future = SettableFuture.create();
@ -240,6 +248,7 @@ public class UninterruptibleFutureTest extends TestCase {
assertEquals(RESULT, getUninterruptibly(future, 0, SECONDS));
}
public void testMakeUninterruptible_timedGetNegativeTimeoutAttempted()
throws TimeoutException, ExecutionException {
SettableFuture<String> future = SettableFuture.create();

View File

@ -16,6 +16,7 @@
package com.google.common.util.concurrent;
/**
* Tests for {@link Monitor}'s uninterruptible methods.
*

View File

@ -16,6 +16,7 @@
package com.google.common.util.concurrent;
import com.google.common.annotations.GwtCompatible;
import com.google.common.util.concurrent.AbstractFuture.TrustedFuture;

View File

@ -46,11 +46,11 @@ public class WrappingScheduledExecutorServiceTest extends TestCase {
MockExecutor mock = new MockExecutor();
TestExecutor testExecutor = new TestExecutor(mock);
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = testExecutor.schedule(DO_NOTHING, 10, TimeUnit.MINUTES);
mock.assertLastMethodCalled("scheduleRunnable", 10, TimeUnit.MINUTES);
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError1 =
testExecutor.schedule(Executors.callable(DO_NOTHING), 5, TimeUnit.SECONDS);
mock.assertLastMethodCalled("scheduleCallable", 5, TimeUnit.SECONDS);
@ -59,12 +59,12 @@ public class WrappingScheduledExecutorServiceTest extends TestCase {
public void testSchedule_repeating() {
MockExecutor mock = new MockExecutor();
TestExecutor testExecutor = new TestExecutor(mock);
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
testExecutor.scheduleWithFixedDelay(DO_NOTHING, 100, 10, TimeUnit.MINUTES);
mock.assertLastMethodCalled("scheduleWithFixedDelay", 100, 10, TimeUnit.MINUTES);
@SuppressWarnings("unused") // go/futurereturn-lsc
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError1 =
testExecutor.scheduleAtFixedRate(DO_NOTHING, 3, 7, TimeUnit.SECONDS);
mock.assertLastMethodCalled("scheduleAtFixedRate", 3, 7, TimeUnit.SECONDS);

View File

View File

@ -31,7 +31,6 @@ import java.lang.annotation.Target;
* work during upgrades. However it is generally inadvisable for <i>libraries</i> (which get
* included on users' CLASSPATHs, outside the library developers' control) to do so.
*
*
* @author Kevin Bourrillion
*/
@Retention(RetentionPolicy.CLASS)

View File

@ -54,7 +54,6 @@ import java.lang.annotation.Target;
*
* <p>Note that a {@code GwtCompatible} type may have some {@link GwtIncompatible} methods.
*
*
* @author Charles Fry
* @author Hayward Chan
*/

View File

View File

View File

View File

@ -542,7 +542,6 @@ public final class Ascii {
* <li>it is safe to use non-ASCII characters in the truncation indicator
* </ul>
*
*
* @throws IllegalArgumentException if {@code maxLength} is less than the length of {@code
* truncationIndicator}
* @since 16.0

View File

@ -55,7 +55,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
* behavior for all converters; implementations of {@link #doForward} and {@link #doBackward} are
* guaranteed to never be passed {@code null}, and must never return {@code null}.
*
*
* <h3>Common ways to use</h3>
*
* <p>Getting a converter:

View File

View File

@ -55,7 +55,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
* <li>accumulation of cache access statistics
* </ul>
*
*
* <p>These features are all optional; caches can be created using all or none of them. By default
* cache instances created by {@code CacheBuilder} will not perform any type of eviction.
*

View File

@ -35,13 +35,15 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
* @author Louis Wasserman
*/
@GwtCompatible
@Beta final class SortedLists {
@Beta
final class SortedLists {
private SortedLists() {}
/**
* A specification for which index to return if the list contains at least one element that
* compares as equal to the key.
*/ enum KeyPresentBehavior {
*/
enum KeyPresentBehavior {
/**
* Return the index of any list element that compares as equal to the key. No guarantees are
* made as to which index is returned, if more than one element compares as equal to the key.
@ -128,7 +130,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
/**
* A specification for which index to return if the list contains no elements that compare as
* equal to the key.
*/ enum KeyAbsentBehavior {
*/
enum KeyAbsentBehavior {
/**
* Return the index of the next lower element in the list, or {@code -1} if there is no such
* element.

View File

@ -50,7 +50,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
*
* @author Louis Wasserman
*/
@GwtCompatible final class TopKSelector<T> {
@GwtCompatible
final class TopKSelector<T> {
/**
* Returns a {@code TopKSelector} that collects the lowest {@code k} elements added to it,

View File

@ -234,7 +234,6 @@ public final class Hashing {
* Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the
* MD5 (128 hash bits) hash function and the given secret key.
*
*
* @param key the secret key
* @throws IllegalArgumentException if the given key is inappropriate for initializing this MAC
* @since 20.0
@ -248,7 +247,6 @@ public final class Hashing {
* MD5 (128 hash bits) hash function and a {@link SecretKeySpec} created from the given byte array
* and the MD5 algorithm.
*
*
* @param key the key material of the secret key
* @since 20.0
*/
@ -260,7 +258,6 @@ public final class Hashing {
* Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the
* SHA-1 (160 hash bits) hash function and the given secret key.
*
*
* @param key the secret key
* @throws IllegalArgumentException if the given key is inappropriate for initializing this MAC
* @since 20.0
@ -274,7 +271,6 @@ public final class Hashing {
* SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte
* array and the SHA-1 algorithm.
*
*
* @param key the key material of the secret key
* @since 20.0
*/
@ -286,7 +282,6 @@ public final class Hashing {
* Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the
* SHA-256 (256 hash bits) hash function and the given secret key.
*
*
* @param key the secret key
* @throws IllegalArgumentException if the given key is inappropriate for initializing this MAC
* @since 20.0
@ -300,7 +295,6 @@ public final class Hashing {
* SHA-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte
* array and the SHA-256 algorithm.
*
*
* @param key the key material of the secret key
* @since 20.0
*/
@ -312,7 +306,6 @@ public final class Hashing {
* Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the
* SHA-512 (512 hash bits) hash function and the given secret key.
*
*
* @param key the secret key
* @throws IllegalArgumentException if the given key is inappropriate for initializing this MAC
* @since 20.0
@ -326,7 +319,6 @@ public final class Hashing {
* SHA-512 (512 hash bits) hash function and a {@link SecretKeySpec} created from the given byte
* array and the SHA-512 algorithm.
*
*
* @param key the key material of the secret key
* @since 20.0
*/
@ -457,7 +449,6 @@ public final class Hashing {
* traffic to {@code charlie}, rather than letting {@code bravo} keep its traffic.
* </ul>
*
*
* <p>See the <a href="http://en.wikipedia.org/wiki/Consistent_hashing">Wikipedia article on
* consistent hashing</a> for more information.
*/
@ -492,7 +483,6 @@ public final class Hashing {
* traffic to {@code charlie}, rather than letting {@code bravo} keep its traffic.
* </ul>
*
*
* <p>See the <a href="http://en.wikipedia.org/wiki/Consistent_hashing">Wikipedia article on
* consistent hashing</a> for more information.
*/

View File

View File

View File

@ -226,7 +226,8 @@ public abstract class BaseEncoding {
*
* @throws DecodingException if the input is not a valid encoded string according to this
* encoding.
*/ final byte[] decodeChecked(CharSequence chars)
*/
final byte[] decodeChecked(CharSequence chars)
throws DecodingException {
chars = trimTrailingPadding(chars);
byte[] tmp = new byte[maxDecodedSize(chars.length())];

View File

@ -14,6 +14,7 @@
package com.google.common.io;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;

View File

@ -28,7 +28,6 @@ import com.google.common.annotations.GwtCompatible;
* <li><a href="http://www.ietf.org/rfc/rfc5988.txt">RFC 5988</a>
* </ul>
*
*
* @author Kurt Alfred Kluever
* @since 11.0
*/

View File

@ -200,7 +200,6 @@ public final class InternetDomainName {
* href="https://tools.ietf.org/html/rfc1123#section-2">RFC 1123</a>.
* </ul>
*
*
* @param domain A domain name (not IP address)
* @throws IllegalArgumentException if {@code domain} is not syntactically valid according to
* {@link #isValid}

View File

@ -24,7 +24,6 @@ import com.google.common.escape.Escaper;
* escaping with {@link com.google.common.html.HtmlEscapers} or {@link
* com.google.common.xml.XmlEscapers}.
*
*
* @author David Beaumont
* @author Chris Povirk
* @since 15.0

View File

@ -69,7 +69,6 @@ public final class Callables {
* Wraps the given callable such that for the duration of {@link Callable#call} the thread that is
* running will have the given name.
*
*
* @param callable The callable to wrap
* @param nameSupplier The supplier of thread names, {@link Supplier#get get} will be called once
* for each invocation of the wrapped callable.
@ -100,7 +99,6 @@ public final class Callables {
* Wraps the given runnable such that for the duration of {@link Runnable#run} the thread that is
* running with have the given name.
*
*
* @param task The Runnable to wrap
* @param nameSupplier The supplier of thread names, {@link Supplier#get get} will be called once
* for each invocation of the wrapped callable.

View File

@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.concurrent.Future;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
/** Aggregate future that collects (stores) results of each future. */

View File

@ -1082,7 +1082,6 @@ public final class Futures extends GwtFuturesCatchingSpecialization {
* IllegalArgumentException here, in part to keep its recommendation simple: Static methods
* should throw IllegalStateException only when they use static state.
*
*
* Why do we deviate here? The answer: We want for fluentFuture.getDone() to throw the same
* exception as Futures.getDone(fluentFuture).
*/

View File

@ -411,7 +411,6 @@ public final class MoreExecutors {
* <p>This should be preferred to {@link #newDirectExecutorService()} because implementing the
* {@link ExecutorService} subinterface necessitates significant performance overhead.
*
*
* @since 18.0
*/
public static Executor directExecutor() {
@ -666,7 +665,8 @@ public final class MoreExecutors {
* implementations.
*/
@SuppressWarnings("GoodTime") // should accept a java.time.Duration
@GwtIncompatible static <T> T invokeAnyImpl(
@GwtIncompatible
static <T> T invokeAnyImpl(
ListeningExecutorService executorService,
Collection<? extends Callable<T>> tasks,
boolean timed,
@ -858,7 +858,6 @@ public final class MoreExecutors {
* right before each task is run. The renaming is best effort, if a {@link SecurityManager}
* prevents the renaming then it will be skipped but the tasks will still execute.
*
*
* @param executor The executor to decorate
* @param nameSupplier The source of names for each task
*/
@ -882,7 +881,6 @@ public final class MoreExecutors {
* right before each task is run. The renaming is best effort, if a {@link SecurityManager}
* prevents the renaming then it will be skipped but the tasks will still execute.
*
*
* @param service The executor to decorate
* @param nameSupplier The source of names for each task
*/
@ -912,7 +910,6 @@ public final class MoreExecutors {
* right before each task is run. The renaming is best effort, if a {@link SecurityManager}
* prevents the renaming then it will be skipped but the tasks will still execute.
*
*
* @param service The executor to decorate
* @param nameSupplier The source of names for each task
*/

View File

@ -30,7 +30,6 @@ import com.google.common.escape.Escapers;
* non-ASCII characters to their numeric entity replacements. These XML escapers provide the minimal
* level of escaping to ensure that the output can be safely included in a Unicode XML document.
*
*
* <p>For details on the behavior of the escapers in this class, see sections <a
* href="http://www.w3.org/TR/2008/REC-xml-20081126/#charsets">2.2</a> and <a
* href="http://www.w3.org/TR/2008/REC-xml-20081126/#syntax">2.4</a> of the XML specification.

View File

View File

View File

View File

View File

@ -1,4 +1,4 @@
# TODO(user,user): Resolve cycles
# TODO(user): Resolve cycles
NAMESPACE com.google.common.collect.testing
NAMESPACE com.google.common.collect.testing.google

View File

@ -1,20 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<source path="">
<!-- Hack to keep collect from hiding collect.testing supersource: -->
<exclude name="**/testing/**"/>
</source>
<!-- We used to set this only for packages that had manual supersource. That worked everywhere that I know of except for one place: when running the GWT util.concurrent tests under Guava. The problem is that GWT responds poorly to two .gwt.xml files in the same Java package: https://goo.gl/pRV3Yn The summary is that it ignores one file in favor of the other. util.concurrent, like nearly all our packages, has two .gwt.xml files: one for prod and one for tests. util.concurrent, unlike our other packages, has, as of this writing, test supersource but no prod supersource. GWT happens to use the prod .gwt.xml, so it looks for no supersource for tests, either. This causes it to fail to find AtomicLongMapTest. Our workaround is to tell GWT that util.concurrent and all other packages have prod supersource, even if they have none. GWT is happy to ignore us when we specify a nonexistent path. (I hope that this workaround does not cause its own problems in the future.) -->
<super-source path="super"/>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.core.Core"/>
<source path="">
<!-- Hack to keep collect from hiding collect.testing supersource: -->
<exclude name="**/testing/**"/>
</source>
<!--
We used to set this only for packages that had manual supersource.
That worked everywhere that I know of except for one place:
when running the GWT util.concurrent tests under Guava.
The problem is that GWT responds poorly to two .gwt.xml files in the same Java package:
https://goo.gl/pRV3Yn
The summary is that it ignores one file in favor of the other.
util.concurrent, like nearly all our packages, has two .gwt.xml files: one for prod and one for tests.
util.concurrent, unlike our other packages, has, as of this writing, test supersource but no prod supersource.
GWT happens to use the prod .gwt.xml, so it looks for no supersource for tests, either.
This causes it to fail to find AtomicLongMapTest.
Our workaround is to tell GWT that util.concurrent and all other packages have prod supersource, even if they have none.
GWT is happy to ignore us when we specify a nonexistent path.
(I hope that this workaround does not cause its own problems in the future.)
-->
<super-source path="super"/>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.core.Core" />
</module>

View File

@ -1,24 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<source path="">
<!-- Hack to keep collect from hiding collect.testing supersource: -->
<exclude name="**/testing/**"/>
</source>
<!-- We used to set this only for packages that had manual supersource. That worked everywhere that I know of except for one place: when running the GWT util.concurrent tests under Guava. The problem is that GWT responds poorly to two .gwt.xml files in the same Java package: https://goo.gl/pRV3Yn The summary is that it ignores one file in favor of the other. util.concurrent, like nearly all our packages, has two .gwt.xml files: one for prod and one for tests. util.concurrent, unlike our other packages, has, as of this writing, test supersource but no prod supersource. GWT happens to use the prod .gwt.xml, so it looks for no supersource for tests, either. This causes it to fail to find AtomicLongMapTest. Our workaround is to tell GWT that util.concurrent and all other packages have prod supersource, even if they have none. GWT is happy to ignore us when we specify a nonexistent path. (I hope that this workaround does not cause its own problems in the future.) -->
<super-source path="super"/>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.common.annotations.Annotations"/>
<inherits name="com.google.gwt.core.Core"/>
<source path="">
<!-- Hack to keep collect from hiding collect.testing supersource: -->
<exclude name="**/testing/**"/>
</source>
<!--
We used to set this only for packages that had manual supersource.
That worked everywhere that I know of except for one place:
when running the GWT util.concurrent tests under Guava.
The problem is that GWT responds poorly to two .gwt.xml files in the same Java package:
https://goo.gl/pRV3Yn
The summary is that it ignores one file in favor of the other.
util.concurrent, like nearly all our packages, has two .gwt.xml files: one for prod and one for tests.
util.concurrent, unlike our other packages, has, as of this writing, test supersource but no prod supersource.
GWT happens to use the prod .gwt.xml, so it looks for no supersource for tests, either.
This causes it to fail to find AtomicLongMapTest.
Our workaround is to tell GWT that util.concurrent and all other packages have prod supersource, even if they have none.
GWT is happy to ignore us when we specify a nonexistent path.
(I hope that this workaround does not cause its own problems in the future.)
-->
<super-source path="super"/>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.common.annotations.Annotations" />
<inherits name="com.google.gwt.core.Core" />
</module>

Some files were not shown because too many files have changed in this diff Show More