public void testAppSubmission2() throws Exception {
doSubmitAndAssert();
}
private void doSubmitAndAssert() throws Exception {
YarnClient client = (YarnClient) ctx.getBean("yarnClient");
assertThat(client, notNullValue());
ApplicationId applicationId = client.submitApplication();
assertThat(applicationId, notNullValue());
YarnApplicationState state = null;
for (int i = 0; i<120; i++) {
state = findState(client, applicationId);
if (state == null) {
break;
}
if (state.equals(YarnApplicationState.FINISHED) || state.equals(YarnApplicationState.FAILED)) {
break;
}
Thread.sleep(1000);
}
assertThat(state, notNullValue());
YarnCluster cluster = (YarnCluster) ctx.getBean("yarnCluster");
File testWorkDir = cluster.getYarnWorkDir();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
String locationPattern = "file:" + testWorkDir.getAbsolutePath() + "/**/" + applicationId.toString() + "/**/*.std*";
Resource[] resources = resolver.getResources(locationPattern);
// get possible appmaster error from stderr file
StringBuilder masterFailReason = new StringBuilder();
for (Resource res : resources) {
File file = res.getFile();
if (file.getName().endsWith("Appmaster.stderr") && file.length() > 0) {
Scanner scanner = new Scanner(file);
masterFailReason.append("[Appmaster.stderr=");
masterFailReason.append(scanner.useDelimiter("\\A").next());
masterFailReason.append("]");
scanner.close();
break;
}
}
masterFailReason.append(", [ApplicationReport Diagnostics=");
masterFailReason.append(client.getApplicationReport(applicationId).getDiagnostics());
masterFailReason.append("], [Num of log files=");
masterFailReason.append(resources.length);
masterFailReason.append("]");
assertThat(masterFailReason.toString(), state, is(YarnApplicationState.FINISHED));