You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yarn-commits@hadoop.apache.org by je...@apache.org on 2013/05/24 00:21:57 UTC

svn commit: r1485877 - in /hadoop/common/trunk/hadoop-yarn-project: ./ hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/

Author: jeagles
Date: Thu May 23 22:21:56 2013
New Revision: 1485877

URL: http://svn.apache.org/r1485877
Log:
YARN-548. Add tests for YarnUncaughtExceptionHandler (Vadim Bondarev via jeagles)

Added:
    hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java
Modified:
    hadoop/common/trunk/hadoop-yarn-project/CHANGES.txt
    hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java

Modified: hadoop/common/trunk/hadoop-yarn-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-yarn-project/CHANGES.txt?rev=1485877&r1=1485876&r2=1485877&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-yarn-project/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-yarn-project/CHANGES.txt Thu May 23 22:21:56 2013
@@ -698,6 +698,9 @@ Release 0.23.8 - UNRELEASED
 
   OPTIMIZATIONS
 
+    YARN-548. Add tests for YarnUncaughtExceptionHandler (Vadim Bondarev via
+    jeagles)
+
   BUG FIXES
 
     YARN-363. Add webapps/proxy directory without which YARN proxy-server fails

Modified: hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java?rev=1485877&r1=1485876&r2=1485877&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java (original)
+++ hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java Thu May 23 22:21:56 2013
@@ -22,6 +22,7 @@ import java.lang.Thread.UncaughtExceptio
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.util.ExitUtil;
 import org.apache.hadoop.util.ShutdownHookManager;
 
 /**
@@ -55,9 +56,9 @@ public class YarnUncaughtExceptionHandle
         } catch (Throwable err) {
           //Again we done want to exit because of logging issues.
         }
-        Runtime.getRuntime().halt(-1);
+        ExitUtil.halt(-1);
       } else {
-        System.exit(-1);
+        ExitUtil.terminate(-1);
       }
     } else {
       LOG.error("Thread " + t + " threw an Exception.", e);

Added: hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java?rev=1485877&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java (added)
+++ hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java Thu May 23 22:21:56 2013
@@ -0,0 +1,115 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.yarn;
+
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import org.apache.hadoop.util.ExitUtil;
+import org.junit.Test;
+
+public class TestYarnUncaughtExceptionHandler {
+
+  private static final YarnUncaughtExceptionHandler exHandler =
+        new YarnUncaughtExceptionHandler();
+  /**
+   * Throw {@code YarnException} inside thread and
+   * check {@code YarnUncaughtExceptionHandler} instance
+   *
+   * @throws InterruptedException
+   */
+  @Test
+  public void testUncaughtExceptionHandlerWithRuntimeException()
+      throws InterruptedException {
+    final YarnUncaughtExceptionHandler spyYarnHandler = spy(exHandler);
+    final YarnException yarnException = new YarnException(
+        "test-yarn-runtime-exception");
+    final Thread yarnThread = new Thread(new Runnable() {
+      @Override
+      public void run() {
+        throw yarnException;
+      }
+    });
+
+    yarnThread.setUncaughtExceptionHandler(spyYarnHandler);
+    assertSame(spyYarnHandler, yarnThread.getUncaughtExceptionHandler());
+    yarnThread.start();
+    yarnThread.join();
+    verify(spyYarnHandler).uncaughtException(yarnThread, yarnException);
+  }
+
+  /**
+   * <p>
+   * Throw {@code Error} inside thread and
+   * check {@code YarnUncaughtExceptionHandler} instance
+   * <p>
+   * Used {@code ExitUtil} class to avoid jvm exit through
+   * {@code System.exit(-1) }
+   *
+   * @throws InterruptedException
+   */
+  @Test
+  public void testUncaughtExceptionHandlerWithError()
+      throws InterruptedException {
+    ExitUtil.disableSystemExit();
+    final YarnUncaughtExceptionHandler spyErrorHandler = spy(exHandler);
+    final java.lang.Error error = new java.lang.Error("test-error");
+    final Thread errorThread = new Thread(new Runnable() {
+      @Override
+      public void run() {
+        throw error;
+      }
+    });
+    errorThread.setUncaughtExceptionHandler(spyErrorHandler);
+    assertSame(spyErrorHandler, errorThread.getUncaughtExceptionHandler());
+    errorThread.start();
+    errorThread.join();
+    verify(spyErrorHandler).uncaughtException(errorThread, error);
+  }
+
+  /**
+   * <p>
+   * Throw {@code OutOfMemoryError} inside thread and
+   * check {@code YarnUncaughtExceptionHandler} instance
+   * <p>
+   * Used {@code ExitUtil} class to avoid jvm exit through
+   * {@code Runtime.getRuntime().halt(-1)}
+   *
+   * @throws InterruptedException
+   */
+  @Test
+  public void testUncaughtExceptionHandlerWithOutOfMemoryError()
+      throws InterruptedException {
+    ExitUtil.disableSystemHalt();
+    final YarnUncaughtExceptionHandler spyOomHandler = spy(exHandler);
+    final OutOfMemoryError oomError = new OutOfMemoryError("out-of-memory-error");
+    final Thread oomThread = new Thread(new Runnable() {
+      @Override
+      public void run() {
+        throw oomError;
+      }
+    });
+    oomThread.setUncaughtExceptionHandler(spyOomHandler);
+    assertSame(spyOomHandler, oomThread.getUncaughtExceptionHandler());
+    oomThread.start();
+    oomThread.join();
+    verify(spyOomHandler).uncaughtException(oomThread, oomError);
+  }
+}