DummyFileOutputFormat dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
dfof.configure(new Configuration());
boolean exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
// check success if directory exists
tmpOutPath.delete();
Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
// check success
tmpOutPath.delete();
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
// ----------- test again with always directory mode
// check success if file exists
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
// check success if directory exists
tmpOutFile.delete();
tmpOutPath.delete();
Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
// check success if file in directory exists
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();
} catch (Exception e) {
exception = true;
}
Assert.assertTrue(!exception);
Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
// check success if no file exists
// delete existing files
tmpOutFile.delete();
tmpOutPath.delete();
dfof = new DummyFileOutputFormat();
dfof.setOutputFilePath(new Path(tmpFilePath));
dfof.setWriteMode(WriteMode.OVERWRITE);
dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
dfof.configure(new Configuration());
exception = false;
try {
dfof.open(0, 1);
dfof.close();