private boolean remove(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) { SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id); try { if (!this.properties.isLockOnWrite() || (creationMetaDataCache.getAdvancedCache().getTransactionManager().getTransaction() == null) || creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) { creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(key); this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionAccessMetaDataKey(id)); return true; } return false; } catch (SystemException e) { throw new CacheException(e); } }
@Override public void execute() { advancedCache(1).lock(key); } });
@Override public void execute() { cache(0).getAdvancedCache().lock(key); } });
private String performWork() { log.info( "Locking " + key); cache.getAdvancedCache().lock(key); return "locked " + key; } }
@Override public Object call() throws Exception { try { cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY).lock("a"); assert false : "Should be throwing an exception in spite of fail silent"; } catch (CacheException e) { // expected } return null; } });
@Override public void call() { cm.getCache().getAdvancedCache().lock("k"); } });
private void runtTest(int lockOwner, int txOwner) throws NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException { Object key = getKeyForCache(lockOwner); tm(txOwner).begin(); advancedCache(txOwner).lock(key); tm(txOwner).commit(); assertNotLocked(key); } }
private void startTxWithLock() throws Exception { sequencer.enter("tx:perform_op"); tm(0).begin(); advancedCache(0).lock(KEY); sequencer.exit("tx:perform_op"); }
public void testLockWithTmRollback() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().rollback(); assertFalse(lockManager().isLocked("k")); }
public void testLockWithTmCommit() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().commit(); assertFalse(lockManager().isLocked("k")); } }
public void testLockSuccess() throws Exception { Cache<String, String> cache1 = cache(0); cache1.put("k", "v"); tm(0).begin(); assert cache1.getAdvancedCache().lock("k"); tm(0).rollback(); }
public void testMultiLockSuccess() throws Exception { Cache<String, String> cache1 = cache(0); cache1.put("k1", "v"); cache1.put("k2", "v"); cache1.put("k3", "v"); tm(0).begin(); assert cache1.getAdvancedCache().lock(Arrays.asList("k1", "k2", "k3")); tm(0).rollback(); }
public void testLockAndGet() throws SystemException, NotSupportedException { Cache<MagicKey, String> cache1 = cache(0), cache2 = cache(1); cache1.put(key, "v"); assert "v".equals(cache1.get(key)) : "Could not find key " + key + " on cache1"; assert "v".equals(cache2.get(key)) : "Could not find key " + key + " on cache2"; tm(0).begin(); log.trace("About to lock"); cache1.getAdvancedCache().lock(key); log.trace("About to get"); assert "v".equals(cache1.get(key)) : "Could not find key " + key + " on cache1"; tm(0).rollback(); }
public void testA() throws Exception { Object a = getKeyForCache(1); tm(0).begin(); cache(0).put("x", "b"); advancedCache(0).lock(a); assertKeyLockedCorrectly(a); tm(0).commit(); } }
@Test (expectedExceptions = TimeoutException.class) public void testLockFailure() throws Exception { Cache<String, String> cache1 = cache(0), cache2 = cache(1); cache1.put("k", "v"); tm(1).begin(); cache2.put("k", "v2"); tm(1).suspend(); tm(0).begin(); cache1.getAdvancedCache().lock("k"); tm(0).rollback(); }
public void testLockWithBatchingRollback() { cache.startBatch(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); cache().endBatch(false); assertFalse(lockManager().isLocked("k")); }
public void testLockWithBatchingCommit() { cache.startBatch(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); cache().endBatch(true); assertFalse(lockManager().isLocked("k")); }
public void testSilentMultiLockFailure() throws Exception { Cache<String, String> cache1 = cache(0), cache2 = cache(1); cache1.put("k1", "v"); cache1.put("k2", "v"); cache1.put("k3", "v"); tm(1).begin(); cache2.put("k3", "v2"); tm(1).suspend(); tm(0).begin(); assert !cache1.getAdvancedCache().withFlags(FAIL_SILENTLY).lock(Arrays.asList("k1", "k2", "k3")); tm(0).rollback(); }
public void testSilentLockFailure() throws Exception { Cache<String, String> cache1 = cache(0), cache2 = cache(1); cache1.put("k", "v"); tm(1).begin(); cache2.put("k", "v2"); tm(1).suspend(); tm(0).begin(); assert !cache1.getAdvancedCache().withFlags(FAIL_SILENTLY).lock("k"); tm(0).rollback(); }