Search in sources :

Example 26 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class StreamDistPartitionHandlingTest method registerBlockingRpcManagerOnInitialPublisherCommand.

private static void registerBlockingRpcManagerOnInitialPublisherCommand(final CheckPoint checkPoint, Cache<?, ?> cache, Executor completionExecutor) {
    RpcManager realManager = TestingUtil.extractComponent(cache, RpcManager.class);
    RpcManager spy = spy(realManager);
    doAnswer(invocation -> Mocks.blockingCompletableFuture(() -> {
        try {
            return (CompletableFuture) invocation.callRealMethod();
        } catch (Throwable throwable) {
            throw new AssertionError(throwable);
        }
    }, checkPoint, completionExecutor).call()).when(spy).invokeCommand(any(Address.class), any(InitialPublisherCommand.class), any(), any());
    TestingUtil.replaceComponent(cache, RpcManager.class, spy, true);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RpcManager(org.infinispan.remoting.rpc.RpcManager) Address(org.infinispan.remoting.transport.Address) InitialPublisherCommand(org.infinispan.reactive.publisher.impl.commands.batch.InitialPublisherCommand)

Example 27 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class StateConsumerTest method test1.

public void test1() throws Exception {
    // create cache configuration
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.clustering().invocationBatching().enable().clustering().cacheMode(CacheMode.DIST_SYNC).clustering().stateTransfer().timeout(30000).locking().lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis()).locking().isolationLevel(IsolationLevel.REPEATABLE_READ);
    Configuration configuration = cb.build();
    PersistentUUIDManager persistentUUIDManager = new PersistentUUIDManagerImpl();
    // create list of 6 members
    Address[] addresses = new Address[4];
    for (int i = 0; i < 4; i++) {
        addresses[i] = new TestAddress(i);
        persistentUUIDManager.addPersistentAddressMapping(addresses[i], PersistentUUID.randomUUID());
    }
    List<Address> members1 = Arrays.asList(addresses[0], addresses[1], addresses[2], addresses[3]);
    List<Address> members2 = Arrays.asList(addresses[0], addresses[1], addresses[2]);
    // create CHes
    DefaultConsistentHashFactory chf = new DefaultConsistentHashFactory();
    KeyPartitioner keyPartitioner = new HashFunctionPartitioner(40);
    DefaultConsistentHash ch1 = chf.create(2, 40, members1, null);
    final DefaultConsistentHash ch2 = chf.updateMembers(ch1, members2, null);
    DefaultConsistentHash ch3 = chf.rebalance(ch2);
    DefaultConsistentHash ch23 = chf.union(ch2, ch3);
    log.debug(ch1);
    log.debug(ch2);
    // create dependencies
    Cache cache = mock(Cache.class);
    when(cache.getName()).thenReturn("testCache");
    when(cache.getStatus()).thenReturn(ComponentStatus.RUNNING);
    pooledExecutorService = new ThreadPoolExecutor(0, 20, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), getTestThreadFactory("Worker"), new ThreadPoolExecutor.CallerRunsPolicy());
    LocalTopologyManager localTopologyManager = mock(LocalTopologyManager.class);
    CacheNotifier cacheNotifier = mock(CacheNotifier.class);
    RpcManager rpcManager = mock(RpcManager.class);
    Transport transport = mock(Transport.class);
    CommandsFactory commandsFactory = mock(CommandsFactory.class);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    InternalDataContainer dataContainer = mock(InternalDataContainer.class);
    TransactionTable transactionTable = mock(TransactionTable.class);
    StateTransferLock stateTransferLock = mock(StateTransferLock.class);
    AsyncInterceptorChain interceptorChain = mock(AsyncInterceptorChain.class);
    InvocationContextFactory icf = mock(InvocationContextFactory.class);
    InternalConflictManager conflictManager = mock(InternalConflictManager.class);
    DistributionManager distributionManager = mock(DistributionManager.class);
    LocalPublisherManager localPublisherManager = mock(LocalPublisherManager.class);
    PerCacheInboundInvocationHandler invocationHandler = mock(PerCacheInboundInvocationHandler.class);
    XSiteStateTransferManager xSiteStateTransferManager = mock(XSiteStateTransferManager.class);
    when(persistenceManager.removeSegments(any())).thenReturn(CompletableFuture.completedFuture(false));
    when(persistenceManager.addSegments(any())).thenReturn(CompletableFuture.completedFuture(false));
    when(persistenceManager.publishKeys(any(), any())).thenReturn(Flowable.empty());
    when(commandsFactory.buildStateTransferStartCommand(anyInt(), any(IntSet.class))).thenAnswer(invocation -> new StateTransferStartCommand(ByteString.fromString("cache1"), (Integer) invocation.getArguments()[0], (IntSet) invocation.getArguments()[1]));
    when(commandsFactory.buildStateTransferGetTransactionsCommand(anyInt(), any(IntSet.class))).thenAnswer(invocation -> new StateTransferGetTransactionsCommand(ByteString.fromString("cache1"), (Integer) invocation.getArguments()[0], (IntSet) invocation.getArguments()[1]));
    when(commandsFactory.buildStateTransferCancelCommand(anyInt(), any(IntSet.class))).thenAnswer(invocation -> new StateTransferCancelCommand(ByteString.fromString("cache1"), (Integer) invocation.getArguments()[0], (IntSet) invocation.getArguments()[1]));
    when(transport.getViewId()).thenReturn(1);
    when(rpcManager.getAddress()).thenReturn(addresses[0]);
    when(rpcManager.getTransport()).thenReturn(transport);
    final Map<Address, Set<Integer>> requestedSegments = new ConcurrentHashMap<>();
    final Set<Integer> flatRequestedSegments = new ConcurrentSkipListSet<>();
    when(rpcManager.invokeCommand(any(Address.class), any(StateTransferGetTransactionsCommand.class), any(ResponseCollector.class), any(RpcOptions.class))).thenAnswer(invocation -> {
        Address recipient = invocation.getArgument(0);
        StateTransferGetTransactionsCommand cmd = invocation.getArgument(1);
        Set<Integer> segments = cmd.getSegments();
        requestedSegments.put(recipient, segments);
        flatRequestedSegments.addAll(segments);
        return CompletableFuture.completedFuture(SuccessfulResponse.create(new ArrayList<TransactionInfo>()));
    });
    Answer<?> successfulResponse = invocation -> CompletableFuture.completedFuture(SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
    when(rpcManager.invokeCommand(any(Address.class), any(StateTransferStartCommand.class), any(ResponseCollector.class), any(RpcOptions.class))).thenAnswer(successfulResponse);
    when(rpcManager.invokeCommand(any(Address.class), any(StateTransferCancelCommand.class), any(ResponseCollector.class), any(RpcOptions.class))).thenAnswer(successfulResponse);
    when(rpcManager.getSyncRpcOptions()).thenReturn(new RpcOptions(DeliverOrder.NONE, 10000, TimeUnit.MILLISECONDS));
    when(rpcManager.blocking(any(CompletionStage.class))).thenAnswer(invocation -> ((CompletionStage) invocation.getArgument(0)).toCompletableFuture().join());
    doNothing().when(xSiteStateTransferManager).onTopologyUpdated(any(CacheTopology.class), anyBoolean());
    // create state provider
    final StateConsumerImpl stateConsumer = new StateConsumerImpl();
    TestingUtil.inject(stateConsumer, cache, TestingUtil.named(NON_BLOCKING_EXECUTOR, pooledExecutorService), localTopologyManager, interceptorChain, icf, configuration, rpcManager, commandsFactory, persistenceManager, dataContainer, transactionTable, stateTransferLock, cacheNotifier, new CommitManager(), new CommandAckCollector(), new TriangleOrderManager(0), new HashFunctionPartitioner(), conflictManager, distributionManager, localPublisherManager, invocationHandler, xSiteStateTransferManager);
    stateConsumer.start();
    final List<InternalCacheEntry> cacheEntries = new ArrayList<>();
    Object key1 = new TestKey("key1", 0, keyPartitioner);
    Object key2 = new TestKey("key2", 0, keyPartitioner);
    cacheEntries.add(new ImmortalCacheEntry(key1, "value1"));
    cacheEntries.add(new ImmortalCacheEntry(key2, "value2"));
    when(dataContainer.iterator()).thenAnswer(invocation -> cacheEntries.iterator());
    when(transactionTable.getLocalTransactions()).thenReturn(Collections.emptyList());
    when(transactionTable.getRemoteTransactions()).thenReturn(Collections.emptyList());
    assertFalse(stateConsumer.hasActiveTransfers());
    // node 4 leaves
    stateConsumer.onTopologyUpdate(new CacheTopology(1, 1, ch2, null, CacheTopology.Phase.NO_REBALANCE, ch2.getMembers(), persistentUUIDManager.mapAddresses(ch2.getMembers())), false);
    assertFalse(stateConsumer.hasActiveTransfers());
    // start a rebalance
    stateConsumer.onTopologyUpdate(new CacheTopology(2, 2, ch2, ch3, ch23, CacheTopology.Phase.READ_OLD_WRITE_ALL, ch23.getMembers(), persistentUUIDManager.mapAddresses(ch23.getMembers())), true);
    assertTrue(stateConsumer.hasActiveTransfers());
    // check that all segments have been requested
    Set<Integer> oldSegments = ch2.getSegmentsForOwner(addresses[0]);
    final Set<Integer> newSegments = ch3.getSegmentsForOwner(addresses[0]);
    newSegments.removeAll(oldSegments);
    log.debugf("Rebalancing. Added segments=%s, old segments=%s", newSegments, oldSegments);
    assertEquals(flatRequestedSegments, newSegments);
    // simulate a cluster state recovery and return to ch2
    Future<Object> future = fork(() -> {
        stateConsumer.onTopologyUpdate(new CacheTopology(3, 2, ch2, null, CacheTopology.Phase.NO_REBALANCE, ch2.getMembers(), persistentUUIDManager.mapAddresses(ch2.getMembers())), false);
        return null;
    });
    stateConsumer.onTopologyUpdate(new CacheTopology(3, 2, ch2, null, CacheTopology.Phase.NO_REBALANCE, ch2.getMembers(), persistentUUIDManager.mapAddresses(ch2.getMembers())), false);
    future.get();
    assertFalse(stateConsumer.hasActiveTransfers());
    // restart the rebalance
    requestedSegments.clear();
    stateConsumer.onTopologyUpdate(new CacheTopology(4, 4, ch2, ch3, ch23, CacheTopology.Phase.READ_OLD_WRITE_ALL, ch23.getMembers(), persistentUUIDManager.mapAddresses(ch23.getMembers())), true);
    assertTrue(stateConsumer.hasActiveTransfers());
    assertEquals(flatRequestedSegments, newSegments);
    // apply state
    ArrayList<StateChunk> stateChunks = new ArrayList<>();
    for (Integer segment : newSegments) {
        stateChunks.add(new StateChunk(segment, Collections.emptyList(), true));
    }
    stateConsumer.applyState(addresses[1], 2, false, stateChunks);
    stateConsumer.stop();
    assertFalse(stateConsumer.hasActiveTransfers());
}
Also used : Arrays(java.util.Arrays) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) LogFactory(org.infinispan.util.logging.LogFactory) StateTransferStartCommand(org.infinispan.commands.statetransfer.StateTransferStartCommand) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) AfterMethod(org.testng.annotations.AfterMethod) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) Future(java.util.concurrent.Future) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) PersistentUUID(org.infinispan.topology.PersistentUUID) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) DefaultConsistentHashFactory(org.infinispan.distribution.ch.impl.DefaultConsistentHashFactory) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) ByteString(org.infinispan.util.ByteString) CommandsFactory(org.infinispan.commands.CommandsFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) LocalPublisherManager(org.infinispan.reactive.publisher.impl.LocalPublisherManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) CacheTopology(org.infinispan.topology.CacheTopology) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) PersistentUUIDManager(org.infinispan.topology.PersistentUUIDManager) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) TestAddress(org.infinispan.distribution.TestAddress) Mockito.mock(org.mockito.Mockito.mock) StateTransferCancelCommand(org.infinispan.commands.statetransfer.StateTransferCancelCommand) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TriangleOrderManager(org.infinispan.distribution.TriangleOrderManager) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CommandAckCollector(org.infinispan.util.concurrent.CommandAckCollector) Assert.assertEquals(org.testng.Assert.assertEquals) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultConsistentHash(org.infinispan.distribution.ch.impl.DefaultConsistentHash) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) Transport(org.infinispan.remoting.transport.Transport) Flowable(io.reactivex.rxjava3.core.Flowable) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) RpcManager(org.infinispan.remoting.rpc.RpcManager) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) NON_BLOCKING_EXECUTOR(org.infinispan.factories.KnownComponentNames.NON_BLOCKING_EXECUTOR) Mockito.when(org.mockito.Mockito.when) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) InternalConflictManager(org.infinispan.conflict.impl.InternalConflictManager) PersistentUUIDManagerImpl(org.infinispan.topology.PersistentUUIDManagerImpl) TimeUnit(java.util.concurrent.TimeUnit) CacheMode(org.infinispan.configuration.cache.CacheMode) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) XSiteStateTransferManager(org.infinispan.xsite.statetransfer.XSiteStateTransferManager) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) StateTransferGetTransactionsCommand(org.infinispan.commands.statetransfer.StateTransferGetTransactionsCommand) Configuration(org.infinispan.configuration.cache.Configuration) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Collections(java.util.Collections) HashFunctionPartitioner(org.infinispan.distribution.ch.impl.HashFunctionPartitioner) TransactionTable(org.infinispan.transaction.impl.TransactionTable) DistributionManager(org.infinispan.distribution.DistributionManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) CommandsFactory(org.infinispan.commands.CommandsFactory) Configuration(org.infinispan.configuration.cache.Configuration) TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) DefaultConsistentHashFactory(org.infinispan.distribution.ch.impl.DefaultConsistentHashFactory) ArrayList(java.util.ArrayList) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) CommandAckCollector(org.infinispan.util.concurrent.CommandAckCollector) SynchronousQueue(java.util.concurrent.SynchronousQueue) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) XSiteStateTransferManager(org.infinispan.xsite.statetransfer.XSiteStateTransferManager) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) StateTransferStartCommand(org.infinispan.commands.statetransfer.StateTransferStartCommand) Transport(org.infinispan.remoting.transport.Transport) Cache(org.infinispan.Cache) TriangleOrderManager(org.infinispan.distribution.TriangleOrderManager) Set(java.util.Set) IntSet(org.infinispan.commons.util.IntSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) StateTransferCancelCommand(org.infinispan.commands.statetransfer.StateTransferCancelCommand) IntSet(org.infinispan.commons.util.IntSet) TransactionTable(org.infinispan.transaction.impl.TransactionTable) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) LocalPublisherManager(org.infinispan.reactive.publisher.impl.LocalPublisherManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DistributionManager(org.infinispan.distribution.DistributionManager) InternalConflictManager(org.infinispan.conflict.impl.InternalConflictManager) CompletionStage(java.util.concurrent.CompletionStage) DefaultConsistentHash(org.infinispan.distribution.ch.impl.DefaultConsistentHash) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) StateTransferGetTransactionsCommand(org.infinispan.commands.statetransfer.StateTransferGetTransactionsCommand) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) CacheTopology(org.infinispan.topology.CacheTopology) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistentUUIDManagerImpl(org.infinispan.topology.PersistentUUIDManagerImpl) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) TestAddress(org.infinispan.distribution.TestAddress) PersistentUUIDManager(org.infinispan.topology.PersistentUUIDManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) HashFunctionPartitioner(org.infinispan.distribution.ch.impl.HashFunctionPartitioner) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager)

