Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup threads for CacheBuilderTest and FuturesTest #7320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ public void run() {
// notification.
assertEquals(expectedKeys, Sets.union(cache.asMap().keySet(), removalNotifications.keySet()));
assertTrue(Sets.intersection(cache.asMap().keySet(), removalNotifications.keySet()).isEmpty());
threadPool.shutdown();
threadPool.awaitTermination(300, SECONDS);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ public ListenableFuture<String> apply(String s) throws Exception {
}
};

ExecutorService service = newSingleThreadExecutor();
ListenableFuture<String> futureResult =
transformAsync(input, function, newSingleThreadExecutor());
transformAsync(input, function, service);

input.set("value");
inFunction.await();
Expand All @@ -457,6 +458,8 @@ public ListenableFuture<String> apply(String s) throws Exception {
// https://github.com/google/guava/issues/1989
assertEquals(1, gotException.getCount());
// gotException.await();
service.shutdown();
service.awaitTermination(30, SECONDS);
}

public void testTransformAsync_cancelPropagatesToAsyncOutput() throws Exception {
Expand Down Expand Up @@ -1167,8 +1170,9 @@ public ListenableFuture<String> apply(Throwable t) throws Exception {
}
};

ExecutorService executor = newSingleThreadExecutor();
ListenableFuture<String> futureResult =
catchingAsync(input, Exception.class, function, newSingleThreadExecutor());
catchingAsync(input, Exception.class, function, executor);

input.setException(new Exception());
inFunction.await();
Expand All @@ -1183,6 +1187,8 @@ public ListenableFuture<String> apply(Throwable t) throws Exception {
// https://github.com/google/guava/issues/1989
assertEquals(1, gotException.getCount());
// gotException.await();
executor.shutdown();
executor.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand Down Expand Up @@ -1794,8 +1800,9 @@ public ListenableFuture<Integer> apply(String input) throws Exception {
}
};
SettableFuture<String> inputFuture = SettableFuture.create();
ExecutorService service = newSingleThreadExecutor();
ListenableFuture<Integer> future =
transformAsync(inputFuture, function, newSingleThreadExecutor());
transformAsync(inputFuture, function, service);
inputFuture.set("value");
inFunction.await();
future.cancel(false);
Expand All @@ -1810,6 +1817,8 @@ public ListenableFuture<Integer> apply(String input) throws Exception {
fail();
} catch (CancellationException expected) {
}
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand Down Expand Up @@ -1904,7 +1913,8 @@ public ListenableFuture<Integer> call() throws InterruptedException {
}
};
SettableFuture<String> inputFuture = SettableFuture.create();
ListenableFuture<Integer> future = submitAsync(callable, newSingleThreadExecutor());
ExecutorService service = newSingleThreadExecutor();
ListenableFuture<Integer> future = submitAsync(callable, service);
inputFuture.set("value");
inFunction.await();
future.cancel(false);
Expand All @@ -1919,6 +1929,8 @@ public ListenableFuture<Integer> call() throws InterruptedException {
fail();
} catch (CancellationException expected) {
}
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand Down Expand Up @@ -2069,6 +2081,7 @@ public ListenableFuture<Integer> call() {
@J2ktIncompatible
@GwtIncompatible // threads
public void testScheduleAsync_asyncCallable_nullInsteadOfFuture() throws Exception {
ExecutorService service = newSingleThreadScheduledExecutor();
ListenableFuture<?> chainedFuture =
scheduleAsync(
constantAsyncCallable(null), 1, NANOSECONDS, newSingleThreadScheduledExecutor());
Expand All @@ -2083,6 +2096,8 @@ public void testScheduleAsync_asyncCallable_nullInsteadOfFuture() throws Excepti
"AsyncCallable.call returned null instead of a Future. "
+ "Did you mean to return immediateFuture(null)?");
}
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand All @@ -2101,8 +2116,9 @@ public ListenableFuture<Integer> call() throws InterruptedException {
return resultFuture;
}
};
ScheduledExecutorService service = newSingleThreadScheduledExecutor();
ListenableFuture<Integer> future =
scheduleAsync(callable, 1, NANOSECONDS, newSingleThreadScheduledExecutor());
scheduleAsync(callable, 1, NANOSECONDS, service);
inFunction.await();
future.cancel(false);
callableDone.countDown();
Expand All @@ -2116,6 +2132,8 @@ public ListenableFuture<Integer> call() throws InterruptedException {
fail();
} catch (CancellationException expected) {
}
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand Down Expand Up @@ -2716,8 +2734,9 @@ public ListenableFuture<String> call() throws Exception {
}
};

ExecutorService service = newSingleThreadExecutor();
ListenableFuture<String> futureResult =
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, service);

stringFuture.set("value");
booleanFuture.set(true);
Expand All @@ -2735,6 +2754,8 @@ public ListenableFuture<String> call() throws Exception {
fail();
} catch (CancellationException expected) {
}
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand All @@ -2759,8 +2780,9 @@ public ListenableFuture<String> call() throws Exception {
}
};

ExecutorService service = newSingleThreadExecutor();
ListenableFuture<String> futureResult =
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, service);

stringFuture.set("value");
booleanFuture.set(true);
Expand All @@ -2772,6 +2794,8 @@ public ListenableFuture<String> call() throws Exception {
} catch (CancellationException expected) {
}
gotException.await();
service.shutdown();
service.awaitTermination(30, SECONDS);
}

public void testWhenAllComplete_runnableResult() throws Exception {
Expand Down Expand Up @@ -2855,8 +2879,9 @@ public void run() {
}
};

ExecutorService service = newSingleThreadExecutor();
ListenableFuture<?> futureResult =
whenAllComplete(stringFuture, booleanFuture).run(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).run(combiner, service);

stringFuture.set("value");
booleanFuture.set(true);
Expand All @@ -2869,6 +2894,8 @@ public void run() {
} catch (CancellationException expected) {
}
combinerCompletedWithoutInterrupt.await();
service.shutdown();
service.awaitTermination(30, SECONDS);
}

@J2ktIncompatible
Expand All @@ -2894,8 +2921,9 @@ public void run() {
}
};

ExecutorService service = newSingleThreadExecutor();
ListenableFuture<?> futureResult =
whenAllComplete(stringFuture, booleanFuture).run(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).run(combiner, service);

stringFuture.set("value");
booleanFuture.set(true);
Expand All @@ -2907,6 +2935,8 @@ public void run() {
} catch (CancellationException expected) {
}
gotException.await();
service.shutdown();
service.awaitTermination(30, SECONDS);
}

public void testWhenAllSucceed() throws Exception {
Expand Down