final String exceptionClassName = ExceptionTask.class.getSimpleName();
File inputFile = null;
File outputFile = null;
File jarFile = null;
JobClient jobClient = null;
try {
inputFile = ServerTestUtils.createInputFile(0);
outputFile = new File(ServerTestUtils.getTempDir() + File.separator + ServerTestUtils.getRandomFilename());
jarFile = ServerTestUtils.createJarFile(exceptionClassName);
// Create job graph
final JobGraph jg = new JobGraph("Job Graph for Exception Test");
// input vertex
final JobFileInputVertex i1 = new JobFileInputVertex("Input 1", jg);
i1.setFileInputClass(FileLineReader.class);
i1.setFilePath(new Path(inputFile.toURI()));
// task vertex 1
final JobTaskVertex t1 = new JobTaskVertex("Task with Exception", jg);
t1.setTaskClass(ExceptionTask.class);
// output vertex
JobFileOutputVertex o1 = new JobFileOutputVertex("Output 1", jg);
o1.setFileOutputClass(FileLineWriter.class);
o1.setFilePath(new Path(outputFile.toURI()));
t1.setVertexToShareInstancesWith(i1);
o1.setVertexToShareInstancesWith(i1);
// connect vertices
i1.connectTo(t1, ChannelType.IN_MEMORY);
t1.connectTo(o1, ChannelType.IN_MEMORY);
// add jar
jg.addJar(new Path(new File(ServerTestUtils.getTempDir() + File.separator + exceptionClassName + ".jar")
.toURI()));
// Create job client and launch job
jobClient = new JobClient(jg, configuration);
// deactivate logging of expected test exceptions
Logger rtLogger = Logger.getLogger(Task.class);
Level rtLevel = rtLogger.getEffectiveLevel();
rtLogger.setLevel(Level.OFF);
try {
jobClient.submitJobAndWait();
} catch (JobExecutionException e) {
// Check if the correct error message is encapsulated in the exception
if (e.getMessage() == null) {
fail("JobExecutionException does not contain an error message");
}
if (!e.getMessage().contains(ExceptionTask.ERROR_MESSAGE)) {
fail("JobExecutionException does not contain the expected error message");
}
return;
}
finally {
rtLogger.setLevel(rtLevel);
}
fail("Expected exception but did not receive it");
} catch (JobGraphDefinitionException jgde) {
fail(jgde.getMessage());
} catch (IOException ioe) {
fail(ioe.getMessage());
} finally {
// Remove temporary files
if (inputFile != null) {
inputFile.delete();
}
if (outputFile != null) {
outputFile.delete();
}
if (jarFile != null) {
jarFile.delete();
}
if (jobClient != null) {
jobClient.close();
}
}
}