hadoop-yarn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeag...@apache.org
Subject svn commit: r1485885 - in /hadoop/common/branches/branch-0.23/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/
Date Thu, 23 May 2013 22:29:49 GMT
Author: jeagles
Date: Thu May 23 22:29:48 2013
New Revision: 1485885

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

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

Modified: hadoop/common/branches/branch-0.23/hadoop-yarn-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-yarn-project/CHANGES.txt?rev=1485885&r1=1485884&r2=1485885&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-yarn-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-yarn-project/CHANGES.txt Thu May 23 22:29:48
2013
@@ -7,6 +7,9 @@ Release 0.23.8 - UNRELEASED
   NEW FEATURES
   
   IMPROVEMENTS
+
+    YARN-548. Add tests for YarnUncaughtExceptionHandler (Vadim Bondarev via
+    jeagles)
   
   OPTIMIZATIONS
  

Modified: hadoop/common/branches/branch-0.23/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/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java?rev=1485885&r1=1485884&r2=1485885&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/YarnUncaughtExceptionHandler.java
Thu May 23 22:29:48 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/branches/branch-0.23/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/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java?rev=1485885&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java
(added)
+++ hadoop/common/branches/branch-0.23/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/TestYarnUncaughtExceptionHandler.java
Thu May 23 22:29:48 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);
+  }
+}



Mime
View raw message