b2.insert(34823, 348234823L);
File f = FileSupport.createTempFile();
try
{
RandomAccess ra = new ReadWritableFileAdapter(f).openForRandomAccess(RandomAccessMode.READ_WRITE);
try
{
long dataSize = b1.writeContentsTo(ra);
ra.seek(0);
int contentsVersion = b2.getContentsVersion();
b2.replaceContentsWith(ra, dataSize);
assertFalse(contentsVersion == b2.getContentsVersion());
assertEquals(3, b2.getKeys().size());
assertRecordEquals(new Record<Integer, Long>(23, 234923L), b2, b2.find(23));
assertRecordEquals(new Record<Integer, Long>(23823, 348723823L), b2, b2.find(23823));
assertRecordEquals(new Record<Integer, Long>(-27237, -23823832L), b2, b2.find(-27237));
// Try to feed it invalid data
ra.seek(1);
try
{
b2.replaceContentsWith(ra, dataSize - 1);
fail();
}
catch (RuntimeException e)
{
// ok
}
}
finally
{
ra.close();
}
}
finally
{
assertTrue(f.delete());