Example 28 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class StateProviderTest method setUp.

@BeforeMethod
public void setUp() {
    // create cache configuration
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.clustering().invocationBatching().enable().clustering().cacheMode(CacheMode.DIST_SYNC).clustering().stateTransfer().timeout(30000).locking().lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis()).locking().isolationLevel(IsolationLevel.REPEATABLE_READ);
    configuration = cb.build();
    cache = mock(Cache.class);
    when(cache.getName()).thenReturn("testCache");
    rpcManager = mock(RpcManager.class);
    commandsFactory = mock(CommandsFactory.class);
    cacheNotifier = mock(ClusterCacheNotifier.class);
    persistenceManager = mock(PersistenceManager.class);
    dataContainer = mock(InternalDataContainer.class);
    transactionTable = mock(TransactionTable.class);
    stateTransferLock = mock(StateTransferLock.class);
    distributionManager = mock(DistributionManager.class);
    ef = mock(InternalEntryFactory.class);
    when(distributionManager.getCacheTopology()).thenAnswer(invocation -> cacheTopology);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusterCacheNotifier(org.infinispan.notifications.cachelistener.cluster.ClusterCacheNotifier) CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) DistributionManager(org.infinispan.distribution.DistributionManager) Cache(org.infinispan.Cache) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 29 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class DistributedStreamIteratorTest method testStayLocalIfAllSegmentsPresentLocally.

