private ControlledRpcManager.BlockedRequest expectCommand(ControlledRpcManager rpcManager) throws InterruptedException { return rpcManager.expectCommand(classToBlock); }
public <T extends ReplicableCommand> BlockedRequests expectCommands(Class<T> expectedCommandClass, Collection<Address> targets) { Map<Address, BlockedRequest<T>> requests = new HashMap<>(); for (int i = 0; i < targets.size(); i++) { BlockedRequest request = expectCommand(expectedCommandClass); requests.put(request.getTarget(), request); } assertEquals(new HashSet<>(targets), requests.keySet()); return new BlockedRequests(requests); }
private ControlledRpcManager.BlockedRequest expectStateRequestCommand(ControlledRpcManager crm, StateRequestCommand.Type type) throws InterruptedException { return crm.expectCommand(StateRequestCommand.class, c -> assertEquals(type, c.getType())); }
public void testReplicationFailure() throws Exception { Cache<?, ?> cache = cache(0); ControlledRpcManager controlledRpcManager = ControlledRpcManager.replaceRpcManager(cache); try { Future<Void> future = fork(() -> { controlledRpcManager.expectCommand(VersionedPrepareCommand.class).fail(); controlledRpcManager.expectCommand(RollbackCommand.class).send().receiveAll(); }); TransactionManager tm = cache(0).getAdvancedCache().getTransactionManager(); tm.begin(); cache(0).put("k0", "v"); Exceptions.expectException(RollbackException.class, tm::commit); future.get(30, TimeUnit.SECONDS); } finally { controlledRpcManager.revertRpcManager(); } } }
ControlledRpcManager.BlockedRequest blockedGetAll = rpcManager.expectCommand(ClusteredGetAllCommand.class); rpcManager.expectCommand(ClusteredGetAllCommand.class).send().receiveAll();
ControlledRpcManager.BlockedRequest blockedReplace = controlledRpcManager.expectCommand(ReplaceCommand.class);
ControlledRpcManager.BlockedRequest blockedPrepare = rpcManager.expectCommand(prepareCommandClass); ControlledRpcManager.BlockedResponseMap blockedPrepareResponses = null; if (!pessimistic) { } else { blockedPrepareResponses.receive(); rpcManager.expectCommand(VersionedCommitCommand.class).send().receiveAll(); rpcManager.expectCommand(TxCompletionNotificationCommand.class).send(); Assert.assertTrue(txOutcome.get()); } finally {
controlledRpcManager.expectCommand(ClusteredGetCommand.class).send().receiveAll(); controlledRpcManager.expectCommand(PrepareCommand.class).send().receiveAll(); ControlledRpcManager.BlockedRequest blockedCommit = controlledRpcManager.expectCommand(CommitCommand.class); controlledRpcManager.expectCommand(CommitCommand.class).send().receiveAll(); controlledRpcManager.expectCommand(TxCompletionNotificationCommand.class).send();
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); }
@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(); } }
ControlledRpcManager.BlockedRequest blockedPrepare = rpcManager.expectCommand(prepareCommandClass); ControlledRpcManager.BlockedResponseMap blockedPrepareResponses = null; if (!pessimistic) { } else { blockedPrepareResponses.receive(); rpcManager.expectCommand(VersionedCommitCommand.class).send().receiveAll(); rpcManager.expectCommand(TxCompletionNotificationCommand.class).send(); Assert.assertTrue(txOutcome.get()); } finally {
Future<Cache> future = fork(() -> joiner.getCache(CACHE_NAME)); ControlledRpcManager.BlockedRequest blockedStateResponse = crm.expectCommand(StateResponseCommand.class);
controlledRpcManager.expectCommand(ClusteredGetCommand.class).send().receiveAll(); ControlledRpcManager.BlockedRequest blockedPrepare = controlledRpcManager.expectCommand(PrepareCommand.class); blockedPrepare.send().receiveAll(); controlledRpcManager.expectCommand(PrepareCommand.class).send().receiveAll();
public void testBiasTimesOut() throws Exception { rpcManager0.excludeCommands(ExceptionAckCommand.class); MagicKey key = new MagicKey(cache(0)); cache(1).put(key, "v0"); assertTrue(biasManager(1).hasLocalBias(key)); timeService.advance(BIAS_LIFESPAN + 1); rpcManager0.expectCommand(RevokeBiasCommand.class).send().receiveAll(); // The local bias is invalidated synchronously with the sync command, but it may take few moments // to remove the remote bias. assertFalse(biasManager(1).hasLocalBias(key)); eventuallyEquals(null, () -> biasManager(0).getRemoteBias(key)); }
public void testNoEntryInL1PutReplacedNullValueConcurrently() throws InterruptedException, ExecutionException, TimeoutException { final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key); final Cache<Object, String> ownerCache = getFirstOwner(key); ControlledRpcManager crm = ControlledRpcManager.replaceRpcManager(nonOwnerCache); crm.excludeCommands(ClusteredGetCommand.class); try { Future<String> future = fork(() -> nonOwnerCache.putIfAbsent(key, firstValue)); // Now wait for the get to return and block it for now ControlledRpcManager.BlockedResponseMap blockedPutResponses = crm.expectCommand(PutKeyValueCommand.class).send().expectAllResponses(); // Owner should have the new value assertEquals(firstValue, ownerCache.remove(key)); // Now let owner key->updateValue go through blockedPutResponses.receive(); // This should be originalValue still as we did the get assertNull(future.get(5, TimeUnit.SECONDS)); // Remove the interceptor now since we don't want to block ourselves - if using phaser this isn't required removeAllBlockingInterceptorsFromCache(nonOwnerCache); assertIsNotInL1(nonOwnerCache, key); // The nonOwnerCache should retrieve new value as it isn't in L1 assertNull(nonOwnerCache.get(key)); assertIsNotInL1(nonOwnerCache, key); } finally { crm.revertRpcManager(); } }
ControlledRpcManager.BlockedRequest blockedGet = rpcManager0.expectCommand(ClusteredGetCommand.class); rpcManager0.expectCommand(ClusteredGetCommand.class).send().receiveAll();
ControlledRpcManager.BlockedRequest blockedGet = rpcManager0.expectCommand(ClusteredGetCommand.class);
ControlledRpcManager.BlockedRequest blockedGet = rpcManager0.expectCommand(ClusteredGetCommand.class);
ControlledRpcManager.BlockedRequest blockedWrite = crm.expectCommand(operation.getCommandClass()); crm.expectCommand(operation.getCommandClass()).send().receiveAll();
ControlledRpcManager.BlockedRequest blockedGet = rpcManager0.expectCommand(ClusteredGetCommand.class);