Skip to content

Commit 9fc864b

Browse files
slfan1989HarshitGupta11
authored andcommitted
YARN-11187. Remove WhiteBox in yarn module. (apache#4463)
Signed-off-by: Akira Ajisaka <[email protected]>
1 parent dfdd1ae commit 9fc864b

File tree

1 file changed

+22
-41
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher

1 file changed

+22
-41
lines changed

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

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher;
1919

2020
import org.apache.hadoop.conf.Configuration;
21-
import org.apache.hadoop.test.Whitebox;
2221
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
2322
import org.apache.hadoop.yarn.api.records.ApplicationId;
2423
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -40,8 +39,6 @@
4039

4140
import java.io.IOException;
4241
import java.util.ArrayList;
43-
import java.util.Collections;
44-
import java.util.HashMap;
4542
import java.util.List;
4643
import java.util.Map;
4744
import java.util.concurrent.ConcurrentHashMap;
@@ -123,10 +120,8 @@ public void setup() throws IllegalArgumentException, IllegalAccessException {
123120
@SuppressWarnings("unchecked")
124121
@Test
125122
public void testLaunchContainerEvent()
126-
throws IllegalArgumentException, IllegalAccessException {
127-
Map<ContainerId, ContainerLaunch> dummyMap =
128-
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
129-
"running");
123+
throws IllegalArgumentException {
124+
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
130125
when(event.getType())
131126
.thenReturn(ContainersLauncherEventType.LAUNCH_CONTAINER);
132127
assertEquals(0, dummyMap.size());
@@ -139,10 +134,8 @@ public void testLaunchContainerEvent()
139134
@SuppressWarnings("unchecked")
140135
@Test
141136
public void testRelaunchContainerEvent()
142-
throws IllegalArgumentException, IllegalAccessException {
143-
Map<ContainerId, ContainerLaunch> dummyMap =
144-
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
145-
"running");
137+
throws IllegalArgumentException {
138+
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
146139
when(event.getType())
147140
.thenReturn(ContainersLauncherEventType.RELAUNCH_CONTAINER);
148141
assertEquals(0, dummyMap.size());
@@ -159,10 +152,8 @@ public void testRelaunchContainerEvent()
159152
@SuppressWarnings("unchecked")
160153
@Test
161154
public void testRecoverContainerEvent()
162-
throws IllegalArgumentException, IllegalAccessException {
163-
Map<ContainerId, ContainerLaunch> dummyMap =
164-
(Map<ContainerId, ContainerLaunch>) Whitebox.getInternalState(spy,
165-
"running");
155+
throws IllegalArgumentException {
156+
Map<ContainerId, ContainerLaunch> dummyMap = spy.running;
166157
when(event.getType())
167158
.thenReturn(ContainersLauncherEventType.RECOVER_CONTAINER);
168159
assertEquals(0, dummyMap.size());
@@ -178,7 +169,7 @@ public void testRecoverContainerEvent()
178169

179170
@Test
180171
public void testRecoverPausedContainerEvent()
181-
throws IllegalArgumentException, IllegalAccessException {
172+
throws IllegalArgumentException {
182173
when(event.getType())
183174
.thenReturn(ContainersLauncherEventType.RECOVER_PAUSED_CONTAINER);
184175
spy.handle(event);
@@ -189,27 +180,23 @@ public void testRecoverPausedContainerEvent()
189180
@Test
190181
public void testCleanupContainerEvent()
191182
throws IllegalArgumentException, IllegalAccessException, IOException {
192-
Map<ContainerId, ContainerLaunch> dummyMap = Collections
193-
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
194-
dummyMap.put(containerId, containerLaunch);
195-
Whitebox.setInternalState(spy, "running", dummyMap);
183+
spy.running.clear();
184+
spy.running.put(containerId, containerLaunch);
196185

197186
when(event.getType())
198187
.thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER);
199-
assertEquals(1, dummyMap.size());
188+
assertEquals(1, spy.running.size());
200189
spy.handle(event);
201-
assertEquals(0, dummyMap.size());
190+
assertEquals(0, spy.running.size());
202191
Mockito.verify(containerLauncher, Mockito.times(1))
203192
.submit(Mockito.any(ContainerCleanup.class));
204193
}
205194

206195
@Test
207196
public void testCleanupContainerForReINITEvent()
208197
throws IllegalArgumentException, IllegalAccessException, IOException {
209-
Map<ContainerId, ContainerLaunch> dummyMap = Collections
210-
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
211-
dummyMap.put(containerId, containerLaunch);
212-
Whitebox.setInternalState(spy, "running", dummyMap);
198+
spy.running.clear();
199+
spy.running.put(containerId, containerLaunch);
213200

214201
when(event.getType())
215202
.thenReturn(ContainersLauncherEventType.CLEANUP_CONTAINER_FOR_REINIT);
@@ -226,9 +213,6 @@ public void testCleanupContainerForReINITEvent()
226213
@Test
227214
public void testSignalContainerEvent()
228215
throws IllegalArgumentException, IllegalAccessException, IOException {
229-
Map<ContainerId, ContainerLaunch> dummyMap = Collections
230-
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
231-
dummyMap.put(containerId, containerLaunch);
232216

233217
SignalContainersLauncherEvent dummyEvent =
234218
mock(SignalContainersLauncherEvent.class);
@@ -238,46 +222,43 @@ public void testSignalContainerEvent()
238222
when(containerId.getApplicationAttemptId().getApplicationId())
239223
.thenReturn(appId);
240224

241-
Whitebox.setInternalState(spy, "running", dummyMap);
225+
spy.running.clear();
226+
spy.running.put(containerId, containerLaunch);
242227
when(dummyEvent.getType())
243228
.thenReturn(ContainersLauncherEventType.SIGNAL_CONTAINER);
244229
when(dummyEvent.getCommand())
245230
.thenReturn(SignalContainerCommand.GRACEFUL_SHUTDOWN);
246231
doNothing().when(containerLaunch)
247232
.signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
248233
spy.handle(dummyEvent);
249-
assertEquals(1, dummyMap.size());
234+
assertEquals(1, spy.running.size());
250235
Mockito.verify(containerLaunch, Mockito.times(1))
251236
.signalContainer(SignalContainerCommand.GRACEFUL_SHUTDOWN);
252237
}
253238

254239
@Test
255240
public void testPauseContainerEvent()
256241
throws IllegalArgumentException, IllegalAccessException, IOException {
257-
Map<ContainerId, ContainerLaunch> dummyMap = Collections
258-
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
259-
dummyMap.put(containerId, containerLaunch);
260-
Whitebox.setInternalState(spy, "running", dummyMap);
242+
spy.running.clear();
243+
spy.running.put(containerId, containerLaunch);
261244
when(event.getType())
262245
.thenReturn(ContainersLauncherEventType.PAUSE_CONTAINER);
263246
doNothing().when(containerLaunch).pauseContainer();
264247
spy.handle(event);
265-
assertEquals(1, dummyMap.size());
248+
assertEquals(1, spy.running.size());
266249
Mockito.verify(containerLaunch, Mockito.times(1)).pauseContainer();
267250
}
268251

269252
@Test
270253
public void testResumeContainerEvent()
271254
throws IllegalArgumentException, IllegalAccessException, IOException {
272-
Map<ContainerId, ContainerLaunch> dummyMap = Collections
273-
.synchronizedMap(new HashMap<ContainerId, ContainerLaunch>());
274-
dummyMap.put(containerId, containerLaunch);
275-
Whitebox.setInternalState(spy, "running", dummyMap);
255+
spy.running.clear();
256+
spy.running.put(containerId, containerLaunch);
276257
when(event.getType())
277258
.thenReturn(ContainersLauncherEventType.RESUME_CONTAINER);
278259
doNothing().when(containerLaunch).resumeContainer();
279260
spy.handle(event);
280-
assertEquals(1, dummyMap.size());
261+
assertEquals(1, spy.running.size());
281262
Mockito.verify(containerLaunch, Mockito.times(1)).resumeContainer();
282263
}
283264
}

0 commit comments

Comments
 (0)