public void testSizeOnCache() throws Exception { final Cache<Object, Object> cache1 = cache(0, "atomic"); final TransactionManager tm1 = tm(0, "atomic"); assertSize(cache1, 0); cache1.put(new MagicKey("Hi", cache1), "Someone"); assertSize(cache1, 1); assertSize(cache1, 1); cache1.put(new MagicKey("Need", cache1), "Read Consistency"); assertSize(cache1, 2); tm1.commit(); assertSize(cache1, 2); assertSize(cache1, 2); cache1.put(new MagicKey("Need Also", cache1), "Speed"); assertSize(cache1, 3); tm1.rollback(); assertSize(cache1, 2); assertSize(cache1, 3); atomicMap.put("mm", "nn"); assertSize(cache1, 3); assertSize(cache1, 3); atomicMap = createAtomicMap(cache1, new MagicKey("testSizeOnCache-second", cache1), true); assertSize(cache1, 4); atomicMap.put("mm", "nn"); assertSize(cache1, 4); tm1.commit(); assertSize(cache1, 4);
@SuppressWarnings("UnusedDeclaration") public void testNoTx() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map = createAtomicMap(cache1, "testNoTx", true); map.put("existing", "existing"); map.put("blah", "blah"); Map<Object, Object> expectedMap = createMap("existing", "existing", "blah", "blah"); assertMap(expectedMap, map); }
public void testDuplicateValue() { final Cache<String, Object> cache = cache(0, "atomic"); assertSize(cache, 0); final Map<String, String> map = createAtomicMap(cache, "duplicateValues", true); map.put("k1", "value"); map.put("k2", "value"); map.put("k3", "value"); map.put("k4", "value"); final Map<Object, Object> expectedMap = createMap("k1", "value", "k2", "value", "k3", "value", "k4", "value"); assertMap(expectedMap, map); }
public void testRollback() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map1 = createAtomicMap(cache1, "testRollback", true); tm(0, "atomic").begin(); map1.put("k1", "v"); map1.put("k2", "v2"); tm(0, "atomic").rollback(); Map<Object, Object> instance = createAtomicMap(cache2, "testRollback", true); assertMap(Collections.emptyMap(), instance); assertMap(Collections.emptyMap(), map1); }
public void testConcurrentWritesAndIteration() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); assertSize(cache1, 0); final Map<String, String> map = createAtomicMap(cache1, "testConcurrentWritesAndIteration", true); assertSize(map, 0); runConcurrently(1, TimeUnit.MINUTES, () -> { Map<String, String> map1 = createAtomicMap(cache1, "testConcurrentWritesAndIteration", true); for (int i = 0; i < 250; i++) { map1.put("key-" + i, "value-" + i); } }, () -> { Map<String, String> map12 = createAtomicMap(cache1, "testConcurrentWritesAndIteration", true); for (int i = 0; i < 250; i++) { map12.keySet(); } }); }
public void testCreateMapInTx() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); tm(0, "atomic").begin(); Map<String, String> map1 = createAtomicMap(cache1, "testCreateMapInTx", true); map1.put("k1", "v1"); tm(0, "atomic").commit(); Map<Object, Object> expectedMap = createMap("k1", "v1"); assertMap(expectedMap, map1); final Map<String, String> map2 = createAtomicMap(cache2, "testCreateMapInTx", true); assertMap(expectedMap, map2); }
@SuppressWarnings("UnusedDeclaration") public void testCommitReadUncommittedValues() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map = createAtomicMap(cache1, "testCommitReadUncommittedValues"); tm(cache1).begin(); map.put("existing", "existing"); map.put("hey", "blah"); tm(cache1).commit(); tm(cache1).begin(); map.put("key one", "fake one"); map.put("key one", "value one"); map.put("blah", "montevideo"); map.put("blah", "buenos aires"); map.remove("blah"); map.put("blah", "toronto"); Map<Object, Object> expectedMap = createMap("key one", "value one", "blah", "toronto", "existing", "existing", "hey", "blah"); assertMap(expectedMap, map); Map<String, String> sameAsMap = createAtomicMap(cache1, "testCommitReadUncommittedValues"); assertMap(expectedMap, sameAsMap); tm(cache1).commit(); assertMap(expectedMap, map); assertMap(expectedMap, sameAsMap); }
public void testRollbackAndThenCommit() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map1 = createAtomicMap(cache1, "testRollbackAndThenCommit", true); tm(0, "atomic").begin(); map1.put("k1", "v"); map1.put("k2", "v2"); tm(0, "atomic").rollback(); Map<Object, Object> expectedMap = Collections.emptyMap(); Map<Object, Object> map2 = createAtomicMap(cache2, "testRollbackAndThenCommit", true); assertMap(expectedMap, map2); assertMap(expectedMap, map1); tm(0, "atomic").begin(); map1.put("k3", "v3"); map1.put("k4", "v4"); tm(0, "atomic").commit(); expectedMap = createMap("k3", "v3", "k4", "v4"); assertMap(expectedMap, map2); assertMap(expectedMap, map1); }
public void testReplicationPutAndClearCommit() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map = createAtomicMap(cache1, "map"); final Map<String, String> map2 = createAtomicMap(cache2, "map", false); Map<Object, Object> expectedMap = createMap("existing", "existing", "blah", "blah"); TestingUtil.getTransactionManager(cache1).begin(); map.put("existing", "existing"); map.put("blah", "blah"); map.size(); TestingUtil.getTransactionManager(cache1).commit(); assertMap(expectedMap, map); assertMap(expectedMap, map2); //ok, do another tx with clear delta changes tm(cache2).begin(); map2.clear(); tm(cache2).commit(); expectedMap = Collections.emptyMap(); assertMap(expectedMap, map); assertMap(expectedMap, map2); }
public void testMultipleTx() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0);
private void testInsertDeleteCycle(MagicKey key) throws Exception { final Cache<MagicKey, Object> cache1 = cache(0, "atomic"); final Cache<MagicKey, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); { TestingUtil.getTransactionManager(cache1).begin(); Map<String, Object> am = createAtomicMap(cache1, key); am.put("k1", "v1"); TestingUtil.getTransactionManager(cache1).commit(); } { TestingUtil.getTransactionManager(cache1).begin(); Map<String, Object> am = createAtomicMap(cache1, key); am.put("k3", "v3"); removeAtomicMap(cache1, key); //! am = createAtomicMap(cache1, key); am.put("k2", "v2"); TestingUtil.getTransactionManager(cache1).commit(); } final boolean fails; { TestingUtil.getTransactionManager(cache1).begin(); Map<String, Object> am = createAtomicMap(cache1, key); //'k1' should no longer exist as we had killed the whole am instance in previous transaction fails = am.containsKey("k1"); TestingUtil.getTransactionManager(cache1).commit(); } assertFalse(fails); }
public void testReplicationPutCommit() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map = createAtomicMap(cache1, "testReplicationPutCommit"); Map<Object, Object> expectedMap = createMap("existing", "existing", "blah", "blah"); tm(cache1).begin(); map.put("existing", "existing"); map.put("blah", "blah"); tm(cache1).commit(); assertMap(expectedMap, map); final Map<Object, Object> other = createAtomicMap(cache2, "testReplicationPutCommit", false); assertMap(expectedMap, other); //ok, do another tx with delta changes tm(cache2).begin(); other.put("existing", "not existing"); other.put("not existing", "peace on Earth"); tm(cache2).commit(); expectedMap = createMap("blah", "blah", "existing", "not existing", "not existing", "peace on Earth"); assertMap(expectedMap, map); assertMap(expectedMap, other); }
public void testReplicationRemoveCommit() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final Map<String, String> map = createAtomicMap(cache1, "testReplicationRemoveCommit"); Map<Object, Object> expectedMap = createMap("existing", "existing", "blah", "blah"); tm(cache1).begin(); map.put("existing", "existing"); map.put("blah", "blah"); tm(cache1).commit(); assertMap(expectedMap, map); final Map<Object, Object> other = createAtomicMap(cache2, "testReplicationRemoveCommit", false); assertMap(expectedMap, other); //ok, do another tx with delta changes tm(cache2).begin(); String removed = map.remove("existing"); assertEquals("Wrong value removed from map '" + map + "'.", "existing", removed); tm(cache2).commit(); expectedMap = createMap("blah", "blah"); assertMap(expectedMap, map); assertMap(expectedMap, other); }
public void testConcurrentReadsOnExistingMap() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); assertSize(cache1, 0); final Map<String, String> map = createAtomicMap(cache1, "testConcurrentReadsOnExistingMap", true); map.put("the-1", "my preciousss"); final Map<Object, Object> expectedMap = createMap("the-1", "my preciousss"); tm(0, "atomic").begin(); assertMap(expectedMap, map); map.put("the-2", "a minor"); Future<Void> f = fork(TestingUtil.withTxCallable(tm(0, "atomic"), (Callable<Void>) () -> { Map<String, String> map1 = createAtomicMap(cache1, "testConcurrentReadsOnExistingMap", true); assertMap(expectedMap, map1); assertNotContainsKey(map1, "the-2"); return null; })); f.get(10, TimeUnit.SECONDS); tm(0, "atomic").commit(); }
public void testConcurrentTx() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0); final TransactionManager tm1 = tm(cache1); final TransactionManager tm2 = tm(cache2); final Map<String, String> map1 = createAtomicMap(cache1, "testConcurrentTx", true); Map<Object, Object> expectedMap = createMap("k1", "initial"); tm1.begin(); map1.put("k1", "initial"); tm1.commit(); final Map<String, String> map2 = createAtomicMap(cache2, "testConcurrentTx", false); assertMap(expectedMap, map1); assertMap(expectedMap, map2); Future<Void> t1 = fork(TestingUtil.withTxCallable(tm1, (Callable<Void>) () -> { map1.put("k1", "tx1Value"); return null; })); Future<Void> t2 = fork(TestingUtil.withTxCallable(tm2, (Callable<Void>) () -> { map2.put("k2", "tx2Value"); return null; })); t2.get(); t1.get(); expectedMap = createMap("k1", "tx1Value", "k2", "tx2Value"); assertMap(expectedMap, map1); assertMap(expectedMap, map2); }
public void testConcurrentWritesOnExistingMap() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); assertSize(cache1, 0); final Map<String, String> map = createAtomicMap(cache1, "testConcurrentReadsOnExistingMap", true); map.put("the-1", "my preciousss");
final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0);
final Cache<String, Object> cache2 = cache(1, "atomic"); assertSize(cache1, 0); assertSize(cache2, 0);