MAPREDUCE-6897. Add Unit Test to ensure Job end notification gets sent even when appMaster stop gets YarnRuntimeException. Contributed by Gergely Novák

This commit is contained in:
Ravi Prakash 2017-06-16 14:25:12 -07:00
parent 9ef2743fa1
commit 82bbcbf37f
1 changed files with 22 additions and 3 deletions

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -30,6 +31,7 @@ import java.io.PrintStream;
import java.net.Proxy; import java.net.Proxy;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.channels.ClosedChannelException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
@ -53,6 +55,7 @@ import org.apache.hadoop.mapreduce.v2.app.rm.ContainerAllocatorEvent;
import org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator; import org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator;
import org.apache.hadoop.mapreduce.v2.app.rm.RMHeartbeatHandler; import org.apache.hadoop.mapreduce.v2.app.rm.RMHeartbeatHandler;
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -197,8 +200,8 @@ public class TestJobEndNotifier extends JobEndNotifier {
} }
@Test private void testNotificationOnLastRetry(boolean withRuntimeException)
public void testNotificationOnLastRetryNormalShutdown() throws Exception { throws Exception {
HttpServer2 server = startHttpServer(); HttpServer2 server = startHttpServer();
// Act like it is the second attempt. Default max attempts is 2 // Act like it is the second attempt. Default max attempts is 2
MRApp app = spy(new MRAppWithCustomContainerAllocator( MRApp app = spy(new MRAppWithCustomContainerAllocator(
@ -210,6 +213,11 @@ public class TestJobEndNotifier extends JobEndNotifier {
JobImpl job = (JobImpl)app.submit(conf); JobImpl job = (JobImpl)app.submit(conf);
app.waitForInternalState(job, JobStateInternal.SUCCEEDED); app.waitForInternalState(job, JobStateInternal.SUCCEEDED);
// Unregistration succeeds: successfullyUnregistered is set // Unregistration succeeds: successfullyUnregistered is set
if (withRuntimeException) {
YarnRuntimeException runtimeException = new YarnRuntimeException(
new ClosedChannelException());
doThrow(runtimeException).when(app).stop();
}
app.shutDownJob(); app.shutDownJob();
Assert.assertTrue(app.isLastAMRetry()); Assert.assertTrue(app.isLastAMRetry());
Assert.assertEquals(1, JobEndServlet.calledTimes); Assert.assertEquals(1, JobEndServlet.calledTimes);
@ -220,6 +228,17 @@ public class TestJobEndNotifier extends JobEndNotifier {
server.stop(); server.stop();
} }
@Test
public void testNotificationOnLastRetryNormalShutdown() throws Exception {
testNotificationOnLastRetry(false);
}
@Test
public void testNotificationOnLastRetryShutdownWithRuntimeException()
throws Exception {
testNotificationOnLastRetry(true);
}
@Test @Test
public void testAbsentNotificationOnNotLastRetryUnregistrationFailure() public void testAbsentNotificationOnNotLastRetryUnregistrationFailure()
throws Exception { throws Exception {