Search in sources :

Example 21 with RpcManager

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

the class XSiteAutoStateTransferTest method clearContent.

@AfterMethod(alwaysRun = true)
@Override
protected void clearContent() throws Throwable {
    for (EmbeddedCacheManager manager : site(0).cacheManagers()) {
        ControlledXSiteStateTransferManager.revertXsiteStateTransferManager(manager.getCache());
        RpcManager rpcManager = TestingUtil.extractComponent(manager.getCache(), RpcManager.class);
        if (rpcManager instanceof ControlledRpcManager) {
            ((ControlledRpcManager) rpcManager).revertRpcManager();
        }
    }
    while (site(0).cacheManagers().size() < defaultNumberOfNodes()) {
        site(0).addCacheManager(null, defaultGlobalConfigurationForSite(0), defaultConfigurationForSite(0), false);
    }
    site(0).waitForClusterToForm(null);
    super.clearContent();
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) AfterMethod(org.testng.annotations.AfterMethod)

Example 22 with RpcManager

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

the class RemoteGetFailureTest method testOneOwnerSuspectedNoFilter.

public void testOneOwnerSuspectedNoFilter(Method m) throws ExecutionException, InterruptedException {
    initAndCheck(m);
    CountDownLatch arrival = new CountDownLatch(2);
    CountDownLatch release1 = new CountDownLatch(1);
    CountDownLatch release2 = new CountDownLatch(1);
    cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release1), 0);
    cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release2), 0);
    Address address1 = address(1);
    Address address2 = address(2);
    List<Address> owners = Arrays.asList(address1, address2);
    ClusteredGetCommand clusteredGet = new ClusteredGetCommand(key, ByteString.fromString(cache(0).getName()), TestingUtil.getSegmentForKey(key, cache(1)), 0);
    final int timeout = 15;
    RpcOptions rpcOptions = new RpcOptions(DeliverOrder.NONE, timeout, TimeUnit.SECONDS);
    RpcManager rpcManager = cache(0).getAdvancedCache().getRpcManager();
    clusteredGet.setTopologyId(rpcManager.getTopologyId());
    CompletableFuture<Map<Address, Response>> future = rpcManager.invokeCommand(owners, clusteredGet, MapResponseCollector.ignoreLeavers(), rpcOptions).toCompletableFuture();
    assertTrue(arrival.await(10, TimeUnit.SECONDS));
    installNewView(cache(0), cache(0), cache(1));
    // RequestCorrelator processes the view asynchronously, so we need to wait a bit for node 2 to be suspected
    Thread.sleep(100);
    // suspection should not fail the operation
    assertFalse(future.isDone());
    long requestAllowed = System.nanoTime();
    release1.countDown();
    Map<Address, Response> responses = future.get();
    long requestCompleted = System.nanoTime();
    long requestSeconds = TimeUnit.NANOSECONDS.toSeconds(requestCompleted - requestAllowed);
    assertTrue("Request took too long: " + requestSeconds, requestSeconds < timeout / 2);
    assertEquals(SuccessfulResponse.create(new ImmortalCacheValue(m.getName())), responses.get(address1));
    assertEquals(CacheNotFoundResponse.INSTANCE, responses.get(address2));
    release2.countDown();
}
Also used : JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) Address(org.infinispan.remoting.transport.Address) RpcManager(org.infinispan.remoting.rpc.RpcManager) CountDownLatch(java.util.concurrent.CountDownLatch) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Response(org.infinispan.remoting.responses.Response) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Map(java.util.Map) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Example 23 with RpcManager

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

the class BaseInvalidationTest method testCacheMode.

public void testCacheMode() throws Exception {
    AdvancedCache<String, String> cache1 = advancedCache(0, "invalidation");
    RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
    Transport origTransport = TestingUtil.extractComponent(cache1, Transport.class);
    try {
        Transport mockTransport = mock(Transport.class);
        rpcManager.setTransport(mockTransport);
        Address addressOne = mock(Address.class);
        Address addressTwo = mock(Address.class);
        List<Address> members = new ArrayList<>(2);
        members.add(addressOne);
        members.add(addressTwo);
        when(mockTransport.getMembers()).thenReturn(members);
        when(mockTransport.getAddress()).thenReturn(addressOne);
        when(mockTransport.invokeCommandOnAll(any(), any(), any(), any(), anyLong(), any())).thenReturn(CompletableFutures.completedNull());
        cache1.put("k", "v");
    } finally {
        if (rpcManager != null)
            rpcManager.setTransport(origTransport);
    }
}
Also used : RpcManagerImpl(org.infinispan.remoting.rpc.RpcManagerImpl) RpcManager(org.infinispan.remoting.rpc.RpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) Address(org.infinispan.remoting.transport.Address) ArrayList(java.util.ArrayList) Transport(org.infinispan.remoting.transport.Transport)

