@Override protected <CK, K, V> Map<K, V> createAtomicMap(Cache<CK, Object> cache, CK key, boolean createIfAbsent) { return getFineGrainedAtomicMap(cache, key, createIfAbsent); }
@Override public Map<String, String> getObject(Cache cache, String key) { return AtomicMapLookup.getFineGrainedAtomicMap(cache, key, false); }
@Override public Map<String, String> createObject(Cache cache, String key) { Map<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); map.put("first", "first component of object with key=" + key); map.put("second", "second component of object with key=" + key); return map; }
private Tuple getTupleFromCacheKey(EK cacheKey, Cache<EK, Map<String,Object>> cache) { FineGrainedAtomicMap<String, Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); if ( atomicMap == null ) { return null; } else { return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.UPDATE ); } }
private Tuple getTupleFromCacheKey(EK cacheKey, Cache<EK, Map<String,Object>> cache) { FineGrainedAtomicMap<String, Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); if ( atomicMap == null ) { return null; } else { return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.UPDATE ); } }
@Override public Association getAssociation(AssociationKey key, AssociationContext associationContext) { Cache<AK, Map<RowKey, Map<String, Object>>> cache = getCacheManager().getAssociationCache( key.getMetadata() ); AK cacheKey = getKeyProvider().getAssociationCacheKey( key ); Map<RowKey, Map<String, Object>> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); return atomicMap == null ? null : new Association( new MapAssociationSnapshot( atomicMap ) ); }
@Override public Association getAssociation(AssociationKey key, AssociationContext associationContext) { Cache<AK, Map<RowKey, Map<String, Object>>> cache = getCacheManager().getAssociationCache( key.getMetadata() ); AK cacheKey = getKeyProvider().getAssociationCacheKey( key ); Map<RowKey, Map<String, Object>> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, false ); return atomicMap == null ? null : new Association( new MapAssociationSnapshot( atomicMap ) ); }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { //TODO we don't verify that it does not yet exist assuming that this has been done before by the calling code //should we improve? Cache<AK, Map<RowKey, Map<String, Object>>> cache = getCacheManager().getAssociationCache( key.getMetadata() ); AK cacheKey = getKeyProvider().getAssociationCacheKey( key ); Map<RowKey, Map<String, Object>> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, true ); return new Association( new MapAssociationSnapshot( atomicMap ) ); }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { //TODO we don't verify that it does not yet exist assuming that this has been done before by the calling code //should we improve? Cache<AK, Map<RowKey, Map<String, Object>>> cache = getCacheManager().getAssociationCache( key.getMetadata() ); AK cacheKey = getKeyProvider().getAssociationCacheKey( key ); Map<RowKey, Map<String, Object>> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, true ); return new Association( new MapAssociationSnapshot( atomicMap ) ); }
public void testFineGrainedAtomicMapWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); cacheManager.defineConfiguration("fgahm_without_batch", builder.build()); Cache<String, String> fgahmCache = cacheManager.getCache("fgahm_without_batch"); FineGrainedAtomicMap<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "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.getFineGrainedAtomicMap(fgahmCache, "key").get("a").equals("b"); }
/** * Verifies we can create a new AtomicMap, use it and then remove it while in the same transaction * See also ISPN-2075. */ public void testDontFailOnImmediateRemovalOfAtomicMaps() throws Exception { final String key = "key1"; final String subKey = "subK"; TestingUtil.withTx(tm, () -> { FineGrainedAtomicMap<String, String> fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); fineGrainedAtomicMap.put(subKey, "some value"); fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); fineGrainedAtomicMap.get(subKey); fineGrainedAtomicMap.put(subKey, "v"); fineGrainedAtomicMap.put(subKey + 2, "v2"); fineGrainedAtomicMap = AtomicMapLookup.getFineGrainedAtomicMap(cache, key); Object object = fineGrainedAtomicMap.get(subKey); assertEquals("Wrong FGAM sub-key value.", "v", object); AtomicMapLookup.removeAtomicMap(cache, key); return null; }); }
@Override public Tuple createTuple(EntityKey key, OperationContext operationContext) { //TODO we don't verify that it does not yet exist assuming that this has been done before by the calling code //should we improve? Cache<EK, Map<String, Object>> cache = getCacheManager().getEntityCache( key.getMetadata() ); EK cacheKey = getKeyProvider().getEntityCacheKey( key ); FineGrainedAtomicMap<String,Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, true ); return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.INSERT ); }
@Override public Tuple createTuple(EntityKey key, OperationContext operationContext) { //TODO we don't verify that it does not yet exist assuming that this has been done before by the calling code //should we improve? Cache<EK, Map<String, Object>> cache = getCacheManager().getEntityCache( key.getMetadata() ); EK cacheKey = getKeyProvider().getEntityCacheKey( key ); FineGrainedAtomicMap<String,Object> atomicMap = AtomicMapLookup.getFineGrainedAtomicMap( cache, cacheKey, true ); return new Tuple( new InfinispanTupleSnapshot( atomicMap ), SnapshotType.INSERT ); }
public void testFineGrainedAtomicMapWithoutTransactionManagerLookupSet() { ConfigurationBuilder builder = buildConfiguration(); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).transactionManagerLookup(null); cacheManager.defineConfiguration("fgahm_without_tmlookup", builder.build()); Cache<String, String> fgahmCache = cacheManager.getCache("fgahm_without_tmlookup"); FineGrainedAtomicMap<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "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.getFineGrainedAtomicMap(fgahmCache, "key").get("a").equals("b"); }
@Test(enabled = false, description = "Doesn't work when the originator isn't the primary owner, see ISPN-5988") public void testFineGrainedMapAfterAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey("key", cache2); getAtomicMap(cache1, key); try { getFineGrainedAtomicMap(cache1, key); fail("Should have failed with an IllegalArgumentException"); } catch (IllegalArgumentException e) { // Expected } }
@Test(expectedExceptions = IllegalStateException.class) public void testFineGrainedAtomicMapNonTransactionWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); cacheManager.defineConfiguration("fgahm_no_tx_without_batch", builder.build()); Cache<String, String> fgahmCache = cacheManager.getCache("fgahm_no_tx_without_batch"); FineGrainedAtomicMap<String, String> map = AtomicMapLookup.getFineGrainedAtomicMap(fgahmCache, "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.getFineGrainedAtomicMap(fgahmCache, "key").get("a").equals("b"); }
public void testFineGrainedMapAfterAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey("key", cache1); getAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getFineGrainedAtomicMap(cache1, key)); }
public void testAtomicMapAfterFineGrainedAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey(cache1); getFineGrainedAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getAtomicMap(cache1, key)); }
public void testAtomicMapAfterFineGrainedAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey(cache2); getFineGrainedAtomicMap(cache1, key); Exceptions.expectException(IllegalStateException.class, "ISPN000457:.*", () -> getAtomicMap(cache1, key)); }
protected final void testFineGrainedAtomicHashMap(boolean executeOnLockOwner) throws Exception { final int txExecutor = executeOnLockOwner ? 0 : 1; FineGrainedAtomicMap<Object, Object> map = AtomicMapLookup.getFineGrainedAtomicMap(cache(txExecutor), fgahmKey);