private void testBeforeTopology(BiFunction<FunctionalMap.ReadWriteMap<String, Integer>, String, Integer> op, int expectedIncrement) throws Exception { cache(0).put("key", 1); // Blocking on receiver side. We cannot block the StateResponseCommand on the server side since // the InternalCacheEntries in its state are the same instances of data stored in DataContainer // - therefore when the command is blocked on sender the command itself would be mutated by applying // the transaction below. BlockingStateConsumer bsc2 = TestingUtil.wrapComponent(cache(2), StateConsumer.class, BlockingStateConsumer::new); tm(2).begin(); FunctionalMap.ReadWriteMap<String, Integer> rw = ReadWriteMapImpl.create( FunctionalMapImpl.create(this.<String, Integer>cache(2).getAdvancedCache())); assertEquals(new Integer(1), op.apply(rw, "key")); Transaction tx = tm(2).suspend(); chf.setOwnerIndexes(0, 2); Future<?> future = fork(() -> { TestResourceTracker.testThreadStarted(this); addClusterEnabledCacheManager(cb).getCache(); }); bsc2.await(); DistributionInfo distributionInfo = cache(2).getAdvancedCache().getDistributionManager().getCacheTopology().getDistribution("key"); assertFalse(distributionInfo.isReadOwner()); assertTrue(distributionInfo.isWriteBackup()); tm(2).resume(tx); tm(2).commit(); bsc2.unblock(); future.get(10, TimeUnit.SECONDS); InternalCacheEntry<Object, Object> ice = cache(2).getAdvancedCache().getDataContainer().get("key"); assertEquals("Current ICE: " + ice, 1 + expectedIncrement, ice.getValue()); }
private void testAfterTopology(BiFunction<FunctionalMap.ReadWriteMap<String, Integer>, String, Integer> op, int expectedIncrement) throws Exception { cache(0).put("key", 1); // Blocking on receiver side. We cannot block the StateResponseCommand on the server side since // the InternalCacheEntries in its state are the same instances of data stored in DataContainer // - therefore when the command is blocked on sender the command itself would be mutated by applying // the transaction below. BlockingStateConsumer bsc2 = TestingUtil.wrapComponent(cache(2), StateConsumer.class, BlockingStateConsumer::new); chf.setOwnerIndexes(0, 2); Future<?> future = fork(() -> { TestResourceTracker.testThreadStarted(this); addClusterEnabledCacheManager(cb).getCache(); }); bsc2.await(); DistributionInfo distributionInfo = cache(2).getAdvancedCache().getDistributionManager().getCacheTopology().getDistribution("key"); assertFalse(distributionInfo.isReadOwner()); assertTrue(distributionInfo.isWriteBackup()); withTx(tm(2), () -> { FunctionalMap.ReadWriteMap<String, Integer> rw = ReadWriteMapImpl.create( FunctionalMapImpl.create(this.<String, Integer>cache(2).getAdvancedCache())); assertEquals(new Integer(1), op.apply(rw, "key")); return null; }); bsc2.unblock(); future.get(10, TimeUnit.SECONDS); InternalCacheEntry<Object, Object> ice = cache(2).getAdvancedCache().getDataContainer().get("key"); assertEquals("Current ICE: " + ice, 1 + expectedIncrement, ice.getValue()); }
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); //CH_UPDATE + REBALANCE_START + CH_UPDATE(blocked) bltm0.expectRebalanceStartAfterLeave().unblock(); bltm1.expectRebalanceStartAfterLeave().unblock(); bltm0.expectPhaseConfirmation().unblock(); bltm1.expectPhaseConfirmation().unblock(); //check if we are in the correct state 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(); //let the cluster finish the state transfer assertInAllCache(key, "v2"); }