diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java index 43907f0..8726705 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.applications.distributedshell; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -63,9 +64,16 @@ public static void setup() throws InterruptedException, IOException { if (url == null) { throw new RuntimeException("Could not find 'yarn-site.xml' dummy file in classpath"); } - yarnCluster.getConfig().set("yarn.application.classpath", new File(url.getPath()).getParent()); + Configuration yarnClusterConfig = yarnCluster.getConfig(); + yarnClusterConfig.set("yarn.application.classpath", new File(url.getPath()).getParent()); + //write the document to a buffer (not directly to the file, as that + //can cause the file being written to get read -which will then fail. + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + yarnClusterConfig.writeXml(bytesOut); + bytesOut.close(); + //write the bytes to the file in the classpath OutputStream os = new FileOutputStream(new File(url.getPath())); - yarnCluster.getConfig().writeXml(os); + os.write(bytesOut.toByteArray()); os.close(); } try { @@ -78,8 +86,11 @@ public static void setup() throws InterruptedException, IOException { @AfterClass public static void tearDown() throws IOException { if (yarnCluster != null) { - yarnCluster.stop(); - yarnCluster = null; + try { + yarnCluster.stop(); + } finally { + yarnCluster = null; + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/java/org/apache/hadoop/yarn/applications/unmanagedamlauncher/TestUnmanagedAMLauncher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/java/org/apache/hadoop/yarn/applications/unmanagedamlauncher/TestUnmanagedAMLauncher.java index 6ab474d..9ae5807 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/java/org/apache/hadoop/yarn/applications/unmanagedamlauncher/TestUnmanagedAMLauncher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/java/org/apache/hadoop/yarn/applications/unmanagedamlauncher/TestUnmanagedAMLauncher.java @@ -18,8 +18,10 @@ package org.apache.hadoop.yarn.applications.unmanagedamlauncher; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -54,14 +56,30 @@ public static void setup() throws InterruptedException, IOException { TestUnmanagedAMLauncher.class.getSimpleName(), 1, 1, 1); yarnCluster.init(conf); yarnCluster.start(); + //get the address + Configuration yarnClusterConfig = yarnCluster.getConfig(); + LOG.info("MiniYARN ResourceManager published address: " + + yarnClusterConfig.get(YarnConfiguration.RM_ADDRESS)); + LOG.info("MiniYARN ResourceManager published web address: " + + yarnClusterConfig.get(YarnConfiguration.RM_WEBAPP_ADDRESS)); + String webapp = yarnClusterConfig.get(YarnConfiguration.RM_WEBAPP_ADDRESS); + assertTrue("Web app address still unbound to a host at " + webapp, + !webapp.startsWith("0.0.0.0")); + LOG.info("Yarn webapp is at "+ webapp); URL url = Thread.currentThread().getContextClassLoader() .getResource("yarn-site.xml"); if (url == null) { throw new RuntimeException( "Could not find 'yarn-site.xml' dummy file in classpath"); } + //write the document to a buffer (not directly to the file, as that + //can cause the file being written to get read -which will then fail. + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + yarnClusterConfig.writeXml(bytesOut); + bytesOut.close(); + //write the bytes to the file in the classpath OutputStream os = new FileOutputStream(new File(url.getPath())); - yarnCluster.getConfig().writeXml(os); + os.write(bytesOut.toByteArray()); os.close(); } try { @@ -74,8 +92,11 @@ public static void setup() throws InterruptedException, IOException { @AfterClass public static void tearDown() throws IOException { if (yarnCluster != null) { - yarnCluster.stop(); - yarnCluster = null; + try { + yarnCluster.stop(); + } finally { + yarnCluster = null; + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/resources/log4j.properties b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/resources/log4j.properties new file mode 100644 index 0000000..315f104 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-unmanaged-am-launcher/src/test/resources/log4j.properties @@ -0,0 +1,37 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# log4j configuration used during build and unit tests + +log4j.rootLogger=INFO,stdout +log4j.threshhold=ALL +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2} (%F:%M(%L)) - %m%n