فهرست منبع

YARN-11187. Remove WhiteBox in yarn module. (#4463)

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
slfan1989 2 سال پیش
والد
کامیت
b31b3ea0f6

+ 22 - 41
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainersLauncher.java

@@ -18,7 +18,6 @@
 package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.test.Whitebox;
 import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -40,8 +39,6 @@ import org.mockito.MockitoAnnotations;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -123,10 +120,8 @@ public class TestContainersLauncher {
   @SuppressWarnings("unchecked")
   @Test
   public void testLaunchContainerEvent()
-      throws IllegalArgumentException, IllegalAccessException {
-    Map<ContainerId, ContainerLaunch> dummyMap =
-        (Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
-            "running");
+      throws IllegalArgumentException {
+    Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.LAUNCH_CONTAINER);
     assertEquals(0, dummyMap.size());
@@ -139,10 +134,8 @@ public class TestContainersLauncher {
   @SuppressWarnings("unchecked")
   @Test
   public void testRelaunchContainerEvent()
-      throws IllegalArgumentException, IllegalAccessException {
-    Map<ContainerId, ContainerLaunch> dummyMap =
-        (Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
-            "running");
+      throws IllegalArgumentException {
+    Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.RELAUNCH_CONTAINER);
     assertEquals(0, dummyMap.size());
@@ -159,10 +152,8 @@ public class TestContainersLauncher {
   @SuppressWarnings("unchecked")
   @Test
   public void testRecoverContainerEvent()
-      throws IllegalArgumentException, IllegalAccessException {
-    Map<ContainerId, ContainerLaunch> dummyMap =
-        (Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
-            "running");
+      throws IllegalArgumentException {
+    Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.RECOVER_CONTAINER);
     assertEquals(0, dummyMap.size());
@@ -178,7 +169,7 @@ public class TestContainersLauncher {
 
   @Test
   public void testRecoverPausedContainerEvent()
-      throws IllegalArgumentException, IllegalAccessException {
+      throws IllegalArgumentException {
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.RECOVER_PAUSED_CONTAINER);
     spy.handle(event);
@@ -189,16 +180,14 @@ public class TestContainersLauncher {
   @Test
   public void testCleanupContainerEvent()
       throws IllegalArgumentException, IllegalAccessException, IOException {
-    Map<ContainerId, ContainerLaunch> dummyMap = Collections
-        .synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
-    dummyMap.put(containerId, containerLaunch);
-    Whitebox.setInternalState(spy, "running", dummyMap);
+    spy.running.clear();
+    spy.running.put(containerId, containerLaunch);
 
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER);
-    assertEquals(1, dummyMap.size());
+    assertEquals(1, spy.running.size());
     spy.handle(event);
-    assertEquals(0, dummyMap.size());
+    assertEquals(0, spy.running.size());
     Mockito.verify(containerLauncher, Mockito.times(1))
         .submit(Mockito.any(ContainerCleanup.class));
   }
@@ -206,10 +195,8 @@ public class TestContainersLauncher {
   @Test
   public void testCleanupContainerForReINITEvent()
       throws IllegalArgumentException, IllegalAccessException, IOException {
-    Map<ContainerId, ContainerLaunch> dummyMap = Collections
-        .synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
-    dummyMap.put(containerId, containerLaunch);
-    Whitebox.setInternalState(spy, "running", dummyMap);
+    spy.running.clear();
+    spy.running.put(containerId, containerLaunch);
 
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER_FOR_REINIT);
@@ -226,9 +213,6 @@ public class TestContainersLauncher {
   @Test
   public void testSignalContainerEvent()
       throws IllegalArgumentException, IllegalAccessException, IOException {
-    Map<ContainerId, ContainerLaunch> dummyMap = Collections
-        .synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
-    dummyMap.put(containerId, containerLaunch);
 
     SignalContainersLauncherEvent dummyEvent =
         mock(SignalContainersLauncherEvent.class);
@@ -238,7 +222,8 @@ public class TestContainersLauncher {
     when(containerId.getApplicationAttemptId().getApplicationId())
         .thenReturn(appId);
 
-    Whitebox.setInternalState(spy, "running", dummyMap);
+    spy.running.clear();
+    spy.running.put(containerId, containerLaunch);
     when(dummyEvent.getType())
         .thenReturn(ContainersLauncherEventType.SIGNAL_CONTAINER);
     when(dummyEvent.getCommand())
@@ -246,7 +231,7 @@ public class TestContainersLauncher {
     doNothing().when(containerLaunch)
         .signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
     spy.handle(dummyEvent);
-    assertEquals(1, dummyMap.size());
+    assertEquals(1, spy.running.size());
     Mockito.verify(containerLaunch, Mockito.times(1))
         .signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
   }
@@ -254,30 +239,26 @@ public class TestContainersLauncher {
   @Test
   public void testPauseContainerEvent()
       throws IllegalArgumentException, IllegalAccessException, IOException {
-    Map<ContainerId, ContainerLaunch> dummyMap = Collections
-        .synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
-    dummyMap.put(containerId, containerLaunch);
-    Whitebox.setInternalState(spy, "running", dummyMap);
+    spy.running.clear();
+    spy.running.put(containerId, containerLaunch);
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.PAUSE_CONTAINER);
     doNothing().when(containerLaunch).pauseContainer();
     spy.handle(event);
-    assertEquals(1, dummyMap.size());
+    assertEquals(1, spy.running.size());
     Mockito.verify(containerLaunch, Mockito.times(1)).pauseContainer();
   }
 
   @Test
   public void testResumeContainerEvent()
       throws IllegalArgumentException, IllegalAccessException, IOException {
-    Map<ContainerId, ContainerLaunch> dummyMap = Collections
-        .synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
-    dummyMap.put(containerId, containerLaunch);
-    Whitebox.setInternalState(spy, "running", dummyMap);
+    spy.running.clear();
+    spy.running.put(containerId, containerLaunch);
     when(event.getType())
         .thenReturn(ContainersLauncherEventType.RESUME_CONTAINER);
     doNothing().when(containerLaunch).resumeContainer();
     spy.handle(event);
-    assertEquals(1, dummyMap.size());
+    assertEquals(1, spy.running.size());
     Mockito.verify(containerLaunch, Mockito.times(1)).resumeContainer();
   }
 }