/** * Expect a command to be invoked remotely and send replies using the {@link BlockedRequest} methods. */ public <T extends ReplicableCommand> BlockedRequest expectCommand(Class<T> expectedCommandClass, Consumer<T> checker) { BlockedRequest blockedRequest = uncheckedGet(expectCommandAsync(expectedCommandClass)); T command = expectedCommandClass.cast(blockedRequest.request.getCommand()); checker.accept(command); return blockedRequest; }
public void receive(Map<Address, Response> responses) { log.tracef("Faking responses for %s: %s", request.getCommand(), responses); responses.forEach((sender, response) -> { // For staggered requests we allow the test to specify only the primary owner's response assertTrue(responses.containsKey(sender)); request.collectResponse(sender, response); }); if (!request.isDone()) { assertEquals(responses.keySet(), request.responseFutures.keySet()); request.collectFinish(); } }
/** * Expect a command to be invoked remotely and send replies using the {@link BlockedRequest} methods. */ public <T extends ReplicableCommand> CompletableFuture<BlockedRequest> expectCommandAsync(Class<T> expectedCommandClass) { throwGlobalError(); log.tracef("Waiting for command %s", expectedCommandClass); CompletableFuture<ControlledRequest> future = new CompletableFuture<>(); waiters.add(future); return future.thenApply(request -> { log.tracef("Blocked command %s", request.command); assertTrue("Expecting a " + expectedCommandClass.getName() + ", got " + request.getCommand(), expectedCommandClass.isInstance(request.getCommand())); return new BlockedRequest<T>(request); }); }
() -> { TimeoutException e = new TimeoutException("Timed out waiting for test to unblock command " + controlledRequest.getCommand()); addGlobalError(e); controlledRequest.fail(e);
/** * Unblock the request, sending it to its targets. * <p> * It will block again when waiting for responses. */ public SentRequest send() { log.tracef("Sending command %s", request.getCommand()); request.send(); if (request.hasCollector()) { return new SentRequest(request); } else { return null; } }
public T getCommand() { return (T) request.getCommand(); }
public CompletionStage<BlockedResponse> expectResponseAsync(Address sender) { request.throwIfFailed(); assertFalse(request.isDone()); return request.responseFuture(sender).thenApply(response -> { log.debugf("Got response for %s from %s: %s", request.getCommand(), sender, response); return new BlockedResponse(request, this, sender, response); }); }
public void replace(Map<Address, Response> newResponses) { assertFalse(request.resultFuture.isDone()); log.tracef("Replacing responses for %s: %s (was %s)", request.getCommand(), newResponses, responseMap); newResponses.forEach(request::collectResponse); if (!request.isDone()) { request.collectFinish(); } }
/** * Avoid sending the request, and finish it with the given responses instead. */ public FakeResponses skipSend() { log.tracef("Not sending request %s", request.getCommand()); request.skipSend(); if (request.hasCollector()) { return new FakeResponses(request); } else { return null; } }
public void receive() { assertFalse(request.resultFuture.isDone()); log.tracef("Unblocking responses for %s: %s", request.getCommand(), responseMap); responseMap.forEach(request::collectResponse); if (!request.isDone()) { request.collectFinish(); } }