protected Address addressOf(Cache<?, ?> cache) { return DistributionTestHelper.addressOf(cache); }
protected void assertIsInContainerImmortal(Cache<?, ?> cache, Object key) { DistributionTestHelper.assertIsInContainerImmortal(cache, key); }
protected void assertIsInL1(Cache<?, ?> cache, Object key) { DistributionTestHelper.assertIsInL1(cache, key); }
public static void assertOwnershipAndNonOwnership(List<? extends Cache> caches, Object key) { EntryVersion ownerVersion = null; for (Cache c: caches) { DataContainer dc = c.getAdvancedCache().getDataContainer(); InternalCacheEntry ice = dc.peek(key); if (isOwner(c, key)) { assert ice != null : "Fail on owner cache " + addressOf(c) + ": dc.get(" + key + ") returned null!"; assert ice instanceof ImmortalCacheEntry : "Fail on owner cache " + addressOf(c) + ": dc.get(" + key + ") returned " + safeType(ice); ownerVersion = ice.getMetadata().version(); } } assertNotNull(ownerVersion); if (caches.size() == 1) { return; } int equalVersions = 0; for (Cache c: caches) { DataContainer dc = c.getAdvancedCache().getDataContainer(); InternalCacheEntry ice = dc.peek(key); if (!isOwner(c, key)) { if (ice == null) continue; if (ice != null && ice.getMetadata() != null && ownerVersion.equals(ice.getMetadata().version())) ++equalVersions; } } assertEquals(equalVersions, 1); }
@Test public void testL1ValuePutCanExpire() { Cache<Object, Object> cache0 = cache(0); Cache<Object, Object> cache1 = cache(1); Cache<Object, Object> cache2 = cache(2); MagicKey hello = new MagicKey("hello", cache0, cache1); DistributionTestHelper.assertIsNotInL1(cache2, hello); // Auto-commit is true cache2.put(hello, "world 1"); DistributionTestHelper.assertIsInL1(cache2, hello); }
public void testDisjointSetTransaction() throws Exception { MagicKey k1 = new MagicKey(cache(0), cache(1)); MagicKey k2 = new MagicKey(cache(1), cache(2)); // make sure the owners of k1 and k2 are NOT the same! Set<Address> k1Owners = new HashSet<Address>(); Set<Address> k2Owners = new HashSet<Address>(); for (Cache<?, ?> cache: caches()) { if (isOwner(cache, k1)) k1Owners.add(addressOf(cache)); if (isOwner(cache, k2)) k2Owners.add(addressOf(cache)); } assert k1Owners.size() == 2: "Expected 2 owners for k1; was " + k1Owners; assert k2Owners.size() == 2: "Expected 2 owners for k1; was " + k2Owners; assert !k1Owners.equals(k2Owners) : format("k1 and k2 should have different ownership set. Was %s and %s", k1Owners, k2Owners); tm(0).begin(); cache(0).put(k1, "v1"); cache(0).put(k2, "v2"); tm(0).commit(); } }
public static void assertInStores(List<? extends Cache> caches, String key, String value) { EntryVersion ownerVersion = null; for (Cache c: caches) { CacheLoader store = TestingUtil.getFirstLoader(c); if (isOwner(c, key)) { assertIsInContainerImmortal(c, key); MarshalledEntry me = store.load(key); assertEquals(me.getValue(), value); ownerVersion = me.getMetadata().version(); } } assertNotNull(ownerVersion); if (caches.size() == 1) { return; } int equalVersions = 0; for (Cache c: caches) { CacheLoader store = TestingUtil.getFirstLoader(c); if (!isOwner(c, key)) { MarshalledEntry me = store.load(key); if (me != null && me.getMetadata() != null && ownerVersion.equals(me.getMetadata().version())) { assertEquals(me.getValue(), value); ++equalVersions; } } } assertEquals(equalVersions, 1); } }
public void testGetCacheEntryNonOwner() { byte[] key = {1, 2, 3}; Cache<byte[], byte[]> owner = getFirstOwner(key, this.<byte[], byte[]>caches()); Cache<byte[], byte[]> nonOwner = getFirstNonOwner(key, this.<byte[], byte[]>caches()); owner.put(key, new byte[]{4, 5, 6}); assertArrayEquals(new byte[]{4, 5, 6}, owner.get(key)); CacheEntry cacheEntry = nonOwner.getAdvancedCache().getCacheEntry(key); assertNotNull(cacheEntry); assertArrayEquals(new byte[]{4, 5, 6}, (byte[]) cacheEntry.getValue()); }
protected Cache<K, V>[] getOwners(Object key) { Cache<K, V>[] arr = new Cache[numOwners]; DistributionTestHelper.getOwners(key, caches).toArray(arr); return arr; }
protected Cache<K, V>[] getNonOwners(Object key, int expectedNumberNonOwners) { Cache<K, V>[] nonOwners = new Cache[expectedNumberNonOwners]; DistributionTestHelper.getNonOwners(key, caches).toArray(nonOwners); return nonOwners; }
protected Cache<K, V> getFirstNonOwner(Object key) { return DistributionTestHelper.getFirstNonOwner(key, caches); }
protected Cache<K, V> getFirstOwner(Object key) { return DistributionTestHelper.getFirstOwner(key, caches); }
protected void assertIsInL1OrNull(Cache<?, ?> cache, Object key) { DistributionTestHelper.assertIsInL1OrNull(cache, key); }
protected void assertIsNotInL1(Cache<?, ?> cache, Object key) { DistributionTestHelper.assertIsNotInL1(cache, key); }
private void assertKeyOwnership(Object key, Cache primaryOwner, Cache... backupOwners) { assertTrue("Wrong ownership for " + key + ".", hasOwners(key, primaryOwner, backupOwners)); }
@Test public void testL1ValueGetCanExpire() { Cache<Object, Object> cache0 = cache(0); Cache<Object, Object> cache1 = cache(1); Cache<Object, Object> cache2 = cache(2); MagicKey hello = new MagicKey("hello", cache0, cache1); DistributionTestHelper.assertIsNotInL1(cache2, hello); // Auto-commit is true cache0.put(hello, "world 1"); assertEquals("world 1", cache2.get(hello)); DistributionTestHelper.assertIsInL1(cache2, hello); }
protected Cache<K, V>[] getOwners(Object key, int expectedNumberOwners) { Cache<K, V>[] arr = new Cache[expectedNumberOwners]; DistributionTestHelper.getOwners(key, caches).toArray(arr); return arr; }
public static <K, V> Cache<K, V> getFirstNonOwner(Object key, List<Cache<K, V>> caches) { return getNonOwners(key, caches).iterator().next(); }
public static <K, V> Cache<K, V> getFirstOwner(Object key, List<Cache<K, V>> caches) { return getOwners(key, caches).iterator().next(); }