public final void reset() { open = true; checkPoint = new CheckPoint(); } }
/** * Allows for decorating an existing answer to apply before and after invocation and release checkpoints as * described in {@link Mocks#blockingMock(CheckPoint, Class, Cache, BiConsumer)}. * @param answer the answer to decorate with a blocking one * @param checkPoint the checkpoint to register with * @param <T> the result type of the answer * @return the new blocking answer */ public static <T> Answer<T> blockingAnswer(Answer<T> answer, CheckPoint checkPoint) { return invocation -> { checkPoint.trigger(BEFORE_INVOCATION); assertTrue(checkPoint.await(BEFORE_RELEASE, 20, TimeUnit.SECONDS)); try { return answer.answer(invocation); } finally { checkPoint.trigger(AFTER_INVOCATION); assertTrue(checkPoint.await(AFTER_RELEASE, 20, TimeUnit.SECONDS)); } }; }
@Override public void beforeState(XSiteStatePushCommand command) throws Exception { checkPoint.trigger("before-state"); checkPoint.awaitStrict("before-update", 30, TimeUnit.SECONDS); } };
final CheckPoint checkPoint = new CheckPoint(); pm = waitUntilAboutToProcessStoreTask(cache, checkPoint); checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS); checkPoint.triggerForever("pre_process_on_all_stores_released"); return null; });
@Test public void verifyNodeLeavesBeforeGettingData() throws TimeoutException, InterruptedException, ExecutionException { Map<Object, String> values = putValueInEachCache(3); Cache<Object, String> cache0 = cache(0, CACHE_NAME); Cache<Object, String> cache1 = cache(1, CACHE_NAME); CheckPoint checkPoint = new CheckPoint(); checkPoint.triggerForever(Mocks.AFTER_RELEASE); waitUntilSendingResponse(cache1, checkPoint); final BlockingQueue<String> returnQueue = new ArrayBlockingQueue<>(10); Future<Void> future = fork(() -> { Iterator<String> iter = cache0.entrySet().stream().map(Map.Entry::getValue).iterator(); while (iter.hasNext()) { String entry = iter.next(); returnQueue.add(entry); } return null; }); // Make sure the thread is waiting for the response checkPoint.awaitStrict(Mocks.BEFORE_INVOCATION, 10, TimeUnit.SECONDS); // Now kill the cache - we should recover killMember(1, CACHE_NAME); checkPoint.trigger(Mocks.BEFORE_RELEASE); future.get(10, TimeUnit.SECONDS); for (Map.Entry<Object, String> entry : values.entrySet()) { assertTrue("Entry wasn't found:" + entry, returnQueue.contains(entry.getValue())); } }
@InTransactionMode(TransactionMode.TRANSACTIONAL) public void testLeaveDuringGetTransactions() throws InterruptedException, TimeoutException { final CheckPoint checkpoint = new CheckPoint(); StateProvider stateProvider = TestingUtil.extractComponent(c2, StateProvider.class); StateProvider spyStateProvider = spy(stateProvider); doAnswer(invocation -> { int topologyId = (Integer) invocation.getArguments()[1]; checkpoint.trigger("GET_TRANSACTIONS"); log.debugf("Blocking the GET_TRANSACTIONS(%d) command on the %s", topologyId, c2); checkpoint.awaitStrict("LEAVE", 10, TimeUnit.SECONDS); return invocation.callRealMethod(); }).when(spyStateProvider).getTransactionsForSegments(any(Address.class), anyInt(), any()); TestingUtil.replaceComponent(c2, StateProvider.class, spyStateProvider, true); long startTime = System.currentTimeMillis(); manager(2).stop(); checkpoint.awaitStrict("GET_TRANSACTIONS", 10, TimeUnit.SECONDS); manager(1).stop(); checkpoint.trigger("LEAVE"); TestingUtil.blockUntilViewsReceived(30000, false, c1); TestingUtil.waitForNoRebalance(c1); long endTime = System.currentTimeMillis(); log.debugf("Recovery took %s", Util.prettyPrintTime(endTime - startTime)); assert endTime - startTime < 30000 : "Recovery took too long: " + Util.prettyPrintTime(endTime - startTime); } }
cache0.put(new MagicKey(cache(0), cache(1)), "local"); CheckPoint iteratorCP = new CheckPoint(); iteratorCP.triggerForever(Mocks.BEFORE_RELEASE); iteratorCP.triggerForever(Mocks.AFTER_RELEASE); assertTrue(iteratorCP.await(Mocks.AFTER_INVOCATION, numMembersInCluster - 1, 10, TimeUnit.SECONDS)); CheckPoint partitionCP = new CheckPoint(); partitionCP.triggerForever(Mocks.BEFORE_RELEASE); partitionCP.triggerForever(Mocks.AFTER_RELEASE);
final CheckPoint checkPoint = new CheckPoint(); ControlledRpcManager blockingRpcManager0 = ControlledRpcManager.replaceRpcManager(cache0); blockingRpcManager0.excludeCommands(BackupWriteCommand.class, BackupAckCommand.class); checkPoint.awaitStrict("pre_commit_entry_" + key + "_from_" + null, 5, SECONDS); boolean blocked = checkPoint.peek(1, SECONDS, "pre_commit_entry_" + key + "_from_" + address(0)) == null; assertTrue(blocked); checkPoint.trigger("resume_commit_entry_" + key + "_from_" + null); checkPoint.awaitStrict("pre_commit_entry_" + key + "_from_" + address(0), 5, SECONDS); checkPoint.trigger("resume_commit_entry_" + key + "_from_" + address(0)); checkPoint.awaitStrict("post_commit_entry_" + key + "_from_" + null, 10, SECONDS); checkPoint.awaitStrict("post_commit_entry_" + key + "_from_" + address(0), 10, SECONDS); checkPoint.trigger("resume_rebalance_confirmation_" + rebalanceTopologyId + "_from_" + address(0)); checkPoint.trigger("resume_rebalance_confirmation_" + rebalanceTopologyId + "_from_" + address(1)); TestingUtil.waitForNoRebalance(cache0, cache1);
@Test(timeOut = 60000) public void testConcurrentStart() throws Exception { TestResourceTracker.testThreadStarted(this); final CheckPoint checkPoint = new CheckPoint(); checkPoint.peek(2, SECONDS, "blocked_0", "blocked_1"); checkPoint.trigger("unblocked_0", CheckPoint.INFINITE); checkPoint.trigger("unblocked_1", CheckPoint.INFINITE);
CheckPoint checkPoint = new CheckPoint(); LocalTopologyManager ltm0 = TestingUtil.extractGlobalComponent(manager(0), LocalTopologyManager.class); int preJoinTopologyId = ltm0.getCacheTopology(CACHE_NAME).getTopologyId(); int duringJoinTopologyId = preJoinTopologyId + 1; checkPoint.trigger("allow_topology_" + duringJoinTopologyId + "_on_" + address(0)); checkPoint.trigger("allow_topology_" + duringJoinTopologyId + "_on_" + address(1)); checkPoint.trigger("allow_topology_" + duringJoinTopologyId + "_on_" + address(2)); checkPoint.trigger("allow_topology_" + postJoinTopologyId + "_on_" + address(0)); eventuallyEquals(postJoinTopologyId, () -> cache0.getDistributionManager().getCacheTopology().getTopologyId()); checkPoint.triggerAll();
public final void unblockCommandAndOpen() { open = true; checkPoint.trigger("after"); }
final CheckPoint checkPoint = new CheckPoint(); checkPoint.awaitStrict("before-chunk", 30, TimeUnit.SECONDS);
public void awaitStrict(String event, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { awaitStrict(event, 1, timeout, unit); }
public void waitUntilBlocked(int count) throws TimeoutException, InterruptedException { String event = checkPoint.peek(5, SECONDS, "blocked_" + count + "_on_" + cache); assertEquals("blocked_" + count + "_on_" + cache, event); }
public boolean await(String event, long timeout, TimeUnit unit) throws InterruptedException { return await(event, 1, timeout, unit); }
public CompletableFuture<Void> future(String event) { return future(event, 1); }
@Test public void testGetBlockingAnotherGetWithMiss() throws Throwable { final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key); final Cache<Object, String> ownerCache = getFirstOwner(key); assertIsNotInL1(nonOwnerCache, key); CheckPoint checkPoint = new CheckPoint(); L1Manager l1Manager = waitUntilL1Registration(nonOwnerCache, checkPoint); try { log.warn("Doing get here - ignore all previous"); Future<String> getFuture = fork(() -> nonOwnerCache.get(key)); // Wait until we are about to write value into data container on non owner checkPoint.awaitStrict("pre_acquire_shared_topology_lock_invoked", 10, TimeUnit.SECONDS); Future<String> getFuture2 = fork(() -> nonOwnerCache.get(key)); Exceptions.expectException(TimeoutException.class, () -> getFuture2.get(1, TimeUnit.SECONDS)); // Let the get complete finally checkPoint.triggerForever("pre_acquire_shared_topology_lock_released"); assertNull(getFuture.get(10, TimeUnit.SECONDS)); assertNull(getFuture2.get(10, TimeUnit.SECONDS)); } finally { TestingUtil.replaceComponent(nonOwnerCache, L1Manager.class, l1Manager, true); } }
populateCache(cache, expectedValues); final CheckPoint checkPoint = new CheckPoint(); checkPoint.trigger("pre_retrieve_entry_invoked"); checkPoint.awaitStrict("pre_retrieve_entry_released", 10, TimeUnit.SECONDS); return invokeAndReturnMock(i, real); }).when(mock).iterator()); }); checkPoint.awaitStrict("pre_retrieve_entry_invoked", 10, TimeUnit.SECONDS); checkPoint.triggerForever("pre_retrieve_entry_released");
CheckPoint checkPoint = new CheckPoint(); checkPoint.trigger(Mocks.BEFORE_RELEASE); waitUntilSendingResponse(cache1, checkPoint); checkPoint.awaitStrict(Mocks.AFTER_INVOCATION, 10, TimeUnit.SECONDS); checkPoint.trigger(Mocks.AFTER_RELEASE);
cache0.put(new MagicKey(cache(0), cache(1)), "local"); CheckPoint iteratorCP = new CheckPoint(); CheckPoint partitionCP = new CheckPoint(); partitionCP.triggerForever(Mocks.BEFORE_RELEASE); partitionCP.triggerForever(Mocks.AFTER_RELEASE); assertTrue(partitionCP.await(Mocks.AFTER_INVOCATION, 10, TimeUnit.SECONDS)); iteratorCP.triggerForever(Mocks.BEFORE_RELEASE); iteratorCP.triggerForever(Mocks.AFTER_RELEASE);