Search in sources :

Example 1 with BlockingDeque

use of java.util.concurrent.BlockingDeque in project mapdb by jankotek.

the class LinkedBlockingDequeTest method testTakeLastFromEmptyBlocksInterruptibly.

/**
     * takeLast() blocks interruptibly when empty
     */
public void testTakeLastFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingDeque(java.util.concurrent.BlockingDeque) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with BlockingDeque

use of java.util.concurrent.BlockingDeque in project mapdb by jankotek.

the class LinkedBlockingDequeTest method testTakeLastFromEmptyAfterInterrupt.

/**
     * takeLast() throws InterruptedException immediately if interrupted
     * before waiting
     */
public void testTakeLastFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingDeque(java.util.concurrent.BlockingDeque) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 3 with BlockingDeque

use of java.util.concurrent.BlockingDeque in project mapdb by jankotek.

the class LinkedBlockingDequeTest method testTakeFirstFromEmptyAfterInterrupt.

/**
     * takeFirst() throws InterruptedException immediately if interrupted
     * before waiting
     */
public void testTakeFirstFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingDeque(java.util.concurrent.BlockingDeque) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 4 with BlockingDeque

use of java.util.concurrent.BlockingDeque in project mapdb by jankotek.

the class LinkedBlockingDequeTest method testTakeFirstFromEmptyBlocksInterruptibly.

/**
     * takeFirst() blocks interruptibly when empty
     */
public void testTakeFirstFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingDeque(java.util.concurrent.BlockingDeque) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

BlockingDeque (java.util.concurrent.BlockingDeque)4 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)4 CountDownLatch (java.util.concurrent.CountDownLatch)2