assertEquals( 3, files.length);
//Now create two buffers with different data to push at the front
final ByteBuffer buffer1 = getFilledBuffer(16);
final ByteBuffer buffer2 = getFilledBuffer(32);
BBContainer pushContainers[] = new BBContainer[2];
pushContainers[0] = DBBPool.dummyWrapBB(buffer1);
pushContainers[1] = DBBPool.dummyWrapBB(buffer2);
m_pbd.push(pushContainers);
assertEquals( 1024 * 1024 * 2 * 98, m_pbd.sizeInBytes());
//Expect this to create a single new file
TreeSet<String> names = getSortedDirectoryListing();
assertEquals( 4, names.size());
assertTrue(names.first().equals("pbd_nonce.-1.pbd"));
assertTrue(names.contains("pbd_nonce.0.pbd"));
assertTrue(names.contains("pbd_nonce.1.pbd"));
assertTrue(names.last().equals("pbd_nonce.2.pbd"));
//Poll the two at the front and check that the contents are what is expected
BBContainer retval1 = m_pbd.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
buffer1.clear();
System.err.println(Long.toHexString(buffer1.getLong(0)) + " " + Long.toHexString(retval1.b().getLong(0)));
assertEquals(retval1.b(), buffer1);
assertEquals(1024 * 1024 * 2 * 97, m_pbd.sizeInBytes());
BBContainer retval2 = m_pbd.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
buffer2.clear();
assertEquals(retval2.b(), buffer2);
assertEquals(1024 * 1024 * 2 * 96, m_pbd.sizeInBytes());
//Expect the file for the two polled objects to still be there
//until the discard
names = getSortedDirectoryListing();
assertEquals( 4, names.size());
} finally {
retval2.discard();
}
} finally {
retval1.discard();
}
assertEquals(1024 * 1024 * 2 * 96, m_pbd.sizeInBytes());
names = getSortedDirectoryListing();
assertEquals( 3, names.size());
assertTrue(names.first().equals("pbd_nonce.0.pbd"));
ByteBuffer defaultBuffer = defaultBuffer();
//Now poll the rest and make sure the data is correct
for (int ii = 0; ii < 96; ii++) {
defaultBuffer.clear();
BBContainer retval = m_pbd.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
assertTrue(defaultBuffer.equals(retval.b()));
retval.discard();
}
assertEquals( 0, m_pbd.sizeInBytes());
assertTrue(m_pbd.isEmpty());