Search in sources :

Example 16 with BinaryDequeReader

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

the class TestPersistentBinaryDeque method testPollWhileClosed.

@Test
public void testPollWhileClosed() throws Exception {
    System.out.println("Running testPollWhileClosed");
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    m_pbd.close();
    try {
        reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
    } catch (IOException e) {
        return;
    }
    fail();
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with BinaryDequeReader

use of org.voltdb.utils.BinaryDeque.BinaryDequeReader 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)

Example 18 with BinaryDequeReader

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

the class TestPersistentBinaryDeque method testOfferThenPoll.

@Test
public void testOfferThenPoll() throws Exception {
    System.out.println("Running testOfferThanPoll");
    BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
    assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
    //Make sure a single file with the appropriate data is created
    m_pbd.offer(defaultContainer());
    File[] files = TEST_DIR.listFiles();
    assertEquals(1, files.length);
    assertTrue("pbd_nonce.0.pbd".equals(files[0].getName()));
    //Now make sure the current write file is stolen and a new write file created
    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 19 with BinaryDequeReader

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

the class TestPBDMultipleReaders method testSegmentClosingWriterMultipleReaders.

@Test
public void testSegmentClosingWriterMultipleReaders() throws Exception {
    assertEquals(1, m_pbd.numOpenSegments());
    int numSegments = 5;
    for (int i = 0; i < numSegments; i++) {
        for (int j = 0; j < s_segmentFillCount; j++) {
            m_pbd.offer(DBBPool.wrapBB(TestPersistentBinaryDeque.getFilledBuffer(j)));
        }
        assertEquals(1, m_pbd.numOpenSegments());
    }
    BinaryDequeReader reader0 = m_pbd.openForRead("reader0");
    BinaryDequeReader reader1 = m_pbd.openForRead("reader1");
    // Position first reader0 on penultimate segment and reader1 on first segment
    for (int i = 0; i < numSegments - 1; i++) {
        for (int j = 0; j < 46; j++) {
            BBContainer bbC = reader0.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
            bbC.discard();
            if (i == 0) {
                bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
                bbC.discard();
            }
        }
        BBContainer bbC = reader0.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        bbC.discard();
        if (i == 0) {
            assertEquals(2, m_pbd.numOpenSegments());
        } else {
            assertEquals(3, m_pbd.numOpenSegments());
        }
    }
    BBContainer bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
    bbC.discard();
    // Both readers finished reading first segment, so that is closed and deleted,
    // which reduces the # of open segments by 1
    assertEquals(2, m_pbd.numOpenSegments());
    // reader0 at penultimate. Move reader1 through segments and check open segments
    for (int i = 1; i < numSegments - 1; i++) {
        for (int j = 0; j < 46; j++) {
            bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
            bbC.discard();
        }
        int expected = (i == numSegments - 2) ? 2 : 3;
        assertEquals(expected, m_pbd.numOpenSegments());
        bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        bbC.discard();
        expected = (i == numSegments - 2) ? 1 : 2;
        assertEquals(expected, m_pbd.numOpenSegments());
    }
    // read the last segment
    for (int j = 0; j < s_segmentFillCount; j++) {
        bbC = reader0.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        bbC.discard();
        bbC = reader1.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        bbC.discard();
    }
    assertEquals(1, m_pbd.numOpenSegments());
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) BBContainer(org.voltcore.utils.DBBPool.BBContainer) Test(org.junit.Test)

Example 20 with BinaryDequeReader

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

the class TestPBDMultipleReaders method testSegmentClosingWriterReader.

@Test
public void testSegmentClosingWriterReader() throws Exception {
    assertEquals(1, m_pbd.numOpenSegments());
    int numSegments = 3;
    for (int i = 0; i < numSegments; i++) {
        for (int j = 0; j < s_segmentFillCount; j++) {
            m_pbd.offer(DBBPool.wrapBB(TestPersistentBinaryDeque.getFilledBuffer(j)));
        }
        assertEquals(1, m_pbd.numOpenSegments());
    }
    BinaryDequeReader reader = m_pbd.openForRead("reader0");
    for (int i = 0; i < numSegments; i++) {
        for (int j = 0; j < 46; j++) {
            BBContainer bbC = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
            bbC.discard();
        }
        int expected = (i == numSegments - 1) ? 1 : 2;
        assertEquals(expected, m_pbd.numOpenSegments());
        BBContainer bbC = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
        bbC.discard();
        // there should only be 1 open because last discard closes and deletes
        assertEquals(1, m_pbd.numOpenSegments());
    }
}
Also used : BinaryDequeReader(org.voltdb.utils.BinaryDeque.BinaryDequeReader) BBContainer(org.voltcore.utils.DBBPool.BBContainer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 BinaryDequeReader (org.voltdb.utils.BinaryDeque.BinaryDequeReader)22 BBContainer (org.voltcore.utils.DBBPool.BBContainer)18 File (java.io.File)9 ByteBuffer (java.nio.ByteBuffer)8 BinaryDequeTruncator (org.voltdb.utils.BinaryDeque.BinaryDequeTruncator)4 TruncatorResponse (org.voltdb.utils.BinaryDeque.TruncatorResponse)4 IOException (java.io.IOException)2