Search in sources :

Example 1 with RpcManager

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());
    }
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) Address(org.infinispan.remoting.transport.Address) MagicKey(org.infinispan.distribution.MagicKey) InitialPublisherCommand(org.infinispan.reactive.publisher.impl.commands.batch.InitialPublisherCommand) Test(org.testng.annotations.Test)

Example 2 with RpcManager

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);
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) AbstractDelegatingRpcManager(org.infinispan.util.AbstractDelegatingRpcManager)

Example 3 with RpcManager

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);
        }
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) RpcManager(org.infinispan.remoting.rpc.RpcManager) CacheStatisticCollector(org.infinispan.extendedstats.CacheStatisticCollector) ExtendedStatisticInterceptor(org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) ReplicatedControlledConsistentHashFactory(org.infinispan.util.ReplicatedControlledConsistentHashFactory) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer) CacheStatisticManager(org.infinispan.extendedstats.CacheStatisticManager) LockManager(org.infinispan.util.concurrent.locks.LockManager) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) TestingUtil.extractLockManager(org.infinispan.test.TestingUtil.extractLockManager) LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Example 4 with RpcManager

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;
}
Also used : CountingRpcManager(org.infinispan.util.CountingRpcManager) RpcManager(org.infinispan.remoting.rpc.RpcManager) CountingRpcManager(org.infinispan.util.CountingRpcManager)

Example 5 with RpcManager

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);
    }
}
Also used : RpcManagerImpl(org.infinispan.remoting.rpc.RpcManagerImpl) RpcManager(org.infinispan.remoting.rpc.RpcManager) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) ObjectName(javax.management.ObjectName) TestingUtil.getCacheObjectName(org.infinispan.test.TestingUtil.getCacheObjectName) MockTransport(org.infinispan.remoting.transport.MockTransport) MockTransport(org.infinispan.remoting.transport.MockTransport) Transport(org.infinispan.remoting.transport.Transport) MagicKey(org.infinispan.distribution.MagicKey) MBeanServer(javax.management.MBeanServer) Test(org.testng.annotations.Test)

Aggregations

RpcManager (org.infinispan.remoting.rpc.RpcManager)37 Address (org.infinispan.remoting.transport.Address)11 CommandsFactory (org.infinispan.commands.CommandsFactory)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RpcOptions (org.infinispan.remoting.rpc.RpcOptions)7 Transport (org.infinispan.remoting.transport.Transport)7 Map (java.util.Map)5 ComponentRegistry (org.infinispan.factories.ComponentRegistry)5 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)4 RpcManagerImpl (org.infinispan.remoting.rpc.RpcManagerImpl)4 AbstractDelegatingRpcManager (org.infinispan.util.AbstractDelegatingRpcManager)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Cache (org.infinispan.Cache)3 IntSet (org.infinispan.commons.util.IntSet)3 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)3 InitialPublisherCommand (org.infinispan.reactive.publisher.impl.commands.batch.InitialPublisherCommand)3 Response (org.infinispan.remoting.responses.Response)3