public void testAtomicMapPutDuringJoin() throws ExecutionException, InterruptedException { Cache cache = cache(0, "atomic"); ControlledRpcManager crm = new ControlledRpcManager(cache.getAdvancedCache().getRpcManager()); TestingUtil.replaceComponent(cache, RpcManager.class, crm, true); MagicKey atomicMapKey = new MagicKey("atomicMapKey", cache); AtomicMap atomicMap = AtomicMapLookup.getAtomicMap(cache, atomicMapKey); atomicMap.put("key1", "value1"); crm.blockBefore(StateResponseCommand.class); ConfigurationBuilder c = getConfigurationBuilder(); final EmbeddedCacheManager joiner = addClusterEnabledCacheManager(c); Future<Cache> future = fork( new Callable<Cache>() { @Override public Cache call() throws Exception { return joiner.getCache("atomic"); } }); crm.waitForCommandToBlock(); // Now we know state transfer will try to create an AtomicMap(key1=value1) on cache2 // Insert another key in the atomic map, and check that cache2 has both keys after the state // transfer atomicMap.put("key2", "value2"); crm.stopBlocking(); Cache cache2 = future.get(); AtomicMap atomicMap2 = AtomicMapLookup.getAtomicMap(cache2, atomicMapKey); assertEquals(new HashSet<String>(Arrays.asList("key1", "key2")), atomicMap2.keySet()); }
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 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"); }
@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(); }
@Test(expectedExceptions = IllegalStateException.class) 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 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 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 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 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 testEviction() throws Exception { final Cache<String, Object> cache1 = cache(0, "atomic"); final Cache<String, Object> cache2 = cache(1, "atomic"); TransactionManager tm1 = cache1.getAdvancedCache().getTransactionManager(); withTx( tm1, new Callable<Void>() { @Override public Void call() throws Exception { // Add atomic map in first node AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map"); map.put("key1", "value1"); map.put("key2", "value2"); return null; } }); // From second node, passivate the map cache2.evict("map"); withTx( tm1, new Callable<Void>() { @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; } }); // Lookup entry from second node and verify it has all the data AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache2, "map"); assertTrue(map.containsKey("key1")); assertTrue(map.containsKey("key2")); assertEquals("new_value1", map.get("key1")); assertEquals("value2", map.get("key2")); }