use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testConstructor7.
/**
* Queue contains all elements of collection used to initialize
*/
@Ignore
@Test
public void testConstructor7() {
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i) ints[i] = i;
Collection<Integer> elements = Arrays.asList(ints);
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE, true, elements);
for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll());
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testTimedOffer.
/**
* timed offer times out if full and elements not taken
*/
@Ignore
@Test
public void testTimedOffer() throws InterruptedException {
final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(new Object());
q.put(new Object());
long startTime = System.nanoTime();
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
pleaseInterrupt.countDown();
try {
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testBlockingPut.
/**
* put blocks interruptibly if full
*/
@Test
public void testBlockingPut() throws InterruptedException {
final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < SIZE; ++i) q.put(i);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
Thread.currentThread().interrupt();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testAdd.
/**
* add succeeds if not full; throws ISE if full
*/
@Test
public void testAdd() {
try {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.add(new Integer(i)));
}
assertEquals(0, q.remainingCapacity());
q.add(new Integer(SIZE));
shouldThrow();
} catch (IllegalStateException success) {
}
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testPutWithTake.
/**
* put blocks interruptibly waiting for take when full
*/
@Test
public void testPutWithTake() throws InterruptedException {
final int capacity = 2;
final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(capacity);
final CountDownLatch pleaseTake = new CountDownLatch(1);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < capacity; i++) q.put(i);
pleaseTake.countDown();
q.put(86);
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
assertEquals(0, q.take());
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
Aggregations