Search in sources :

Example 36 with BBContainer

use of org.voltcore.utils.DBBPool.BBContainer 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)

Example 37 with BBContainer

use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testCloseOldSegments.

@Test
public void testCloseOldSegments() throws Exception {
    System.out.println("Running testCloseOldSegments");
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
    final int total = 100;
    //Make sure several files with the appropriate data is created
    for (int i = 0; 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 = 0; i < total; i++) {
        BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        retval.discard();
    }
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) BBContainer(org.voltcore.utils.DBBPool.BBContainer) File(java.io.File) Test(org.junit.Test)

Example 38 with BBContainer

use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testOfferMaxSize.

@Test
public void testOfferMaxSize() throws Exception {
    System.out.println("Running testOfferMaxSize");
    BBContainer cont = DBBPool.wrapBB(ByteBuffer.allocateDirect(1024 * 1024 * 64));
    try {
        m_pbd.offer(cont);
    } catch (IOException e) {
        return;
    } finally {
        cont.discard();
    }
    fail();
}
Also used : BBContainer(org.voltcore.utils.DBBPool.BBContainer) IOException(java.io.IOException) Test(org.junit.Test)

Example 39 with BBContainer

use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testOfferCloseReopenOffer.

@Test
public void testOfferCloseReopenOffer() throws Exception {
    System.out.println("Running testOfferCloseThenReopen");
    //Make it create two full segments
    for (int ii = 0; ii < 96; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    File[] files = TEST_DIR.listFiles();
    assertEquals(3, files.length);
    m_pbd.sync();
    m_pbd.close();
    m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    int cnt = reader.getNumObjects();
    assertEquals(cnt, 96);
    for (int ii = 96; ii < 192; ii++) {
        m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
    }
    m_pbd.sync();
    cnt = reader.getNumObjects();
    assertEquals(cnt, 192);
    //Now poll all of it and make sure the data is correct
    for (int ii = 0; ii < 192; ii++) {
        ByteBuffer defaultBuffer = getFilledBuffer(ii);
        BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        try {
            assertTrue(defaultBuffer.equals(retval.b()));
        } finally {
            retval.discard();
        }
        defaultBuffer.clear();
    }
    //Expect just the current write segment
    TreeSet<String> names = getSortedDirectoryListing();
    assertEquals(1, names.size());
    assertTrue(names.first().equals("pbd_nonce.5.pbd"));
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) BBContainer(org.voltcore.utils.DBBPool.BBContainer) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 40 with BBContainer

use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.

the class TestPersistentBinaryDeque method testOfferCloseThenReopen.

@Test
public void testOfferCloseThenReopen() throws Exception {
    System.out.println("Running testOfferCloseThenReopen");
    //Make it create two full segments
    for (int ii = 0; ii < 96; ii++) {
        m_pbd.offer(defaultContainer());
    }
    File[] files = TEST_DIR.listFiles();
    assertEquals(3, files.length);
    m_pbd.sync();
    m_pbd.close();
    m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    ByteBuffer defaultBuffer = defaultBuffer();
    //Now poll all of it and make sure the data is correct
    for (int ii = 0; ii < 96; ii++) {
        defaultBuffer.clear();
        BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        assertTrue(defaultBuffer.equals(retval.b()));
        retval.discard();
    }
    //Expect just the current write segment
    TreeSet<String> names = getSortedDirectoryListing();
    assertEquals(1, names.size());
    assertTrue(names.first().equals("pbd_nonce.3.pbd"));
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) BBContainer(org.voltcore.utils.DBBPool.BBContainer) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

BBContainer (org.voltcore.utils.DBBPool.BBContainer)57 Test (org.junit.Test)22 ByteBuffer (java.nio.ByteBuffer)21 BinaryDequeReader (org.voltdb.utils.BinaryDeque.BinaryDequeReader)18 IOException (java.io.IOException)15 File (java.io.File)10 JSONObject (org.json_voltpatches.JSONObject)4 BinaryDequeTruncator (org.voltdb.utils.BinaryDeque.BinaryDequeTruncator)4 TruncatorResponse (org.voltdb.utils.BinaryDeque.TruncatorResponse)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 FileInputStream (java.io.FileInputStream)2 Collection (java.util.Collection)2 Random (java.util.Random)2 Callable (java.util.concurrent.Callable)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 PureJavaCrc32C (org.apache.hadoop_voltpatches.util.PureJavaCrc32C)2 JSONException (org.json_voltpatches.JSONException)2 JSONString (org.json_voltpatches.JSONString)2 HashinatorConfig (org.voltdb.TheHashinator.HashinatorConfig)2