if (di.writeOwners().contains(ownerAddress)) { return valueToTest; if (di.writeOwners().contains(ownerAddress)) { return valueToTest;
private void assertOwnershipConsensus(String key) { List l1 = getCacheTopology(c1).getDistribution(key).writeOwners(); List l2 = getCacheTopology(c2).getDistribution(key).writeOwners(); List l3 = getCacheTopology(c3).getDistribution(key).writeOwners(); List l4 = getCacheTopology(c4).getDistribution(key).writeOwners(); assertEquals("L1 "+l1+" and L2 "+l2+" don't agree.", l1, l2); assertEquals("L2 "+l2+" and L3 "+l3+" don't agree.", l2, l3); assertEquals("L3 "+l3+" and L4 "+l4+" don't agree.", l3, l4); }
protected void assertMapsToAddress(Object o, Address addr) { LocalizedCacheTopology cacheTopology = caches.get(0).getAdvancedCache().getDistributionManager().getCacheTopology(); List<Address> addresses = cacheTopology.getDistribution(o).writeOwners(); assertEquals("Expected key " + o + " to map to address " + addr + ". List of addresses is" + addresses, true, addresses.contains(addr)); }
@Test (dependsOnMethods = "testServersDropped") public void testCollocatedKey() { LocalizedCacheTopology cacheTopology = manager(0).getCache(cacheName).getAdvancedCache().getDistributionManager().getCacheTopology(); for (int i = 0; i < 1000; i++) { List<Address> addresses = cacheTopology.getDistribution(i).writeOwners(); Object collocatedKey = keyAffinityService.getCollocatedKey(i); List<Address> addressList = cacheTopology.getDistribution(collocatedKey).writeOwners(); assertEquals(addresses, addressList); } }
private void assertOwnership(String key) { for (Cache<?, ?> cache : caches()) { Collection<Address> writeOwners = cache.getAdvancedCache().getDistributionManager().getCacheTopology() .getDistribution(key).writeOwners(); assertEquals(Arrays.asList(address(1), address(2)), writeOwners); } }
private Optional<Cache<Object, Person>> findCache(Ownership ownership, Object key) { List<Cache<Object, Person>> caches = caches(); ClusteringDependentLogic cdl = cache1.getAdvancedCache().getComponentRegistry().getComponent(ClusteringDependentLogic.class); DistributionInfo distribution = cdl.getCacheTopology().getDistribution(key); Predicate<Cache<?, ?>> predicate = null; switch (ownership) { case PRIMARY: predicate = c -> c.getAdvancedCache().getRpcManager().getAddress().equals(distribution.primary()); break; case BACKUP: predicate = c -> distribution.writeBackups().contains(c.getAdvancedCache().getRpcManager().getAddress()); break; case NON_OWNER: predicate = c -> !distribution.writeOwners().contains(c.getAdvancedCache().getRpcManager().getAddress()); } return caches.stream().filter(predicate).findFirst(); }
@Override public Result execute(Session session) throws StatementException { Cache<Object, Object> cache = session.getCache(keyData.getCacheName()); Codec codec = session.getCodec(); if (options.size() > 0) { for (Option option : options) { switch (option.toEnum(Options.class)) { case CODEC: { if (option.getParameter() == null) { throw log.missingOptionParameter(option.getName()); } else { codec = session.getCodec(option.getParameter()); } } } } } DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager(); if(distributionManager!=null) { Object key = keyData.getKey(); Collection<Address> addresses = distributionManager.getCacheTopology() .getDistribution(codec.encodeKey(key)).writeOwners(); return new StringResult(addresses.toString()); } else { throw log.cacheNotDistributed(); } }
private <K> void assertExistence(final K key) { LocalizedCacheTopology cacheTopology = cache(addresses[0]).getAdvancedCache().getDistributionManager().getCacheTopology(); final List<Address> addresses = cacheTopology.getDistribution(key).writeOwners(); log.debug(key + " should be present on = " + addresses); eventuallyEquals(2, () -> caches().stream().mapToInt(c -> c.getAdvancedCache().getDataContainer().containsKey(key) ? 1 : 0).sum()); for (Cache<? super K, ?> c : caches()) { if (cacheMode.isScattered()) { eventuallyEquals("Failure for key " + key + " on cache " + address(c), true, () -> addresses.contains(address(c)) ? c.getAdvancedCache().getDataContainer().containsKey(key) : true); } else { eventuallyEquals("Failure for key " + key + " on cache " + address(c), addresses.contains(address(c)), () -> c.getAdvancedCache().getDataContainer().containsKey(key)); } } }
List<Address> owners = cacheTopology.getDistribution(command.getKey()).writeOwners(); if (owners.contains(rpcManager.getAddress())) { return invokeNextAndHandle( ctx, command, (rCtx, rCommand, rv, throwable) ->
private <K, V> CacheHelper<K, V> create(List<Cache<K, V>> cacheList) { CacheHelper<K, V> cacheHelper = new CacheHelper<>(); for (Cache<K, V> cache : cacheList) { ClusteringDependentLogic clusteringDependentLogic = extractComponent(cache, ClusteringDependentLogic.class); DistributionInfo distributionInfo = clusteringDependentLogic.getCacheTopology().getDistribution(key); log.debugf("owners for key %s are %s", key, distributionInfo.writeOwners()); if (distributionInfo.isPrimary()) { log.debug("Cache " + address(cache) + " is the primary owner"); assertTrue(cacheHelper.addCache(Ownership.PRIMARY, cache)); } else if (distributionInfo.isWriteBackup()) { log.debug("Cache " + address(cache) + " is the backup owner"); assertTrue(cacheHelper.addCache(Ownership.BACKUP, cache)); } else { log.debug("Cache " + address(cache) + " is the non owner"); assertTrue(cacheHelper.addCache(Ownership.NON_OWNER, cache) || cacheMode.isScattered()); } } return cacheHelper; }
dm0.getCacheTopology().getPendingCH().locateOwnersForSegment(0)); assertEquals(Arrays.asList(address(1), address(2), address(3), address(0)), dm0.getCacheTopology().getDistribution("k1").writeOwners());