Example 24 with RpcManager

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

the class ForceSyncAsyncFlagsTest method testForceSyncFlagUsage.

public void testForceSyncFlagUsage() throws Exception {
    ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.REPL_ASYNC, false);
    builder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0));
    createClusteredCaches(2, "replAsync", builder);
    AdvancedCache<String, String> cache1 = this.<String, String>cache(0, "replAsync").getAdvancedCache();
    cache(1, "replAsync").getAdvancedCache();
    Transport originalTransport = TestingUtil.extractGlobalComponent(cache1.getCacheManager(), Transport.class);
    RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
    Transport mockTransport = spy(originalTransport);
    rpcManager.setTransport(mockTransport);
    cache1.put("k", "v");
    verify(mockTransport).sendToAll(any(ReplicableCommand.class), any(DeliverOrder.class));
    reset(mockTransport);
    // verify FORCE_SYNCHRONOUS flag on ASYNC cache
    cache1.withFlags(Flag.FORCE_SYNCHRONOUS).put("k", "v");
    verify(mockTransport).invokeCommandOnAll(any(), any(), any(), any(), anyLong(), any());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RpcManagerImpl(org.infinispan.remoting.rpc.RpcManagerImpl) RpcManager(org.infinispan.remoting.rpc.RpcManager) ReplicableCommand(org.infinispan.commands.ReplicableCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) ReplicatedControlledConsistentHashFactory(org.infinispan.util.ReplicatedControlledConsistentHashFactory) Transport(org.infinispan.remoting.transport.Transport)

Example 25 with RpcManager

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

the class NoLockLostOnLongTxTest method testCheckTransactionRpcCommand.

public void testCheckTransactionRpcCommand() throws Exception {
    // default cache is transactional
    Cache<String, String> cache0 = cache(0);
    Cache<String, String> cache1 = cache(1);
    CommandsFactory factory = cache0.getAdvancedCache().getComponentRegistry().getCommandsFactory();
    RpcManager rpcManager = cache0.getAdvancedCache().getRpcManager();
    RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
    ResponseCollector<Collection<GlobalTransaction>> collector = CheckTransactionRpcCommand.responseCollector();
    Address remoteAddress = cache1.getAdvancedCache().getRpcManager().getAddress();
    TransactionTable transactionTable = cache1.getAdvancedCache().getComponentRegistry().getTransactionTable();
    CheckTransactionRpcCommand rpcCommand = factory.buildCheckTransactionRpcCommand(Collections.emptyList());
    Collection<GlobalTransaction> result = rpcManager.invokeCommand(remoteAddress, rpcCommand, collector, rpcOptions).toCompletableFuture().join();
    assertTrue("Expected an empty collection but got: " + result, result.isEmpty());
    TransactionManager tm = cache1.getAdvancedCache().getTransactionManager();
    tm.begin();
    cache1.put("k", "v");
    rpcCommand = factory.buildCheckTransactionRpcCommand(transactionTable.getLocalGlobalTransaction());
    result = rpcManager.invokeCommand(remoteAddress, rpcCommand, collector, rpcOptions).toCompletableFuture().join();
    assertTrue("Expected an empty collection but got: " + result, result.isEmpty());
    tm.commit();
    GlobalTransaction nonExistingGtx = new GlobalTransaction(remoteAddress, false);
    nonExistingGtx.setId(-1);
    Collection<GlobalTransaction> list = Collections.singletonList(nonExistingGtx);
    rpcCommand = factory.buildCheckTransactionRpcCommand(list);
    result = rpcManager.invokeCommand(remoteAddress, rpcCommand, collector, rpcOptions).toCompletableFuture().join();
    assertEquals("Wrong list returned.", list, result);
}
Also used : CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) Address(org.infinispan.remoting.transport.Address) TransactionTable(org.infinispan.transaction.impl.TransactionTable) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) CheckTransactionRpcCommand(org.infinispan.commands.remote.CheckTransactionRpcCommand) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) EmbeddedTransactionManager(org.infinispan.transaction.tm.EmbeddedTransactionManager) TransactionManager(javax.transaction.TransactionManager) Collection(java.util.Collection)

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