Skip to content

Commit d9cc9ff

Browse files
committed
YARN-11263. Fix Junit Test & CheckStyle.
1 parent cde7db9 commit d9cc9ff

File tree

9 files changed

+55
-53
lines changed

9 files changed

+55
-53
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
2326
import org.slf4j.Logger;
2427
import org.slf4j.LoggerFactory;
2528

@@ -28,8 +31,8 @@
2831
import org.apache.hadoop.fs.permission.FsPermission;
2932
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3033
import org.apache.hadoop.yarn.server.nodemanager.containermanager.TestContainerManager;
31-
import org.junit.After;
32-
import org.junit.Assume;
34+
35+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
3336

3437
public class TestContainerManagerWithLCE extends TestContainerManager {
3538

@@ -49,10 +52,10 @@ public TestContainerManagerWithLCE() throws UnsupportedFileSystemException {
4952
TestContainerManagerWithLCE.class.getName() + "-tmpDir");
5053
}
5154

55+
@BeforeEach
5256
@Override
5357
public void setup() throws IOException {
54-
Assume.assumeTrue("LCE binary path is not passed. Not running the test",
55-
shouldRunTest());
58+
assumeTrue(shouldRunTest(), "LCE binary path is not passed. Not running the test");
5659
super.setup();
5760
localFS.setPermission(new Path(localDir.getCanonicalPath()),
5861
new FsPermission(
@@ -62,7 +65,7 @@ public void setup() throws IOException {
6265
(short) 0777));
6366
}
6467

65-
@After
68+
@AfterEach
6669
@Override
6770
public void tearDown() throws IOException, InterruptedException {
6871
if (shouldRunTest()) {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,19 +1193,19 @@ protected void testContainerLaunchAndExit(int exitCode) throws IOException,
11931193
ContainerStatus containerStatus = containerManager.
11941194
getContainerStatuses(gcsRequest).getContainerStatuses().get(0);
11951195

1196-
// Verify exit status matches exit state of script
1197-
assertEquals(exitCode, containerStatus.getExitStatus());
1196+
// Verify exit status matches exit state of script
1197+
assertEquals(exitCode, containerStatus.getExitStatus());
11981198
}
11991199

12001200
@Test
12011201
public void testContainerLaunchAndExitSuccess() throws IOException,
12021202
InterruptedException, YarnException {
1203-
containerManager.start();
1204-
int exitCode = 0;
1203+
containerManager.start();
1204+
int exitCode = 0;
12051205

1206-
// launch context for a command that will return exit code 0
1207-
// and verify exit code returned
1208-
testContainerLaunchAndExit(exitCode);
1206+
// launch context for a command that will return exit code 0
1207+
// and verify exit code returned
1208+
testContainerLaunchAndExit(exitCode);
12091209
}
12101210

12111211
@Test
@@ -2265,8 +2265,8 @@ public void testGetLocalizationStatuses() throws Exception {
22652265
.get(containerId).size());
22662266
LocalizationStatus status = statusResponse.getLocalizationStatuses()
22672267
.get(containerId).iterator().next();
2268-
assertEquals("resource key", "dest_file1",
2269-
status.getResourceKey());
2268+
assertEquals("dest_file1",
2269+
status.getResourceKey(), "resource key");
22702270
assertEquals(LocalizationState.COMPLETED,
22712271
status.getLocalizationState(), "resource status");
22722272

@@ -2331,8 +2331,8 @@ public void testGetLocalizationStatusesMultiContainers() throws Exception {
23312331
.getLocalizationStatuses().get(container1);
23322332
assertEquals(1, statuses.size());
23332333
LocalizationStatus status = statuses.get(0);
2334-
assertEquals("resource key", "dest_file1",
2335-
status.getResourceKey());
2334+
assertEquals("dest_file1",
2335+
status.getResourceKey(), "resource key");
23362336
assertEquals(LocalizationState.COMPLETED,
23372337
status.getLocalizationState(), "resource status");
23382338
});

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public class TestCGroupElasticMemoryController {
5959
public void testConstructorOff()
6060
throws YarnException {
6161
assertThrows(YarnException.class, () -> {
62-
new CGroupElasticMemoryController(
62+
new CGroupElasticMemoryController(
6363
conf,
6464
null,
6565
null,
6666
false,
6767
false,
6868
10000
69-
);
69+
);
7070
});
7171
}
7272

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandlerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ public void testReacquireContainer() throws ResourceHandlerException {
506506
@Test
507507
public void testSha256CalculationFails() throws ResourceHandlerException {
508508
ResourceHandlerException exception =
509-
assertThrows(ResourceHandlerException.class, () -> {
510-
dummyAocx.delete();
511-
fpgaResourceHandler.preStart(mockContainer(0, 1, "GEMM"));
512-
});
509+
assertThrows(ResourceHandlerException.class, () -> {
510+
dummyAocx.delete();
511+
fpgaResourceHandler.preStart(mockContainer(0, 1, "GEMM"));
512+
});
513513
assertEquals("Could not calculate SHA-256", exception.getMessage());
514514
}
515515

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/gpu/TestGpuResourceAllocator.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,28 @@ public void testThreeContainersJustTwoOfThemSatisfied()
343343
throws ResourceHandlerException, IOException {
344344
ResourceHandlerException exception =
345345
assertThrows(ResourceHandlerException.class, () -> {
346-
addGpus(new GpuDevice(1, 1), new GpuDevice(1, 2),
347-
new GpuDevice(1, 3), new GpuDevice(1, 4),
348-
new GpuDevice(1, 5), new GpuDevice(1, 6));
349-
Container container = createMockContainer(3, 5L);
350-
Container container2 = createMockContainer(2, 6L);
351-
Container container3 = createMockContainer(2, 6L);
352-
353-
GpuAllocation allocation = testSubject.assignGpus(container);
354-
assertAllocatedGpus(3, 3, container, allocation);
355-
assertEquals(3, testSubject.getDeviceAllocationMapping().size());
356-
assertEquals(3, testSubject.getAssignedGpus().size());
357-
assertEquals(6, testSubject.getAllowedGpus().size());
358-
assertEquals(3, testSubject.getAvailableGpus());
359-
360-
GpuAllocation allocation2 = testSubject.assignGpus(container2);
361-
assertAllocatedGpus(2, 4, container2, allocation2);
362-
assertEquals(5, testSubject.getDeviceAllocationMapping().size());
363-
assertEquals(5, testSubject.getAssignedGpus().size());
364-
assertEquals(6, testSubject.getAllowedGpus().size());
365-
assertEquals(1, testSubject.getAvailableGpus());
366-
367-
testSubject.assignGpus(container3);
346+
addGpus(new GpuDevice(1, 1), new GpuDevice(1, 2),
347+
new GpuDevice(1, 3), new GpuDevice(1, 4),
348+
new GpuDevice(1, 5), new GpuDevice(1, 6));
349+
Container container = createMockContainer(3, 5L);
350+
Container container2 = createMockContainer(2, 6L);
351+
Container container3 = createMockContainer(2, 6L);
352+
353+
GpuAllocation allocation = testSubject.assignGpus(container);
354+
assertAllocatedGpus(3, 3, container, allocation);
355+
assertEquals(3, testSubject.getDeviceAllocationMapping().size());
356+
assertEquals(3, testSubject.getAssignedGpus().size());
357+
assertEquals(6, testSubject.getAllowedGpus().size());
358+
assertEquals(3, testSubject.getAvailableGpus());
359+
360+
GpuAllocation allocation2 = testSubject.assignGpus(container2);
361+
assertAllocatedGpus(2, 4, container2, allocation2);
362+
assertEquals(5, testSubject.getDeviceAllocationMapping().size());
363+
assertEquals(5, testSubject.getAssignedGpus().size());
364+
assertEquals(6, testSubject.getAllowedGpus().size());
365+
assertEquals(1, testSubject.getAvailableGpus());
366+
367+
testSubject.assignGpus(container3);
368368
});
369369

370370
assertThat(exception.getMessage()).contains("Failed to find enough GPUs");

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ public class TestDockerContainerRuntime {
182182
private final static String ENV_OCI_CONTAINER_RUN_PRIVILEGED_CONTAINER =
183183
formatOciEnvKey(RUNTIME_TYPE, RUN_PRIVILEGED_CONTAINER_SUFFIX);
184184

185-
// @Parameterized.Parameters(name = "https={0}")
186185
public static Collection<Object[]> data() {
187186
return Arrays.asList(new Object[][] {
188187
{true}, {false}
@@ -1846,7 +1845,7 @@ public void testDefaultRWMountsInvalid(boolean pHttps) throws ContainerExecution
18461845
public void testContainerLivelinessFileExistsNoException(boolean pHttps,
18471846
@TempDir java.nio.file.Path path) throws Exception {
18481847
initHttps(pHttps);
1849-
File testTempDir = Files.createDirectory(path).toFile();
1848+
File testTempDir = path.toFile();
18501849
File procPidPath = new File(testTempDir + File.separator + signalPid);
18511850
procPidPath.createNewFile();
18521851
procPidPath.deleteOnExit();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ public void testLocalizerRunnerException() throws Exception {
820820

821821
@Test
822822
@Timeout(value = 10)
823-
@SuppressWarnings("unchecked") // mocked generics
823+
@SuppressWarnings({"unchecked", "methodlength"}) // mocked generics
824824
public void testLocalizationHeartbeat() throws Exception {
825825
List<Path> localDirs = new ArrayList<Path>();
826826
String[] sDirs = new String[1];

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ public void testFailedDirsLocalFileDeletionAfterUpload() throws Exception {
15851585

15861586
@Test
15871587
@Timeout(value = 50)
1588-
@SuppressWarnings("unchecked")
1588+
@SuppressWarnings({"unchecked", "methodlength"})
15891589
public void testLogAggregationServiceWithPatterns() throws Exception {
15901590

15911591
LogAggregationContext logAggregationContextWithIncludePatterns =

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nec/TestVEDeviceDiscoverer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ public void testNonVESlotFilesAreSkipped() throws IOException {
240240
@Test
241241
public void testNonBlockOrCharFilesAreRejected() throws IOException {
242242
IllegalArgumentException exception =
243-
assertThrows(IllegalArgumentException.class, () -> {
244-
createVeSlotFile(0);
245-
when(mockCommandExecutor.getOutput()).thenReturn("0:0:regular file");
246-
discoverer.getDevicesFromPath(testFolder);
247-
});
243+
assertThrows(IllegalArgumentException.class, () -> {
244+
createVeSlotFile(0);
245+
when(mockCommandExecutor.getOutput()).thenReturn("0:0:regular file");
246+
discoverer.getDevicesFromPath(testFolder);
247+
});
248248
assertThat(exception.getMessage()).contains("File is neither a char nor block device");
249249
}
250250

0 commit comments

Comments
 (0)