public void testWriteFileThenRemountFSAndRead() throws Exception {
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(