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(); } }
public Status insert(String table, String key, Map<String, ByteIterator> values) { try { if (clustered) { AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key); row.clear(); StringByteIterator.putAllAsStrings(row, values); } else { infinispanManager.getCache(table).put(key, values); } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
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"); }
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"); }
atomicMap.put(1, "value1"); atomicMap.put(2, "value2"); atomicMap.put(3, "value3"); tm().commit(); atomicMap.remove(1); AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY); assertEquals(3, otMap.size()); readLatch.countDown(); otMap.remove(2); commitLatch.await(10, TimeUnit.SECONDS); assertEquals(new HashSet<>(Arrays.asList(3)), atomicMap.keySet());
@SuppressWarnings({ "rawtypes", "unchecked" }) private void removeEntry(final org.infinispan.Cache cache, final Object o) { final CompoundKey key = (CompoundKey) o; final AtomicMap map = AtomicMapLookup.getAtomicMap(cache, key.getName(), false); map.remove(key); }
public void testConcurrentPut() throws Exception { final CountDownLatch readLatch = new CountDownLatch(1); final CountDownLatch commitLatch = new CountDownLatch(1); AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY); tm().begin(); atomicMap.put(1, "value1"); Future<Object> future = fork(() -> { try { tm().begin(); AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY); assertEquals(0, otMap.size()); readLatch.countDown(); otMap.put(2, "value2"); commitLatch.await(10, TimeUnit.SECONDS); tm().commit(); } catch (Exception e) { tm().rollback(); throw e; } return null; }); readLatch.await(10, TimeUnit.SECONDS); tm().commit(); commitLatch.countDown(); future.get(10, TimeUnit.SECONDS); assertEquals(new HashSet<>(Arrays.asList(1, 2)), atomicMap.keySet()); }
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(); } }
@Override public Collection<Serializable> getAllKeys(String category) { try { AtomicMap<Serializable, Void> m = getKeysPerCategoryCollection(category); return m.keySet(); // the keyset are the DS keys } catch (CacheException ce) { return null; } }
assertTrue(map.containsKey("key1")); assertTrue(map.containsKey("key2")); assertEquals("new_value1", map.get("key1")); assertEquals("value2", map.get("key2"));
@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(); } }
private boolean hasChild(AdvancedCache<?, ?> cache, Object o) { return getStructure(cache).containsKey(o); }
private void doWriteSkewTest(final Cache<Object, Object> cache, final Object mapKey, final List<Cache<Object, Object>> caches) throws Exception { final TransactionManager tm = tm(cache); Map<Object, Object> atomicMap = getAtomicMap(cache, mapKey, true); //let's put some values atomicMap.put("k1", "v1"); tm.begin(); AssertJUnit.assertEquals("v1", atomicMap.get("k1")); final Transaction tx1 = tm.suspend(); tm.begin(); AssertJUnit.assertEquals("v1", atomicMap.get("k1")); final Transaction tx2 = tm.suspend(); tm.resume(tx1); atomicMap.put("k1", "v2"); tm.commit(); tm.resume(tx2); AssertJUnit.assertEquals("v1", atomicMap.get("k1")); atomicMap.put("k1", "v3"); try { tm.commit(); fail(); } catch (RollbackException e) { //expected safeRollback(tm); } for (Cache<Object, Object> cache1 : caches) { AssertJUnit.assertEquals("v2", getAtomicMap(cache1, mapKey).get("k1")); } }
private Set<Node<K, V>> getChildren(AdvancedCache<?, ?> cache) { startAtomic(); try { Set<Node<K, V>> result = new HashSet<Node<K, V>>(); for (Fqn f : getStructure().values()) { NodeImpl<K, V> n = new NodeImpl<K, V>(f, cache, batchContainer); result.add(n); } return Immutables.immutableSetWrap(result); } finally { endAtomic(); } }
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"); }