Source:
public void testPrimaryOwnerGoesDownAfterBackupRaisesEvent() throws InterruptedException, TimeoutException, ExecutionException, BrokenBarrierException { 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); CyclicBarrier barrier = new CyclicBarrier(3); BlockingInterceptor blockingInterceptor0 = new BlockingInterceptor(barrier, PutKeyValueCommand.class, true, false); cache0.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor0, EntryWrappingInterceptor.class); BlockingInterceptor blockingInterceptor2 = new BlockingInterceptor(barrier, PutKeyValueCommand.class, true, false); cache2.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor2, EntryWrappingInterceptor.class); final MagicKey key = new MagicKey(cache1); Future<String> future = fork(() -> cache0.put(key, FIRST_VALUE)); barrier.await(10, TimeUnit.SECONDS); cache0.getAdvancedCache().getAsyncInterceptorChain().removeInterceptor(BlockingInterceptor.class); cache2.getAdvancedCache().getAsyncInterceptorChain().removeInterceptor(BlockingInterceptor.class); blockingInterceptor0.suspend(true); blockingInterceptor2.suspend(true); TestingUtil.killCacheManagers(cache1.getCacheManager()); barrier.await(10, TimeUnit.SECONDS); String returnValue = future.get(10, TimeUnit.SECONDS); assertEquals(FIRST_VALUE, returnValue); assertTrue(clusterListener.events.size() >= 2); sassertTrue(clusterListener.events.size() <= 3); checkEvent(clusterListener.events.get(0), key, true, false); checkEvent(clusterListener.events.get(1), key, false, true); }

Target:
public void testPrimaryOwnerGoesDownAfterBackupRaisesEvent() throws InterruptedException, TimeoutException, ExecutionException, BrokenBarrierException { 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); CyclicBarrier barrier = new CyclicBarrier(3); BlockingInterceptor blockingInterceptor0 = new BlockingInterceptor(barrier, PutKeyValueCommand.class, true, false); cache0.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor0, EntryWrappingInterceptor.class); BlockingInterceptor blockingInterceptor2 = new BlockingInterceptor(barrier, PutKeyValueCommand.class, true, false); cache2.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor2, EntryWrappingInterceptor.class); final MagicKey key = new MagicKey(cache1); Future<String> future = fork(() -> cache0.put(key, FIRST_VALUE)); barrier.await(10, TimeUnit.SECONDS); cache0.getAdvancedCache().getAsyncInterceptorChain().removeInterceptor(BlockingInterceptor.class); cache2.getAdvancedCache().getAsyncInterceptorChain().removeInterceptor(BlockingInterceptor.class); blockingInterceptor0.suspend(true); blockingInterceptor2.suspend(true); TestingUtil.killCacheManagers(cache1.getCacheManager()); barrier.await(10, TimeUnit.SECONDS); String returnValue = future.get(10, TimeUnit.SECONDS); assertEquals(FIRST_VALUE, returnValue); assertTrue(clusterListener.events.size() >= 2); assertTrue(clusterListener.events.size() <= 3); checkEvent(clusterListener.events.get(0), key, true, false); checkEvent(clusterListener.events.get(1), key, false, true); }