use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testReaderNumObjects.
@Test
public void testReaderNumObjects() throws Exception {
System.out.println("Running testReaderNumObjects");
String cursor1 = "testPBD1";
BinaryDequeReader reader1 = m_pbd.openForRead(cursor1);
int count = 0;
int totalAdded = 0;
assertEquals(count, reader1.getNumObjects());
assertNull(reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
assertEquals(count, reader1.getNumObjects());
count++;
m_pbd.offer(defaultContainer());
totalAdded++;
assertEquals(count, reader1.getNumObjects());
// a second reader
String cursor2 = "testPBD2";
BinaryDequeReader reader2 = m_pbd.openForRead(cursor2);
pollDiscard(reader1);
assertEquals(count - 1, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
pollDiscard(reader2);
count--;
assertEquals(count, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
// offer segments
for (int i = 0; i < 50; i++) {
m_pbd.offer(defaultContainer());
totalAdded++;
count++;
assertEquals(count, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
}
for (int i = 0; i < 50; i++) {
pollDiscard(reader1);
assertEquals(count - 1, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
pollDiscard(reader2);
count--;
assertEquals(count, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
}
final int segmentfullCount = 47;
// start a 3rd reader after segments have been deleted
String cursor3 = "testPBD3";
BinaryDequeReader lateReader = m_pbd.openForRead(cursor3);
int toAddForLate = totalAdded % segmentfullCount;
assertEquals(count + toAddForLate, lateReader.getNumObjects());
// offer segments with all 3 readers
for (int i = 0; i < 50; i++) {
m_pbd.offer(defaultContainer());
count++;
assertEquals(count, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
assertEquals(count + toAddForLate, lateReader.getNumObjects());
}
for (int i = 0; i < 50; i++) {
pollDiscard(reader1);
assertEquals(count - 1, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
assertEquals(count + toAddForLate, lateReader.getNumObjects());
pollDiscard(reader2);
assertEquals(count - 1, reader1.getNumObjects());
assertEquals(count - 1, reader2.getNumObjects());
assertEquals(count + toAddForLate, lateReader.getNumObjects());
pollDiscard(lateReader);
count--;
assertEquals(count, reader1.getNumObjects());
assertEquals(count, reader2.getNumObjects());
assertEquals(count + toAddForLate, lateReader.getNumObjects());
}
assert (count == 0);
for (int i = 0; i < toAddForLate; i++) {
pollDiscard(lateReader);
assertEquals(toAddForLate - i - 1, lateReader.getNumObjects());
}
assertEquals(0, reader1.getNumObjects());
assertEquals(0, reader2.getNumObjects());
assertEquals(0, lateReader.getNumObjects());
}
use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testNonceWithDots.
@Test
public void testNonceWithDots() throws Exception {
System.out.println("Running testNonceWithDots");
PersistentBinaryDeque pbd = new PersistentBinaryDeque("ha.ha", TEST_DIR, logger);
pbd.offer(defaultContainer());
pbd.close();
pbd = new PersistentBinaryDeque("ha.ha", TEST_DIR, logger);
BinaryDequeReader reader = pbd.openForRead(CURSOR_ID);
BBContainer bb = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
ByteBuffer defaultBuffer = defaultBuffer();
defaultBuffer.clear();
assertEquals(defaultBuffer, bb.b());
pbd.close();
} finally {
bb.discard();
}
}
Aggregations