/** * Avoid sending the request, and finish it with the given responses instead. */ public FakeResponses skipSend(Address target) { return requests.get(target).skipSend(); }
public void skipSendAndReceiveAsync(Address target, Response fakeResponse) { requests.get(target).skipSend().receiveAsync(target, fakeResponse); } }
public void skipSendAndReceive(Address target, Response fakeResponse) { requests.get(target).skipSend().receive(target, fakeResponse); }
@Test public void testGetOccursAfterReplaceRunningBeforeWithRemoteException() throws Exception { final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key); final Cache<Object, String> ownerCache = getFirstOwner(key); ownerCache.put(key, firstValue); CyclicBarrier barrier = new CyclicBarrier(2); addBlockingInterceptorBeforeTx(nonOwnerCache, barrier, ReplaceCommand.class, false); ControlledRpcManager controlledRpcManager = ControlledRpcManager.replaceRpcManager(nonOwnerCache); try { // The replace will internally block the get until it gets the remote value Future<Boolean> futureReplace = fork(() -> nonOwnerCache.replace(key, firstValue, secondValue)); barrier.await(5, TimeUnit.SECONDS); Future<String> futureGet = fork(() -> nonOwnerCache.get(key)); // The get will blocks locally on the L1WriteSynchronizer registered by the replace command Exceptions.expectException(TimeoutException.class, () -> futureGet.get(100, TimeUnit.MILLISECONDS)); controlledRpcManager.expectNoCommand(); // Continue the replace barrier.await(5, TimeUnit.SECONDS); // That also unblocks the get command and allows it to perform the remote get controlledRpcManager.expectCommand(ClusteredGetCommand.class) .skipSend() .receive(address(ownerCache), new ExceptionResponse(new TestException())); Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureReplace); Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureGet); } finally { removeAllBlockingInterceptorsFromCache(nonOwnerCache); controlledRpcManager.revertRpcManager(); } }
public void testPrimaryOwnerGoesDownBeforeBackupRaisesEvent() throws InterruptedException, TimeoutException, ExecutionException { final Cache<Object, String> cache0 = cache(0, CACHE_NAME); Cache<Object, String> cache1 = cache(1, CACHE_NAME); Cache<Object, String> cache2 = cache(2, CACHE_NAME); ClusterListener clusterListener = new ClusterListener(); cache0.addListener(clusterListener); // Now we want to block the outgoing put to the backup owner ControlledRpcManager controlledRpcManager = ControlledRpcManager.replaceRpcManager(cache1); final MagicKey key = new MagicKey(cache1, cache2); Future<String> future = fork(() -> cache0.put(key, FIRST_VALUE)); // Wait until the primary owner has sent the put command successfully to backup ControlledRpcManager.BlockedRequest blockedPut = controlledRpcManager.expectCommand(PutKeyValueCommand.class); // Kill the cache now TestingUtil.killCacheManagers(cache1.getCacheManager()); blockedPut.skipSend().receive(address(0), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE, address(2), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE); // This should return null normally, but since it was retried it returns it's own value :( // Maybe some day this can work properly assertEquals(null, future.get(10, TimeUnit.SECONDS)); // We should have received an event that was marked as retried - maybe even two! assertTrue(clusterListener.events.size() >= 1); assertTrue(clusterListener.events.size() <= 2); checkEvent(clusterListener.events.get(0), key, true, true); }