setUp();
final String fileName = "RWTest";
FSDirectory rootDir = getFs().getRootEntry().getDirectory();
FSFile file = null;
ByteBuffer data = ByteBuffer.wrap(TestUtils.getTestData(FILE_SIZE_IN_WORDS));
if (config.isReadOnly()) {
try {
file = rootDir.addFile(fileName).getFile();
fail("addFile must throw ReadOnlyFileSystemException in readOnly mode");
} catch (ReadOnlyFileSystemException rofse) {
// success
}
} else {
file = rootDir.addFile(fileName).getFile();
file.write(0, data);
file.flush();
assertSize("bad file.length after write", data.capacity(), file.getLength());
}
remountFS(config, config.isReadOnly());
if (!config.isReadOnly()) {
FSDirectory rootDir2 = getFs().getRootEntry().getDirectory();
FSFile file2 = rootDir2.getEntry(fileName).getFile();
assertNotNull("file not saved", file2);
assertSize("bad file.length after remount", data.capacity(), file2.getLength());
ByteBuffer data2 = ByteBuffer.allocate(data.capacity());
log.debug(
getFs().getClass().getName() + ": buffer after alloc\n" + FSUtils.toString(data2.array(), 0, 512));
file2.read(0, data2);
log.debug(getFs().getClass().getName() + ": buffer after read\n" + FSUtils.toString(data2.array(), 0, 512));
assertTrue("read and written data are differents", TestUtils.equals(data.array(), data2.array()));
}
}