.../mapreduce/v2/app/webapp/TestAppController.java | 88 +++++++++++++++++----- 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAppController.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAppController.java index 92786e3..4a5b295 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAppController.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAppController.java @@ -20,7 +20,10 @@ import static org.mockito.Mockito.*; import java.io.IOException; + +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; @@ -31,11 +34,14 @@ import org.apache.hadoop.mapreduce.v2.app.job.Job; import org.apache.hadoop.mapreduce.v2.app.job.Task; import org.apache.hadoop.mapreduce.v2.util.MRApps; +import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.webapp.Controller.RequestContext; import org.apache.hadoop.yarn.webapp.MimeType; import org.apache.hadoop.yarn.webapp.ResponseInfo; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; @@ -47,11 +53,17 @@ private Job job; private static final String taskId = "task_01_01_m_01"; + private static final String RM1_NODE_ID = "rm1"; + private static final String RM2_NODE_ID = "rm2"; + private static String dummyHostNames[] = { "host1", "host2", "host3" }; + private static final String anyIpAddress = "1.2.3.4"; + private static Map savedStaticResolution = new HashMap<>(); + @Before public void setUp() throws IOException { AppContext context = mock(AppContext.class); - when(context.getApplicationID()).thenReturn( - ApplicationId.newInstance(0, 0)); + when(context.getApplicationID()) + .thenReturn(ApplicationId.newInstance(0, 0)); when(context.getApplicationName()).thenReturn("AppName"); when(context.getUser()).thenReturn("User"); when(context.getStartTime()).thenReturn(System.currentTimeMillis()); @@ -67,6 +79,25 @@ public void setUp() throws IOException { App app = new App(context); Configuration configuration = new Configuration(); + final String rmAddress = "host1:8088"; + configuration.set(YarnConfiguration.RM_WEBAPP_ADDRESS, rmAddress); + final String rm1Address = "host2:8088"; + final String rm2Address = "host3:8088"; + configuration.set(YarnConfiguration.RM_WEBAPP_ADDRESS + "." + RM1_NODE_ID, + rm1Address); + configuration.set(YarnConfiguration.RM_WEBAPP_ADDRESS + "." + RM2_NODE_ID, + rm2Address); + configuration.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); + configuration.set(YarnConfiguration.RM_HA_IDS, RM1_NODE_ID + "," + + RM2_NODE_ID); + + String previousIpAddress; + for (String hostName : dummyHostNames) { + if (null != (previousIpAddress = NetUtils.getStaticResolution(hostName))) { + savedStaticResolution.put(hostName, previousIpAddress); + } + NetUtils.addStaticResolution(hostName, anyIpAddress); + } ctx = mock(RequestContext.class); appController = new AppControllerForTest(app, configuration, ctx); @@ -108,8 +139,8 @@ private void verifyExpectations(String message) { public void testInfo() { appController.info(); - Iterator iterator = appController.getResponseInfo() - .iterator(); + Iterator iterator = + appController.getResponseInfo().iterator(); ResponseInfo.Item item = iterator.next(); assertEquals("Application ID:", item.key); assertEquals("application_0_0000", item.value); @@ -128,7 +159,8 @@ public void testInfo() { } /** - * Test method 'job'. Should print message about error or set JobPage class for rendering + * Test method 'job'. Should print message about error or set JobPage class + * for rendering */ @Test public void testGetJob() { @@ -155,7 +187,8 @@ public void testGetJob() { } /** - * Test method 'jobCounters'. Should print message about error or set CountersPage class for rendering + * Test method 'jobCounters'. Should print message about error or set + * CountersPage class for rendering */ @Test public void testGetJobCounters() { @@ -183,7 +216,8 @@ public void testGetJobCounters() { } /** - * Test method 'taskCounters'. Should print message about error or set CountersPage class for rendering + * Test method 'taskCounters'. Should print message about error or set + * CountersPage class for rendering */ @Test public void testGetTaskCounters() { @@ -210,8 +244,10 @@ public void testGetTaskCounters() { appController.taskCounters(); assertEquals(CountersPage.class, appController.getClazz()); } + /** - * Test method 'singleJobCounter'. Should set SingleCounterPage class for rendering + * Test method 'singleJobCounter'. Should set SingleCounterPage class for + * rendering */ @Test @@ -221,7 +257,8 @@ public void testGetSingleJobCounter() throws IOException { } /** - * Test method 'singleTaskCounter'. Should set SingleCounterPage class for rendering + * Test method 'singleTaskCounter'. Should set SingleCounterPage class for + * rendering */ @Test public void testGetSingleTaskCounter() throws IOException { @@ -230,43 +267,47 @@ public void testGetSingleTaskCounter() throws IOException { assertNotNull(appController.getProperty().get(AppController.COUNTER_GROUP)); assertNotNull(appController.getProperty().get(AppController.COUNTER_NAME)); } + /** - * Test method 'tasks'. Should set TasksPage class for rendering + * Test method 'tasks'. Should set TasksPage class for rendering */ @Test public void testTasks() { - + appController.tasks(); - + assertEquals(TasksPage.class, appController.getClazz()); } + /** - * Test method 'task'. Should set TaskPage class for rendering and information for title + * Test method 'task'. Should set TaskPage class for rendering and information + * for title */ @Test public void testTask() { - + appController.task(); - assertEquals("Attempts for " + taskId , + assertEquals("Attempts for " + taskId, appController.getProperty().get("title")); assertEquals(TaskPage.class, appController.getClazz()); } /** - * Test method 'conf'. Should set JobConfPage class for rendering + * Test method 'conf'. Should set JobConfPage class for rendering */ @Test public void testConfiguration() { - + appController.conf(); assertEquals(JobConfPage.class, appController.getClazz()); } /** - * Test method 'conf'. Should set AttemptsPage class for rendering or print information about error + * Test method 'conf'. Should set AttemptsPage class for rendering or print + * information about error */ @Test public void testAttempts() { @@ -307,4 +348,15 @@ public void testAttempts() { assertEquals(AttemptsPage.class, appController.getClazz()); } + /** + * test bad request should Resolve HA RAM Address + */ + @Test + public void testResolveHARMAdress() { + final String rmRemoteUrl = appController.getProperty().get(AMParams.RM_WEB); + final String rm1Address = "http://host2:8088"; + Assert.assertEquals( + "ResolvedRemoteRMWebAppUrl should resolve to the first HA RM address", + rm1Address, rmRemoteUrl); + } }