private void testStayLocalIfAllSegmentsPresentLocally(boolean rehashAware) {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    RpcManager rpcManager = Mocks.replaceComponentWithSpy(cache0, RpcManager.class);
    putValueInEachCache(3);
    KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache0, KeyPartitioner.class);
    ConsistentHash ch = cache0.getAdvancedCache().getDistributionManager().getWriteConsistentHash();
    IntSet segmentsCache0 = IntSets.from(ch.getSegmentsForOwner(address(0)));
    CacheStream<Map.Entry<Object, String>> stream = cache0.entrySet().stream();
    if (!rehashAware)
        stream = stream.disableRehashAware();
    Map<Object, String> entries = mapFromIterator(stream.filterKeySegments(segmentsCache0).iterator());
    Map<Integer, Set<Map.Entry<Object, String>>> entriesPerSegment = generateEntriesPerSegment(keyPartitioner, entries.entrySet());
    // We should not see keys from other segments, but there may be segments without any keys
    assertTrue(segmentsCache0.containsAll(entriesPerSegment.keySet()));
    verify(rpcManager, never()).invokeCommand(any(Address.class), any(InitialPublisherCommand.class), any(), any());
}
Also used : ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Set(java.util.Set) IntSet(org.infinispan.commons.util.IntSet) HashSet(java.util.HashSet) RpcManager(org.infinispan.remoting.rpc.RpcManager) Address(org.infinispan.remoting.transport.Address) IntSet(org.infinispan.commons.util.IntSet) InitialPublisherCommand(org.infinispan.reactive.publisher.impl.commands.batch.InitialPublisherCommand) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class StateReceiverTest method createAndInitStateReceiver.

