use of java.util.concurrent.locks.ReentrantReadWriteLock in project ignite by apache.
the class ReadWriteLockMultiThreadedTest method testNotOwnedLockRelease.
/**
*
*/
public void testNotOwnedLockRelease() {
ReadWriteLock lock = new ReentrantReadWriteLock();
lock.readLock().unlock();
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project ignite by apache.
the class ReadWriteLockMultiThreadedTest method testReadThenWriteLockAcquire.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "LockAcquiredButNotSafelyReleased" })
public void testReadThenWriteLockAcquire() throws Exception {
ReadWriteLock lock = new ReentrantReadWriteLock();
lock.readLock().lock();
lock.writeLock().lock();
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project ignite by apache.
the class ReadWriteLockMultiThreadedTest method testWriteLockAcquire.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "LockAcquiredButNotSafelyReleased" })
public void testWriteLockAcquire() throws Exception {
final ReadWriteLock lock = new ReentrantReadWriteLock();
lock.readLock().lock();
X.println("Read lock acquired.");
IgniteInternalFuture fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
X.println("Attempting to acquire write lock: " + lock);
lock.writeLock().lock();
try {
X.println("Write lock acquired: " + lock);
return null;
} finally {
lock.writeLock().unlock();
}
}
}, 1, "write-lock");
Thread.sleep(2000);
IgniteInternalFuture fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
X.println("Attempting to acquire read lock: " + lock);
lock.readLock().lock();
try {
X.println("Read lock acquired: " + lock);
return null;
} finally {
lock.readLock().unlock();
}
}
}, 1, "read-lock");
Thread.sleep(2000);
X.println(">>> Dump threads now! <<<");
Thread.sleep(15 * 1000);
X.println("Read lock released: " + lock);
lock.readLock().unlock();
fut1.get();
fut2.get();
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method nonBlockingReset.
// OAK-2620
@Test
public void nonBlockingReset() throws Exception {
final List<String> failure = Lists.newArrayList();
final AtomicReference<ReentrantReadWriteLock> mergeLock = new AtomicReference<ReentrantReadWriteLock>();
MemoryDocumentStore store = new MemoryDocumentStore() {
@Override
public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
for (Map.Entry<Key, Operation> entry : update.getChanges().entrySet()) {
if (entry.getKey().getName().equals(NodeDocument.COLLISIONS)) {
ReentrantReadWriteLock rwLock = mergeLock.get();
if (rwLock.getReadHoldCount() > 0 || rwLock.getWriteHoldCount() > 0) {
failure.add("Branch reset still holds merge lock");
break;
}
}
}
return super.findAndUpdate(collection, update);
}
};
DocumentNodeStore ds = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
// do not retry merges
ds.setMaxBackOffMillis(0);
DocumentNodeState root = ds.getRoot();
final DocumentNodeStoreBranch b = ds.createBranch(root);
// branch state is now Unmodified
assertTrue(b.getMergeLock() instanceof ReentrantReadWriteLock);
mergeLock.set((ReentrantReadWriteLock) b.getMergeLock());
NodeBuilder builder = root.builder();
builder.child("foo");
b.setRoot(builder.getNodeState());
// branch state is now InMemory
builder.child("bar");
b.setRoot(builder.getNodeState());
try {
b.merge(new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
NodeBuilder foo = after.builder().child("foo");
for (int i = 0; i <= DocumentMK.UPDATE_LIMIT; i++) {
foo.setProperty("prop", i);
}
throw new CommitFailedException("Fail", 0, "");
}
}, CommitInfo.EMPTY);
} catch (CommitFailedException e) {
// expected
}
for (String s : failure) {
fail(s);
}
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project jena by apache.
the class TestTDBInternal method exclusive_1.
@Test
public void exclusive_1() {
DatasetGraph dsg = TDBFactory.createDatasetGraph();
TransactionManager txnmgr = TDBInternal.getTransactionManager(dsg);
checkTxnMgr(txnmgr, 0, 0);
ReentrantReadWriteLock rwx = (ReentrantReadWriteLock) txnmgr.getExclusivityLock$();
checkLock(rwx, 0, 0);
dsg.begin(ReadWrite.WRITE);
// Exclusivity reader lock.
checkLock(rwx, 1, 0);
checkTxnMgr(txnmgr, 0, 1);
dsg.commit();
// Exclusivity reader lock.
checkLock(rwx, 0, 0);
checkTxnMgr(txnmgr, 0, 0);
dsg.end();
// Exclusivity reader lock.
checkLock(rwx, 0, 0);
checkTxnMgr(txnmgr, 0, 0);
}
Aggregations