@Test
public void writeAndRead() throws Exception {
Utils.DO_CLEAR = false;
LOG.info("BEGIN writeAndRead");
VMWareDisk disk = new VMWareDisk(diskFile);
// write
LOG.info("writeAndRead: writing...");
int size = IOHandler.SECTOR_SIZE * 100;
ByteBuffer expectedData = IOUtils.allocate(size);
for (int i = 0; i < (size / 4); i++) {
expectedData.putInt(i);
}
expectedData.rewind();
disk.write(0, expectedData);
disk.flush();
// read
LOG.info("writeAndRead: reading...");
VMWareDisk disk2 = new VMWareDisk(diskFile);
Assert.assertEquals("disk has different size", disk.getLength(), disk2.getLength());
Assert.assertEquals("disk has different descriptor", disk.getDescriptor(), disk2
.getDescriptor());
expectedData.rewind();
ByteBuffer actualData = IOUtils.allocate(size);
disk2.read(0, actualData);
for (int i = 0; i < (size / 4); i++) {
int actual = actualData.getInt(i);
int expected = expectedData.getInt();
Assert.assertEquals("bad data at index " + (i * 4), expected, actual);
}