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();
}
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();
}
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);
}
}
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());
}
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);
}
Aggregations