Search in sources :

Example 1 with ReadLock

use of org.apache.jackrabbit.core.state.ISMLocking.ReadLock in project jackrabbit by apache.

the class AbstractISMLockingTest method testReadBlocksWrite.

/**
     * Checks the following requirement: <p/> <i>While a read lock is held for a given item with id
     * <code>I</code> an implementation must ensure that no write lock is issued for a change log that
     * contains a reference to an item with id <code>I</code>. </i>
     *
     * @throws InterruptedException on interruption; this will err the test
     */
public void testReadBlocksWrite() throws InterruptedException {
    ReadLock rLock = locking.acquireReadLock(state.getId());
    for (ChangeLog changeLog : logs) {
        verifyBlocked(startWriterThread(locking, changeLog));
    }
    rLock.release();
}
Also used : ReadLock(org.apache.jackrabbit.core.state.ISMLocking.ReadLock)

Example 2 with ReadLock

use of org.apache.jackrabbit.core.state.ISMLocking.ReadLock in project jackrabbit by apache.

the class AbstractISMLockingTest method testDowngrade.

/**
     * Checks if a downgraded write lock allows other threads to read again.
     *
     * @throws InterruptedException on interruption; this will err the test
     */
public void testDowngrade() throws InterruptedException {
    for (ChangeLog changeLog : logs) {
        WriteLock wLock = locking.acquireWriteLock(changeLog);
        verifyBlocked(startReaderThread(locking, state.getId()));
        ReadLock rLock = wLock.downgrade();
        verifyNotBlocked(startReaderThread(locking, state.getId()));
        rLock.release();
    }
}
Also used : ReadLock(org.apache.jackrabbit.core.state.ISMLocking.ReadLock) WriteLock(org.apache.jackrabbit.core.state.ISMLocking.WriteLock)

Example 3 with ReadLock

use of org.apache.jackrabbit.core.state.ISMLocking.ReadLock in project jackrabbit by apache.

the class DefaultISMLockingDeadlockTest method test.

public void test() throws InterruptedException {
    final ISMLocking lock = new DefaultISMLocking();
    WriteLock w1 = lock.acquireWriteLock(null);
    ReadLock r1 = w1.downgrade();
    final InterruptedException[] ex = new InterruptedException[1];
    Thread thread = new Thread() {

        public void run() {
            try {
                lock.acquireWriteLock(null).release();
            } catch (InterruptedException e) {
                ex[0] = e;
            }
        }
    };
    thread.start();
    Thread.sleep(100);
    lock.acquireReadLock(null).release();
    r1.release();
    thread.join();
    if (ex[0] != null) {
        throw ex[0];
    }
}
Also used : ISMLocking(org.apache.jackrabbit.core.state.ISMLocking) DefaultISMLocking(org.apache.jackrabbit.core.state.DefaultISMLocking) ReadLock(org.apache.jackrabbit.core.state.ISMLocking.ReadLock) WriteLock(org.apache.jackrabbit.core.state.ISMLocking.WriteLock) DefaultISMLocking(org.apache.jackrabbit.core.state.DefaultISMLocking)

Aggregations

ReadLock (org.apache.jackrabbit.core.state.ISMLocking.ReadLock)3 WriteLock (org.apache.jackrabbit.core.state.ISMLocking.WriteLock)2 DefaultISMLocking (org.apache.jackrabbit.core.state.DefaultISMLocking)1 ISMLocking (org.apache.jackrabbit.core.state.ISMLocking)1