protected ControlledRpcManager(RpcManager realOne, Cache<?, ?> cache) { super(realOne); this.cache = cache; executor = Executors.newScheduledThreadPool( 0, r -> new Thread(r, "ControlledRpc-" + threadCount.getAndIncrement() + "," + realOne.getAddress())); }
Cache<?, ?> cache(Address addr) { for (Cache<?, ?> c : caches()) { if (c.getAdvancedCache().getRpcManager().getAddress().equals(addr)) return c; } throw new RuntimeException("Address: " + addr); }
private <K, V> Cache<K, V> getCacheForAddress(Address a) { for (Cache<K, V> c: this.<K, V>caches()) if (c.getAdvancedCache().getRpcManager().getAddress().equals(a)) return c; return null; }
protected void assertKeyAvailableForRead(Cache<?, ?> c, Object k, Object expectedValue) { log.tracef("Checking key %s is available on %s", k, c); assertEquals(c.get(k), expectedValue, "Cache " + c.getAdvancedCache().getRpcManager().getAddress() + " doesn't see the right value: "); // While we keep the null values in the map inside interceptor stack, these are removed in CacheImpl.getAll Map<Object, Object> expectedMap = expectedValue == null ? Collections.emptyMap() : Collections.singletonMap(k, expectedValue); assertEquals(c.getAdvancedCache().getAll(Collections.singleton(k)), expectedMap, "Cache " + c.getAdvancedCache().getRpcManager().getAddress() + " doesn't see the right value: "); }
@SuppressWarnings("unchecked") private Cache<MagicKey, String> getCacheForAddress(Address a) { for (Cache<?, ?> c: caches()) if (c.getAdvancedCache().getRpcManager().getAddress().equals(a)) return (Cache<MagicKey, String>) c; return null; }
@SuppressWarnings("unchecked") private Cache<MagicKey, String> getNonOwner(List<Address> a) { for (Cache<?, ?> c: caches()) if (!a.contains(c.getAdvancedCache().getRpcManager().getAddress())) return (Cache<MagicKey, String>) c; return null; }
public void assertActualMembers() { Set<org.infinispan.remoting.transport.Address> expected = cachesInThisPartition().stream() .map(c -> c.getAdvancedCache().getRpcManager().getAddress()) .collect(Collectors.toSet()); for (Cache c : cachesInThisPartition()) { eventuallyEquals(expected, () -> new HashSet<>(c.getAdvancedCache().getDistributionManager().getCacheTopology().getActualMembers())); } }
ClusteredQueryInvoker(Cache<?, ?> localCacheInstance, ExecutorService asyncExecutor) { this.asyncExecutor = asyncExecutor; this.rpcManager = localCacheInstance.getAdvancedCache().getComponentRegistry().getLocalComponent(RpcManager.class); this.localCacheInstance = localCacheInstance; this.myAddress = localCacheInstance.getAdvancedCache().getRpcManager().getAddress(); this.rpcOptions = rpcManager.getRpcOptionsBuilder(ResponseMode.SYNCHRONOUS).timeout(10000, TimeUnit.MILLISECONDS).build(); }
public void testCancelAndGet() throws Exception { DistributedExecutorService des = createDES(getCache()); List<Address> cacheMembers = getCache().getAdvancedCache().getRpcManager().getMembers(); List<Address> members = new ArrayList<>(cacheMembers); assertEquals(caches(cacheName()).size(), members.size()); members.remove(getCache().getAdvancedCache().getRpcManager().getAddress()); DistributedTaskBuilder<Integer> tb = des.createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); final Future<Integer> future = des.submit(members.get(0),tb.build()); future.cancel(true); expectException(CancellationException.class, () -> future.get()); latchHolder.get().open(); }
private Cache<String, Foo> getKeyLocation(String key) { Address cache1Address = cache1.getAdvancedCache().getRpcManager().getAddress(); LocalizedCacheTopology cacheTopology = cache1.getAdvancedCache().getDistributionManager().getCacheTopology(); DistributionInfo distribution = cacheTopology.getDistribution(key); Address primary = distribution.primary(); return primary.equals(cache1Address) ? cache1 : cache2; }
public void testBasicTargetCallableWithNullTask() { Cache<Object, Object> cache1 = getCache(); DistributedExecutorService des = createDES(cache1); Address target = cache1.getAdvancedCache().getRpcManager().getAddress(); expectException(IllegalArgumentException.class, () -> des.submit(target, (Callable) null)); }
public void testBasicTargetDistributedTaskWithNullTask() { Cache<Object, Object> cache1 = getCache(); DistributedExecutorService des = createDES(cache1); Address target = cache1.getAdvancedCache().getRpcManager().getAddress(); expectException(NullPointerException.class, () -> des.submit(target, (DistributedTask) null)); }
protected Object createSameHashCodeKey(String name) { final Address address = cache.getAdvancedCache().getRpcManager().getAddress(); DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager(); int hashCode = 0; SameHashCodeKey key = new SameHashCodeKey(name, hashCode); while (!distributionManager.getCacheTopology().getDistribution(key).primary().equals(address)) { hashCode++; key = new SameHashCodeKey(name, hashCode); } return key; }
public void testBasicTargetLocalDistributedCallableWithoutSpecTimeout() throws Exception { Cache<Object, Object> cache1 = cache(0, cacheName()); // initiate task from cache1 and execute on same node DistributedExecutorService des = createDES(cache1); Address target = cache1.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder builder = des .createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); Future<Integer> future = des.submit(target, builder.build()); Thread.sleep(100); latchHolder.get().open(); assertEquals((Integer) 1, future.get()); }
public void testTimeoutOnLocalNode() throws Exception { AdvancedCache<Object, Object> localCache = getCache().getAdvancedCache(); DistributedExecutorService des = createDES(localCache); Future<Integer> future = des.submit(localCache.getRpcManager().getAddress(), new SleepingSimpleCallable(latchHolder)); expectException(TimeoutException.class, () -> future.get(100, TimeUnit.MILLISECONDS)); latchHolder.get().open(); }
public void testBasicTargetRemoteDistributedCallableWithException() throws Exception { Cache<Object, Object> cache1 = cache(0, cacheName()); Cache<Object, Object> cache2 = cache(1, cacheName()); // initiate task from cache1 and execute on same node DistributedExecutorService des = createDES(cache1); Address target = cache2.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder builder = des .createDistributedTaskBuilder(new ExceptionThrowingCallable()); Future<Integer> future = des.submit(target, builder.build()); expectException(ExecutionException.class, () -> future.get()); }
public void testBasicTargetDistributedCallableWithTimeout() throws Exception { Cache<Object, Object> cache1 = getCache(); // initiate task from cache1 and select cache2 as target DistributedExecutorService des = createDES(cache1); Address target = cache1.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder<Integer> builder = des.createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); builder.timeout(10, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); expectException(ExecutionException.class, TimeoutException.class, () -> future.get()); latchHolder.get().open(); }
public void testBasicTargetLocalDistributedCallableWithLowFutureAndHighTaskTimeout() throws Exception { Cache<Object, Object> cache1 = cache(0, cacheName()); // initiate task from cache1 and execute on same node DistributedExecutorService des = createDES(cache1); Address target = cache1.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder builder = des .createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); builder.timeout(10000, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); expectException(TimeoutException.class, () -> future.get(100, TimeUnit.MILLISECONDS)); latchHolder.get().open(); }
public void testBasicTargetRemoteDistributedCallableWithLowFutureAndHighTaskTimeout() throws Exception { Cache<Object, Object> cache1 = cache(0, cacheName()); Cache<Object, Object> cache2 = cache(1, cacheName()); // initiate task from cache1 and execute on same node DistributedExecutorService des = createDES(cache1); Address target = cache2.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder builder = des .createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); builder.timeout(10000, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); expectException(TimeoutException.class, () -> future.get(100, TimeUnit.MILLISECONDS)); latchHolder.get().open(); }
protected void verifyInitialData(Cache<Object, Object> c) { Address address = c.getAdvancedCache().getRpcManager().getAddress(); log.debugf("Checking values on cache " + address); assertEquals("Incorrect value for key " + A_B_NAME, JOE, c.get(A_B_NAME)); assertEquals("Incorrect value for key " + A_B_AGE, TWENTY, c.get(A_B_AGE)); assertEquals("Incorrect value for key " + A_C_NAME, BOB, c.get(A_C_NAME)); assertEquals("Incorrect value for key " + A_C_AGE, FORTY, c.get(A_C_AGE)); }