use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistributedStreamIteratorRepeatableReadTxTest method testCacheCollectionsIncludesEntriesNotYetCommitted.
/**
* See ISPN-12731 Cache collections ignore values added in transaction
*/
public void testCacheCollectionsIncludesEntriesNotYetCommitted() throws Exception {
Cache<Object, String> cache = cache(0, CACHE_NAME);
TransactionManager tm = tm(cache);
tm.begin();
try {
Map<Object, String> inserted = new LinkedHashMap<>();
for (int i = 0; i < 3; ++i) {
Object key = new MagicKey(cache(i, CACHE_NAME));
cache.put(key, key.toString());
inserted.put(key, key.toString());
}
// cache collections use streams internally
Set<Object> expectedKeys = inserted.keySet();
Set<Object> keySetResults = new HashSet<>(cache.keySet());
assertEquals(expectedKeys, keySetResults);
Set<String> expectedValues = new HashSet<>(inserted.values());
Set<String> valuesResults = new HashSet<>(cache.values());
assertEquals(expectedValues, valuesResults);
Set<Map.Entry<Object, String>> expectedEntries = inserted.entrySet();
Set<Map.Entry<Object, String>> entrySetResults = new HashSet<>(cache.entrySet());
assertEquals(expectedEntries, entrySetResults);
} finally {
tm.rollback();
}
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistL1WriteSkewTest method testL1ValueGetCanExpire.
@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);
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistL1WriteSkewTest method testL1ValuePutCanExpire.
@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);
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistWriteSkewTest method testResendPrepare.
public void testResendPrepare() throws Exception {
Cache<Object, Object> cache0 = cache(0);
Cache<Object, Object> cache1 = cache(1);
Cache<Object, Object> cache2 = cache(2);
Cache<Object, Object> cache3 = cache(3);
MagicKey hello = new MagicKey("hello", cache(2));
// Auto-commit is true
cache0.put(hello, "world");
// create a write skew
tm(2).begin();
assertEquals("world", cache2.get(hello));
Transaction t = tm(2).suspend();
// Implicit tx. Prepare should be retried.
cache(0).put(hello, "world 2");
assertEquals("world 2", cache0.get(hello));
assertEquals("world 2", cache1.get(hello));
assertEquals("world 2", cache2.get(hello));
assertEquals("world 2", cache3.get(hello));
tm(2).resume(t);
cache2.put(hello, "world 3");
try {
tm(2).commit();
fail("This transaction should roll back");
} catch (RollbackException expected) {
// expected
}
assertEquals("world 2", cache0.get(hello));
assertEquals("world 2", cache1.get(hello));
assertEquals("world 2", cache2.get(hello));
assertEquals("world 2", cache3.get(hello));
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistWriteSkewTest method testWriteSkewMultiEntries.
public void testWriteSkewMultiEntries() throws Exception {
Cache<Object, Object> cache0 = cache(0);
Cache<Object, Object> cache1 = cache(1);
Cache<Object, Object> cache2 = cache(2);
Cache<Object, Object> cache3 = cache(3);
MagicKey hello = new MagicKey("hello", cache(2));
MagicKey hello2 = new MagicKey("hello2", cache(3));
MagicKey hello3 = new MagicKey("hello3", cache(0));
tm(1).begin();
cache1.put(hello, "world 1");
cache1.put(hello2, "world 1");
cache1.put(hello3, "world 1");
tm(1).commit();
tm(1).begin();
cache1.put(hello2, "world 2");
cache1.put(hello3, "world 2");
assertEquals("world 1", cache1.get(hello));
assertEquals("world 2", cache1.get(hello2));
assertEquals("world 2", cache1.get(hello3));
Transaction t = tm(1).suspend();
// Induce a write skew
// Auto-commit is true
cache3.put(hello, "world 3");
for (Cache<Object, Object> c : caches()) {
assertEquals("world 3", c.get(hello));
assertEquals("world 1", c.get(hello2));
assertEquals("world 1", c.get(hello3));
}
tm(1).resume(t);
cache1.put(hello, "world 2");
try {
tm(1).commit();
fail("Transaction should roll back");
} catch (RollbackException re) {
// expected
}
for (Cache<Object, Object> c : caches()) {
assertEquals("world 3", c.get(hello));
assertEquals("world 1", c.get(hello2));
assertEquals("world 1", c.get(hello3));
}
}
Aggregations