From aa4c744aef7f2536f9054bf1692a2c693d862364 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Wed, 17 Apr 2019 21:48:19 +0530 Subject: [PATCH] YARN-9470. Fix order of actual and expected expression in assert statements Signed-off-by: Akira Ajisaka --- .../hadoop-yarn-services-core/pom.xml | 6 ++ .../yarn/service/TestYarnNativeServices.java | 3 +- .../yarn/service/client/TestServiceCLI.java | 13 ++-- .../service/utils/TestServiceApiUtil.java | 3 +- .../hadoop-yarn/hadoop-yarn-client/pom.xml | 5 ++ .../api/async/impl/TestAMRMClientAsync.java | 3 +- .../yarn/client/api/impl/TestAHSClient.java | 3 +- .../client/api/impl/TestAHSv2ClientImpl.java | 34 +++++---- .../yarn/client/api/impl/TestAMRMClient.java | 3 +- ...stOpportunisticContainerAllocationE2E.java | 3 +- .../yarn/client/api/impl/TestYarnClient.java | 39 +++++----- .../impl/TestYarnClientWithReservation.java | 10 ++- .../hadoop/yarn/client/cli/TestYarnCLI.java | 13 ++-- .../hadoop-yarn/hadoop-yarn-common/pom.xml | 5 ++ .../hadoop/yarn/api/TestResourcePBImpl.java | 3 +- ...TestLogAggregationIndexFileController.java | 7 +- .../org/apache/hadoop/yarn/util/TestApps.java | 3 +- .../hadoop/yarn/util/TestConverterUtils.java | 9 ++- .../yarn/util/TestTimelineServiceHelper.java | 4 +- .../yarn/util/resource/TestResourceUtils.java | 28 +++---- .../hadoop-yarn/hadoop-yarn-csi/pom.xml | 5 ++ .../csi/adaptor/TestCsiAdaptorService.java | 13 ++-- .../pom.xml | 5 ++ .../webapp/TestAHSWebServices.java | 19 ++--- .../hadoop-yarn-server-common/pom.xml | 5 ++ .../manager/BasePolicyManagerTest.java | 9 ++- .../hadoop-yarn-server-nodemanager/pom.xml | 5 ++ .../TestLinuxContainerExecutorWithMocks.java | 46 +++++------ .../TestContainerManagerRecovery.java | 13 ++-- .../launcher/TestContainerLaunch.java | 21 ++--- .../resources/TestResourceHandlerModule.java | 6 +- .../TestResourceLocalizationService.java | 9 ++- .../TestLogAggregationService.java | 3 +- .../TestNvidiaGPUPluginForRuntimeV2.java | 31 ++++---- .../TestNMLeveldbStateStoreService.java | 32 ++++---- .../nodemanager/webapp/TestNMWebServices.java | 9 ++- .../pom.xml | 5 ++ .../resourcemanager/TestClientRMService.java | 23 +++--- .../TestKillApplicationWithRMHA.java | 3 +- .../resourcemanager/TestRMAdminService.java | 3 +- .../yarn/server/resourcemanager/TestRMHA.java | 5 +- .../server/resourcemanager/TestRMRestart.java | 5 +- .../resourcemanager/TestRMServerUtils.java | 9 ++- .../TestWorkPreservingRMRestart.java | 16 ++-- .../metrics/TestSystemMetricsPublisher.java | 3 +- ...acityPreemptionPolicyPreemptToBalance.java | 4 +- .../TestFileSystemNodeAttributeStore.java | 13 ++-- .../nodelabels/TestRMNodeLabelsManager.java | 76 ++++++++++--------- .../recovery/TestFSRMStateStore.java | 5 +- .../recovery/TestZKRMStateStore.java | 7 +- .../TestReservationSystemUtil.java | 9 ++- .../planning/TestAlignedPlanner.java | 33 ++++---- .../rmapp/TestRMAppTransitions.java | 4 +- .../capacity/TestApplicationLimits.java | 26 ++++--- .../capacity/TestApplicationPriority.java | 8 +- .../capacity/TestCapacityScheduler.java | 4 +- .../fair/TestConfigurableResource.java | 13 +++- .../fair/TestContinuousScheduling.java | 8 +- .../scheduler/fair/TestFSLeafQueue.java | 10 ++- .../scheduler/fair/TestFairScheduler.java | 32 ++++---- .../scheduler/fifo/TestFifoScheduler.java | 15 ++-- .../policy/TestFifoOrderingPolicy.java | 10 ++- .../TestFifoOrderingPolicyForPendingApps.java | 8 +- .../volume/csi/TestVolumeProcessor.java | 9 ++- .../webapp/TestRMWebServicesNodes.java | 5 +- .../webapp/TestRMWebServicesReservation.java | 3 +- .../pom.xml | 5 ++ .../TestEntityGroupFSTimelineStore.java | 3 +- .../pom.xml | 6 ++ .../TestHBaseStorageFlowRunCompaction.java | 4 +- .../pom.xml | 6 ++ .../collector/TestTimelineCollector.java | 5 +- .../hadoop-yarn-server-web-proxy/pom.xml | 5 ++ .../webproxy/TestWebAppProxyServlet.java | 3 +- .../webproxy/amfilter/TestAmFilter.java | 3 +- .../webproxy/amfilter/TestSecureAmFilter.java | 4 +- 76 files changed, 501 insertions(+), 345 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml index 695d93bc1b..ff585f944c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml @@ -250,6 +250,12 @@ test + + org.assertj + assertj-core + test + + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java index 6c38511ed7..0512e5845b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java @@ -61,6 +61,7 @@ import java.util.*; import java.util.concurrent.TimeoutException; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.api.records.YarnApplicationState.FINISHED; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.*; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_COMMAND_ARGUMENT_ERROR; @@ -904,7 +905,7 @@ private void checkEachCompInstancesInOrder(Component component, String int i = 0; for (String s : instances) { - Assert.assertEquals(component.getName() + "-" + i, s); + assertThat(s).isEqualTo(component.getName() + "-" + i); i++; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java index 41be8c7e57..f75c0afdbe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java @@ -50,6 +50,7 @@ import java.util.Arrays; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.client.api.AppAdminClient.YARN_APP_ADMIN_CLIENT_PREFIX; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.DEPENDENCY_TARBALL_PATH; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.YARN_SERVICE_BASE_PATH; @@ -172,7 +173,7 @@ public void testInitiateServiceUpgrade() throws Exception { "-initiate", ExampleAppJson.resourceName(ExampleAppJson.APP_JSON), "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test (timeout = 180000) @@ -182,7 +183,7 @@ public void testInitiateAutoFinalizeServiceUpgrade() throws Exception { "-autoFinalize", "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test @@ -194,7 +195,7 @@ public void testUpgradeInstances() throws Exception { "-instances", "comp1-0,comp1-1", "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test @@ -206,7 +207,7 @@ public void testUpgradeComponents() throws Exception { "-components", "comp1,comp2", "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test @@ -218,7 +219,7 @@ public void testGetInstances() throws Exception { "-components", "comp1,comp2", "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test @@ -229,7 +230,7 @@ public void testCancelUpgrade() throws Exception { String[] args = {"app", "-upgrade", "app-1", "-cancel", "-appTypes", DUMMY_APP_TYPE}; int result = cli.run(ApplicationCLI.preProcessArgs(args)); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); } @Test (timeout = 180000) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java index 2bf59b8afc..3c9b52448d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java @@ -45,6 +45,7 @@ import java.util.Collections; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.service.conf.RestApiConstants.DEFAULT_UNLIMITED_LIFETIME; import static org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages.*; import static org.junit.Assert.assertEquals; @@ -268,7 +269,7 @@ public void testArtifacts() throws IOException { Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); } - assertEquals(app.getLifetime(), DEFAULT_UNLIMITED_LIFETIME); + assertThat(app.getLifetime()).isEqualTo(DEFAULT_UNLIMITED_LIFETIME); } private static Resource createValidResource() { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml index 5de2cb4cb1..81ff752e98 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml @@ -84,6 +84,11 @@ junit test + + org.assertj + assertj-core + test + org.apache.hadoop diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java index f56747e346..3cd4414c93 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.client.api.async.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyInt; @@ -596,7 +597,7 @@ public float getProgress() { @Override public void onError(Throwable e) { - Assert.assertEquals(e.getMessage(), "Exception from callback handler"); + assertThat(e).hasMessage("Exception from callback handler"); callStopAndNotify(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java index 3dbd1dd4f2..dcb8a17d36 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -84,7 +85,7 @@ public void testGetApplications() throws YarnException, IOException { Assert.assertEquals(reports, expectedReports); reports = client.getApplications(); - Assert.assertEquals(reports.size(), 4); + assertThat(reports).hasSize(4); client.stop(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java index 1e0a1d6550..f4d7a56297 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -80,14 +81,14 @@ public void testGetContainerReport() throws IOException, YarnException { when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null)) .thenReturn(createApplicationTimelineEntity(appId, true, false)); ContainerReport report = client.getContainerReport(containerId); - Assert.assertEquals(report.getContainerId(), containerId); - Assert.assertEquals(report.getAssignedNode().getHost(), "test host"); - Assert.assertEquals(report.getAssignedNode().getPort(), 100); - Assert.assertEquals(report.getAllocatedResource().getVirtualCores(), 8); - Assert.assertEquals(report.getCreationTime(), 123456); - Assert.assertEquals(report.getLogUrl(), - "https://localhost:8188/ahs/logs/test host:100/" - + "container_0_0001_01_000001/container_0_0001_01_000001/user1"); + assertThat(report.getContainerId()).isEqualTo(containerId); + assertThat(report.getAssignedNode().getHost()).isEqualTo("test host"); + assertThat(report.getAssignedNode().getPort()).isEqualTo(100); + assertThat(report.getAllocatedResource().getVirtualCores()).isEqualTo(8); + assertThat(report.getCreationTime()).isEqualTo(123456); + assertThat(report.getLogUrl()).isEqualTo("https://localhost:8188/ahs/logs/" + + "test host:100/container_0_0001_01_000001/" + + "container_0_0001_01_000001/user1"); } @Test @@ -100,10 +101,10 @@ public void testGetAppAttemptReport() throws IOException, YarnException { .thenReturn(createAppAttemptTimelineEntity(appAttemptId)); ApplicationAttemptReport report = client.getApplicationAttemptReport(appAttemptId); - Assert.assertEquals(report.getApplicationAttemptId(), appAttemptId); - Assert.assertEquals(report.getFinishTime(), Integer.MAX_VALUE + 2L); - Assert.assertEquals(report.getOriginalTrackingUrl(), - "test original tracking url"); + assertThat(report.getApplicationAttemptId()).isEqualTo(appAttemptId); + assertThat(report.getFinishTime()).isEqualTo(Integer.MAX_VALUE + 2L); + assertThat(report.getOriginalTrackingUrl()). + isEqualTo("test original tracking url"); } @Test @@ -112,11 +113,12 @@ public void testGetAppReport() throws IOException, YarnException { when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null)) .thenReturn(createApplicationTimelineEntity(appId, false, false)); ApplicationReport report = client.getApplicationReport(appId); - Assert.assertEquals(report.getApplicationId(), appId); - Assert.assertEquals(report.getAppNodeLabelExpression(), "test_node_label"); + assertThat(report.getApplicationId()).isEqualTo(appId); + assertThat(report.getAppNodeLabelExpression()). + isEqualTo("test_node_label"); Assert.assertTrue(report.getApplicationTags().contains("Test_APP_TAGS_1")); - Assert.assertEquals(report.getYarnApplicationState(), - YarnApplicationState.FINISHED); + assertThat(report.getYarnApplicationState()). + isEqualTo(YarnApplicationState.FINISHED); } private static TimelineEntity createApplicationTimelineEntity( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java index da4f6ee5c8..24666f066d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -1616,7 +1617,7 @@ private void waitForContainerCompletion(int numIterations, for(ContainerStatus cStatus :allocResponse .getCompletedContainersStatuses()) { if(releases.contains(cStatus.getContainerId())) { - assertEquals(cStatus.getState(), ContainerState.COMPLETE); + assertThat(cStatus.getState()).isEqualTo(ContainerState.COMPLETE); assertEquals(-100, cStatus.getExitStatus()); releases.remove(cStatus.getContainerId()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestOpportunisticContainerAllocationE2E.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestOpportunisticContainerAllocationE2E.java index 753c00ba6f..870862b9cd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestOpportunisticContainerAllocationE2E.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestOpportunisticContainerAllocationE2E.java @@ -81,6 +81,7 @@ import java.util.Set; import java.util.TreeSet; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -657,7 +658,7 @@ public void testMixedAllocationAndRelease() throws YarnException, for (ContainerStatus cStatus : allocResponse .getCompletedContainersStatuses()) { if (releases.contains(cStatus.getContainerId())) { - assertEquals(cStatus.getState(), ContainerState.COMPLETE); + assertThat(cStatus.getState()).isEqualTo(ContainerState.COMPLETE); assertEquals(-100, cStatus.getExitStatus()); releases.remove(cStatus.getContainerId()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java index 3848b10682..4af97e4212 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java @@ -93,6 +93,7 @@ import java.util.Map; import java.util.Set; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -416,7 +417,7 @@ public void testGetApplications() throws YarnException, IOException { List expectedReports = ((MockYarnClient)client).getReports(); List reports = client.getApplications(); - Assert.assertEquals(reports, expectedReports); + assertThat(reports).isEqualTo(expectedReports); Set appTypes = new HashSet<>(); appTypes.add("YARN"); @@ -424,7 +425,7 @@ public void testGetApplications() throws YarnException, IOException { reports = client.getApplications(appTypes, null); - Assert.assertEquals(reports.size(), 2); + assertThat(reports).hasSize(2); Assert .assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports .get(1).getApplicationType().equals("NON-YARN")) @@ -439,7 +440,7 @@ public void testGetApplications() throws YarnException, IOException { appStates.add(YarnApplicationState.FINISHED); appStates.add(YarnApplicationState.FAILED); reports = client.getApplications(null, appStates); - Assert.assertEquals(reports.size(), 2); + assertThat(reports).hasSize(2); Assert .assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports .get(1).getApplicationType().equals("NON-MAPREDUCE")) @@ -469,9 +470,9 @@ public void testGetApplicationAttempts() throws YarnException, IOException { List reports = client .getApplicationAttempts(applicationId); Assert.assertNotNull(reports); - Assert.assertEquals(reports.get(0).getApplicationAttemptId(), + assertThat(reports.get(0).getApplicationAttemptId()).isEqualTo( ApplicationAttemptId.newInstance(applicationId, 1)); - Assert.assertEquals(reports.get(1).getApplicationAttemptId(), + assertThat(reports.get(1).getApplicationAttemptId()).isEqualTo( ApplicationAttemptId.newInstance(applicationId, 2)); client.stop(); } @@ -492,7 +493,7 @@ public void testGetApplicationAttempt() throws YarnException, IOException { ApplicationAttemptReport report = client .getApplicationAttemptReport(appAttemptId); Assert.assertNotNull(report); - Assert.assertEquals(report.getApplicationAttemptId().toString(), + assertThat(report.getApplicationAttemptId().toString()).isEqualTo( expectedReports.get(0).getCurrentApplicationAttemptId().toString()); client.stop(); } @@ -512,11 +513,11 @@ public void testGetContainers() throws YarnException, IOException { applicationId, 1); List reports = client.getContainers(appAttemptId); Assert.assertNotNull(reports); - Assert.assertEquals(reports.get(0).getContainerId(), + assertThat(reports.get(0).getContainerId()).isEqualTo( (ContainerId.newContainerId(appAttemptId, 1))); - Assert.assertEquals(reports.get(1).getContainerId(), + assertThat(reports.get(1).getContainerId()).isEqualTo( (ContainerId.newContainerId(appAttemptId, 2))); - Assert.assertEquals(reports.get(2).getContainerId(), + assertThat(reports.get(2).getContainerId()).isEqualTo( (ContainerId.newContainerId(appAttemptId, 3))); //First2 containers should come from RM with updated state information and @@ -554,9 +555,9 @@ public List getContainers( List reports = client.getContainers(appAttemptId); Assert.assertNotNull(reports); Assert.assertTrue(reports.size() == 2); - Assert.assertEquals(reports.get(0).getContainerId(), + assertThat(reports.get(0).getContainerId()).isEqualTo( (ContainerId.newContainerId(appAttemptId, 1))); - Assert.assertEquals(reports.get(1).getContainerId(), + assertThat(reports.get(1).getContainerId()).isEqualTo( (ContainerId.newContainerId(appAttemptId, 2))); //Only 2 running containers from RM are present when AHS throws exception @@ -586,13 +587,13 @@ public void testGetContainerReport() throws YarnException, IOException { ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); ContainerReport report = client.getContainerReport(containerId); Assert.assertNotNull(report); - Assert.assertEquals(report.getContainerId().toString(), + assertThat(report.getContainerId().toString()).isEqualTo( (ContainerId.newContainerId(expectedReports.get(0) .getCurrentApplicationAttemptId(), 1)).toString()); containerId = ContainerId.newContainerId(appAttemptId, 3); report = client.getContainerReport(containerId); Assert.assertNotNull(report); - Assert.assertEquals(report.getContainerId().toString(), + assertThat(report.getContainerId().toString()).isEqualTo( (ContainerId.newContainerId(expectedReports.get(0) .getCurrentApplicationAttemptId(), 3)).toString()); Assert.assertNotNull(report.getExecutionType()); @@ -609,16 +610,16 @@ public void testGetLabelsToNodes() throws YarnException, IOException { Map> expectedLabelsToNodes = ((MockYarnClient)client).getLabelsToNodesMap(); Map> labelsToNodes = client.getLabelsToNodes(); - Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); - Assert.assertEquals(labelsToNodes.size(), 3); + assertThat(labelsToNodes).isEqualTo(expectedLabelsToNodes); + assertThat(labelsToNodes).hasSize(3); // Get labels to nodes for selected labels Set setLabels = new HashSet<>(Arrays.asList("x", "z")); expectedLabelsToNodes = ((MockYarnClient)client).getLabelsToNodesMap(setLabels); labelsToNodes = client.getLabelsToNodes(setLabels); - Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); - Assert.assertEquals(labelsToNodes.size(), 2); + assertThat(labelsToNodes).isEqualTo(expectedLabelsToNodes); + assertThat(labelsToNodes).hasSize(2); client.stop(); client.close(); @@ -634,8 +635,8 @@ public void testGetNodesToLabels() throws YarnException, IOException { Map> expectedNodesToLabels = ((MockYarnClient) client) .getNodeToLabelsMap(); Map> nodesToLabels = client.getNodeToLabels(); - Assert.assertEquals(nodesToLabels, expectedNodesToLabels); - Assert.assertEquals(nodesToLabels.size(), 1); + assertThat(nodesToLabels).isEqualTo(expectedNodesToLabels); + assertThat(nodesToLabels).hasSize(1); client.stop(); client.close(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientWithReservation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientWithReservation.java index 0836b7b9c9..717647724a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientWithReservation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientWithReservation.java @@ -62,6 +62,8 @@ import java.util.Collections; import java.util.stream.Collectors; +import static org.assertj.core.api.Assertions.assertThat; + /** * This class is to test class {@link YarnClient) and {@link YarnClientImpl} @@ -432,7 +434,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); duration = 30000; deadline = sRequest.getReservationDefinition().getDeadline(); @@ -447,7 +449,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); arrival = clock.getTime(); // List reservations, search by end time before the reservation start @@ -460,7 +462,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); // List reservations, search by very small end time. request = ReservationListRequest @@ -470,7 +472,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); } finally { // clean-up diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 17d570f30c..939ae46171 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -19,6 +19,7 @@ import org.apache.hadoop.yarn.api.records.NodeAttribute; import org.apache.hadoop.yarn.api.records.NodeAttributeType; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -1685,26 +1686,26 @@ public void testNodeCLIUsageInfo() throws Exception { public void testMissingArguments() throws Exception { ApplicationCLI cli = createAndGetAppCLI(); int result = cli.run(new String[] { "application", "-status" }); - Assert.assertEquals(result, -1); + assertThat(result).isEqualTo(-1); Assert.assertEquals(String.format("Missing argument for options%n%1s", createApplicationCLIHelpMessage()), sysOutStream.toString()); sysOutStream.reset(); result = cli.run(new String[] { "applicationattempt", "-status" }); - Assert.assertEquals(result, -1); + assertThat(result).isEqualTo(-1); Assert.assertEquals(String.format("Missing argument for options%n%1s", createApplicationAttemptCLIHelpMessage()), sysOutStream.toString()); sysOutStream.reset(); result = cli.run(new String[] { "container", "-status" }); - Assert.assertEquals(result, -1); + assertThat(result).isEqualTo(-1); Assert.assertEquals(String.format("Missing argument for options %1s", createContainerCLIHelpMessage()), normalize(sysOutStream.toString())); sysOutStream.reset(); NodeCLI nodeCLI = createAndGetNodeCLI(); result = nodeCLI.run(new String[] { "-status" }); - Assert.assertEquals(result, -1); + assertThat(result).isEqualTo(-1); Assert.assertEquals(String.format("Missing argument for options%n%1s", createNodeCLIHelpMessage()), sysOutStream.toString()); } @@ -2017,7 +2018,7 @@ public void testUpdateApplicationPriority() throws Exception { cli.run(new String[] { "application", "-appId", applicationId.toString(), "-updatePriority", "1" }); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); verify(client).updateApplicationPriority(any(ApplicationId.class), any(Priority.class)); @@ -2413,7 +2414,7 @@ public void testUpdateApplicationTimeout() throws Exception { int result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-updateLifetime", "10" }); - Assert.assertEquals(result, 0); + assertThat(result).isEqualTo(0); verify(client) .updateApplicationTimeouts(any(UpdateApplicationTimeoutsRequest.class)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml index 14efd2a033..c28c297927 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml @@ -114,6 +114,11 @@ mockito-core test + + org.assertj + assertj-core + test + org.apache.hadoop diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestResourcePBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestResourcePBImpl.java index f9d296d2cb..c92e73f44f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestResourcePBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestResourcePBImpl.java @@ -34,6 +34,7 @@ import org.junit.Before; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; /** @@ -294,7 +295,7 @@ public void testParsingResourceTags() { ResourceUtils.getResourceTypes().get("resource3"); Assert.assertTrue(info.getAttributes().isEmpty()); Assert.assertFalse(info.getTags().isEmpty()); - Assert.assertEquals(info.getTags().size(), 2); + assertThat(info.getTags()).hasSize(2); info.getTags().remove("resource3_tag_1"); info.getTags().remove("resource3_tag_2"); Assert.assertTrue(info.getTags().isEmpty()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/ifile/TestLogAggregationIndexFileController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/ifile/TestLogAggregationIndexFileController.java index 7922679757..64e0b20957 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/ifile/TestLogAggregationIndexFileController.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/filecontroller/ifile/TestLogAggregationIndexFileController.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.logaggregation.filecontroller.ifile; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; @@ -288,7 +289,7 @@ public boolean isRollover(final FileContext fc, // We can only get the logs/logmeta from the first write. meta = fileFormat.readAggregatedLogsMeta( logRequest); - Assert.assertEquals(meta.size(), 1); + assertThat(meta.size()).isEqualTo(1); for (ContainerLogMeta log : meta) { Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); @@ -319,7 +320,7 @@ public boolean isRollover(final FileContext fc, fileFormat.closeWriter(); meta = fileFormat.readAggregatedLogsMeta( logRequest); - Assert.assertEquals(meta.size(), 2); + assertThat(meta.size()).isEqualTo(2); for (ContainerLogMeta log : meta) { Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); @@ -347,7 +348,7 @@ public boolean isRollover(final FileContext fc, Assert.assertTrue(status.length == 2); meta = fileFormat.readAggregatedLogsMeta( logRequest); - Assert.assertEquals(meta.size(), 3); + assertThat(meta.size()).isEqualTo(3); for (ContainerLogMeta log : meta) { Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestApps.java index 0d65d659f4..5db8046c15 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestApps.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -52,7 +53,7 @@ public void testSetEnvFromInputString() { String badEnv = "1,,2=a=b,3=a=,4==,5==a,==,c-3=3,="; environment.clear(); Apps.setEnvFromInputString(environment, badEnv, File.pathSeparator); - assertEquals(environment.size(), 0); + assertThat(environment).isEmpty(); // Test "=" in the value part environment.clear(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java index 077558b96a..57542218aa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.util; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -93,12 +94,12 @@ public void testNodeIdWithDefaultPort() throws URISyntaxException { NodeId nid; nid = ConverterUtils.toNodeIdWithDefaultPort("node:10"); - assertEquals(nid.getPort(), 10); - assertEquals(nid.getHost(), "node"); + assertThat(nid.getPort()).isEqualTo(10); + assertThat(nid.getHost()).isEqualTo("node"); nid = ConverterUtils.toNodeIdWithDefaultPort("node"); - assertEquals(nid.getPort(), 0); - assertEquals(nid.getHost(), "node"); + assertThat(nid.getPort()).isEqualTo(0); + assertThat(nid.getHost()).isEqualTo("node"); } @Test(expected = IllegalArgumentException.class) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestTimelineServiceHelper.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestTimelineServiceHelper.java index d3d815b218..21a27baccd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestTimelineServiceHelper.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestTimelineServiceHelper.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.yarn.util; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -59,7 +61,7 @@ public void testMapCastToHashMap() { HashMap alternateHashMap = TimelineServiceHelper.mapCastToHashMap(firstTreeMap); Assert.assertEquals(firstTreeMap.size(), alternateHashMap.size()); - Assert.assertEquals(alternateHashMap.get(key), value); + assertThat(alternateHashMap.get(key)).isEqualTo(value); // Test complicated hashmap be casted correctly Map> complicatedHashMap = diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java index f7ec4f803f..7a701a4e90 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java @@ -18,6 +18,8 @@ package org.apache.hadoop.yarn.util.resource; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes; @@ -501,27 +503,25 @@ public void testMultipleOpsForResourcesWithTags() throws Exception { ResourceInformation.newInstance("yarn.io/test-volume", "", 3)); Resource addedResource = Resources.add(resourceA, resourceB); - Assert.assertEquals(addedResource.getMemorySize(), 5); - Assert.assertEquals(addedResource.getVirtualCores(), 10); - Assert.assertEquals( - addedResource.getResourceInformation("resource1").getValue(), 8); + assertThat(addedResource.getMemorySize()).isEqualTo(5); + assertThat(addedResource.getVirtualCores()).isEqualTo(10); + assertThat(addedResource.getResourceInformation("resource1").getValue()). + isEqualTo(8); // Verify that value of resourceA and resourceB is not added up for // "yarn.io/test-volume". - Assert.assertEquals( - addedResource.getResourceInformation("yarn.io/test-volume").getValue(), - 2); + assertThat(addedResource.getResourceInformation("yarn.io/test-volume"). + getValue()).isEqualTo(2); Resource mulResource = Resources.multiplyAndRoundDown(resourceA, 3); - Assert.assertEquals(mulResource.getMemorySize(), 6); - Assert.assertEquals(mulResource.getVirtualCores(), 12); - Assert.assertEquals( - mulResource.getResourceInformation("resource1").getValue(), 15); + assertThat(mulResource.getMemorySize()).isEqualTo(6); + assertThat(mulResource.getVirtualCores()).isEqualTo(12); + assertThat(mulResource.getResourceInformation("resource1").getValue()). + isEqualTo(15); // Verify that value of resourceA is not multiplied up for // "yarn.io/test-volume". - Assert.assertEquals( - mulResource.getResourceInformation("yarn.io/test-volume").getValue(), - 2); + assertThat(mulResource.getResourceInformation("yarn.io/test-volume"). + getValue()).isEqualTo(2); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/pom.xml index 9b2be66e6a..aa03cbf24a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/pom.xml @@ -73,6 +73,11 @@ junit junit + + org.assertj + assertj-core + test + org.apache.hadoop hadoop-common diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/src/test/java/org/apache/hadoop/yarn/csi/adaptor/TestCsiAdaptorService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/src/test/java/org/apache/hadoop/yarn/csi/adaptor/TestCsiAdaptorService.java index c415ced748..2375b06bc4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/src/test/java/org/apache/hadoop/yarn/csi/adaptor/TestCsiAdaptorService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/src/test/java/org/apache/hadoop/yarn/csi/adaptor/TestCsiAdaptorService.java @@ -52,6 +52,7 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.AccessMode.MULTI_NODE_MULTI_WRITER; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM; @@ -333,8 +334,8 @@ public void testCustomizedAdaptor() throws IOException, YarnException { // Test getPluginInfo GetPluginInfoResponse pluginInfo = adaptorClient.getPluginInfo(GetPluginInfoRequest.newInstance()); - Assert.assertEquals(pluginInfo.getDriverName(), "customized-driver"); - Assert.assertEquals(pluginInfo.getVersion(), "1.0"); + assertThat(pluginInfo.getDriverName()).isEqualTo("customized-driver"); + assertThat(pluginInfo.getVersion()).isEqualTo("1.0"); // Test validateVolumeCapacity ValidateVolumeCapabilitiesRequest request = @@ -412,8 +413,8 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException { // Test getPluginInfo GetPluginInfoResponse pluginInfo = client1.getPluginInfo(GetPluginInfoRequest.newInstance()); - Assert.assertEquals(pluginInfo.getDriverName(), "customized-driver-1"); - Assert.assertEquals(pluginInfo.getVersion(), "1.0"); + assertThat(pluginInfo.getDriverName()).isEqualTo("customized-driver-1"); + assertThat(pluginInfo.getVersion()).isEqualTo("1.0"); // Test validateVolumeCapacity ValidateVolumeCapabilitiesRequest request = @@ -440,8 +441,8 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException { driver2Addr.getLocalPort())); GetPluginInfoResponse pluginInfo2 = client2.getPluginInfo(GetPluginInfoRequest.newInstance()); - Assert.assertEquals(pluginInfo2.getDriverName(), "customized-driver-2"); - Assert.assertEquals(pluginInfo2.getVersion(), "1.0"); + assertThat(pluginInfo2.getDriverName()).isEqualTo("customized-driver-2"); + assertThat(pluginInfo2.getVersion()).isEqualTo("1.0"); services.stop(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml index 22f28e2d9c..38e8cf130b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml @@ -76,6 +76,11 @@ junit test + + org.assertj + assertj-core + test + com.google.inject diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java index ab53c48b11..65bd0056da 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -678,7 +679,7 @@ public void testContainerLogsForFinishedApps() throws Exception { .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); - assertEquals(responseText.getBytes().length, fullTextSize); + assertThat(responseText.getBytes()).hasSize(fullTextSize); r = resource(); response = r.path("ws").path("v1") @@ -689,7 +690,7 @@ public void testContainerLogsForFinishedApps() throws Exception { .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); - assertEquals(responseText.getBytes().length, fullTextSize); + assertThat(responseText.getBytes()).hasSize(fullTextSize); } @Test(timeout = 10000) @@ -880,8 +881,8 @@ public void testContainerLogsMetaForRunningApps() throws Exception { List logMeta = logInfo .getContainerLogsInfo(); assertTrue(logMeta.size() == 1); - assertEquals(logMeta.get(0).getFileName(), fileName); - assertEquals(logMeta.get(0).getFileSize(), String.valueOf( + assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName); + assertThat(logMeta.get(0).getFileSize()).isEqualTo(String.valueOf( content.length())); } else { assertEquals(logInfo.getLogType(), @@ -908,11 +909,11 @@ public void testContainerLogsMetaForRunningApps() throws Exception { List logMeta = logInfo .getContainerLogsInfo(); assertTrue(logMeta.size() == 1); - assertEquals(logMeta.get(0).getFileName(), fileName); - assertEquals(logMeta.get(0).getFileSize(), String.valueOf( + assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName); + assertThat(logMeta.get(0).getFileSize()).isEqualTo(String.valueOf( content.length())); } else { - assertEquals(logInfo.getLogType(), + assertThat(logInfo.getLogType()).isEqualTo( ContainerLogAggregationType.LOCAL.toString()); } } @@ -946,8 +947,8 @@ public void testContainerLogsMetaForFinishedApps() throws Exception { List logMeta = responseText.get(0) .getContainerLogsInfo(); assertTrue(logMeta.size() == 1); - assertEquals(logMeta.get(0).getFileName(), fileName); - assertEquals(logMeta.get(0).getFileSize(), + assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName); + assertThat(logMeta.get(0).getFileSize()).isEqualTo( String.valueOf(content.length())); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml index 62f37470bd..7377cd7cad 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml @@ -95,6 +95,11 @@ mockito-core test + + org.assertj + assertj-core + test + org.apache.zookeeper zookeeper diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/manager/BasePolicyManagerTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/manager/BasePolicyManagerTest.java index bd99cb52ee..55be316e8b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/manager/BasePolicyManagerTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/manager/BasePolicyManagerTest.java @@ -17,6 +17,8 @@ package org.apache.hadoop.yarn.server.federation.policies.manager; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyInitializationContext; import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.FederationAMRMProxyPolicy; import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException; @@ -24,7 +26,6 @@ import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; import org.apache.hadoop.yarn.server.federation.utils.FederationPoliciesTestUtil; -import org.junit.Assert; import org.junit.Test; /** @@ -92,10 +93,10 @@ protected static void serializeAndDeserializePolicyManager( FederationRouterPolicy federationRouterPolicy = wfp2.getRouterPolicy(context, null); - Assert.assertEquals(federationAMRMProxyPolicy.getClass(), - expAMRMProxyPolicy); + assertThat(federationAMRMProxyPolicy). + isExactlyInstanceOf(expAMRMProxyPolicy); - Assert.assertEquals(federationRouterPolicy.getClass(), expRouterPolicy); + assertThat(federationRouterPolicy).isExactlyInstanceOf(expRouterPolicy); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml index 3c74a2002d..1a86a9af12 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml @@ -131,6 +131,11 @@ mockito-core test + + org.assertj + assertj-core + test + com.google.inject guice diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java index 51c7d963d7..3d9d33c5a1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -306,33 +307,34 @@ public void testStartLocalizer() throws IOException { .build()); List result=readMockParams(); - Assert.assertEquals(result.size(), 26); - Assert.assertEquals(result.get(0), YarnConfiguration.DEFAULT_NM_NONSECURE_MODE_LOCAL_USER); - Assert.assertEquals(result.get(1), "test"); - Assert.assertEquals(result.get(2), "0" ); - Assert.assertEquals(result.get(3), "application_0"); - Assert.assertEquals(result.get(4), "12345"); - Assert.assertEquals(result.get(5), "/bin/nmPrivateCTokensPath"); - Assert.assertEquals(result.get(9), "-classpath" ); - Assert.assertEquals(result.get(12), "-Xmx256m" ); - Assert.assertEquals(result.get(13), + assertThat(result).hasSize(26); + assertThat(result.get(0)).isEqualTo(YarnConfiguration. + DEFAULT_NM_NONSECURE_MODE_LOCAL_USER); + assertThat(result.get(1)).isEqualTo("test"); + assertThat(result.get(2)).isEqualTo("0"); + assertThat(result.get(3)).isEqualTo("application_0"); + assertThat(result.get(4)).isEqualTo("12345"); + assertThat(result.get(5)).isEqualTo("/bin/nmPrivateCTokensPath"); + assertThat(result.get(9)).isEqualTo("-classpath"); + assertThat(result.get(12)).isEqualTo("-Xmx256m"); + assertThat(result.get(13)).isEqualTo( "-Dlog4j.configuration=container-log4j.properties" ); - Assert.assertEquals(result.get(14), + assertThat(result.get(14)).isEqualTo( String.format("-Dyarn.app.container.log.dir=%s/application_0/12345", mockExec.getConf().get(YarnConfiguration.NM_LOG_DIRS))); - Assert.assertEquals(result.get(15), + assertThat(result.get(15)).isEqualTo( "-Dyarn.app.container.log.filesize=0"); - Assert.assertEquals(result.get(16), "-Dhadoop.root.logger=INFO,CLA"); - Assert.assertEquals(result.get(17), + assertThat(result.get(16)).isEqualTo("-Dhadoop.root.logger=INFO,CLA"); + assertThat(result.get(17)).isEqualTo( "-Dhadoop.root.logfile=container-localizer-syslog"); - Assert.assertEquals(result.get(18), - "org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer"); - Assert.assertEquals(result.get(19), "test"); - Assert.assertEquals(result.get(20), "application_0"); - Assert.assertEquals(result.get(21), "12345"); - Assert.assertEquals(result.get(22), "localhost"); - Assert.assertEquals(result.get(23), "8040"); - Assert.assertEquals(result.get(24), "nmPrivateCTokensPath"); + assertThat(result.get(18)).isEqualTo("org.apache.hadoop.yarn.server." + + "nodemanager.containermanager.localizer.ContainerLocalizer"); + assertThat(result.get(19)).isEqualTo("test"); + assertThat(result.get(20)).isEqualTo("application_0"); + assertThat(result.get(21)).isEqualTo("12345"); + assertThat(result.get(22)).isEqualTo("localhost"); + assertThat(result.get(23)).isEqualTo("8040"); + assertThat(result.get(24)).isEqualTo("nmPrivateCTokensPath"); } catch (InterruptedException e) { LOG.error("Error:"+e.getMessage(),e); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java index e129caab1a..e920105abf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -302,7 +303,7 @@ public void testApplicationRecovery() throws Exception { // simulate log aggregation completion app.handle(new ApplicationEvent(app.getAppId(), ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); - assertEquals(app.getApplicationState(), ApplicationState.FINISHED); + assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED); app.handle(new ApplicationEvent(app.getAppId(), ApplicationEventType.APPLICATION_LOG_HANDLING_FINISHED)); @@ -362,7 +363,7 @@ public void testNMRecoveryForAppFinishedWithLogAggregationFailure() app.handle(new ApplicationEvent(app.getAppId(), ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); - assertEquals(app.getApplicationState(), ApplicationState.FINISHED); + assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED); // application is still in NM context. assertEquals(1, context.getApplications().size()); @@ -386,7 +387,7 @@ public void testNMRecoveryForAppFinishedWithLogAggregationFailure() // is needed. app.handle(new ApplicationEvent(app.getAppId(), ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); - assertEquals(app.getApplicationState(), ApplicationState.FINISHED); + assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED); // simulate log aggregation failed. app.handle(new ApplicationEvent(app.getAppId(), @@ -528,7 +529,8 @@ public void testContainerSchedulerRecovery() throws Exception { ResourceUtilization utilization = ResourceUtilization.newInstance(1024, 2048, 1.0F); - assertEquals(cm.getContainerScheduler().getNumRunningContainers(), 1); + assertThat(cm.getContainerScheduler().getNumRunningContainers()). + isEqualTo(1); assertEquals(utilization, cm.getContainerScheduler().getCurrentUtilization()); @@ -544,7 +546,8 @@ public void testContainerSchedulerRecovery() throws Exception { assertNotNull(app); waitForNMContainerState(cm, cid, ContainerState.RUNNING); - assertEquals(cm.getContainerScheduler().getNumRunningContainers(), 1); + assertThat(cm.getContainerScheduler().getNumRunningContainers()). + isEqualTo(1); assertEquals(utilization, cm.getContainerScheduler().getCurrentUtilization()); cm.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java index e048577219..bda78032e1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java @@ -18,9 +18,11 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -124,7 +126,6 @@ import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper; import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin; import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin; -import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; @@ -212,7 +213,7 @@ public void testSpecialCharSymlinks() throws IOException { = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir); shexc.execute(); - assertEquals(shexc.getExitCode(), 0); + assertThat(shexc.getExitCode()).isEqualTo(0); //Capture output from prelaunch.out List output = Files.readAllLines(Paths.get(localLogDir.getAbsolutePath(), ContainerLaunch.CONTAINER_PRE_LAUNCH_STDOUT), @@ -1485,7 +1486,7 @@ public void testWindowsShellScriptBuilderCommand() throws IOException { "X", Shell.WINDOWS_MAX_SHELL_LENGTH -callCmd.length() + 1))); fail("longCommand was expected to throw"); } catch(IOException e) { - assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); + assertThat(e).hasMessageContaining(expectedMessage); } // Composite tests, from parts: less, exact and + @@ -1507,7 +1508,7 @@ public void testWindowsShellScriptBuilderCommand() throws IOException { org.apache.commons.lang3.StringUtils.repeat("X", 2048 - callCmd.length()))); fail("long commands was expected to throw"); } catch(IOException e) { - assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); + assertThat(e).hasMessageContaining(expectedMessage); } } @@ -1530,7 +1531,7 @@ public void testWindowsShellScriptBuilderEnv() throws IOException { "A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length()) + 1); fail("long env was expected to throw"); } catch(IOException e) { - assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); + assertThat(e).hasMessageContaining(expectedMessage); } } @@ -1555,8 +1556,8 @@ public void testWindowsShellScriptBuilderMkdir() throws IOException { "X", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length())/2 +1))); fail("long mkdir was expected to throw"); } catch(IOException e) { - assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); - } + assertThat(e).hasMessageContaining(expectedMessage); + } } @Test (timeout = 10000) @@ -1586,7 +1587,7 @@ public void testWindowsShellScriptBuilderLink() throws IOException { "Y", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2) + 1)); fail("long link was expected to throw"); } catch(IOException e) { - assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); + assertThat(e).hasMessageContaining(expectedMessage); } } @@ -1747,7 +1748,7 @@ public void testDebuggingInformation() throws IOException { new String[] { tempFile.getAbsolutePath() }, tmpDir); shexc.execute(); - assertEquals(shexc.getExitCode(), 0); + assertThat(shexc.getExitCode()).isEqualTo(0); File directorInfo = new File(localLogDir, ContainerExecutor.DIRECTORY_CONTENTS); File scriptCopy = new File(localLogDir, tempFile.getName()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestResourceHandlerModule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestResourceHandlerModule.java index 94563035b0..171bfafc4f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestResourceHandlerModule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestResourceHandlerModule.java @@ -20,6 +20,8 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.nodemanager.Context; @@ -71,7 +73,7 @@ public void testOutboundBandwidthHandler() { List resourceHandlers = resourceHandlerChain .getResourceHandlerList(); //Exactly one resource handler in chain - Assert.assertEquals(resourceHandlers.size(), 1); + assertThat(resourceHandlers).hasSize(1); //Same instance is expected to be in the chain. Assert.assertTrue(resourceHandlers.get(0) == resourceHandler); } else { @@ -102,7 +104,7 @@ public void testDiskResourceHandler() throws Exception { List resourceHandlers = resourceHandlerChain.getResourceHandlerList(); // Exactly one resource handler in chain - Assert.assertEquals(resourceHandlers.size(), 1); + assertThat(resourceHandlers).hasSize(1); // Same instance is expected to be in the chain. Assert.assertTrue(resourceHandlers.get(0) == handler); } else { diff --git a/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 b/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 index 9f5f608fed..8871bf6d1e 100644 --- a/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 +++ b/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 @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -1325,15 +1326,15 @@ private void doLocalization(ResourceLocalizationService spyService, // hence its not removed despite ref cnt being 0. LocalizedResource rsrc1 = tracker.getLocalizedResource(req1); assertNotNull(rsrc1); - assertEquals(rsrc1.getState(), ResourceState.LOCALIZED); - assertEquals(rsrc1.getRefCount(), 0); + assertThat(rsrc1.getState()).isEqualTo(ResourceState.LOCALIZED); + assertThat(rsrc1.getRefCount()).isEqualTo(0); // Container c1 was killed but this resource is referenced by container c2 // as well hence its ref cnt is 1. LocalizedResource rsrc2 = tracker.getLocalizedResource(req2); assertNotNull(rsrc2); - assertEquals(rsrc2.getState(), ResourceState.DOWNLOADING); - assertEquals(rsrc2.getRefCount(), 1); + assertThat(rsrc2.getState()).isEqualTo(ResourceState.DOWNLOADING); + assertThat(rsrc2.getRefCount()).isEqualTo(1); // As container c1 was killed and this resource was not referenced by any // other container, hence its removed. diff --git a/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 b/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 index 000b73bf12..796c7e74ce 100644 --- a/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 +++ b/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 @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.logaggregation; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -870,7 +871,7 @@ public LogAggregationFileController getLogAggregationFileController( }; checkEvents(appEventHandler, expectedEvents, false, "getType", "getApplicationID", "getDiagnostic"); - Assert.assertEquals(logAggregationService.getInvalidTokenApps().size(), 1); + assertThat(logAggregationService.getInvalidTokenApps()).hasSize(1); // verify trying to collect logs for containers/apps we don't know about // doesn't blow up and tear down the NM logAggregationService.handle(new LogHandlerContainerFinishedEvent( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nvidia/TestNvidiaGPUPluginForRuntimeV2.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nvidia/TestNvidiaGPUPluginForRuntimeV2.java index 595ee08a5e..7b848cfc5c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nvidia/TestNvidiaGPUPluginForRuntimeV2.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nvidia/TestNvidiaGPUPluginForRuntimeV2.java @@ -39,6 +39,7 @@ import java.util.Set; import java.util.TreeSet; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anySet; @@ -265,7 +266,7 @@ public void testTopologySchedulingWithPackPolicy() throws Exception { reset(spyPlugin); Set allocation = spyPlugin.allocateDevices(copyAvailableDevices, 1, env); - Assert.assertEquals(allocation.size(), 1); + assertThat(allocation).hasSize(1); verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet()); Assert.assertFalse(spyPlugin.isTopoInitialized()); @@ -273,7 +274,7 @@ public void testTopologySchedulingWithPackPolicy() throws Exception { reset(spyPlugin); allocation = spyPlugin.allocateDevices(allDevices, 1, env); // ensure no topology scheduling needed - Assert.assertEquals(allocation.size(), 1); + assertThat(allocation).hasSize(1); verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet()); reset(spyPlugin); // Case 2. allocate all available @@ -285,13 +286,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception { int count = 2; Map pairToWeight = spyPlugin.getDevicePairToWeight(); allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); Device[] allocatedDevices = allocation.toArray(new Device[count]); // Check weights @@ -302,13 +303,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception { reset(spyPlugin); count = 3; allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin, times(0)).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); allocatedDevices = allocation.toArray(new Device[count]); // check weights @@ -327,13 +328,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception { iterator.remove(); count = 2; allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin, times(0)).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); allocatedDevices = allocation.toArray(new Device[count]); // check weights @@ -377,13 +378,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception { int count = 2; Map pairToWeight = spyPlugin.getDevicePairToWeight(); allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); Device[] allocatedDevices = allocation.toArray(new Device[count]); // Check weights @@ -394,13 +395,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception { reset(spyPlugin); count = 3; allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin, times(0)).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); allocatedDevices = allocation.toArray(new Device[count]); // check weights @@ -419,13 +420,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception { iterator.remove(); count = 2; allocation = spyPlugin.allocateDevices(allDevices, count, env); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); // the costTable should be init and used topology scheduling verify(spyPlugin, times(0)).initCostTable(); Assert.assertTrue(spyPlugin.isTopoInitialized()); verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), anySet(), anyMap()); - Assert.assertEquals(allocation.size(), count); + assertThat(allocation).hasSize(count); allocatedDevices = allocation.toArray(new Device[count]); // check weights @@ -574,7 +575,7 @@ public void testTopologySchedulingPerformanceWithPackPolicyWithNVLink() report.readFromFile(); ArrayList dataSet = report.getDataSet(); - Assert.assertEquals(dataSet.size(), 2952); + assertThat(dataSet).hasSize(2952); String[] allModels = {"alexnet", "resnet50", "vgg16", "inception3"}; int[] batchSizes = {32, 64, 128}; int[] gpuCounts = {2, 3, 4, 5, 6, 7}; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java index 157e5d39be..bd86f596bc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.recovery; +import static org.assertj.core.api.Assertions.assertThat; import static org.fusesource.leveldbjni.JniDBFactory.bytes; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -36,6 +37,7 @@ import java.io.File; import java.io.IOException; + import java.io.Serializable; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -1350,9 +1352,9 @@ public void testUnexpectedKeyDoesntThrowException() throws IOException { @Test public void testAMRMProxyStorage() throws IOException { RecoveredAMRMProxyState state = stateStore.loadAMRMProxyState(); - assertEquals(state.getCurrentMasterKey(), null); - assertEquals(state.getNextMasterKey(), null); - assertEquals(state.getAppContexts().size(), 0); + assertThat(state.getCurrentMasterKey()).isNull(); + assertThat(state.getNextMasterKey()).isNull(); + assertThat(state.getAppContexts()).isEmpty(); ApplicationId appId1 = ApplicationId.newInstance(1, 1); ApplicationId appId2 = ApplicationId.newInstance(1, 2); @@ -1384,18 +1386,18 @@ public void testAMRMProxyStorage() throws IOException { state = stateStore.loadAMRMProxyState(); assertEquals(state.getCurrentMasterKey(), secretManager.getCurrentMasterKeyData().getMasterKey()); - assertEquals(state.getNextMasterKey(), null); - assertEquals(state.getAppContexts().size(), 2); + assertThat(state.getNextMasterKey()).isNull(); + assertThat(state.getAppContexts()).hasSize(2); // app1 Map map = state.getAppContexts().get(attemptId1); assertNotEquals(map, null); - assertEquals(map.size(), 2); + assertThat(map).hasSize(2); assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key2), data2)); // app2 map = state.getAppContexts().get(attemptId2); assertNotEquals(map, null); - assertEquals(map.size(), 2); + assertThat(map).hasSize(2); assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key2), data2)); @@ -1414,14 +1416,14 @@ public void testAMRMProxyStorage() throws IOException { assertEquals(state.getAppContexts().size(), 2); // app1 map = state.getAppContexts().get(attemptId1); - assertNotEquals(map, null); - assertEquals(map.size(), 2); + assertThat(map).isNotNull(); + assertThat(map).hasSize(2); assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key2), data2)); // app2 map = state.getAppContexts().get(attemptId2); - assertNotEquals(map, null); - assertEquals(map.size(), 1); + assertThat(map).isNotNull(); + assertThat(map).hasSize(1); assertTrue(Arrays.equals(map.get(key2), data2)); // Activate next master key and remove all entries of app1 @@ -1434,12 +1436,12 @@ public void testAMRMProxyStorage() throws IOException { state = stateStore.loadAMRMProxyState(); assertEquals(state.getCurrentMasterKey(), secretManager.getCurrentMasterKeyData().getMasterKey()); - assertEquals(state.getNextMasterKey(), null); - assertEquals(state.getAppContexts().size(), 1); + assertThat(state.getNextMasterKey()).isNull(); + assertThat(state.getAppContexts()).hasSize(1); // app2 only map = state.getAppContexts().get(attemptId2); - assertNotEquals(map, null); - assertEquals(map.size(), 1); + assertThat(map).isNotNull(); + assertThat(map).hasSize(1); assertTrue(Arrays.equals(map.get(key2), data2)); } finally { secretManager.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java index 62774f5d43..740af8f974 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebServices.java @@ -96,6 +96,7 @@ import java.util.List; import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -704,7 +705,7 @@ private void testContainerLogs(WebResource r, ContainerId containerId) List logMeta = responseList.get(0) .getContainerLogsInfo(); assertTrue(logMeta.size() == 1); - assertEquals(logMeta.get(0).getFileName(), filename); + assertThat(logMeta.get(0).getFileName()).isEqualTo(filename); // now create an aggregated log in Remote File system File tempLogDir = new File("target", @@ -724,19 +725,19 @@ private void testContainerLogs(WebResource r, ContainerId containerId) assertEquals(200, response.getStatus()); responseList = response.getEntity(new GenericType< List>(){}); - assertEquals(responseList.size(), 2); + assertThat(responseList).hasSize(2); for (ContainerLogsInfo logInfo : responseList) { if(logInfo.getLogType().equals( ContainerLogAggregationType.AGGREGATED.toString())) { List meta = logInfo.getContainerLogsInfo(); assertTrue(meta.size() == 1); - assertEquals(meta.get(0).getFileName(), aggregatedLogFile); + assertThat(meta.get(0).getFileName()).isEqualTo(aggregatedLogFile); } else { assertEquals(logInfo.getLogType(), ContainerLogAggregationType.LOCAL.toString()); List meta = logInfo.getContainerLogsInfo(); assertTrue(meta.size() == 1); - assertEquals(meta.get(0).getFileName(), filename); + assertThat(meta.get(0).getFileName()).isEqualTo(filename); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml index f40ca0efe6..45eca49c18 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml @@ -57,6 +57,11 @@ junit test + + org.assertj + assertj-core + test + org.mockito mockito-core diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java index 6049c11dbb..3eed0be25b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -1788,7 +1789,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); duration = 30000; deadline = sRequest.getReservationDefinition().getDeadline(); @@ -1808,7 +1809,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); arrival = clock.getTime(); // List reservations, search by end time before the reservation start @@ -1826,7 +1827,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); // List reservations, search by very small end time. request = ReservationListRequest @@ -1841,7 +1842,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { // Ensure all reservations are filtered out. Assert.assertNotNull(response); - Assert.assertEquals(response.getReservationAllocationState().size(), 0); + assertThat(response.getReservationAllocationState()).isEmpty(); rm.stop(); } @@ -2012,7 +2013,7 @@ protected ClientRMService createClientRMService() { Arrays.asList(node1A))); Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( Arrays.asList(node1B, node3B))); - Assert.assertEquals(labelsToNodes.get(labelY.getName()), null); + assertThat(labelsToNodes.get(labelY.getName())).isNull(); rpc.stopProxy(client, conf); rm.close(); @@ -2113,10 +2114,10 @@ protected ClientRMService createClientRMService() { client.getAttributesToNodes(request); Map> attrs = response.getAttributesToNodes(); - Assert.assertEquals(response.getAttributesToNodes().size(), 4); - Assert.assertEquals(attrs.get(dist.getAttributeKey()).size(), 2); - Assert.assertEquals(attrs.get(os.getAttributeKey()).size(), 1); - Assert.assertEquals(attrs.get(gpu.getAttributeKey()).size(), 1); + assertThat(response.getAttributesToNodes()).hasSize(4); + assertThat(attrs.get(dist.getAttributeKey())).hasSize(2); + assertThat(attrs.get(os.getAttributeKey())).hasSize(1); + assertThat(attrs.get(gpu.getAttributeKey())).hasSize(1); Assert.assertTrue(findHostnameAndValInMapping(node1, "3_0_2", attrs.get(dist.getAttributeKey()))); Assert.assertTrue(findHostnameAndValInMapping(node2, "3_0_2", @@ -2130,7 +2131,7 @@ protected ClientRMService createClientRMService() { client.getAttributesToNodes(request2); Map> attrs2 = response2.getAttributesToNodes(); - Assert.assertEquals(attrs2.size(), 1); + assertThat(attrs2).hasSize(1); Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", attrs2.get(docker.getAttributeKey()))); @@ -2141,7 +2142,7 @@ protected ClientRMService createClientRMService() { client.getAttributesToNodes(request3); Map> attrs3 = response3.getAttributesToNodes(); - Assert.assertEquals(attrs3.size(), 2); + assertThat(attrs3).hasSize(2); Assert.assertTrue(findHostnameAndValInMapping(node1, "windows64", attrs3.get(os.getAttributeKey()))); Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java index 30443d7506..979d8c7b97 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import java.io.IOException; @@ -150,7 +151,7 @@ public void testKillAppWhenFailOverHappensDuringApplicationKill() MockAM am0 = launchAM(app0, rm1, nm1); // ensure that the app is in running state - Assert.assertEquals(app0.getState(), RMAppState.RUNNING); + assertThat(app0.getState()).isEqualTo(RMAppState.RUNNING); // kill the app. rm1.killApp(app0.getApplicationId()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java index 01c89d389b..6659f107ef 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -608,7 +609,7 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager, Assert.assertEquals(accessList.getAclString(), aclString); } else { - Assert.assertEquals(accessList.getAclString(), "*"); + assertThat(accessList.getAclString()).isEqualTo("*"); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java index 3b3bd4b424..4b11296efb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java @@ -22,6 +22,7 @@ import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -381,14 +382,14 @@ public void testHAIDLookup() { rm = new MockRM(conf); rm.init(conf); - assertEquals(conf.get(YarnConfiguration.RM_HA_ID), RM2_NODE_ID); + assertThat(conf.get(YarnConfiguration.RM_HA_ID)).isEqualTo(RM2_NODE_ID); //test explicitly lookup HA-ID configuration.set(YarnConfiguration.RM_HA_ID, RM1_NODE_ID); conf = new YarnConfiguration(configuration); rm = new MockRM(conf); rm.init(conf); - assertEquals(conf.get(YarnConfiguration.RM_HA_ID), RM1_NODE_ID); + assertThat(conf.get(YarnConfiguration.RM_HA_ID)).isEqualTo(RM1_NODE_ID); //test if RM_HA_ID can not be found configuration diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java index f09850afaf..87a9423522 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.isA; @@ -609,7 +610,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { MockAM am2 = launchAM(app1, rm1, nm1); Assert.assertEquals(1, rmAppState.size()); - Assert.assertEquals(app1.getState(), RMAppState.RUNNING); + assertThat(app1.getState()).isEqualTo(RMAppState.RUNNING); Assert.assertEquals(app1.getAppAttempts() .get(app1.getCurrentAppAttempt().getAppAttemptId()) .getAppAttemptState(), RMAppAttemptState.RUNNING); @@ -665,7 +666,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { rmApp = rm3.getRMContext().getRMApps().get(app1.getApplicationId()); // application should be in ACCEPTED state rm3.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); - Assert.assertEquals(rmApp.getState(), RMAppState.ACCEPTED); + assertThat(rmApp.getState()).isEqualTo(RMAppState.ACCEPTED); // new attempt should not be started Assert.assertEquals(3, rmApp.getAppAttempts().size()); // am1 and am2 attempts should be in FAILED state where as am3 should be diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java index 9c233b9cf9..78fa90ded2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.api.records.ContainerUpdateType.INCREASE_RESOURCE; import static org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils.RESOURCE_OUTSIDE_ALLOWED_RANGE; @@ -140,22 +141,22 @@ public void testQueryRMNodes() throws Exception { List result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.SHUTDOWN)); Assert.assertTrue(result.size() != 0); - Assert.assertEquals(result.get(0), rmNode1); + assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.DECOMMISSIONED); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.DECOMMISSIONED)); Assert.assertTrue(result.size() != 0); - Assert.assertEquals(result.get(0), rmNode1); + assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.LOST); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.LOST)); Assert.assertTrue(result.size() != 0); - Assert.assertEquals(result.get(0), rmNode1); + assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.REBOOTED); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.REBOOTED)); Assert.assertTrue(result.size() != 0); - Assert.assertEquals(result.get(0), rmNode1); + assertThat(result.get(0)).isEqualTo(rmNode1); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java index fa5f135153..d503cb44fb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java @@ -100,6 +100,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler @@ -263,7 +265,8 @@ public void testSchedulerRecovery() throws Exception { scheduler.getRMContainer(amContainer.getContainerId()))); assertTrue(schedulerAttempt.getLiveContainers().contains( scheduler.getRMContainer(runningContainer.getContainerId()))); - assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); + assertThat(schedulerAttempt.getCurrentConsumption()). + isEqualTo(usedResources); // *********** check appSchedulingInfo state *********** assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); @@ -421,7 +424,8 @@ public void testDynamicQueueRecovery() throws Exception { .contains(scheduler.getRMContainer(amContainer.getContainerId()))); assertTrue(schedulerAttempt.getLiveContainers() .contains(scheduler.getRMContainer(runningContainer.getContainerId()))); - assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); + assertThat(schedulerAttempt.getCurrentConsumption()). + isEqualTo(usedResources); // *********** check appSchedulingInfo state *********** assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); @@ -775,8 +779,9 @@ private void verifyAppRecoveryWithWrongQueueConfig( ApplicationReport report = rm2.getApplicationReport(app.getApplicationId()); assertEquals(report.getFinalApplicationStatus(), FinalApplicationStatus.KILLED); - assertEquals(report.getYarnApplicationState(), YarnApplicationState.KILLED); - assertEquals(report.getDiagnostics(), diagnostics); + assertThat(report.getYarnApplicationState()). + isEqualTo(YarnApplicationState.KILLED); + assertThat(report.getDiagnostics()).isEqualTo(diagnostics); //Reload previous state with cloned app sub context object RMState newState = memStore2.reloadStateWithClonedAppSubCtxt(state); @@ -1730,7 +1735,8 @@ public void testDynamicAutoCreatedQueueRecovery(String user, String queueName) .contains(scheduler.getRMContainer(amContainer.getContainerId()))); assertTrue(schedulerAttempt.getLiveContainers() .contains(scheduler.getRMContainer(runningContainer.getContainerId()))); - assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); + assertThat(schedulerAttempt.getCurrentConsumption()). + isEqualTo(usedResources); // *********** check appSchedulingInfo state *********** assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java index 64c90637f2..35f55c6d47 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.metrics; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -290,7 +291,7 @@ public void testPublishApplicationMetrics() throws Exception { } else if (event.getEventType().equals( ApplicationMetricsConstants.STATE_UPDATED_EVENT_TYPE)) { hasStateUpdateEvent = true; - Assert.assertEquals(event.getTimestamp(), stateUpdateTimeStamp); + assertThat(event.getTimestamp()).isEqualTo(stateUpdateTimeStamp); Assert.assertEquals(YarnApplicationState.RUNNING.toString(), event .getEventInfo().get( ApplicationMetricsConstants.STATE_EVENT_INFO)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java index 6f67e4b13c..8c0eee6865 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.Map; import java.util.Set; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; @@ -230,7 +231,8 @@ public void testPreemptionToBalanceWithConfiguredTimeout() throws IOException { FifoCandidatesSelector pcs = (FifoCandidatesSelector) pc.getKey(); if (pcs.getAllowQueuesBalanceAfterAllQueuesSatisfied() == true) { hasFifoSelector = true; - assertEquals(pcs.getMaximumKillWaitTimeMs(), FB_MAX_BEFORE_KILL); + assertThat(pcs.getMaximumKillWaitTimeMs()). + isEqualTo(FB_MAX_BEFORE_KILL); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java index a53b88e962..a05cf3eb5c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -139,8 +140,8 @@ public void testRecoverWithMirror() throws Exception { toAddAttributes); Map attrs = mgr.getAttributesForNode("host0"); - Assert.assertEquals(attrs.size(), 1); - Assert.assertEquals(attrs.keySet().toArray()[0], docker); + assertThat(attrs).hasSize(1); + assertThat(attrs.keySet().toArray()[0]).isEqualTo(docker); mgr.stop(); // Start new attribute manager with same path @@ -154,8 +155,8 @@ public void testRecoverWithMirror() throws Exception { Assert.assertEquals("host1 size", 1, mgr.getAttributesForNode("host1").size()); attrs = mgr.getAttributesForNode("host0"); - Assert.assertEquals(attrs.size(), 1); - Assert.assertEquals(attrs.keySet().toArray()[0], docker); + assertThat(attrs).hasSize(1); + assertThat(attrs.keySet().toArray()[0]).isEqualTo(docker); //------host0---- // current - docker // replace - gpu @@ -181,8 +182,8 @@ public void testRecoverWithMirror() throws Exception { Assert.assertEquals("host1 size", 2, mgr.getAttributesForNode("host1").size()); attrs = mgr.getAttributesForNode("host0"); - Assert.assertEquals(attrs.size(), 1); - Assert.assertEquals(attrs.keySet().toArray()[0], gpu); + assertThat(attrs).hasSize(1); + assertThat(attrs.keySet().toArray()[0]).isEqualTo(gpu); attrs = mgr.getAttributesForNode("host1"); Assert.assertTrue(attrs.keySet().contains(docker)); Assert.assertTrue(attrs.keySet().contains(gpu)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java index 1da6f93f66..5c9b073def 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -88,37 +90,37 @@ public void testGetLabelResourceWhenNodeActiveDeactive() throws Exception { mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"), toNodeId("n2"), toSet("p2"), toNodeId("n3"), toSet("p3"))); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), EMPTY_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel("p2", null), EMPTY_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel("p3", null), EMPTY_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null), - EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo(EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)). + isEqualTo(EMPTY_RESOURCE); // active two NM to n1, one large and one small mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("n1", 2), LARGE_NODE); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo( Resources.add(SMALL_RESOURCE, LARGE_NODE)); // check add labels multiple times shouldn't overwrite // original attributes on labels like resource mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p4")); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo( Resources.add(SMALL_RESOURCE, LARGE_NODE)); Assert.assertEquals(mgr.getResourceByLabel("p4", null), EMPTY_RESOURCE); // change the large NM to small, check if resource updated mgr.updateNodeResource(NodeId.newInstance("n1", 2), SMALL_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); // deactive one NM, and check if resource updated mgr.deactivateNode(NodeId.newInstance("n1", 1)); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), SMALL_RESOURCE); + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(SMALL_RESOURCE); // continus deactive, check if resource updated mgr.deactivateNode(NodeId.newInstance("n1", 2)); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(EMPTY_RESOURCE); // Add two NM to n1 back mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE); @@ -126,8 +128,8 @@ public void testGetLabelResourceWhenNodeActiveDeactive() throws Exception { // And remove p1, now the two NM should come to default label, mgr.removeFromClusterNodeLabels(ImmutableSet.of("p1")); - Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null), - Resources.add(SMALL_RESOURCE, LARGE_NODE)); + assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)). + isEqualTo(Resources.add(SMALL_RESOURCE, LARGE_NODE)); } @Test(timeout = 5000) @@ -152,10 +154,10 @@ public void testGetLabelResource() throws Exception { // change label of n1 to p2 mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p2"))); - Assert.assertEquals(mgr.getResourceByLabel("p1", null), EMPTY_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel("p2", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(EMPTY_RESOURCE); + assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); - Assert.assertEquals(mgr.getResourceByLabel("p3", null), SMALL_RESOURCE); + assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(SMALL_RESOURCE); // add more labels mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p4", "p5", "p6")); @@ -180,17 +182,17 @@ public void testGetLabelResource() throws Exception { mgr.activateNode(NodeId.newInstance("n9", 1), SMALL_RESOURCE); // check varibles - Assert.assertEquals(mgr.getResourceByLabel("p1", null), SMALL_RESOURCE); - Assert.assertEquals(mgr.getResourceByLabel("p2", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(SMALL_RESOURCE); + assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 3)); - Assert.assertEquals(mgr.getResourceByLabel("p3", null), + assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); - Assert.assertEquals(mgr.getResourceByLabel("p4", null), + assertThat(mgr.getResourceByLabel("p4", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 1)); - Assert.assertEquals(mgr.getResourceByLabel("p5", null), - Resources.multiply(SMALL_RESOURCE, 1)); - Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null), + assertThat(mgr.getResourceByLabel("p5", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 1)); + assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)). + isEqualTo(Resources.multiply(SMALL_RESOURCE, 1)); // change a bunch of nodes -> labels // n4 -> p2 @@ -212,17 +214,17 @@ public void testGetLabelResource() throws Exception { toNodeId("n9"), toSet("p1"))); // check varibles - Assert.assertEquals(mgr.getResourceByLabel("p1", null), + assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); - Assert.assertEquals(mgr.getResourceByLabel("p2", null), + assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 3)); - Assert.assertEquals(mgr.getResourceByLabel("p3", null), + assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); - Assert.assertEquals(mgr.getResourceByLabel("p4", null), + assertThat(mgr.getResourceByLabel("p4", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 0)); - Assert.assertEquals(mgr.getResourceByLabel("p5", null), + assertThat(mgr.getResourceByLabel("p5", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 0)); - Assert.assertEquals(mgr.getResourceByLabel("", null), + assertThat(mgr.getResourceByLabel("", null)).isEqualTo( Resources.multiply(SMALL_RESOURCE, 2)); } @@ -413,9 +415,9 @@ public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOExc mgr.activateNode(NodeId.newInstance("n1", 4), SMALL_RESOURCE); // check resource of no label, it should be small * 4 - Assert.assertEquals( - mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), - Resources.multiply(SMALL_RESOURCE, 4)); + assertThat( + mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null)). + isEqualTo(Resources.multiply(SMALL_RESOURCE, 4)); // change two of these nodes to p1, check resource of no_label and P1 mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1")); @@ -423,12 +425,12 @@ public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOExc toNodeId("n1:2"), toSet("p1"))); // check resource - Assert.assertEquals( - mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), - Resources.multiply(SMALL_RESOURCE, 2)); - Assert.assertEquals( - mgr.getResourceByLabel("p1", null), - Resources.multiply(SMALL_RESOURCE, 2)); + assertThat( + mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null)). + isEqualTo(Resources.multiply(SMALL_RESOURCE, 2)); + assertThat( + mgr.getResourceByLabel("p1", null)).isEqualTo( + Resources.multiply(SMALL_RESOURCE, 2)); } @Test(timeout = 5000) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java index cd2a0fa208..13faff0fc8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -125,8 +126,8 @@ public RMStateStore getRMStateStore() throws Exception { YarnConfiguration.YARN_INTERMEDIATE_DATA_ENCRYPTION, true); } this.store = new TestFileSystemRMStore(conf); - Assert.assertEquals(store.getNumRetries(), 8); - Assert.assertEquals(store.getRetryInterval(), 900L); + assertThat(store.getNumRetries()).isEqualTo(8); + assertThat(store.getRetryInterval()).isEqualTo(900L); Assert.assertTrue(store.fs.getConf() == store.fsConf); FileSystem previousFs = store.fs; store.startInternal(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java index 23c2b9a4ff..f21ff96209 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java @@ -76,6 +76,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -435,14 +436,14 @@ public void testZKRootPathAcls() throws Exception { rm.getRMContext().getRMAdminService().transitionToActive(req); ZKRMStateStore stateStore = (ZKRMStateStore) rm.getRMContext().getStateStore(); List acls = stateStore.getACL(rootPath); - assertEquals(acls.size(), 2); + assertThat(acls).hasSize(2); // CREATE and DELETE permissions for root node based on RM ID verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls); verifyZKACL( "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls); acls = stateStore.getACL(parentPath); - assertEquals(1, acls.size()); + assertThat(acls).hasSize(1); assertEquals(perm, acls.get(0).getPerms()); rm.close(); @@ -463,7 +464,7 @@ public void testZKRootPathAcls() throws Exception { rm.start(); rm.getRMContext().getRMAdminService().transitionToActive(req); acls = stateStore.getACL(rootPath); - assertEquals(acls.size(), 2); + assertThat(acls).hasSize(2); verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls); verifyZKACL( "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java index d383bac218..a092e0d527 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java @@ -17,6 +17,7 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import org.apache.hadoop.yarn.api.records.ReservationAllocationState; @@ -49,9 +50,9 @@ public void testConvertAllocationsToReservationInfo() { .convertAllocationsToReservationInfo( Collections.singleton(allocation), true); - Assert.assertEquals(infoList.size(), 1); - Assert.assertEquals(infoList.get(0).getReservationId().toString(), - id.toString()); + assertThat(infoList).hasSize(1); + assertThat(infoList.get(0).getReservationId().toString()).isEqualTo( + id.toString()); Assert.assertFalse(infoList.get(0).getResourceAllocationRequests() .isEmpty()); } @@ -104,7 +105,7 @@ public void testConvertAllocationsToReservationInfoEmptySet() { .convertAllocationsToReservationInfo( Collections.emptySet(), false); - Assert.assertEquals(infoList.size(), 0); + assertThat(infoList).isEmpty(); } private ReservationAllocation createReservationAllocation(long startTime, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java index 9fa85595db..e26f945868 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java @@ -18,7 +18,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -990,8 +991,9 @@ public void testGetDurationInterval() throws PlanningException { StageAllocatorLowCostAligned.getDurationInterval(10*step, 30*step, planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); - assertEquals(durationInterval.numCanFit(), 4); - assertEquals(durationInterval.getTotalCost(), 0.55, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(4); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0.55, within(0.00001)); // 2. // currLoad: should start at 20*step, end at 31*step with a null value @@ -1003,8 +1005,9 @@ public void testGetDurationInterval() throws PlanningException { planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); System.out.println(durationInterval); - assertEquals(durationInterval.numCanFit(), 3); - assertEquals(durationInterval.getTotalCost(), 0.56, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(3); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0.56, within(0.00001)); // 3. // currLoad: should start at 20*step, end at 30*step with a null value @@ -1015,8 +1018,9 @@ public void testGetDurationInterval() throws PlanningException { StageAllocatorLowCostAligned.getDurationInterval(15*step, 30*step, planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); - assertEquals(durationInterval.numCanFit(), 4); - assertEquals(durationInterval.getTotalCost(), 0.55, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(4); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0.55, within(0.00001)); // 4. // currLoad: should start at 20*step, end at 31*step with a null value @@ -1028,8 +1032,9 @@ public void testGetDurationInterval() throws PlanningException { planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); System.out.println(durationInterval); - assertEquals(durationInterval.numCanFit(), 3); - assertEquals(durationInterval.getTotalCost(), 0.56, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(3); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0.56, within(0.00001)); // 5. // currLoad: should only contain one entry at startTime @@ -1042,8 +1047,9 @@ public void testGetDurationInterval() throws PlanningException { planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); System.out.println(durationInterval); - assertEquals(durationInterval.numCanFit(), 8); - assertEquals(durationInterval.getTotalCost(), 0.05, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(8); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0.05, within(0.00001)); // 6. // currLoad: should start at 39*step, end at 41*step with a null value @@ -1055,8 +1061,9 @@ public void testGetDurationInterval() throws PlanningException { planLoads, planModifications, clusterCapacity, netRLERes, res, step, requestedResources); System.out.println(durationInterval); - assertEquals(durationInterval.numCanFit(), 0); - assertEquals(durationInterval.getTotalCost(), 0, 0.00001); + assertThat(durationInterval.numCanFit()).isEqualTo(0); + assertThat(durationInterval.getTotalCost()). + isCloseTo(0, within(0.00001)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index dc189c1bea..e5d7e3fb63 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -105,6 +105,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -1278,7 +1279,8 @@ public void testGetAppReport() throws IOException { assertAppState(RMAppState.NEW, app); ApplicationReport report = app.createAndGetApplicationReport(null, true); Assert.assertNotNull(report.getApplicationResourceUsageReport()); - Assert.assertEquals(report.getApplicationResourceUsageReport(),RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); + assertThat(report.getApplicationResourceUsageReport()). + isEqualTo(RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); report = app.createAndGetApplicationReport("clientuser", true); Assert.assertNotNull(report.getApplicationResourceUsageReport()); Assert.assertTrue("bad proxy url for app", diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java index 6958182028..172db0a3d6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -308,14 +309,15 @@ public void testLimitsComputation() throws Exception { queue.getUserAMResourceLimit()); Resource amResourceLimit = Resource.newInstance(160 * GB, 1); - assertEquals(queue.calculateAndGetAMResourceLimit(), amResourceLimit); - assertEquals(queue.getUserAMResourceLimit(), + assertThat(queue.calculateAndGetAMResourceLimit()). + isEqualTo(amResourceLimit); + assertThat(queue.getUserAMResourceLimit()).isEqualTo( Resource.newInstance(80*GB, 1)); // Assert in metrics - assertEquals(queue.getMetrics().getAMResourceLimitMB(), + assertThat(queue.getMetrics().getAMResourceLimitMB()).isEqualTo( amResourceLimit.getMemorySize()); - assertEquals(queue.getMetrics().getAMResourceLimitVCores(), + assertThat(queue.getMetrics().getAMResourceLimitVCores()).isEqualTo( amResourceLimit.getVirtualCores()); assertEquals( @@ -327,11 +329,11 @@ public void testLimitsComputation() throws Exception { clusterResource = Resources.createResource(120 * 16 * GB); root.updateClusterResource(clusterResource, new ResourceLimits( clusterResource)); - - assertEquals(queue.calculateAndGetAMResourceLimit(), + + assertThat(queue.calculateAndGetAMResourceLimit()).isEqualTo( Resource.newInstance(192 * GB, 1)); - assertEquals(queue.getUserAMResourceLimit(), - Resource.newInstance(96*GB, 1)); + assertThat(queue.getUserAMResourceLimit()).isEqualTo( + Resource.newInstance(96*GB, 1)); assertEquals( (int)(clusterResource.getMemorySize() * queue.getAbsoluteCapacity()), @@ -378,11 +380,11 @@ public void testLimitsComputation() throws Exception { (long) csConf.getMaximumApplicationMasterResourcePerQueuePercent( queue.getQueuePath()) ); - - assertEquals(queue.calculateAndGetAMResourceLimit(), + + assertThat(queue.calculateAndGetAMResourceLimit()).isEqualTo( Resource.newInstance(800 * GB, 1)); - assertEquals(queue.getUserAMResourceLimit(), - Resource.newInstance(400*GB, 1)); + assertThat(queue.getUserAMResourceLimit()).isEqualTo( + Resource.newInstance(400*GB, 1)); // Change the per-queue max applications. csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications", diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java index cad0151cf0..fea82e5388 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -140,9 +140,9 @@ public void testApplicationOrderingWithPriority() throws Exception { // Now, the first assignment will be for app2 since app2 is of highest // priority - assertEquals(q.getApplications().size(), 2); - assertEquals(q.getApplications().iterator().next() - .getApplicationAttemptId(), appAttemptId2); + assertThat(q.getApplications()).hasSize(2); + assertThat(q.getApplications().iterator().next().getApplicationAttemptId()) + .isEqualTo(appAttemptId2); rm.stop(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java index fd8fa0535c..ae4009ab8f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_VCORES; @@ -5251,7 +5252,8 @@ public void testContainerAllocationLocalitySkipped() throws Exception { RMNode node1 = rm.getRMContext().getRMNodes().get(nm1.getNodeId()); cs.handle(new NodeUpdateSchedulerEvent(node1)); ContainerId cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 1l); - Assert.assertEquals(cs.getRMContainer(cid).getState(), RMContainerState.ACQUIRED); + assertThat(cs.getRMContainer(cid).getState()). + isEqualTo(RMContainerState.ACQUIRED); cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 2l); Assert.assertNull(cs.getRMContainer(cid)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestConfigurableResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestConfigurableResource.java index 249d1f77ca..debd8ae7eb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestConfigurableResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestConfigurableResource.java @@ -22,6 +22,7 @@ import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -52,8 +53,10 @@ public void testGetResourceWithPercentage() { public void testGetResourceWithAbsolute() { ConfigurableResource configurableResource = new ConfigurableResource(Resources.createResource(3072, 3)); - assertEquals(configurableResource.getResource().getMemorySize(), 3072); - assertEquals(configurableResource.getResource().getVirtualCores(), 3); + assertThat(configurableResource.getResource().getMemorySize()). + isEqualTo(3072); + assertThat(configurableResource.getResource().getVirtualCores()). + isEqualTo(3); assertEquals( configurableResource.getResource(clusterResource).getMemorySize(), @@ -62,7 +65,9 @@ public void testGetResourceWithAbsolute() { configurableResource.getResource(clusterResource).getVirtualCores(), 3); - assertEquals(configurableResource.getResource(null).getMemorySize(), 3072); - assertEquals(configurableResource.getResource(null).getVirtualCores(), 3); + assertThat(configurableResource.getResource(null).getMemorySize()). + isEqualTo(3072); + assertThat(configurableResource.getResource(null).getVirtualCores()). + isEqualTo(3); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java index 81500dbfcd..5dac862216 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java @@ -43,6 +43,7 @@ import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.After; import org.junit.Assert; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -153,9 +154,10 @@ public void testSortedNodes() throws Exception { scheduler.handle(nodeEvent2); // available resource - Assert.assertEquals(scheduler.getClusterResource().getMemorySize(), - 16 * 1024); - Assert.assertEquals(scheduler.getClusterResource().getVirtualCores(), 16); + assertThat(scheduler.getClusterResource().getMemorySize()). + isEqualTo(16 * 1024); + assertThat(scheduler.getClusterResource().getVirtualCores()). + isEqualTo(16); // send application request ApplicationAttemptId appAttemptId = diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java index 0cf1a7b416..9c47b6be0f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSLeafQueue.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -90,8 +91,9 @@ public void testUpdateDemand() { String queueName = "root.queue1"; FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null); schedulable.setMaxShare(new ConfigurableResource(maxResource)); - assertEquals(schedulable.getMetrics().getMaxApps(), Integer.MAX_VALUE); - assertEquals(schedulable.getMetrics().getSchedulingPolicy(), + assertThat(schedulable.getMetrics().getMaxApps()). + isEqualTo(Integer.MAX_VALUE); + assertThat(schedulable.getMetrics().getSchedulingPolicy()).isEqualTo( SchedulingPolicy.DEFAULT_POLICY.getName()); FSAppAttempt app = mock(FSAppAttempt.class); @@ -124,8 +126,8 @@ public void test() throws Exception { resourceManager.start(); scheduler = (FairScheduler) resourceManager.getResourceScheduler(); for(FSQueue queue: scheduler.getQueueManager().getQueues()) { - assertEquals(queue.getMetrics().getMaxApps(), Integer.MAX_VALUE); - assertEquals(queue.getMetrics().getSchedulingPolicy(), + assertThat(queue.getMetrics().getMaxApps()).isEqualTo(Integer.MAX_VALUE); + assertThat(queue.getMetrics().getSchedulingPolicy()).isEqualTo( SchedulingPolicy.DEFAULT_POLICY.getName()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java index e76e7e3637..d9f29f1be1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java @@ -114,6 +114,7 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -4623,17 +4624,17 @@ public void testResourceUsageByMoveApp() throws Exception { FSQueue queue2 = queueMgr.getLeafQueue("parent2.queue2", true); FSQueue queue1 = queueMgr.getLeafQueue("parent1.queue1", true); - Assert.assertEquals(parent2.getResourceUsage().getMemorySize(), 0); - Assert.assertEquals(queue2.getResourceUsage().getMemorySize(), 0); - Assert.assertEquals(parent1.getResourceUsage().getMemorySize(), 1 * GB); - Assert.assertEquals(queue1.getResourceUsage().getMemorySize(), 1 * GB); + assertThat(parent2.getResourceUsage().getMemorySize()).isEqualTo(0); + assertThat(queue2.getResourceUsage().getMemorySize()).isEqualTo(0); + assertThat(parent1.getResourceUsage().getMemorySize()).isEqualTo(1 * GB); + assertThat(queue1.getResourceUsage().getMemorySize()).isEqualTo(1 * GB); scheduler.moveApplication(appAttId.getApplicationId(), "parent2.queue2"); - Assert.assertEquals(parent2.getResourceUsage().getMemorySize(), 1 * GB); - Assert.assertEquals(queue2.getResourceUsage().getMemorySize(), 1 * GB); - Assert.assertEquals(parent1.getResourceUsage().getMemorySize(), 0); - Assert.assertEquals(queue1.getResourceUsage().getMemorySize(), 0); + assertThat(parent2.getResourceUsage().getMemorySize()).isEqualTo(1 * GB); + assertThat(queue2.getResourceUsage().getMemorySize()).isEqualTo(1 * GB); + assertThat(parent1.getResourceUsage().getMemorySize()).isEqualTo(0); + assertThat(queue1.getResourceUsage().getMemorySize()).isEqualTo(0); } @Test (expected = YarnException.class) @@ -5070,20 +5071,20 @@ public void handle(Event event) { Resource usedResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getAllocatedResource(); - Assert.assertEquals(usedResource.getMemorySize(), 0); - Assert.assertEquals(usedResource.getVirtualCores(), 0); + assertThat(usedResource.getMemorySize()).isEqualTo(0); + assertThat(usedResource.getVirtualCores()).isEqualTo(0); // Check total resource of scheduler node is also changed to 0 GB 0 core Resource totalResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getTotalResource(); - Assert.assertEquals(totalResource.getMemorySize(), 0 * GB); - Assert.assertEquals(totalResource.getVirtualCores(), 0); + assertThat(totalResource.getMemorySize()).isEqualTo(0 * GB); + assertThat(totalResource.getVirtualCores()).isEqualTo(0); // Check the available resource is 0/0 Resource availableResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource(); - Assert.assertEquals(availableResource.getMemorySize(), 0); - Assert.assertEquals(availableResource.getVirtualCores(), 0); + assertThat(availableResource.getMemorySize()).isEqualTo(0); + assertThat(availableResource.getVirtualCores()).isEqualTo(0); } private NodeManager registerNode(String hostName, int containerManagerPort, @@ -5159,8 +5160,7 @@ public void testContainerAllocationWithContainerIdLeap() throws Exception { // container will be allocated at node2 scheduler.handle(new NodeUpdateSchedulerEvent(node2)); - assertEquals(scheduler.getSchedulerApp(app2). - getLiveContainers().size(), 1); + assertThat(scheduler.getSchedulerApp(app2).getLiveContainers()).hasSize(1); long maxId = 0; for (RMContainer container : diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/TestFifoScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/TestFifoScheduler.java index f9093c18d4..dc94e5e6d7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/TestFifoScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/TestFifoScheduler.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -333,7 +334,7 @@ public void testUpdateResourceOnNode() throws Exception { NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0); scheduler.handle(nodeEvent1); - assertEquals(scheduler.getNumClusterNodes(), 1); + assertThat(scheduler.getNumClusterNodes()).isEqualTo(1); Resource newResource = Resources.createResource(1024, 4); @@ -1286,20 +1287,20 @@ public void handle(Event event) { Resource usedResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getAllocatedResource(); - Assert.assertEquals(usedResource.getMemorySize(), 1 * GB); - Assert.assertEquals(usedResource.getVirtualCores(), 1); + assertThat(usedResource.getMemorySize()).isEqualTo(1 * GB); + assertThat(usedResource.getVirtualCores()).isEqualTo(1); // Check total resource of scheduler node is also changed to 1 GB 1 core Resource totalResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getTotalResource(); - Assert.assertEquals(totalResource.getMemorySize(), 1 * GB); - Assert.assertEquals(totalResource.getVirtualCores(), 1); + assertThat(totalResource.getMemorySize()).isEqualTo(1 * GB); + assertThat(totalResource.getVirtualCores()).isEqualTo(1); // Check the available resource is 0/0 Resource availableResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource(); - Assert.assertEquals(availableResource.getMemorySize(), 0); - Assert.assertEquals(availableResource.getVirtualCores(), 0); + assertThat(availableResource.getMemorySize()).isEqualTo(0); + assertThat(availableResource.getVirtualCores()).isEqualTo(0); } private void checkApplicationResourceUsage(int expected, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicy.java index 447618f4f2..776f6c6962 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicy.java @@ -25,6 +25,8 @@ import org.apache.hadoop.yarn.api.records.Priority; +import static org.assertj.core.api.Assertions.assertThat; + public class TestFifoOrderingPolicy { @Test @@ -33,14 +35,14 @@ public void testFifoOrderingPolicy() { new FifoOrderingPolicy(); MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r2 = new MockSchedulableEntity(); - - Assert.assertEquals(policy.getComparator().compare(r1, r2), 0); + + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(0); r1.setSerial(1); - Assert.assertEquals(policy.getComparator().compare(r1, r2), 1); + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(1); r2.setSerial(2); - Assert.assertEquals(policy.getComparator().compare(r1, r2), -1); + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(-1); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java index befa8e6c32..5fa9a1d0a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/policy/TestFifoOrderingPolicyForPendingApps.java @@ -23,6 +23,8 @@ import org.junit.Assert; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class TestFifoOrderingPolicyForPendingApps { @Test @@ -33,16 +35,16 @@ public void testFifoOrderingPolicyForPendingApps() { MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r2 = new MockSchedulableEntity(); - Assert.assertEquals(policy.getComparator().compare(r1, r2), 0); + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(0); r1.setSerial(1); r1.setRecovering(true); - Assert.assertEquals(policy.getComparator().compare(r1, r2), -1); + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(-1); r1.setRecovering(false); r2.setSerial(2); r2.setRecovering(true); - Assert.assertEquals(policy.getComparator().compare(r1, r2), 1); + assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(1); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java index 5113ba532d..370c527cec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java @@ -64,6 +64,7 @@ import java.util.Arrays; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -316,13 +317,13 @@ public void testVolumeResourceAllocate() throws Exception { Assert.assertEquals(1, allocated.size()); Container alloc = allocated.get(0); - Assert.assertEquals(alloc.getResource().getMemorySize(), 1024); - Assert.assertEquals(alloc.getResource().getVirtualCores(), 1); + assertThat(alloc.getResource().getMemorySize()).isEqualTo(1024); + assertThat(alloc.getResource().getVirtualCores()).isEqualTo(1); ResourceInformation allocatedVolume = alloc.getResource().getResourceInformation(VOLUME_RESOURCE_NAME); Assert.assertNotNull(allocatedVolume); - Assert.assertEquals(allocatedVolume.getValue(), 1024); - Assert.assertEquals(allocatedVolume.getUnits(), "Mi"); + assertThat(allocatedVolume.getValue()).isEqualTo(1024); + assertThat(allocatedVolume.getUnits()).isEqualTo("Mi"); rm.stop(); } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java index e8f62d03ea..c3f41f62f6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.webapp; +import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -1088,8 +1089,8 @@ private void verifyNodeAllocationTag(JSONObject json, for (int j=0; jmockito-core test + + org.assertj + assertj-core + test + com.fasterxml.jackson.core jackson-databind diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java index 61da3c8930..6435416635 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java @@ -60,6 +60,7 @@ import java.util.Map; import java.util.Set; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -414,7 +415,7 @@ store.new AppLogs(mainTestAppId, mainTestAppDirPath, TimelineEntities entities = tdm.getEntities("type_1", null, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser()); - assertEquals(entities.getEntities().size(), 1); + assertThat(entities.getEntities()).hasSize(1); for (TimelineEntity entity : entities.getEntities()) { assertEquals((Long) 123L, entity.getStartTime()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/pom.xml index 01eeec9382..43021d38ad 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/pom.xml @@ -324,6 +324,12 @@ test + + org.assertj + assertj-core + test + + org.apache.hbase hbase-testing-util diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/TestHBaseStorageFlowRunCompaction.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/TestHBaseStorageFlowRunCompaction.java index e0a58da980..475cb7a306 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/TestHBaseStorageFlowRunCompaction.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/TestHBaseStorageFlowRunCompaction.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.timelineservice.storage.flow; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @@ -119,7 +120,8 @@ public void testWriteNonNumericData() throws Exception { Cell actualValue = r.getColumnLatestCell( FlowRunColumnFamily.INFO.getBytes(), columnNameBytes); assertNotNull(CellUtil.cloneValue(actualValue)); - assertEquals(Bytes.toString(CellUtil.cloneValue(actualValue)), value); + assertThat(Bytes.toString(CellUtil.cloneValue(actualValue))). + isEqualTo(value); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml index 81ee6e274b..7293a0699d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml @@ -131,6 +131,12 @@ test + + org.assertj + assertj-core + test + + org.mockito mockito-core diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java index 80517922f8..766c2cd4bc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.Set; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -109,7 +110,7 @@ public void testAggregation() throws Exception { TimelineEntities testEntities = generateTestEntities(groups, n); TimelineEntity resultEntity = TimelineCollector.aggregateEntities( testEntities, "test_result", "TEST_AGGR", true); - assertEquals(resultEntity.getMetrics().size(), groups * 3); + assertThat(resultEntity.getMetrics()).hasSize(groups * 3); for (int i = 0; i < groups; i++) { Set metrics = resultEntity.getMetrics(); @@ -130,7 +131,7 @@ public void testAggregation() throws Exception { TimelineEntities testEntities1 = generateTestEntities(1, n); TimelineEntity resultEntity1 = TimelineCollector.aggregateEntities( testEntities1, "test_result", "TEST_AGGR", false); - assertEquals(resultEntity1.getMetrics().size(), 3); + assertThat(resultEntity1.getMetrics()).hasSize(3); Set metrics = resultEntity1.getMetrics(); for (TimelineMetric m : metrics) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml index 8eaa24b11d..17715a5574 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml @@ -74,6 +74,11 @@ junit test + + org.assertj + assertj-core + test + org.apache.hadoop diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java index f04bc9a39f..6cc1d22d58 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.webproxy; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -334,7 +335,7 @@ public void testWebAppProxyPassThroughHeaders() throws Exception { "Access-Control-Request-Headers", "Authorization"); proxyConn.addRequestProperty(UNKNOWN_HEADER, "unknown"); // Verify if four headers mentioned above have been added - assertEquals(proxyConn.getRequestProperties().size(), 4); + assertThat(proxyConn.getRequestProperties()).hasSize(4); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); // Verify if number of headers received by end server is 9. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java index 8b0c1a4c2f..641c2bf406 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java @@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertEquals; @@ -163,7 +164,7 @@ public void testFindRedirectUrl() throws Exception { spy.proxyUriBases.put(rm2, rm2Url); spy.rmUrls = new String[] { rm1, rm2 }; - assertEquals(spy.findRedirectUrl(), rm1Url); + assertThat(spy.findRedirectUrl()).isEqualTo(rm1Url); } private String startHttpServer() throws Exception { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestSecureAmFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestSecureAmFilter.java index e87b76541e..0a88243823 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestSecureAmFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestSecureAmFilter.java @@ -25,7 +25,7 @@ import java.util.HashSet; import java.util.HashMap; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -137,7 +137,7 @@ public void testFindRedirectUrl() throws Exception { assertTrue(spy.isValidUrl(rm1Url)); assertFalse(spy.isValidUrl(rm2Url)); - assertEquals(spy.findRedirectUrl(), rm1Url); + assertThat(spy.findRedirectUrl()).isEqualTo(rm1Url); } private String startSecureHttpServer() throws Exception {