From 82bbcbf37f8137112a6270932b2ad7572785c387 Mon Sep 17 00:00:00 2001 From: Ravi Prakash Date: Fri, 16 Jun 2017 14:25:12 -0700 Subject: [PATCH] =?UTF-8?q?MAPREDUCE-6897.=20Add=20Unit=20Test=20to=20ensu?= =?UTF-8?q?re=20Job=20end=20notification=20gets=20sent=20even=20when=20app?= =?UTF-8?q?Master=20stop=20gets=20YarnRuntimeException.=20Contributed=20by?= =?UTF-8?q?=20Gergely=20Nov=C3=A1k?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapreduce/v2/app/TestJobEndNotifier.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestJobEndNotifier.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestJobEndNotifier.java index ecfa43c447..d122a9b246 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestJobEndNotifier.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestJobEndNotifier.java @@ -19,6 +19,7 @@ package org.apache.hadoop.mapreduce.v2.app; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -30,6 +31,7 @@ import java.net.Proxy; import java.net.URI; import java.net.URISyntaxException; +import java.nio.channels.ClosedChannelException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -53,6 +55,7 @@ import org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator; import org.apache.hadoop.mapreduce.v2.app.rm.RMHeartbeatHandler; import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.junit.Assert; import org.junit.Test; @@ -197,8 +200,8 @@ public void testNotifyRetries() throws InterruptedException { } - @Test - public void testNotificationOnLastRetryNormalShutdown() throws Exception { + private void testNotificationOnLastRetry(boolean withRuntimeException) + throws Exception { HttpServer2 server = startHttpServer(); // Act like it is the second attempt. Default max attempts is 2 MRApp app = spy(new MRAppWithCustomContainerAllocator( @@ -210,16 +213,32 @@ public void testNotificationOnLastRetryNormalShutdown() throws Exception { JobImpl job = (JobImpl)app.submit(conf); app.waitForInternalState(job, JobStateInternal.SUCCEEDED); // Unregistration succeeds: successfullyUnregistered is set + if (withRuntimeException) { + YarnRuntimeException runtimeException = new YarnRuntimeException( + new ClosedChannelException()); + doThrow(runtimeException).when(app).stop(); + } app.shutDownJob(); Assert.assertTrue(app.isLastAMRetry()); Assert.assertEquals(1, JobEndServlet.calledTimes); Assert.assertEquals("jobid=" + job.getID() + "&status=SUCCEEDED", JobEndServlet.requestUri.getQuery()); Assert.assertEquals(JobState.SUCCEEDED.toString(), - JobEndServlet.foundJobState); + JobEndServlet.foundJobState); server.stop(); } + @Test + public void testNotificationOnLastRetryNormalShutdown() throws Exception { + testNotificationOnLastRetry(false); + } + + @Test + public void testNotificationOnLastRetryShutdownWithRuntimeException() + throws Exception { + testNotificationOnLastRetry(true); + } + @Test public void testAbsentNotificationOnNotLastRetryUnregistrationFailure() throws Exception {