public final class CompletionStageTestAwaiter<T> extends Object
CompletionStage
.
Note that if you have a CompletableFuture
instead of a CompletionStage
,
then you could just use CompletableFuture.join()
, which does the same thing as
the await500ms(CompletionStage)
here. However, to test operations
which return only a CompletionStage
but not a full CompletableFuture
,
you use this. (CompletionStage
is often a more suitable operation return type,
because it "does not define methods for initially creating,
forcibly completing normally or exceptionally, probing completion
status or results, or awaiting completion of a stage".)
Note that the CompletionStage.toCompletableFuture()
"back-door" may "throw an
UnsupportedOperationException if an implementation does not inter-operate
with CompletableFuture".
In production code, you normally never should have to await/join/get results
returned as CompletionStage
. If you are, you're probably using an API wrong.
(Valid deviations to this rule include scenarios where you bridge an async API to an existing
legacy API, which you cannot change, using synchronous signature methods which do not return an
async types such as CompletionStage
or (a subtype of) Future
.)
See the CompletionStageAwaitExampleTest
for an illustration how to use this.
Modifier and Type | Method and Description |
---|---|
static <T> T |
await(CompletionStage<T> completionStage,
long timeout,
TimeUnit unit)
Await a configurable amount of time for the CompletionStage argument to complete.
|
static <T> T |
await500ms(CompletionStage<T> completionStage)
Await max.
|
public static <T> T await500ms(CompletionStage<T> completionStage) throws TimeoutException
CompletionException
- if it completed unsuccessfullyCancellationException
- if it got cancelled while awaiting completionTimeoutException
- if it timed out awaiting completionpublic static <T> T await(CompletionStage<T> completionStage, long timeout, TimeUnit unit) throws TimeoutException
CompletionException
- if it completed unsuccessfullyCancellationException
- if it got cancelled while awaiting completionTimeoutException
- if it timed out awaiting completionCopyright © 2019 OpenDaylight. All rights reserved.