use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testCloseEmptyShouldNotDelete.
@Test
public void testCloseEmptyShouldNotDelete() throws Exception {
System.out.println("Running testCloseEmptyShouldNotDelete");
TreeSet<String> listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd.close();
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd.parseAndTruncate(new BinaryDequeTruncator() {
@Override
public TruncatorResponse parse(BBContainer bbc) {
fail();
return null;
}
});
for (int ii = 0; ii < 96; ii++) {
m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
}
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
for (long ii = 0; ii < 96; ii++) {
BBContainer cont = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
assertNotNull(cont);
assertEquals(cont.b().remaining(), 1024 * 1024 * 2);
while (cont.b().remaining() > 15) {
assertEquals(ii, cont.b().getLong());
cont.b().getLong();
}
} catch (Throwable t) {
System.err.println("Something threw");
t.printStackTrace();
throw t;
} finally {
cont.discard();
}
}
}
use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testDontCloseReadSegment.
@Test
public void testDontCloseReadSegment() throws Exception {
System.out.println("Running testOfferPollOfferMoreThanPoll");
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
final int total = 100;
//Make sure a single file with the appropriate data is created
for (int i = 0; i < 5; i++) {
m_pbd.offer(defaultContainer());
}
assertEquals(1, TEST_DIR.listFiles().length);
// Read one buffer from the segment so that it's considered being polled from.
reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY).discard();
for (int i = 5; i < total; i++) {
m_pbd.offer(defaultContainer());
}
File[] files = TEST_DIR.listFiles();
assertEquals(3, files.length);
Set<String> actualFiles = Sets.newHashSet();
for (File f : files) {
actualFiles.add(f.getName());
}
Set<String> expectedFiles = Sets.newHashSet();
for (int i = 0; i < 3; i++) {
expectedFiles.add("pbd_nonce." + i + ".pbd");
}
Assert.assertEquals(expectedFiles, actualFiles);
//Now make sure the current write file is stolen and a new write file created
for (int i = 1; i < total; i++) {
BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
retval.discard();
}
}
use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPBDMultipleReaders method testOpenReaders.
@Test
public void testOpenReaders() throws Exception {
String cursorId = "reader";
BinaryDequeReader reader1 = m_pbd.openForRead(cursorId);
BinaryDequeReader reader2 = m_pbd.openForRead(cursorId);
BinaryDequeReader another = m_pbd.openForRead("another");
assertTrue(reader1 == reader2);
assertFalse(reader1 == another);
int numBuffers = 50;
for (int i = 0; i < numBuffers; i++) {
m_pbd.offer(DBBPool.wrapBB(TestPersistentBinaryDeque.getFilledBuffer(i)));
}
for (int j = 0; j < numBuffers; j++) {
BBContainer bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
bbC.discard();
}
assertTrue(reader1.isEmpty());
assertTrue(reader2.isEmpty());
assertFalse(another.isEmpty());
}
use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPBDMultipleReaders method testSegmentClosingWriterReaderLockStep.
@Test
public void testSegmentClosingWriterReaderLockStep() throws Exception {
assertEquals(1, m_pbd.numOpenSegments());
BinaryDequeReader reader = m_pbd.openForRead("reader0");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < s_segmentFillCount; j++) {
m_pbd.offer(DBBPool.wrapBB(TestPersistentBinaryDeque.getFilledBuffer(j)));
BBContainer bbC = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
bbC.discard();
}
assertEquals(1, m_pbd.numOpenSegments());
}
}
use of org.voltdb.utils.BinaryDeque.BinaryDequeReader in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testTruncateFirstElement.
@Test
public void testTruncateFirstElement() throws Exception {
System.out.println("Running testTruncateFirstElement");
TreeSet<String> listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
for (int ii = 0; ii < 150; ii++) {
m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
}
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 4);
m_pbd.close();
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 4);
m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 5);
m_pbd.parseAndTruncate(new BinaryDequeTruncator() {
@Override
public TruncatorResponse parse(BBContainer bbc) {
return PersistentBinaryDeque.fullTruncateResponse();
}
});
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
}
Aggregations