Cache cache1 = cache(0, "replSync");
Cache cache2 = cache(1, "replSync");
waitForClusterToForm("replSync");
Transport originalTransport = null;
RpcManagerImpl rpcManager = null;
RpcManagerImpl asyncRpcManager = null;
try {
ConfigurationBuilder asyncCache = getDefaultClusteredCacheConfig(CacheMode.REPL_ASYNC, false);
asyncCache.clustering().async().asyncMarshalling(true);
defineConfigurationOnAllManagers("asyncCache", asyncCache);
Cache asyncCache1 = manager(0).getCache("asyncCache");
Cache asyncCache2 = manager(1).getCache("asyncCache");
waitForClusterToForm("asyncCache");
// this is shared by all caches managed by the cache manager
originalTransport = TestingUtil.extractGlobalComponent(cache1.getCacheManager(), Transport.class);
Transport mockTransport = spy(originalTransport);
// replace the transport with a mock object
rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
rpcManager.setTransport(mockTransport);
// check that the replication call was sync
cache1.put("k", "v");
verify(mockTransport).invokeRemotely((List<Address>) anyObject(),
(CacheRpcCommand) anyObject(), eq(ResponseMode.SYNCHRONOUS), anyLong(),
anyBoolean(), (ResponseFilter) anyObject(), anyBoolean(), anyBoolean());
// resume to test for async
asyncRpcManager = (RpcManagerImpl) TestingUtil.extractComponent(asyncCache1, RpcManager.class);
asyncRpcManager.setTransport(mockTransport);
reset(mockTransport);
asyncCache1.put("k", "v");
verify(mockTransport).invokeRemotely((List<Address>) anyObject(),
(CacheRpcCommand) anyObject(), eq(ResponseMode.ASYNCHRONOUS), anyLong(),
anyBoolean(), (ResponseFilter) anyObject(), anyBoolean(), anyBoolean());
} finally {
// replace original transport
if (rpcManager != null)
rpcManager.setTransport(originalTransport);
if (asyncRpcManager != null)
asyncRpcManager.setTransport(originalTransport);
}
}