public final void testAtomicHasMapLockingOnLockOwner() throws Exception { testAtomicHashMap(true); }
public final void testFineGrainedAtomicHashMapLockingOnLockOwner() throws Exception { testFineGrainedAtomicHashMap(true); }
protected final void testAtomicHashMap(boolean executeOnLockOwner) throws Exception { final int txExecutor = executeOnLockOwner ? 0 : 1; AtomicMap<Object, Object> map = AtomicMapLookup.getAtomicMap(cache(txExecutor), ahmKey); tm(txExecutor).begin(); map.put("key1", VALUE); map.put("key2", VALUE); map.put("key3", VALUE); final Transaction tx1 = tm(txExecutor).suspend(); ControlledRpcManager rpcManager = ControlledRpcManager.replaceRpcManager(cache(txExecutor)); try { Future<Boolean> txOutcome = fork(() -> { try { tm(txExecutor).resume(tx1); tm(txExecutor).commit(); return Boolean.TRUE; } catch (Exception e) { assertKeysLocked(0, ahmKey); assertKeysLocked(1, EMPTY_ARRAY); assertKeysLocked(2, EMPTY_ARRAY);
@Override protected void createCacheManagers() throws Throwable { for (int i = 0; i < NUM_NODES; ++i) { collectors[i] = new CollectKeysInterceptor(); ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true); builder.transaction().lockingMode(pessimistic ? LockingMode.PESSIMISTIC : LockingMode.OPTIMISTIC); builder.customInterceptors().addInterceptor().interceptor(collectors[i]) .before(TxInterceptor.class); builder.clustering().hash().numOwners(2).groups().enabled(); addClusterEnabledCacheManager(builder); } waitForClusterToForm(); ahmKey = new MagicKey("AtomicMap", cache(0)); fgahmKey = new MagicKey("FineGrainedAtomicMap", cache(0)); }
protected void assertKeysLocked(int index, Object... keys) { LockManager lockManager = lockManager(index); Assert.assertNotNull(keys); for (Object key : keys) { Assert.assertTrue(lockManager.isLocked(key), key + " is not locked in cache(" + index + ")."); } }
protected final void testFineGrainedAtomicHashMap(boolean executeOnLockOwner) throws Exception { final int txExecutor = executeOnLockOwner ? 0 : 1; FineGrainedAtomicMap<Object, Object> map = AtomicMapLookup.getFineGrainedAtomicMap(cache(txExecutor), fgahmKey); tm(txExecutor).begin(); for (int keyIndex = 0; keyIndex < 100; ++keyIndex) { map.put("key" + keyIndex, VALUE); final Transaction tx1 = tm(txExecutor).suspend(); log.infof("%s composite keys collected.", collectors[txExecutor].getKeys().size()); ControlledRpcManager rpcManager = ControlledRpcManager.replaceRpcManager(cache(txExecutor)); try { Future<Boolean> txOutcome = fork(() -> { try { tm(txExecutor).resume(tx1); tm(txExecutor).commit(); return Boolean.TRUE; } catch (Exception e) { assertKeysLocked(0, collectors[txExecutor].getKeys().toArray()); assertKeysLocked(1, EMPTY_ARRAY); assertKeysLocked(2, EMPTY_ARRAY);
public final void testAtomicHasMapLockingOnNonLockOwner() throws Exception { testAtomicHashMap(false); }
public final void testFineGrainedAtomicHashMapLockingOnNonLockOwner() throws Exception { testFineGrainedAtomicHashMap(false); }