use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class DistributedWriteBehindStreamIteratorTest method testBackupSegmentsOptimizationWithWriteBehindStore.
@Test(dataProvider = "rehashAware")
public void testBackupSegmentsOptimizationWithWriteBehindStore(boolean rehashAware) {
Cache<Object, String> cache1 = cache(1, CACHE_NAME);
RpcManager rpcManager = Mocks.replaceComponentWithSpy(cache1, RpcManager.class);
for (Cache<Object, String> cache : this.<Object, String>caches(CACHE_NAME)) {
MagicKey key = new MagicKey(cache);
cache.put(key, key.toString());
}
// Remember that segment ownership is as {0, 1}, {1, 2}, {2, 1}
CacheStream<Map.Entry<Object, String>> stream = cache1.entrySet().stream();
if (!rehashAware)
stream = stream.disableRehashAware();
int invocationCount;
if (cacheMode.isReplicated()) {
Map<Object, String> entries = mapFromIterator(stream.iterator());
assertEquals(caches(CACHE_NAME).size(), entries.size());
invocationCount = cacheManagers.size() - 1;
} else {
// Distributed cache
// Cache1 owns 1 (primary) and 2 (backup)
// When it is a write behind shared store it will have to go remote otherwise will stay local
Map<Object, String> entries = mapFromIterator(stream.filterKeySegments(IntSets.immutableSet(2)).iterator());
assertEquals(1, entries.size());
invocationCount = 1;
}
// on the primary owner, so we could miss updates
if (asyncStore && sharedStore) {
verify(rpcManager, times(invocationCount)).invokeCommand(any(Address.class), any(InitialPublisherCommand.class), any(), any());
} else {
verify(rpcManager, never()).invokeCommand(any(Address.class), any(InitialPublisherCommand.class), any(), any());
}
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class WriteSkewConsistencyTest method injectReorderResponseRpcManager.
private void injectReorderResponseRpcManager(Cache<?, ?> toInject, Cache<?, ?> lastResponse) {
RpcManager rpcManager = extractComponent(toInject, RpcManager.class);
ReorderResponsesRpcManager newRpcManager = new ReorderResponsesRpcManager(address(lastResponse), rpcManager);
replaceComponent(toInject, RpcManager.class, newRpcManager, true);
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class PessimisticLockingTxClusterExtendedStatisticLogicTest method createCacheManagers.
@Override
protected void createCacheManagers() {
for (int i = 0; i < NUM_NODES; ++i) {
ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
builder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0));
//
builder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ).lockAcquisitionTimeout(// the timeout are triggered by the TimeService!
60000);
builder.transaction().recovery().disable();
builder.transaction().lockingMode(LockingMode.PESSIMISTIC);
// builder.versioning().enable().scheme(VersioningScheme.SIMPLE);
extendedStatisticInterceptors[i] = new ExtendedStatisticInterceptor();
builder.customInterceptors().addInterceptor().interceptor(extendedStatisticInterceptors[i]).after(TxInterceptor.class);
addClusterEnabledCacheManager(builder);
}
waitForClusterToForm();
for (int i = 0; i < NUM_NODES; ++i) {
ExtendedStatisticInterceptor interceptor = extendedStatisticInterceptors[i];
CacheStatisticManager manager = extractField(interceptor, "cacheStatisticManager");
CacheStatisticCollector collector = extractField(manager, "cacheStatisticCollector");
ConcurrentGlobalContainer globalContainer = extractField(collector, "globalContainer");
ExtendedStatisticRpcManager rpcManager = (ExtendedStatisticRpcManager) extractComponent(cache(i), RpcManager.class);
ExtendedStatisticLockManager lockManager = (ExtendedStatisticLockManager) extractLockManager(cache(i));
lockManagers[i] = lockManager;
replaceField(TEST_TIME_SERVICE, "timeService", manager, CacheStatisticManager.class);
replaceField(TEST_TIME_SERVICE, "timeService", collector, CacheStatisticCollector.class);
replaceField(TEST_TIME_SERVICE, "timeService", globalContainer, ConcurrentGlobalContainer.class);
replaceField(TEST_TIME_SERVICE, "timeService", interceptor, ExtendedStatisticInterceptor.class);
replaceField(TEST_TIME_SERVICE, "timeService", lockManager, ExtendedStatisticLockManager.class);
replaceField(TEST_TIME_SERVICE, "timeService", rpcManager, ExtendedStatisticRpcManager.class);
controlledRpcManager[i] = ControlledRpcManager.replaceRpcManager(cache(i));
transactionTrackInterceptors[i] = TransactionTrackInterceptor.injectInCache(cache(i));
if (i == 0) {
LockManager actualLockManager = lockManager.getActual();
LockContainer container = extractField(actualLockManager, "lockContainer");
TestingUtil.inject(container, new WithinThreadExecutor(), lockManagerTimeService);
}
}
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class RepeatableReadRemoteGetCountTest method replaceRpcManager.
private CountingRpcManager replaceRpcManager(Cache cache) {
RpcManager current = TestingUtil.extractComponent(cache, RpcManager.class);
if (current instanceof CountingRpcManager) {
return (CountingRpcManager) current;
}
CountingRpcManager countingRpcManager = new CountingRpcManager(current);
TestingUtil.replaceComponent(cache, RpcManager.class, countingRpcManager, true);
return countingRpcManager;
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class RpcManagerMBeanTest method testSuccessRatio.
@Test(dependsOnMethods = "testEnableJmxStats")
public void testSuccessRatio() throws Exception {
Cache<MagicKey, Object> cache1 = manager(0).getCache();
Cache<MagicKey, Object> cache2 = manager(1).getCache();
MBeanServer mBeanServer = mBeanServerLookup.getMBeanServer();
ObjectName rpcManager1 = getCacheObjectName(jmxDomain1, getDefaultCacheName() + "(repl_sync)", "RpcManager");
// the previous test has reset the statistics
assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationCount"), (long) 0);
assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationFailures"), (long) 0);
assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), "N/A");
RpcManagerImpl rpcManager = (RpcManagerImpl) extractComponent(cache1, RpcManager.class);
Transport originalTransport = rpcManager.getTransport();
try {
MockTransport transport = new MockTransport(address(0));
transport.init(originalTransport.getViewId(), originalTransport.getMembers());
rpcManager.setTransport(transport);
CompletableFuture<Object> put1 = cache1.putAsync(new MagicKey("a1", cache1), "b1");
timeService.advance(50);
transport.expectCommand(SingleRpcCommand.class).singleResponse(address(2), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
put1.get(10, TimeUnit.SECONDS);
CompletableFuture<Object> put2 = cache1.putAsync(new MagicKey("a2", cache2), "b2");
timeService.advance(10);
transport.expectCommand(SingleRpcCommand.class).singleResponse(address(2), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
put2.get(10, TimeUnit.SECONDS);
assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationCount"), (long) 2);
assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), "100%");
long avgReplTime = (long) mBeanServer.getAttribute(rpcManager1, "AverageReplicationTime");
assertEquals(avgReplTime, 30);
// If cache1 is the primary owner it will be a broadcast, otherwise a unicast
CompletableFuture<Object> put3 = cache1.putAsync(new MagicKey("a3", cache1), "b3");
transport.expectCommand(SingleRpcCommand.class).throwException(new RuntimeException());
Exceptions.expectCompletionException(CacheException.class, put3);
CompletableFuture<Object> put4 = cache1.putAsync(new MagicKey("a4", cache2), "b4");
transport.expectCommand(SingleRpcCommand.class).throwException(new RuntimeException());
Exceptions.expectCompletionException(CacheException.class, put4);
assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), ("50%"));
} finally {
rpcManager.setTransport(originalTransport);
}
}
Aggregations