public BlockedTopology expectRebalanceStartAfterLeave() throws InterruptedException { // After a node leaves, the coordinator sends a NO_REBALANCE topology update with the remaining members // Then it immediately starts the rebalance with a READ_OLD topology update // The members can receive the topology updates in either order BlockedTopology topology0 = expectTopologyUpdate(); if (topology0.getType() == Type.REBALANCE_START) { expectTopologyUpdate(CacheTopology.Phase.NO_REBALANCE).unblock(); } else { topology0.unblock(); topology0 = expectTopologyUpdate(CacheTopology.Phase.READ_OLD_WRITE_ALL); } return topology0; }
/** * Expect a topology updates and unblock it. * <p> * If the update requires confirmation, unblock the confirmation as well. */ public void confirmTopologyUpdate(CacheTopology.Phase phase) throws InterruptedException { expectTopologyUpdate(phase).unblock(); if (needConfirmation(phase)) { expectPhaseConfirmation().unblock(); } }
public static void confirmTopologyUpdate(CacheTopology.Phase phase, BlockingLocalTopologyManager... topologyManagers) throws InterruptedException { for (BlockingLocalTopologyManager topologyManager : topologyManagers) { topologyManager.expectTopologyUpdate(phase).unblock(); } if (needConfirmation(phase)) { for (BlockingLocalTopologyManager topologyManager : topologyManagers) { topologyManager.expectPhaseConfirmation().unblock(); } } }
public BlockedTopology expectTopologyUpdate(CacheTopology.Phase phase) throws InterruptedException { BlockedTopology blockedTopology = expectTopologyUpdate(); assertTrue("Expected a CH_UPDATE or REBALANCE_START, but got a CONFIRMATION", blockedTopology.getType() != Type.CONFIRMATION); assertEquals(phase, blockedTopology.getCacheTopology().getPhase()); return blockedTopology; }
public BlockedTopology expectTopologyUpdate(CacheTopology.Phase phase, int topologyId) throws InterruptedException { BlockedTopology blockedTopology = expectTopologyUpdate(); assertEquals(topologyId, blockedTopology.getCacheTopology().getTopologyId()); assertEquals(phase, blockedTopology.getCacheTopology().getPhase()); return blockedTopology; }
private BlockingLocalTopologyManager.BlockedTopology blockNewRebalance(BlockingLocalTopologyManager ltm, BlockingLocalTopologyManager.BlockedTopology blockedTopology) throws InterruptedException { if (blockedTopology.getCacheTopology().getPhase() == CacheTopology.Phase.READ_NEW_WRITE_ALL) { // Block the rebalance start first, and only then unblock the previous topology // Otherwise the order of the rebalance start and topology confirmation wouldn't be deterministic BlockingLocalTopologyManager.BlockedTopology newTopology = ltm.expectTopologyUpdate(CacheTopology.Phase.READ_OLD_WRITE_ALL); blockedTopology.unblock(); ltm.expectPhaseConfirmation().unblock(); return newTopology; } else { assertEquals(CacheTopology.Phase.READ_OLD_WRITE_ALL, blockedTopology.getCacheTopology().getPhase()); ltm.confirmTopologyUpdate(CacheTopology.Phase.READ_NEW_WRITE_ALL); return blockedTopology; } }
localTopologyManager0.expectTopologyUpdate(CacheTopology.Phase.READ_NEW_WRITE_ALL).unblock(); localTopologyManager2.expectTopologyUpdate(CacheTopology.Phase.READ_NEW_WRITE_ALL).unblock(); BlockingLocalTopologyManager.BlockedConfirmation blockedConfirmation0 = localTopologyManager0.expectPhaseConfirmation(); BlockingLocalTopologyManager.BlockedTopology blockedTopology0 = localTopologyManager0.expectTopologyUpdate(); BlockingLocalTopologyManager.BlockedTopology blockedTopology2 = localTopologyManager2.expectTopologyUpdate();
/** * x-site state transfer is triggered during a cache topology change. */ private void doXSiteStateTransferDuringTopologyChange(TopologyEvent event) throws Exception { log.debugf("Start topology change during x-site state transfer with %s", event); initBeforeTest(); final TestCaches<Object, Object> testCaches = createTestCache(event, LON); log.debugf("Controlled cache=%s, Coordinator cache=%s, Cache to remove=%s", addressOf(testCaches.controllerCache), addressOf(testCaches.coordinator), testCaches.removeIndex < 0 ? "NONE" : addressOf(cache(LON, testCaches.removeIndex))); BlockingLocalTopologyManager topologyManager = replaceTopologyManagerDefaultCache(testCaches.controllerCache.getCacheManager()); final Future<Void> topologyEventFuture = triggerTopologyChange(LON, testCaches.removeIndex); // We could get either the NO_REBALANCE update or the READ_OLD rebalance start first BlockingLocalTopologyManager.BlockedTopology blockedTopology = topologyManager.expectTopologyUpdate(); log.debug("Start x-site state transfer"); startStateTransfer(testCaches.coordinator, NYC); assertOnline(LON, NYC); blockedTopology.unblock(); topologyEventFuture.get(); awaitLocalStateTransfer(LON); awaitXSiteStateSent(LON); assertData(); }
BlockedTopology t1 = ltm2.expectTopologyUpdate(CacheTopology.Phase.NO_REBALANCE, stableTopologyId + 1); if (t1.getCacheTopology().getTopologyId() == stableTopologyId + 1) assertEquals(CacheTopology.Phase.NO_REBALANCE, t1.getPhase()); BlockedTopology t2 = ltm2.expectTopologyUpdate(CacheTopology.Phase.TRANSITORY, stableTopologyId + 2); assertEquals(CacheTopology.Phase.TRANSITORY, t2.getPhase()); assertEquals(2, t2.getCacheTopology().getActualMembers().size()); BlockedTopology t3 = ltm2.expectTopologyUpdate(CacheTopology.Phase.NO_REBALANCE, stableTopologyId + 3); assertEquals(2, t3.getCacheTopology().getActualMembers().size()); assertEquals(null, t3.getCacheTopology().getPendingCH());