private V put(AdvancedCache cache, K key, V value) { startAtomic(); try { AtomicMap<K, V> map = getDataInternal(cache); return map.put(key, value); } finally { endAtomic(); } }
private V replace(AdvancedCache<?, ?> cache, K key, V value) { startAtomic(); try { AtomicMap<K, V> map = getAtomicMap(cache, dataKey); if (map.containsKey(key)) return map.put(key, value); else return null; } finally { endAtomic(); } }
private V putIfAbsent(AdvancedCache<?, ?> cache, K key, V value) { startAtomic(); try { AtomicMap<K, V> data = getDataInternal(cache); if (!data.containsKey(key)) return data.put(key, value); return data.get(key); } finally { endAtomic(); } }
@Test(expectedExceptions = IllegalStateException.class) public void testRemovalOfAtomicMap() throws SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("hello", "world"); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); tm.begin(); map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("hello2", "world2"); assert map.size() == 2; AtomicMapLookup.removeAtomicMap(cache, "key"); map.size(); tm.commit(); } }
public void testChangesOnAtomicMap() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); }
public void testRestoreAtomicMap(Method m) { cacheManager.defineConfiguration(m.getName(), configureCacheLoader(null, false).build()); Cache<String, Object> cache = cacheManager.getCache(m.getName()); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, m.getName()); map.put("a", "b"); //evict from memory cache.evict(m.getName()); // now re-retrieve the map assertEquals("b", AtomicMapLookup.getAtomicMap(cache, m.getName()).get("a")); }
@Test public void testRestoreTransactionalAtomicMap(final Method m) throws Exception { cacheManager.defineConfiguration(m.getName(), configureCacheLoader(null, false).build()); Cache<String, Object> cache = cacheManager.getCache(m.getName()); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); tm.begin(); final AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, m.getName()); map.put("a", "b"); tm.commit(); //evict from memory cache.evict(m.getName()); // now re-retrieve the map and make sure we see the diffs assertEquals("b", AtomicMapLookup.getAtomicMap(cache, m.getName()).get("a")); }
public void testReplicationRollback() throws Exception { Cache<String, Object> cache1 = cache(0, "atomic"); Cache<String, Object> cache2 = cache(1, "atomic"); assertIsEmptyMap(cache2, "map"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map"); TestingUtil.getTransactionManager(cache1).begin(); map.put("existing", "existing"); map.put("blah", "blah"); TestingUtil.getTransactionManager(cache1).rollback(); assertIsEmpty(map); assertIsEmptyMap(cache1, "map"); assertIsEmptyMap(cache2, "map"); } }
public void testReplicationCommitCreateMapInTransaction(Method m) throws Exception { Cache<String, Object> cache1 = cache(0, "atomic"); Cache<String, Object> cache2 = cache(1, "atomic"); TestingUtil.getTransactionManager(cache1).begin(); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, m.getName()); map.put("a", "b"); TestingUtil.getTransactionManager(cache1).commit(); assert map.size() == 1; assert map.get("a").equals("b"); assert map.containsKey("a"); assert AtomicMapLookup.getAtomicMap(cache2, m.getName()).size() == 1; assert AtomicMapLookup.getAtomicMap(cache2, m.getName()).get("a").equals("b"); assert AtomicMapLookup.getAtomicMap(cache2, m.getName()).containsKey("a"); }
public void testChangesOnAtomicMapNoLocks() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); assert map.isEmpty(); // InvocationContextContainer icc = TestingUtil.extractComponent(cache, InvocationContextContainer.class); // InvocationContext ic = icc.createInvocationContext(false, -1); // ic.setFlags(SKIP_LOCKING); log.debug("Doing a put"); // assert icc.getInvocationContext(true).hasFlag(SKIP_LOCKING); map.put("a", "b"); log.debug("Put complete"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); }
public void testReplicationCommit() throws Exception { Cache<String, Object> cache1 = cache(0, "atomic"); Cache<String, Object> cache2 = cache(1, "atomic"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map"); TestingUtil.getTransactionManager(cache1).begin(); map.put("existing", "existing"); map.put("blah", "blah"); TestingUtil.getTransactionManager(cache1).commit(); assert map.size() == 2; assert map.get("blah").equals("blah"); assert map.containsKey("blah"); assert AtomicMapLookup.getAtomicMap(cache2, "map").size() == 2; assert AtomicMapLookup.getAtomicMap(cache2, "map").get("blah").equals("blah"); assert AtomicMapLookup.getAtomicMap(cache2, "map").containsKey("blah"); }
@Override public Void call() throws Exception { // Modify atomic map from first node AtomicMap<String, String> map = AtomicMapLookup .getAtomicMap(cache1, "map"); map.put("key1", "new_value1"); assertTrue(map.containsKey("key2")); assertEquals("value2", map.get("key2")); return null; } });
public void testReadSafetyRollback() throws Exception { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map"); tm.begin(); map.put("blah", "blah"); assert map.size() == 1; assert map.get("blah").equals("blah"); assert map.containsKey("blah"); Transaction t = tm.suspend(); assertIsEmpty(map); assertIsEmptyMap(cache, "map"); tm.resume(t); tm.rollback(); assertIsEmpty(map); assertIsEmptyMap(cache, "map"); }
public void testTxChangesOnAtomicMap() throws Exception { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); tm().begin(); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); Transaction t = tm().suspend(); assert AtomicMapLookup.getAtomicMap(cache, "key").get("a") == null; tm().resume(t); tm().commit(); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); }
public void testTxChangesOnAtomicMapNoLocks() throws Exception { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); tm().begin(); assert map.isEmpty(); // TestingUtil.extractComponent(cache, InvocationContextContainer.class).createInvocationContext(true, -1).setFlags(SKIP_LOCKING); map.put("a", "b"); assert map.get("a").equals("b"); Transaction t = tm().suspend(); assert AtomicMapLookup.getAtomicMap(cache, "key").get("a") == null; tm().resume(t); tm().commit(); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); }
public void testAtomicMapWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); cacheManager.defineConfiguration("ahm_without_batch", builder.build()); Cache<String, String> ahmCache = cacheManager.getCache("ahm_without_batch"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b"); }
public void testAtomicMapWithoutTransactionManagerLookupSet() { ConfigurationBuilder builder = buildConfiguration(); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).transactionManagerLookup(null); cacheManager.defineConfiguration("ahm_without_tmlookup", builder.build()); Cache<String, String> ahmCache = cacheManager.getCache("ahm_without_tmlookup"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b"); }
public void testAtomicMapNonTransactionWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); cacheManager.defineConfiguration("ahm_no_tx_without_batch", builder.build()); Cache<String, String> ahmCache = cacheManager.getCache("ahm_no_tx_without_batch"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b"); }
public void testAtomicMapBackup() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache("LON", 0), "amKey"); assert map.isEmpty(); log.trace("Update is here"); map.put("a", "fancyValue"); assertEquals("fancyValue", map.get("a")); assertEquals("fancyValue", AtomicMapLookup.getAtomicMap(backup("LON"), "amKey").get("a")); }