@Override protected void createCacheManagers() throws Throwable { super.createCacheManagers(); }
@Override protected String[] parameterNames() { return concat(super.parameterNames(), "shared", "preload", "segmented"); }
@Override protected Object[] parameterValues() { return concat(super.parameterValues(), shared, preload, segmented); }
protected void assertOnAllCachesAndOwnership(Object key, String value) { assertOwnershipAndNonOwnership(key, l1CacheEnabled); // checking the values will bring the keys to L1, so we want to do it after checking ownership assertOnAllCaches(key, value); }
protected Cache<K, V>[] getNonOwnersExcludingSelf(Object key, Address self) { Cache<K, V>[] nonOwners = getNonOwners(key); boolean selfInArray = false; for (Cache<?, ?> c : nonOwners) { if (addressOf(c).equals(self)) { selfInArray = true; break; } } if (selfInArray) { Cache<K, V>[] nonOwnersExclSelf = new Cache[nonOwners.length - 1]; int i = 0; for (Cache<K, V> c : nonOwners) { if (!addressOf(c).equals(self)) nonOwnersExclSelf[i++] = c; } return nonOwnersExclSelf; } else { return nonOwners; } }
protected void assertOnAllCaches(Object key, String value) { for (Cache<K, V> c : caches) { Object realVal = c.get(key); if (value == null) { assert realVal == null : "Expecting [" + key + "] to equal [" + value + "] on cache [" + addressOf(c) + "] but was [" + realVal + "]. Owners are " + Arrays.toString(getOwners(key)); } else { assert value.equals(realVal) : "Expecting [" + key + "] to equal [" + value + "] on cache [" + addressOf(c) + "] but was [" + realVal + "]"; } } // Allow some time for all ClusteredGetCommands to finish executing TestingUtil.sleepThread(100); }
protected void assertOwnershipAndNonOwnership(Object key, boolean allowL1) { for (Cache<K, V> c : caches) { DataContainer dc = c.getAdvancedCache().getDataContainer(); InternalCacheEntry ice = dc.get(key); if (isOwner(c, key)) { assert ice != null && ice.getValue() != null : "Fail on owner cache " + addressOf(c) + ": dc.get(" + key + ") returned " + ice; assert ice instanceof ImmortalCacheEntry : "Fail on owner cache " + addressOf(c) + ": dc.get(" + key + ") returned " + safeType(ice); } else { if (allowL1) { assert ice == null || ice.getValue() == null || ice.isL1Entry() : "Fail on non-owner cache " + addressOf(c) + ": dc.get(" + key + ") returned " + safeType(ice); } else { // Segments no longer owned are invalidated asynchronously eventually("Fail on non-owner cache " + addressOf(c) + ": dc.get(" + key + ")", () -> { InternalCacheEntry ice2 = dc.get(key); return ice2 == null || ice2.getValue() == null; }); } } } }
protected void initAndTest() { for (Cache<K, V> c : caches) assert c.isEmpty(); // TODO: A bit hacky, this should be moved somewhere else really... Cache<Object, Object> firstCache = (Cache<Object, Object>) caches.get(0); firstCache.put("k1", "value"); asyncWait("k1", PutKeyValueCommand.class); assertOnAllCachesAndOwnership("k1", "value"); }
@Override protected void createCacheManagers() throws Throwable { cacheName = "dist"; configuration = buildConfiguration(); // Create clustered caches with failure detection protocols on caches = createClusteredCaches(INIT_CLUSTER_SIZE, cacheName, configuration, new TransportFlags().withFD(false)); if (INIT_CLUSTER_SIZE > 0) c1 = caches.get(0); if (INIT_CLUSTER_SIZE > 1) c2 = caches.get(1); if (INIT_CLUSTER_SIZE > 2) c3 = caches.get(2); if (INIT_CLUSTER_SIZE > 3) c4 = caches.get(3); cacheAddresses = new ArrayList<>(INIT_CLUSTER_SIZE); for (Cache cache : caches) { EmbeddedCacheManager cacheManager = cache.getCacheManager(); cacheAddresses.add(cacheManager.getAddress()); } }
@Override protected ConfigurationBuilder buildConfiguration() { ConfigurationBuilder builder = super.buildConfiguration(); builder.locking().isolationLevel(isolationLevel); return builder; }
@Override public Object[] factory() { return new Object[] { new RehashWithSharedStoreTest().segmented(false), new RehashWithSharedStoreTest().segmented(true), new RehashWithSharedStoreTest().segmented(false).numOwners(1).l1(false).cacheMode(CacheMode.SCATTERED_SYNC).transactional(false), new RehashWithSharedStoreTest().segmented(true).numOwners(1).l1(false).cacheMode(CacheMode.SCATTERED_SYNC).transactional(false), }; }
/** * Blocks and waits for a replication event on async caches * @param key key that causes the replication. Used to determine which caches to listen on. If null, all caches * are checked * @param command command to listen for */ protected void asyncWait(Object key, Class<? extends VisitableCommand> command) { asyncWait(key, command::isInstance); }
protected void assertRemovedOnAllCaches(Object key) { assertOnAllCaches(key, null); }
@Override protected ConfigurationBuilder buildConfiguration() { ConfigurationBuilder builder = super.buildConfiguration(); builder.clustering().hash(). consistentHashFactory(factory). numSegments(1); return builder; }
@Override protected void createCacheManagers() throws Throwable { super.createCacheManagers(); for (EmbeddedCacheManager cacheManager : cacheManagers) { MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cacheManager); multimapCacheCluster.put(cacheManager.getAddress(), multimapCacheManager.get(cacheName)); } }
@Override protected String[] parameterNames() { return concat(super.parameterNames(), "fromOwner"); }
@Override protected Object[] parameterValues() { return concat(super.parameterValues(), fromOwner ? Boolean.TRUE : Boolean.FALSE); }
@Override protected ConfigurationBuilder buildConfiguration() { ConfigurationBuilder builder = super.buildConfiguration(); builder .memory() .size(MAX_ENTRIES) .persistence() .passivation(true) .addStore(DummyInMemoryStoreConfigurationBuilder.class); return builder; }
@Override protected void createCacheManagers() throws Throwable { super.createCacheManagers(); ownerCacheStore = TestingUtil.extractComponent(cache(0, cacheName), PersistenceManager.class).getStores(DummyInMemoryStore.class).iterator().next(); nonOwnerCacheStore = TestingUtil.extractComponent(cache(1, cacheName), PersistenceManager.class).getStores(DummyInMemoryStore.class).iterator().next(); }
@Override protected ConfigurationBuilder buildConfiguration() { ConfigurationBuilder builder = super.buildConfiguration(); ControlledConsistentHashFactory.Default chf = new ControlledConsistentHashFactory.Default( new int[][]{{0, 1}, {1, 2}}); builder.clustering().hash().numOwners(2).numSegments(2).consistentHashFactory(chf); return builder; }