mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 12:16:13 +02:00
Ensure client events are handled in the correct thread in consistent primitive tests.
Change-Id: Ic6db44ec8fc393d6194eeba8b3f84c28245a254a
This commit is contained in:
parent
f3f050ab74
commit
931d3e7a4a
@ -127,8 +127,8 @@ public class TestClusterCommunicationService implements ClusterCommunicationServ
|
||||
public <M, R> void addSubscriber(
|
||||
MessageSubject subject,
|
||||
Function<byte[], M> decoder,
|
||||
|
||||
Function<M, CompletableFuture<R>> handler, Function<R, byte[]> encoder) {
|
||||
Function<M, CompletableFuture<R>> handler,
|
||||
Function<R, byte[]> encoder) {
|
||||
subscribers.put(subject, message -> {
|
||||
CompletableFuture<byte[]> future = new CompletableFuture<>();
|
||||
try {
|
||||
@ -153,12 +153,16 @@ public class TestClusterCommunicationService implements ClusterCommunicationServ
|
||||
Consumer<M> handler,
|
||||
Executor executor) {
|
||||
subscribers.put(subject, message -> {
|
||||
try {
|
||||
handler.accept(decoder.apply(message));
|
||||
} catch (Exception e) {
|
||||
return Futures.exceptionalFuture(new MessagingException.RemoteHandlerFailure());
|
||||
}
|
||||
return Futures.completedFuture(null);
|
||||
CompletableFuture<byte[]> future = new CompletableFuture<>();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
handler.accept(decoder.apply(message));
|
||||
future.complete(null);
|
||||
} catch (Exception e) {
|
||||
future.completeExceptionally(new MessagingException.RemoteHandlerFailure());
|
||||
}
|
||||
});
|
||||
return future;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user