use of org.neo4j.kernel.impl.util.IdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldHaveOneThreadWaitForARemoval.
@Test
public void shouldHaveOneThreadWaitForARemoval() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
queue.offer(3);
queue.offer(5);
// WHEN another thread comes in and awaits 5
OtherThreadExecutor<Void> t2 = cleanup.add(new OtherThreadExecutor<Void>("T2", null));
Future<Object> await5 = t2.executeDontWait(awaitHead(queue, 5));
t2.waitUntilWaiting();
// ... and head (3) gets removed
queue.removeChecked(3);
// THEN the other thread should be OK to continue
await5.get();
}
use of org.neo4j.kernel.impl.util.IdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldOfferQueueABunchOfIds.
@Test
public void shouldOfferQueueABunchOfIds() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
// WHEN
for (int i = 0; i < 7; i++) {
queue.offer(i);
}
// THEN
for (int i = 0; i < 7; i++) {
assertFalse(queue.isEmpty());
queue.waitFor(i);
queue.removeChecked(i);
}
assertTrue(queue.isEmpty());
}
use of org.neo4j.kernel.impl.util.IdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldOfferAwaitAndRemoveRoundAndRound.
@Test
public void shouldOfferAwaitAndRemoveRoundAndRound() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
long offeredId = 0, awaitedId = 0;
queue.offer(offeredId++);
queue.offer(offeredId++);
// WHEN
for (int i = 0; i < 20; i++) {
queue.waitFor(awaitedId);
queue.removeChecked(awaitedId++);
queue.offer(offeredId++);
assertFalse(queue.isEmpty());
}
// THEN
queue.removeChecked(awaitedId++);
queue.removeChecked(awaitedId++);
assertTrue(queue.isEmpty());
}
use of org.neo4j.kernel.impl.util.IdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldExtendArrayWhenIdsAreWrappingAround.
@Test
public void shouldExtendArrayWhenIdsAreWrappingAround() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
for (int i = 0; i < 3; i++) {
queue.offer(i);
queue.removeChecked(i);
}
// ^-- headIndex and offerIndex
for (int i = 3; i < 8; i++) {
queue.offer(i);
}
// Now we're at [5,6,2,3,4]
// ^-- headIndex and offerIndex%length
// WHEN offering one more, so that the queue is forced to resize
queue.offer(8);
// THEN it should have been offered as well as all the previous ids should be intact
for (int i = 3; i <= 8; i++) {
assertFalse(queue.isEmpty());
queue.removeChecked(i);
}
assertTrue(queue.isEmpty());
}
Aggregations