@BeforeMethod
private void createAndInitStateReceiver() {
    CommandsFactory commandsFactory = mock(CommandsFactory.class);
    InternalDataContainer<?, ?> dataContainer = mock(InternalDataContainer.class);
    RpcManager rpcManager = mock(RpcManager.class);
    CacheNotifier<?, ?> cacheNotifier = mock(CacheNotifier.class);
    Answer<?> answer = invocation -> {
        Collection<Address> recipients = (Collection<Address>) invocation.getArguments()[0];
        Address recipient = recipients.iterator().next();
        Map<Address, Response> results = new HashMap<>(1);
        results.put(recipient, SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
        return results;
    };
    when(rpcManager.invokeCommand(any(Collection.class), any(ConflictResolutionStartCommand.class), any(), any())).thenAnswer(answer);
    when(rpcManager.invokeCommand(any(Collection.class), any(StateTransferCancelCommand.class), any(), any())).thenAnswer(answer);
    when(rpcManager.getSyncRpcOptions()).thenAnswer(invocation -> new RpcOptions(DeliverOrder.PER_SENDER, 10000, TimeUnit.MILLISECONDS));
    StateReceiverImpl<Object, Object> stateReceiver = new StateReceiverImpl<>();
    TestingUtil.inject(stateReceiver, cacheNotifier, commandsFactory, dataContainer, rpcManager, stateTransferExecutor);
    stateReceiver.start();
    stateReceiver.onDataRehash(createEventImpl(2, 4, Event.Type.DATA_REHASHED));
    this.localizedCacheTopology = createLocalizedCacheTopology(4);
    this.stateReceiver = spy(stateReceiver);
}
Also used : Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) PersistentUUID(org.infinispan.topology.PersistentUUID) AssertJUnit.assertNull(org.testng.AssertJUnit.assertNull) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) Mockito.doReturn(org.mockito.Mockito.doReturn) DefaultConsistentHashFactory(org.infinispan.distribution.ch.impl.DefaultConsistentHashFactory) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) CommandsFactory(org.infinispan.commands.CommandsFactory) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CancellationException(java.util.concurrent.CancellationException) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) CacheTopology(org.infinispan.topology.CacheTopology) Executors(java.util.concurrent.Executors) List(java.util.List) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Exceptions(org.infinispan.commons.test.Exceptions) ConflictResolutionStartCommand(org.infinispan.commands.statetransfer.ConflictResolutionStartCommand) InboundTransferTask(org.infinispan.statetransfer.InboundTransferTask) PersistentUUIDManager(org.infinispan.topology.PersistentUUIDManager) EventImpl(org.infinispan.notifications.cachelistener.event.impl.EventImpl) TestAddress(org.infinispan.distribution.TestAddress) Mockito.mock(org.mockito.Mockito.mock) StateTransferCancelCommand(org.infinispan.commands.statetransfer.StateTransferCancelCommand) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) StateChunk(org.infinispan.statetransfer.StateChunk) Answer(org.mockito.stubbing.Answer) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) Response(org.infinispan.remoting.responses.Response) AfterClass(org.testng.annotations.AfterClass) CacheException(org.infinispan.commons.CacheException) CacheEntry(org.infinispan.container.entries.CacheEntry) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) RpcManager(org.infinispan.remoting.rpc.RpcManager) Mockito.when(org.mockito.Mockito.when) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) PersistentUUIDManagerImpl(org.infinispan.topology.PersistentUUIDManagerImpl) TimeUnit(java.util.concurrent.TimeUnit) CacheMode(org.infinispan.configuration.cache.CacheMode) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Event(org.infinispan.notifications.cachelistener.event.Event) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collections(java.util.Collections) HashFunctionPartitioner(org.infinispan.distribution.ch.impl.HashFunctionPartitioner) CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) StateTransferCancelCommand(org.infinispan.commands.statetransfer.StateTransferCancelCommand) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) ConflictResolutionStartCommand(org.infinispan.commands.statetransfer.ConflictResolutionStartCommand) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) BeforeMethod(org.testng.annotations.BeforeMethod)

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