configurationBuilder.customInterceptors().addInterceptor().after(StateTransferInterceptor.class).interceptor(new DelayInterceptor());
return configurationBuilder;
}
public void testForwardToJoinerNonTransactional() throws Exception {
EmbeddedCacheManager cm1 = addClusterEnabledCacheManager(buildConfig(false));
final Cache<Object, Object> c1 = cm1.getCache();
DelayInterceptor di1 = findInterceptor(c1, DelayInterceptor.class);
EmbeddedCacheManager cm2 = addClusterEnabledCacheManager(buildConfig(false));
Cache<Object, Object> c2 = cm2.getCache();
DelayInterceptor di2 = findInterceptor(c2, DelayInterceptor.class);
waitForStateTransfer(2, c1, c2);
Future<Object> f = fork(new Callable<Object>() {
@Override
public Object call() throws Exception {
log.tracef("Initiating a put command on %s", c1);
// The put command is replicated to cache c2, and it blocks in the DelayInterceptor.
c1.put("k", "v");
return null;
}
});
// c3 joins, topology id changes
EmbeddedCacheManager cm3 = addClusterEnabledCacheManager(buildConfig(false));
Cache<Object, Object> c3 = cm3.getCache();
DelayInterceptor di3 = findInterceptor(c3, DelayInterceptor.class);
waitForStateTransfer(4, c1, c2, c3);
// Unblock the replicated command on c2.
// StateTransferInterceptor will forward the command to c3.
// The DelayInterceptor on c3 will then block, waiting for an unblock() call.
log.tracef("Forwarding the command from %s", c2);
di2.unblock(1);
// Wait to ensure that the c3 receives the forwarded commands in the "right" order
Thread.sleep(1000);
// Unblock the command on the originator (c1), while forwarding is still in progress.
// StateTransferInterceptor will forward the command to c2 and c3.
di1.unblock(1);
// Unblock the command forwarded from c1 on c2 (c2 won't forward the command again).
// Don't unblock the command on c3, because we'd actually unblock the command forwarded from c2.
di2.unblock(2);
// c4 joins, topology id changes
EmbeddedCacheManager cm4 = addClusterEnabledCacheManager(buildConfig(false));
Cache<Object, Object> c4 = cm4.getCache();
DelayInterceptor di4 = findInterceptor(c4, DelayInterceptor.class);
waitForStateTransfer(6, c1, c2, c3, c4);
// Allow command forwarded from c2 to proceed on c3.
// StateTransferInterceptor will then forward the command to c1 and c4.