Skip to content

Commit ad1aa12

Browse files
author
fanshilun
committed
YARN-11263. Fix Junit Test & CheckStyle.
1 parent 3075017 commit ad1aa12

File tree

114 files changed

+4185
-3906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+4185
-3906
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
<artifactId>junit-platform-launcher</artifactId>
105105
<scope>test</scope>
106106
</dependency>
107+
<dependency>
108+
<groupId>org.mockito</groupId>
109+
<artifactId>mockito-junit-jupiter</artifactId>
110+
<scope>test</scope>
111+
</dependency>
107112
<dependency>
108113
<groupId>org.slf4j</groupId>
109114
<artifactId>slf4j-api</artifactId>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/NodeManagerTestBase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl;
4040
import org.apache.hadoop.yarn.server.nodemanager.health.NodeHealthCheckerService;
4141
import org.apache.hadoop.yarn.server.nodemanager.metrics.NodeManagerMetrics;
42-
import org.junit.jupiter.api.Assertions;
4342
import org.junit.jupiter.api.BeforeEach;
4443
import org.slf4j.Logger;
4544
import org.slf4j.LoggerFactory;
@@ -49,6 +48,8 @@
4948
import java.net.InetAddress;
5049
import java.net.UnknownHostException;
5150

51+
import static org.junit.jupiter.api.Assertions.fail;
52+
5253
public class NodeManagerTestBase {
5354
// temp fix until metrics system can auto-detect itself running in unit test:
5455
static {
@@ -78,7 +79,7 @@ protected YarnConfiguration createNMConfig(int port) throws IOException {
7879
localhostAddress = InetAddress.getByName("localhost")
7980
.getCanonicalHostName();
8081
} catch (UnknownHostException e) {
81-
Assertions.fail("Unable to get localhost address: " + e.getMessage());
82+
fail("Unable to get localhost address: " + e.getMessage());
8283
}
8384
conf.setInt(YarnConfiguration.NM_PMEM_MB, 5 * 1024); // 5GB
8485
conf.set(YarnConfiguration.NM_ADDRESS, localhostAddress + ":" + port);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerReacquisitionContext;
4949
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerReapContext;
5050
import org.apache.hadoop.yarn.server.nodemanager.util.NodeManagerHardwareUtils;
51-
import org.junit.jupiter.api.Assertions;
5251
import org.junit.jupiter.api.Test;
5352
import org.junit.jupiter.api.Timeout;
5453
import org.slf4j.Logger;
5554
import org.slf4j.LoggerFactory;
5655

5756
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
58-
import static org.junit.jupiter.api.Assertions.*;
57+
import static org.junit.jupiter.api.Assertions.assertEquals;
58+
import static org.junit.jupiter.api.Assertions.assertTrue;
5959
import static org.mockito.ArgumentMatchers.any;
6060
import static org.mockito.Mockito.doReturn;
6161
import static org.mockito.Mockito.mock;
@@ -74,8 +74,8 @@ public class TestContainerExecutor {
7474
public void testRunCommandNoPriority() throws Exception {
7575
Configuration conf = new Configuration();
7676
String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf);
77-
assertTrue(
78-
command[0].equals(Shell.WINUTILS) || command[0].equals("bash"), "first command should be the run command for the platform");
77+
assertTrue(command[0].equals(Shell.WINUTILS) || command[0].equals("bash"),
78+
"first command should be the run command for the platform");
7979
}
8080

8181
@Test
@@ -86,8 +86,8 @@ public void testRunCommandwithPriority() throws Exception {
8686
String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf);
8787
if (Shell.WINDOWS) {
8888
// windows doesn't currently support
89-
assertEquals(
90-
Shell.WINUTILS, command[0], "first command should be the run command for the platform");
89+
assertEquals(Shell.WINUTILS, command[0],
90+
"first command should be the run command for the platform");
9191
} else {
9292
assertEquals("first command should be nice", "nice", command[0]);
9393
assertEquals("second command should be -n", "-n", command[1]);
@@ -100,8 +100,8 @@ public void testRunCommandwithPriority() throws Exception {
100100
command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf);
101101
if (Shell.WINDOWS) {
102102
// windows doesn't currently support
103-
assertEquals(
104-
Shell.WINUTILS, command[0], "first command should be the run command for the platform");
103+
assertEquals(Shell.WINUTILS, command[0],
104+
"first command should be the run command for the platform");
105105
} else {
106106
assertEquals("first command should be nice", "nice", command[0]);
107107
assertEquals("second command should be -n", "-n", command[1]);
@@ -120,7 +120,7 @@ public void testRunCommandWithNoResources() {
120120
// Assert the cpu and memory limits are set correctly in the command
121121
String[] expected = { Shell.WINUTILS, "task", "create", "-m", "-1", "-c",
122122
"-1", "group1", "cmd /c " + "echo" };
123-
Assertions.assertTrue(Arrays.equals(expected, command));
123+
assertTrue(Arrays.equals(expected, command));
124124
}
125125

126126
@Test
@@ -134,7 +134,7 @@ public void testRunCommandWithMemoryOnlyResources() {
134134
// Assert the cpu and memory limits are set correctly in the command
135135
String[] expected = { Shell.WINUTILS, "task", "create", "-m", "1024", "-c",
136136
"-1", "group1", "cmd /c " + "echo" };
137-
Assertions.assertTrue(Arrays.equals(expected, command));
137+
assertTrue(Arrays.equals(expected, command));
138138
}
139139

140140
@Test
@@ -150,39 +150,39 @@ public void testRunCommandWithCpuAndMemoryResources() {
150150
containerExecutor.getRunCommand("echo", "group1", null, null, conf,
151151
Resource.newInstance(1024, 1));
152152
int nodeVCores = NodeManagerHardwareUtils.getVCores(conf);
153-
Assertions.assertEquals(YarnConfiguration.DEFAULT_NM_VCORES, nodeVCores);
153+
assertEquals(YarnConfiguration.DEFAULT_NM_VCORES, nodeVCores);
154154
int cpuRate = Math.min(10000, (containerCores * 10000) / nodeVCores);
155155

156156
// Assert the cpu and memory limits are set correctly in the command
157157
String[] expected =
158158
{Shell.WINUTILS, "task", "create", "-m", "1024", "-c",
159159
String.valueOf(cpuRate), "group1", "cmd /c " + "echo" };
160-
Assertions.assertEquals(Arrays.toString(expected), Arrays.toString(command));
160+
assertEquals(Arrays.toString(expected), Arrays.toString(command));
161161

162162
conf.setBoolean(YarnConfiguration.NM_ENABLE_HARDWARE_CAPABILITY_DETECTION,
163163
true);
164164
int nodeCPUs = NodeManagerHardwareUtils.getNodeCPUs(conf);
165165
float yarnCPUs = NodeManagerHardwareUtils.getContainersCPUs(conf);
166166
nodeVCores = NodeManagerHardwareUtils.getVCores(conf);
167-
Assertions.assertEquals(nodeCPUs, (int) yarnCPUs);
168-
Assertions.assertEquals(nodeCPUs, nodeVCores);
167+
assertEquals(nodeCPUs, (int) yarnCPUs);
168+
assertEquals(nodeCPUs, nodeVCores);
169169
command =
170170
containerExecutor.getRunCommand("echo", "group1", null, null, conf,
171171
Resource.newInstance(1024, 1));
172172
cpuRate = Math.min(10000, (containerCores * 10000) / nodeVCores);
173173
expected[6] = String.valueOf(cpuRate);
174-
Assertions.assertEquals(Arrays.toString(expected), Arrays.toString(command));
174+
assertEquals(Arrays.toString(expected), Arrays.toString(command));
175175

176176
int yarnCpuLimit = 80;
177177
conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT,
178178
yarnCpuLimit);
179179
yarnCPUs = NodeManagerHardwareUtils.getContainersCPUs(conf);
180180
nodeVCores = NodeManagerHardwareUtils.getVCores(conf);
181-
Assertions.assertEquals(nodeCPUs * 0.8, yarnCPUs, 0.01);
181+
assertEquals(nodeCPUs * 0.8, yarnCPUs, 0.01);
182182
if (nodeCPUs == 1) {
183-
Assertions.assertEquals(1, nodeVCores);
183+
assertEquals(1, nodeVCores);
184184
} else {
185-
Assertions.assertEquals((int) (nodeCPUs * 0.8), nodeVCores);
185+
assertEquals((int) (nodeCPUs * 0.8), nodeVCores);
186186
}
187187
command =
188188
containerExecutor.getRunCommand("echo", "group1", null, null, conf,
@@ -191,7 +191,7 @@ public void testRunCommandWithCpuAndMemoryResources() {
191191
int containerPerc = (yarnCpuLimit * containerCores) / nodeVCores;
192192
cpuRate = Math.min(10000, 100 * containerPerc);
193193
expected[6] = String.valueOf(cpuRate);
194-
Assertions.assertEquals(Arrays.toString(expected), Arrays.toString(command));
194+
assertEquals(Arrays.toString(expected), Arrays.toString(command));
195195
}
196196

197197
@Test
@@ -212,7 +212,7 @@ public void testExecContainer() throws Exception {
212212
containerExecutor.execContainer(ctx);
213213
} catch (Exception e) {
214214
// socket exception should be thrown immediately, without RPC retries.
215-
Assertions.assertTrue(e instanceof ContainerExecutionException);
215+
assertTrue(e instanceof ContainerExecutionException);
216216
}
217217
}
218218

@@ -234,7 +234,7 @@ public void testCleanupBeforeLaunch() throws Exception {
234234
.thenReturn(localResources);
235235
when(container.getUser()).thenReturn(System.getProperty("user.name"));
236236
containerExecutor.cleanupBeforeRelaunch(container);
237-
Assertions.assertTrue(!Files.exists(linkName));
237+
assertTrue(!Files.exists(linkName));
238238
}
239239

240240
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
import static org.apache.hadoop.fs.CreateFlag.CREATE;
2222
import static org.apache.hadoop.fs.CreateFlag.OVERWRITE;
23-
import static org.junit.jupiter.api.Assertions.assertTrue;
2423
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotSame;
25+
import static org.junit.jupiter.api.Assertions.assertNull;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
import static org.junit.jupiter.api.Assertions.fail;
2528
import static org.mockito.ArgumentMatchers.any;
2629
import static org.mockito.ArgumentMatchers.anyBoolean;
2730
import static org.mockito.ArgumentMatchers.isA;
@@ -86,7 +89,6 @@
8689
import org.apache.hadoop.yarn.server.nodemanager.executor.LocalizerStartContext;
8790
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService;
8891
import org.junit.jupiter.api.AfterAll;
89-
import org.junit.jupiter.api.Assertions;
9092
import org.junit.jupiter.api.BeforeEach;
9193
import org.junit.jupiter.api.Test;
9294
import org.junit.jupiter.api.Timeout;
@@ -170,7 +172,7 @@ public void testDirPermissions() throws Exception {
170172
for (String dir : localDirs) {
171173
FileStatus stats = lfs.getFileStatus(
172174
new Path(new Path(dir, ContainerLocalizer.USERCACHE), user));
173-
Assertions.assertEquals(userCachePerm, stats.getPermission());
175+
assertEquals(userCachePerm, stats.getPermission());
174176
}
175177

176178
for (String dir : localDirs) {
@@ -179,12 +181,12 @@ public void testDirPermissions() throws Exception {
179181
Path appCachePath = new Path(userCachePath,
180182
ContainerLocalizer.APPCACHE);
181183
FileStatus stats = lfs.getFileStatus(appCachePath);
182-
Assertions.assertEquals(appCachePerm, stats.getPermission());
184+
assertEquals(appCachePerm, stats.getPermission());
183185
stats = lfs.getFileStatus(
184186
new Path(userCachePath, ContainerLocalizer.FILECACHE));
185-
Assertions.assertEquals(fileCachePerm, stats.getPermission());
187+
assertEquals(fileCachePerm, stats.getPermission());
186188
stats = lfs.getFileStatus(new Path(appCachePath, appId));
187-
Assertions.assertEquals(appDirPerm, stats.getPermission());
189+
assertEquals(appDirPerm, stats.getPermission());
188190
}
189191

190192
String[] permissionsArray = { "000", "111", "555", "710", "777" };
@@ -198,7 +200,7 @@ public void testDirPermissions() throws Exception {
198200

199201
for (String dir : logDirs) {
200202
FileStatus stats = lfs.getFileStatus(new Path(dir, appId));
201-
Assertions.assertEquals(logDirPerm, stats.getPermission());
203+
assertEquals(logDirPerm, stats.getPermission());
202204
lfs.delete(new Path(dir, appId), true);
203205
}
204206
}
@@ -311,7 +313,7 @@ private void testLaunchContainerCopyFiles(boolean https) throws Exception {
311313
lfs.delete(workDir, true);
312314
try {
313315
lfs.getFileStatus(workDir);
314-
Assertions.fail("Expected FileNotFoundException on " + workDir);
316+
fail("Expected FileNotFoundException on " + workDir);
315317
} catch (FileNotFoundException e) {
316318
// expected
317319
}
@@ -327,33 +329,33 @@ private void testLaunchContainerCopyFiles(boolean https) throws Exception {
327329
Path finalTrustorePath = new Path(workDir,
328330
ContainerLaunch.TRUSTSTORE_FILE);
329331

330-
Assertions.assertTrue(lfs.getFileStatus(workDir).isDirectory());
331-
Assertions.assertTrue(lfs.getFileStatus(finalScriptPath).isFile());
332-
Assertions.assertTrue(lfs.getFileStatus(finalTokensPath).isFile());
332+
assertTrue(lfs.getFileStatus(workDir).isDirectory());
333+
assertTrue(lfs.getFileStatus(finalScriptPath).isFile());
334+
assertTrue(lfs.getFileStatus(finalTokensPath).isFile());
333335
if (https) {
334-
Assertions.assertTrue(lfs.getFileStatus(finalKeystorePath).isFile());
335-
Assertions.assertTrue(lfs.getFileStatus(finalTrustorePath).isFile());
336+
assertTrue(lfs.getFileStatus(finalKeystorePath).isFile());
337+
assertTrue(lfs.getFileStatus(finalTrustorePath).isFile());
336338
} else {
337339
try {
338340
lfs.getFileStatus(finalKeystorePath);
339-
Assertions.fail("Expected FileNotFoundException on " + finalKeystorePath);
341+
fail("Expected FileNotFoundException on " + finalKeystorePath);
340342
} catch (FileNotFoundException e) {
341343
// expected
342344
}
343345
try {
344346
lfs.getFileStatus(finalTrustorePath);
345-
Assertions.fail("Expected FileNotFoundException on " + finalKeystorePath);
347+
fail("Expected FileNotFoundException on " + finalKeystorePath);
346348
} catch (FileNotFoundException e) {
347349
// expected
348350
}
349351
}
350352

351-
Assertions.assertEquals("script", readStringFromPath(lfs, finalScriptPath));
352-
Assertions.assertEquals("tokens", readStringFromPath(lfs, finalTokensPath));
353+
assertEquals("script", readStringFromPath(lfs, finalScriptPath));
354+
assertEquals("tokens", readStringFromPath(lfs, finalTokensPath));
353355
if (https) {
354-
Assertions.assertEquals("keystore", readStringFromPath(lfs,
356+
assertEquals("keystore", readStringFromPath(lfs,
355357
finalKeystorePath));
356-
Assertions.assertEquals("truststore", readStringFromPath(lfs,
358+
assertEquals("truststore", readStringFromPath(lfs,
357359
finalTrustorePath));
358360
}
359361
}
@@ -389,8 +391,8 @@ public void testContainerLaunchError()
389391
public Object answer(InvocationOnMock invocationOnMock)
390392
throws Throwable {
391393
String diagnostics = (String) invocationOnMock.getArguments()[0];
392-
assertTrue(
393-
diagnostics.contains("No such file or directory"), "Invalid Diagnostics message: " + diagnostics);
394+
assertTrue(diagnostics.contains("No such file or directory"),
395+
"Invalid Diagnostics message: " + diagnostics);
394396
return null;
395397
}
396398
}
@@ -415,10 +417,9 @@ public Object answer(InvocationOnMock invocationOnMock)
415417
ContainerDiagnosticsUpdateEvent event =
416418
(ContainerDiagnosticsUpdateEvent) invocationOnMock
417419
.getArguments()[0];
418-
assertTrue(
419-
event.getDiagnosticsUpdate().contains("No such file or directory"), "Invalid Diagnostics message: "
420-
+ event.getDiagnosticsUpdate()
421-
);
420+
assertTrue(event.getDiagnosticsUpdate().contains("No such file or directory"),
421+
"Invalid Diagnostics message: "
422+
+ event.getDiagnosticsUpdate());
422423
return null;
423424
}
424425
}).when(container).handle(any(ContainerDiagnosticsUpdateEvent.class));
@@ -466,7 +467,7 @@ public Object answer(InvocationOnMock invocationOnMock)
466467
.setLocalDirs(localDirs)
467468
.setLogDirs(logDirs)
468469
.build());
469-
Assertions.assertNotSame(0, ret);
470+
assertNotSame(0, ret);
470471
} finally {
471472
mockExec.deleteAsUser(new DeletionAsUserContext.Builder()
472473
.setUser(appSubmitter)
@@ -602,7 +603,7 @@ public ContainerLocalizer createContainerLocalizer(String user,
602603
.build());
603604

604605
} catch (IOException e) {
605-
Assertions.fail("StartLocalizer failed to copy token file: "
606+
fail("StartLocalizer failed to copy token file: "
606607
+ StringUtils.stringifyException(e));
607608
} finally {
608609
mockExec.deleteAsUser(new DeletionAsUserContext.Builder()
@@ -857,7 +858,7 @@ public void testAllocateNumaMemoryResource() throws Exception {
857858
ContainerId.fromString("container_1481156246874_0001_01_000004"));
858859
when(mockContainer.getResource())
859860
.thenReturn(Resource.newInstance(80000, 2));
860-
Assertions.assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
861+
assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
861862

862863
// allocates node 1 for memory and cpu
863864
testAllocateNumaResource("container_1481156246874_0001_01_000005",
@@ -884,7 +885,7 @@ public void testAllocateNumaCpusResource() throws Exception {
884885
when(mockContainer.getContainerId()).thenReturn(
885886
ContainerId.fromString("container_1481156246874_0001_01_000004"));
886887
when(mockContainer.getResource()).thenReturn(Resource.newInstance(2048, 2));
887-
Assertions.assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
888+
assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
888889

889890
// allocates node 1 for memory and cpu
890891
testAllocateNumaResource("container_1481156246874_0001_01_000005",
@@ -935,7 +936,7 @@ public void testReacquireContainer() throws Exception {
935936
.thenReturn(Resource.newInstance(1024, 2));
936937

937938
// returns null since there are no sufficient resources available for the request
938-
Assertions.assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
939+
assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
939940
}
940941

941942
@Test
@@ -944,7 +945,7 @@ public void testConcatStringCommands() {
944945
assertEquals(containerExecutor.concatStringCommands(null, new String[]{"hello"})[0],
945946
new String[]{"hello"}[0]);
946947
// test both array of string as null
947-
Assertions.assertNull(containerExecutor.concatStringCommands(null, null));
948+
assertNull(containerExecutor.concatStringCommands(null, null));
948949
// test case when both arrays are not null and of equal length
949950
String[] res = containerExecutor.concatStringCommands(new String[]{"one"},
950951
new String[]{"two"});

0 commit comments

Comments
 (0)