private void doTest(Operation operation, boolean init) throws Exception {
final MagicKey key = new MagicKey(cache(1), cache(2));
if (init) {
cache(0).put(key, "v1");
assertInAllCache(key, "v1");
}
BlockingLocalTopologyManager bltm0 = replaceTopologyManagerDefaultCache(manager(0));
BlockingLocalTopologyManager bltm1 = replaceTopologyManagerDefaultCache(manager(1));
killMember(2, null, false);
bltm0.expectRebalanceStartAfterLeave().unblock();
bltm1.expectRebalanceStartAfterLeave().unblock();
bltm0.expectPhaseConfirmation().unblock();
bltm1.expectPhaseConfirmation().unblock();
LocalizedCacheTopology cacheTopology = TestingUtil.extractComponent(cache(0), DistributionManager.class).getCacheTopology();
DistributionInfo distributionInfo = cacheTopology.getDistribution(key);
assertFalse(distributionInfo.isReadOwner());
assertTrue(distributionInfo.isWriteOwner());
assertEquals(address(1), distributionInfo.primary());
operation.put(key, "v2", cache(1));
BlockingLocalTopologyManager.finishRebalance(CacheTopology.Phase.READ_ALL_WRITE_ALL, bltm0, bltm1);
waitForClusterToForm();
assertInAllCache(key, "v2");
}