FileSystem fs = cluster.getFileSystem(conf);
try {
DFSWriteProfilingData profile = new DFSWriteProfilingData();
DFSClient.setProfileDataForNextOutputStream(profile);
// create a new file.
Path file1 = new Path("/simpleFlush.dat");
FSDataOutputStream stm = createFile(fs, file1, 3);
System.out.println("Created file simpleFlush.dat");
// write to file
int mid = fileSize/2;
try {
stm.write(fileContents, 0, mid);
stm.sync();
if (!datnodeInlineChecksum && clientInlineChecksum) {
TestCase
.fail("Client should fail writing to datanode with inline checksum disabled with inline checksum enabled in client side");
}
} catch (IOException ioe) {
if (datnodeInlineChecksum || !clientInlineChecksum) {
throw ioe;
} else {
return;
}
}
System.out.println("Wrote and Flushed first part of file.");
// write the remainder of the file
stm.write(fileContents, mid, fileSize - mid);
System.out.println("Written second part of file");
stm.sync();
stm.sync();
System.out.println("Wrote and Flushed second part of file.");
// verify that full blocks are sane
checkFile(fs, file1, 1);
stm.close();
System.out.println("Closed file.");
// verify that entire file is good
checkFullFile(fs, file1);
System.out.println("Profile: " + profile.toString());
} catch (IOException e) {
System.out.println("Exception :" + e);
throw e;
} catch (Throwable e) {