Source:
public void after_txn_commit_near_cache_should_be_invalidated() throws Exception { Config cfg = getConfig(); String mapName = "cache"; MapConfig cacheConfig = cfg.getMapConfig(mapName); NearCacheConfig nearCacheConfig = new NearCacheConfig(); nearCacheConfig.setInvalidateOnChange(true) .setCacheLocalEntries(true) .setInMemoryFormat(inMemoryFormat) .setSerializeKeys(serializeKeys); cacheConfig.setNearCacheConfig(nearCacheConfig); HazelcastInstance server = createHazelcastInstance(cfg); IMap map = server.getMap(mapName); String key = "key"; String oldValue = "oldValue"; String updatedValue = "updatedValue"; map.put(key, oldValue); Object valueReadBeforeTxnFromNonTxnMap = map.get(key); HazelcastXAResource xaResource = server.getXAResource(); tm.begin(); Object valueReadInsideTxnFromTxnMapBeforeUpdate = null; Object valueReadInsideTxnFromTxnMapAfterUpdate = null; Object valueReadInsideTxnFromNonTxnMapAfterUpdate = null; boolean error = false; try { Transaction transaction = tm.getTransaction(); transaction.enlistResource(xaResource); TransactionContext ctx = xaResource.getTransactionContext(); TransactionalMap txnMap = ctx.getMap(mapName); valueReadInsideTxnFromTxnMapBeforeUpdate = txnMap.get(key); txnMap.put(key, updatedValue); valueReadInsideTxnFromTxnMapAfterUpdate = txnMap.get(key); valueReadInsideTxnFromNonTxnMapAfterUpdate = map.get(key); } catch (Exception e) { e.printStackTrace(); error = true; } finally { close(error, xaResource); } assertEquals(oldValue, valueReadInsideTxnFromTxnMapBeforeUpdate); assertEquals(updatedValue, valueReadInsideTxnFromTxnMapAfterUpdate); assertEquals(oldValue, valueReadBeforeTxnFromNonTxnMap); assertEquals(oldValue, valueReadInsideTxnFromNonTxnMapAfterUpdate); Object valueReadAfterTxnFromNonTxnMap = map.get(key); assertEquals(updatedValue, valueReadAfterTxnFromNonTxnMap); }

Target:
public void after_txn_commit_near_cache_should_be_invalidated() throws Exception { Config cfg = getConfig(); String mapName = "cache"; MapConfig cacheConfig = cfg.getMapConfig(mapName); NearCacheConfig nearCacheConfig = new NearCacheConfig(); nearCacheConfig.setInvalidateOnChange(true) .setCacheLocalEntries(true) .setInMemoryFormat(inMemoryFormat) .setSerializeKeys(serializeKeys); cacheConfig.setNearCacheConfig(nearCacheConfig); HazelcastInstance server = createHazelcastInstance(cfg); IMap map = server.getMap(mapName); String key = "key"; String oldValue = "oldValue"; String updatedValue = "updatedValue"; map.put(key, oldValue); Object valueReadBeforeTxnFromNonTxnMap = map.get(key); HazelcastXAResource xaResource = server.getXAResource(); tm.begin(); Object valueReadInsideTxnFromTxnMapBeforeUpdate = null; Object valueReadInsideTxnFromTxnMapAfterUpdate = null; Object valueReadInsideTxnFromNonTxnMapAfterUpdate = null; boolean error = false; try { Transaction transaction = tm.getTransaction(); transaction.enlistResource(xaResource); TransactionContext ctx = xaResource.getTransactionContext(); TransactionalMap txnMap = ctx.getMap(mapName); valueReadInsideTxnFromTxnMapBeforeUpdate = txnMap.get(key); txnMap.put(key, updatedValue); valueReadInsideTxnFromTxnMapAfterUpdate = txnMap.get(key); valueReadInsideTxnFromNonTxnMapAfterUpdate = map.get(key); } catch (Exception e) { error = true; throw ExceptionUtil.rethrow(e); } finally { close(error, xaResource); } assertEquals(oldValue, valueReadInsideTxnFromTxnMapBeforeUpdate); assertEquals(updatedValue, valueReadInsideTxnFromTxnMapAfterUpdate); assertEquals(oldValue, valueReadBeforeTxnFromNonTxnMap); assertEquals(oldValue, valueReadInsideTxnFromNonTxnMapAfterUpdate); Object valueReadAfterTxnFromNonTxnMap = map.get(key); assertEquals(updatedValue, valueReadAfterTxnFromNonTxnMap); }