Search in sources :

Example 1 with TruncatorResponse

use of org.voltdb.utils.BinaryDeque.TruncatorResponse 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();
        }
    }
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) TruncatorResponse(org.voltdb.utils.BinaryDeque.TruncatorResponse) BBContainer(org.voltcore.utils.DBBPool.BBContainer) BinaryDequeTruncator(org.voltdb.utils.BinaryDeque.BinaryDequeTruncator) Test(org.junit.Test)

Example 2 with TruncatorResponse

use of org.voltdb.utils.BinaryDeque.TruncatorResponse 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));
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) TruncatorResponse(org.voltdb.utils.BinaryDeque.TruncatorResponse) BBContainer(org.voltcore.utils.DBBPool.BBContainer) BinaryDequeTruncator(org.voltdb.utils.BinaryDeque.BinaryDequeTruncator) Test(org.junit.Test)

Example 3 with TruncatorResponse

use of org.voltdb.utils.BinaryDeque.TruncatorResponse in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testTruncator.

@Test
public void testTruncator() throws Exception {
    System.out.println("Running testTruncator");
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
    for (int ii = 0; ii < 160; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    m_pbd.close();
    m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
    TreeSet<String> listing = getSortedDirectoryListing();
    assertEquals(listing.size(), 5);
    m_pbd.parseAndTruncate(new BinaryDequeTruncator() {

        private long m_objectsParsed = 0;

        @Override
        public TruncatorResponse parse(BBContainer bbc) {
            ByteBuffer b = bbc.b();
            assertEquals(b.getLong(0), m_objectsParsed);
            assertEquals(b.remaining(), 1024 * 1024 * 2);
            if (b.getLong(0) == 45) {
                b.limit(b.remaining() / 2);
                return new PersistentBinaryDeque.ByteBufferTruncatorResponse(b.slice());
            }
            while (b.remaining() > 15) {
                assertEquals(b.getLong(), m_objectsParsed);
                b.getLong();
            }
            m_objectsParsed++;
            return null;
        }
    });
    reader = m_pbd.openForRead(CURSOR_ID);
    assertEquals(95420416, reader.sizeInBytes());
    listing = getSortedDirectoryListing();
    assertEquals(listing.size(), 2);
    for (int ii = 46; ii < 96; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    long actualSizeInBytes = 0;
    long reportedSizeInBytes = reader.sizeInBytes();
    long blocksFound = 0;
    BBContainer cont = null;
    while ((cont = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY)) != null) {
        try {
            ByteBuffer buffer = cont.b();
            if (blocksFound == 45) {
                assertEquals(buffer.remaining(), 1024 * 1024);
            } else {
                assertEquals(buffer.remaining(), 1024 * 1024 * 2);
            }
            actualSizeInBytes += buffer.remaining();
            while (buffer.remaining() > 15) {
                assertEquals(buffer.getLong(), blocksFound);
                buffer.getLong();
            }
        } finally {
            blocksFound++;
            cont.discard();
        }
    }
    assertEquals(actualSizeInBytes, reportedSizeInBytes);
    assertEquals(blocksFound, 96);
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) TruncatorResponse(org.voltdb.utils.BinaryDeque.TruncatorResponse) BBContainer(org.voltcore.utils.DBBPool.BBContainer) BinaryDequeTruncator(org.voltdb.utils.BinaryDeque.BinaryDequeTruncator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with TruncatorResponse

use of org.voltdb.utils.BinaryDeque.TruncatorResponse in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testTruncatorWithFullTruncateReturn.

@Test
public void testTruncatorWithFullTruncateReturn() throws Exception {
    System.out.println("Running testTruncatorWithFullTruncateReturn");
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
    for (int ii = 0; ii < 150; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    m_pbd.close();
    m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
    TreeSet<String> listing = getSortedDirectoryListing();
    assertEquals(listing.size(), 5);
    m_pbd.parseAndTruncate(new BinaryDequeTruncator() {

        private long m_objectsParsed = 0;

        @Override
        public TruncatorResponse parse(BBContainer bbc) {
            ByteBuffer b = bbc.b();
            if (b.getLong(0) != m_objectsParsed) {
                System.out.println("asd");
            }
            assertEquals(b.getLong(0), m_objectsParsed);
            assertEquals(b.remaining(), 1024 * 1024 * 2);
            if (b.getLong(0) == 45) {
                b.limit(b.remaining() / 2);
                return PersistentBinaryDeque.fullTruncateResponse();
            }
            while (b.remaining() > 15) {
                assertEquals(b.getLong(), m_objectsParsed);
                b.getLong();
            }
            m_objectsParsed++;
            return null;
        }
    });
    listing = getSortedDirectoryListing();
    assertEquals(listing.size(), 2);
    for (int ii = 46; ii < 96; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    reader = m_pbd.openForRead(CURSOR_ID);
    long actualSizeInBytes = 0;
    long reportedSizeInBytes = reader.sizeInBytes();
    long blocksFound = 0;
    BBContainer cont = null;
    while ((cont = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY)) != null) {
        try {
            ByteBuffer buffer = cont.b();
            if (blocksFound == 45) {
                //white lie, so we expect the right block contents
                blocksFound++;
            }
            assertEquals(buffer.remaining(), 1024 * 1024 * 2);
            actualSizeInBytes += buffer.remaining();
            while (buffer.remaining() > 15) {
                assertEquals(buffer.getLong(), blocksFound);
                buffer.getLong();
            }
        } finally {
            blocksFound++;
            cont.discard();
        }
    }
    assertEquals(actualSizeInBytes, reportedSizeInBytes);
    assertEquals(blocksFound, 96);
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) TruncatorResponse(org.voltdb.utils.BinaryDeque.TruncatorResponse) BBContainer(org.voltcore.utils.DBBPool.BBContainer) BinaryDequeTruncator(org.voltdb.utils.BinaryDeque.BinaryDequeTruncator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 BBContainer (org.voltcore.utils.DBBPool.BBContainer)4 BinaryDequeReader (org.voltdb.utils.BinaryDeque.BinaryDequeReader)4 BinaryDequeTruncator (org.voltdb.utils.BinaryDeque.BinaryDequeTruncator)4 TruncatorResponse (org.voltdb.utils.BinaryDeque.TruncatorResponse)4 ByteBuffer (java.nio.ByteBuffer)2