YARN-9470. Fix order of actual and expected expression in assert statements

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
Prabhu Joseph 2019-04-17 21:48:19 +05:30 committed by Akira Ajisaka
parent 6e4399ea61
commit aa4c744aef
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
76 changed files with 501 additions and 345 deletions

View File

@ -250,6 +250,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -61,6 +61,7 @@
import java.util.*; import java.util.*;
import java.util.concurrent.TimeoutException; 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.api.records.YarnApplicationState.FINISHED;
import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.*; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.*;
import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_COMMAND_ARGUMENT_ERROR; 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; int i = 0;
for (String s : instances) { for (String s : instances) {
Assert.assertEquals(component.getName() + "-" + i, s); assertThat(s).isEqualTo(component.getName() + "-" + i);
i++; i++;
} }
} }

View File

@ -50,6 +50,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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.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.DEPENDENCY_TARBALL_PATH;
import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.YARN_SERVICE_BASE_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), "-initiate", ExampleAppJson.resourceName(ExampleAppJson.APP_JSON),
"-appTypes", DUMMY_APP_TYPE}; "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test (timeout = 180000) @Test (timeout = 180000)
@ -182,7 +183,7 @@ public void testInitiateAutoFinalizeServiceUpgrade() throws Exception {
"-autoFinalize", "-autoFinalize",
"-appTypes", DUMMY_APP_TYPE}; "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test @Test
@ -194,7 +195,7 @@ public void testUpgradeInstances() throws Exception {
"-instances", "comp1-0,comp1-1", "-instances", "comp1-0,comp1-1",
"-appTypes", DUMMY_APP_TYPE}; "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test @Test
@ -206,7 +207,7 @@ public void testUpgradeComponents() throws Exception {
"-components", "comp1,comp2", "-components", "comp1,comp2",
"-appTypes", DUMMY_APP_TYPE}; "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test @Test
@ -218,7 +219,7 @@ public void testGetInstances() throws Exception {
"-components", "comp1,comp2", "-components", "comp1,comp2",
"-appTypes", DUMMY_APP_TYPE}; "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test @Test
@ -229,7 +230,7 @@ public void testCancelUpgrade() throws Exception {
String[] args = {"app", "-upgrade", "app-1", String[] args = {"app", "-upgrade", "app-1",
"-cancel", "-appTypes", DUMMY_APP_TYPE}; "-cancel", "-appTypes", DUMMY_APP_TYPE};
int result = cli.run(ApplicationCLI.preProcessArgs(args)); int result = cli.run(ApplicationCLI.preProcessArgs(args));
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
} }
@Test (timeout = 180000) @Test (timeout = 180000)

View File

@ -45,6 +45,7 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; 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.conf.RestApiConstants.DEFAULT_UNLIMITED_LIFETIME;
import static org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages.*; import static org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -268,7 +269,7 @@ public void testArtifacts() throws IOException {
Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage());
} }
assertEquals(app.getLifetime(), DEFAULT_UNLIMITED_LIFETIME); assertThat(app.getLifetime()).isEqualTo(DEFAULT_UNLIMITED_LIFETIME);
} }
private static Resource createValidResource() { private static Resource createValidResource() {

View File

@ -84,6 +84,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- 'mvn dependency:analyze' fails to detect use of this dependency --> <!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.client.api.async.impl; 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.any;
import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
@ -596,7 +597,7 @@ public float getProgress() {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Assert.assertEquals(e.getMessage(), "Exception from callback handler"); assertThat(e).hasMessage("Exception from callback handler");
callStopAndNotify(); callStopAndNotify();
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.client.api.impl; 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.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -84,7 +85,7 @@ public void testGetApplications() throws YarnException, IOException {
Assert.assertEquals(reports, expectedReports); Assert.assertEquals(reports, expectedReports);
reports = client.getApplications(); reports = client.getApplications();
Assert.assertEquals(reports.size(), 4); assertThat(reports).hasSize(4);
client.stop(); client.stop();
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.client.api.impl; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -80,14 +81,14 @@ public void testGetContainerReport() throws IOException, YarnException {
when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null)) when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null))
.thenReturn(createApplicationTimelineEntity(appId, true, false)); .thenReturn(createApplicationTimelineEntity(appId, true, false));
ContainerReport report = client.getContainerReport(containerId); ContainerReport report = client.getContainerReport(containerId);
Assert.assertEquals(report.getContainerId(), containerId); assertThat(report.getContainerId()).isEqualTo(containerId);
Assert.assertEquals(report.getAssignedNode().getHost(), "test host"); assertThat(report.getAssignedNode().getHost()).isEqualTo("test host");
Assert.assertEquals(report.getAssignedNode().getPort(), 100); assertThat(report.getAssignedNode().getPort()).isEqualTo(100);
Assert.assertEquals(report.getAllocatedResource().getVirtualCores(), 8); assertThat(report.getAllocatedResource().getVirtualCores()).isEqualTo(8);
Assert.assertEquals(report.getCreationTime(), 123456); assertThat(report.getCreationTime()).isEqualTo(123456);
Assert.assertEquals(report.getLogUrl(), assertThat(report.getLogUrl()).isEqualTo("https://localhost:8188/ahs/logs/"
"https://localhost:8188/ahs/logs/test host:100/" + "test host:100/container_0_0001_01_000001/"
+ "container_0_0001_01_000001/container_0_0001_01_000001/user1"); + "container_0_0001_01_000001/user1");
} }
@Test @Test
@ -100,10 +101,10 @@ public void testGetAppAttemptReport() throws IOException, YarnException {
.thenReturn(createAppAttemptTimelineEntity(appAttemptId)); .thenReturn(createAppAttemptTimelineEntity(appAttemptId));
ApplicationAttemptReport report = ApplicationAttemptReport report =
client.getApplicationAttemptReport(appAttemptId); client.getApplicationAttemptReport(appAttemptId);
Assert.assertEquals(report.getApplicationAttemptId(), appAttemptId); assertThat(report.getApplicationAttemptId()).isEqualTo(appAttemptId);
Assert.assertEquals(report.getFinishTime(), Integer.MAX_VALUE + 2L); assertThat(report.getFinishTime()).isEqualTo(Integer.MAX_VALUE + 2L);
Assert.assertEquals(report.getOriginalTrackingUrl(), assertThat(report.getOriginalTrackingUrl()).
"test original tracking url"); isEqualTo("test original tracking url");
} }
@Test @Test
@ -112,11 +113,12 @@ public void testGetAppReport() throws IOException, YarnException {
when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null)) when(spyTimelineReaderClient.getApplicationEntity(appId, "ALL", null))
.thenReturn(createApplicationTimelineEntity(appId, false, false)); .thenReturn(createApplicationTimelineEntity(appId, false, false));
ApplicationReport report = client.getApplicationReport(appId); ApplicationReport report = client.getApplicationReport(appId);
Assert.assertEquals(report.getApplicationId(), appId); assertThat(report.getApplicationId()).isEqualTo(appId);
Assert.assertEquals(report.getAppNodeLabelExpression(), "test_node_label"); assertThat(report.getAppNodeLabelExpression()).
isEqualTo("test_node_label");
Assert.assertTrue(report.getApplicationTags().contains("Test_APP_TAGS_1")); Assert.assertTrue(report.getApplicationTags().contains("Test_APP_TAGS_1"));
Assert.assertEquals(report.getYarnApplicationState(), assertThat(report.getYarnApplicationState()).
YarnApplicationState.FINISHED); isEqualTo(YarnApplicationState.FINISHED);
} }
private static TimelineEntity createApplicationTimelineEntity( private static TimelineEntity createApplicationTimelineEntity(

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.client.api.impl; 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.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -1616,7 +1617,7 @@ private void waitForContainerCompletion(int numIterations,
for(ContainerStatus cStatus :allocResponse for(ContainerStatus cStatus :allocResponse
.getCompletedContainersStatuses()) { .getCompletedContainersStatuses()) {
if(releases.contains(cStatus.getContainerId())) { if(releases.contains(cStatus.getContainerId())) {
assertEquals(cStatus.getState(), ContainerState.COMPLETE); assertThat(cStatus.getState()).isEqualTo(ContainerState.COMPLETE);
assertEquals(-100, cStatus.getExitStatus()); assertEquals(-100, cStatus.getExitStatus());
releases.remove(cStatus.getContainerId()); releases.remove(cStatus.getContainerId());
} }

View File

@ -81,6 +81,7 @@
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -657,7 +658,7 @@ public void testMixedAllocationAndRelease() throws YarnException,
for (ContainerStatus cStatus : allocResponse for (ContainerStatus cStatus : allocResponse
.getCompletedContainersStatuses()) { .getCompletedContainersStatuses()) {
if (releases.contains(cStatus.getContainerId())) { if (releases.contains(cStatus.getContainerId())) {
assertEquals(cStatus.getState(), ContainerState.COMPLETE); assertThat(cStatus.getState()).isEqualTo(ContainerState.COMPLETE);
assertEquals(-100, cStatus.getExitStatus()); assertEquals(-100, cStatus.getExitStatus());
releases.remove(cStatus.getContainerId()); releases.remove(cStatus.getContainerId());
} }

View File

@ -93,6 +93,7 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -416,7 +417,7 @@ public void testGetApplications() throws YarnException, IOException {
List<ApplicationReport> expectedReports = ((MockYarnClient)client).getReports(); List<ApplicationReport> expectedReports = ((MockYarnClient)client).getReports();
List<ApplicationReport> reports = client.getApplications(); List<ApplicationReport> reports = client.getApplications();
Assert.assertEquals(reports, expectedReports); assertThat(reports).isEqualTo(expectedReports);
Set<String> appTypes = new HashSet<>(); Set<String> appTypes = new HashSet<>();
appTypes.add("YARN"); appTypes.add("YARN");
@ -424,7 +425,7 @@ public void testGetApplications() throws YarnException, IOException {
reports = reports =
client.getApplications(appTypes, null); client.getApplications(appTypes, null);
Assert.assertEquals(reports.size(), 2); assertThat(reports).hasSize(2);
Assert Assert
.assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports .assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports
.get(1).getApplicationType().equals("NON-YARN")) .get(1).getApplicationType().equals("NON-YARN"))
@ -439,7 +440,7 @@ public void testGetApplications() throws YarnException, IOException {
appStates.add(YarnApplicationState.FINISHED); appStates.add(YarnApplicationState.FINISHED);
appStates.add(YarnApplicationState.FAILED); appStates.add(YarnApplicationState.FAILED);
reports = client.getApplications(null, appStates); reports = client.getApplications(null, appStates);
Assert.assertEquals(reports.size(), 2); assertThat(reports).hasSize(2);
Assert Assert
.assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports .assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports
.get(1).getApplicationType().equals("NON-MAPREDUCE")) .get(1).getApplicationType().equals("NON-MAPREDUCE"))
@ -469,9 +470,9 @@ public void testGetApplicationAttempts() throws YarnException, IOException {
List<ApplicationAttemptReport> reports = client List<ApplicationAttemptReport> reports = client
.getApplicationAttempts(applicationId); .getApplicationAttempts(applicationId);
Assert.assertNotNull(reports); Assert.assertNotNull(reports);
Assert.assertEquals(reports.get(0).getApplicationAttemptId(), assertThat(reports.get(0).getApplicationAttemptId()).isEqualTo(
ApplicationAttemptId.newInstance(applicationId, 1)); ApplicationAttemptId.newInstance(applicationId, 1));
Assert.assertEquals(reports.get(1).getApplicationAttemptId(), assertThat(reports.get(1).getApplicationAttemptId()).isEqualTo(
ApplicationAttemptId.newInstance(applicationId, 2)); ApplicationAttemptId.newInstance(applicationId, 2));
client.stop(); client.stop();
} }
@ -492,7 +493,7 @@ public void testGetApplicationAttempt() throws YarnException, IOException {
ApplicationAttemptReport report = client ApplicationAttemptReport report = client
.getApplicationAttemptReport(appAttemptId); .getApplicationAttemptReport(appAttemptId);
Assert.assertNotNull(report); Assert.assertNotNull(report);
Assert.assertEquals(report.getApplicationAttemptId().toString(), assertThat(report.getApplicationAttemptId().toString()).isEqualTo(
expectedReports.get(0).getCurrentApplicationAttemptId().toString()); expectedReports.get(0).getCurrentApplicationAttemptId().toString());
client.stop(); client.stop();
} }
@ -512,11 +513,11 @@ public void testGetContainers() throws YarnException, IOException {
applicationId, 1); applicationId, 1);
List<ContainerReport> reports = client.getContainers(appAttemptId); List<ContainerReport> reports = client.getContainers(appAttemptId);
Assert.assertNotNull(reports); Assert.assertNotNull(reports);
Assert.assertEquals(reports.get(0).getContainerId(), assertThat(reports.get(0).getContainerId()).isEqualTo(
(ContainerId.newContainerId(appAttemptId, 1))); (ContainerId.newContainerId(appAttemptId, 1)));
Assert.assertEquals(reports.get(1).getContainerId(), assertThat(reports.get(1).getContainerId()).isEqualTo(
(ContainerId.newContainerId(appAttemptId, 2))); (ContainerId.newContainerId(appAttemptId, 2)));
Assert.assertEquals(reports.get(2).getContainerId(), assertThat(reports.get(2).getContainerId()).isEqualTo(
(ContainerId.newContainerId(appAttemptId, 3))); (ContainerId.newContainerId(appAttemptId, 3)));
//First2 containers should come from RM with updated state information and //First2 containers should come from RM with updated state information and
@ -554,9 +555,9 @@ public List<ContainerReport> getContainers(
List<ContainerReport> reports = client.getContainers(appAttemptId); List<ContainerReport> reports = client.getContainers(appAttemptId);
Assert.assertNotNull(reports); Assert.assertNotNull(reports);
Assert.assertTrue(reports.size() == 2); Assert.assertTrue(reports.size() == 2);
Assert.assertEquals(reports.get(0).getContainerId(), assertThat(reports.get(0).getContainerId()).isEqualTo(
(ContainerId.newContainerId(appAttemptId, 1))); (ContainerId.newContainerId(appAttemptId, 1)));
Assert.assertEquals(reports.get(1).getContainerId(), assertThat(reports.get(1).getContainerId()).isEqualTo(
(ContainerId.newContainerId(appAttemptId, 2))); (ContainerId.newContainerId(appAttemptId, 2)));
//Only 2 running containers from RM are present when AHS throws exception //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); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
ContainerReport report = client.getContainerReport(containerId); ContainerReport report = client.getContainerReport(containerId);
Assert.assertNotNull(report); Assert.assertNotNull(report);
Assert.assertEquals(report.getContainerId().toString(), assertThat(report.getContainerId().toString()).isEqualTo(
(ContainerId.newContainerId(expectedReports.get(0) (ContainerId.newContainerId(expectedReports.get(0)
.getCurrentApplicationAttemptId(), 1)).toString()); .getCurrentApplicationAttemptId(), 1)).toString());
containerId = ContainerId.newContainerId(appAttemptId, 3); containerId = ContainerId.newContainerId(appAttemptId, 3);
report = client.getContainerReport(containerId); report = client.getContainerReport(containerId);
Assert.assertNotNull(report); Assert.assertNotNull(report);
Assert.assertEquals(report.getContainerId().toString(), assertThat(report.getContainerId().toString()).isEqualTo(
(ContainerId.newContainerId(expectedReports.get(0) (ContainerId.newContainerId(expectedReports.get(0)
.getCurrentApplicationAttemptId(), 3)).toString()); .getCurrentApplicationAttemptId(), 3)).toString());
Assert.assertNotNull(report.getExecutionType()); Assert.assertNotNull(report.getExecutionType());
@ -609,16 +610,16 @@ public void testGetLabelsToNodes() throws YarnException, IOException {
Map<String, Set<NodeId>> expectedLabelsToNodes = Map<String, Set<NodeId>> expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap(); ((MockYarnClient)client).getLabelsToNodesMap();
Map<String, Set<NodeId>> labelsToNodes = client.getLabelsToNodes(); Map<String, Set<NodeId>> labelsToNodes = client.getLabelsToNodes();
Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); assertThat(labelsToNodes).isEqualTo(expectedLabelsToNodes);
Assert.assertEquals(labelsToNodes.size(), 3); assertThat(labelsToNodes).hasSize(3);
// Get labels to nodes for selected labels // Get labels to nodes for selected labels
Set<String> setLabels = new HashSet<>(Arrays.asList("x", "z")); Set<String> setLabels = new HashSet<>(Arrays.asList("x", "z"));
expectedLabelsToNodes = expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap(setLabels); ((MockYarnClient)client).getLabelsToNodesMap(setLabels);
labelsToNodes = client.getLabelsToNodes(setLabels); labelsToNodes = client.getLabelsToNodes(setLabels);
Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); assertThat(labelsToNodes).isEqualTo(expectedLabelsToNodes);
Assert.assertEquals(labelsToNodes.size(), 2); assertThat(labelsToNodes).hasSize(2);
client.stop(); client.stop();
client.close(); client.close();
@ -634,8 +635,8 @@ public void testGetNodesToLabels() throws YarnException, IOException {
Map<NodeId, Set<String>> expectedNodesToLabels = ((MockYarnClient) client) Map<NodeId, Set<String>> expectedNodesToLabels = ((MockYarnClient) client)
.getNodeToLabelsMap(); .getNodeToLabelsMap();
Map<NodeId, Set<String>> nodesToLabels = client.getNodeToLabels(); Map<NodeId, Set<String>> nodesToLabels = client.getNodeToLabels();
Assert.assertEquals(nodesToLabels, expectedNodesToLabels); assertThat(nodesToLabels).isEqualTo(expectedNodesToLabels);
Assert.assertEquals(nodesToLabels.size(), 1); assertThat(nodesToLabels).hasSize(1);
client.stop(); client.stop();
client.close(); client.close();

View File

@ -62,6 +62,8 @@
import java.util.Collections; import java.util.Collections;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* This class is to test class {@link YarnClient) and {@link YarnClientImpl} * This class is to test class {@link YarnClient) and {@link YarnClientImpl}
@ -432,7 +434,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations()
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
duration = 30000; duration = 30000;
deadline = sRequest.getReservationDefinition().getDeadline(); deadline = sRequest.getReservationDefinition().getDeadline();
@ -447,7 +449,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations()
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
arrival = clock.getTime(); arrival = clock.getTime();
// List reservations, search by end time before the reservation start // List reservations, search by end time before the reservation start
@ -460,7 +462,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations()
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
// List reservations, search by very small end time. // List reservations, search by very small end time.
request = ReservationListRequest request = ReservationListRequest
@ -470,7 +472,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations()
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
} finally { } finally {
// clean-up // clean-up

View File

@ -19,6 +19,7 @@
import org.apache.hadoop.yarn.api.records.NodeAttribute; import org.apache.hadoop.yarn.api.records.NodeAttribute;
import org.apache.hadoop.yarn.api.records.NodeAttributeType; 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.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
@ -1685,26 +1686,26 @@ public void testNodeCLIUsageInfo() throws Exception {
public void testMissingArguments() throws Exception { public void testMissingArguments() throws Exception {
ApplicationCLI cli = createAndGetAppCLI(); ApplicationCLI cli = createAndGetAppCLI();
int result = cli.run(new String[] { "application", "-status" }); 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", Assert.assertEquals(String.format("Missing argument for options%n%1s",
createApplicationCLIHelpMessage()), sysOutStream.toString()); createApplicationCLIHelpMessage()), sysOutStream.toString());
sysOutStream.reset(); sysOutStream.reset();
result = cli.run(new String[] { "applicationattempt", "-status" }); 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", Assert.assertEquals(String.format("Missing argument for options%n%1s",
createApplicationAttemptCLIHelpMessage()), sysOutStream.toString()); createApplicationAttemptCLIHelpMessage()), sysOutStream.toString());
sysOutStream.reset(); sysOutStream.reset();
result = cli.run(new String[] { "container", "-status" }); result = cli.run(new String[] { "container", "-status" });
Assert.assertEquals(result, -1); assertThat(result).isEqualTo(-1);
Assert.assertEquals(String.format("Missing argument for options %1s", Assert.assertEquals(String.format("Missing argument for options %1s",
createContainerCLIHelpMessage()), normalize(sysOutStream.toString())); createContainerCLIHelpMessage()), normalize(sysOutStream.toString()));
sysOutStream.reset(); sysOutStream.reset();
NodeCLI nodeCLI = createAndGetNodeCLI(); NodeCLI nodeCLI = createAndGetNodeCLI();
result = nodeCLI.run(new String[] { "-status" }); result = nodeCLI.run(new String[] { "-status" });
Assert.assertEquals(result, -1); assertThat(result).isEqualTo(-1);
Assert.assertEquals(String.format("Missing argument for options%n%1s", Assert.assertEquals(String.format("Missing argument for options%n%1s",
createNodeCLIHelpMessage()), sysOutStream.toString()); createNodeCLIHelpMessage()), sysOutStream.toString());
} }
@ -2017,7 +2018,7 @@ public void testUpdateApplicationPriority() throws Exception {
cli.run(new String[] { "application", "-appId", cli.run(new String[] { "application", "-appId",
applicationId.toString(), applicationId.toString(),
"-updatePriority", "1" }); "-updatePriority", "1" });
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
verify(client).updateApplicationPriority(any(ApplicationId.class), verify(client).updateApplicationPriority(any(ApplicationId.class),
any(Priority.class)); any(Priority.class));
@ -2413,7 +2414,7 @@ public void testUpdateApplicationTimeout() throws Exception {
int result = cli.run(new String[] { "application", "-appId", int result = cli.run(new String[] { "application", "-appId",
applicationId.toString(), "-updateLifetime", "10" }); applicationId.toString(), "-updateLifetime", "10" });
Assert.assertEquals(result, 0); assertThat(result).isEqualTo(0);
verify(client) verify(client)
.updateApplicationTimeouts(any(UpdateApplicationTimeoutsRequest.class)); .updateApplicationTimeouts(any(UpdateApplicationTimeoutsRequest.class));
} }

View File

@ -114,6 +114,11 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- 'mvn dependency:analyze' fails to detect use of this dependency --> <!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>

View File

@ -34,6 +34,7 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
@ -294,7 +295,7 @@ public void testParsingResourceTags() {
ResourceUtils.getResourceTypes().get("resource3"); ResourceUtils.getResourceTypes().get("resource3");
Assert.assertTrue(info.getAttributes().isEmpty()); Assert.assertTrue(info.getAttributes().isEmpty());
Assert.assertFalse(info.getTags().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_1");
info.getTags().remove("resource3_tag_2"); info.getTags().remove("resource3_tag_2");
Assert.assertTrue(info.getTags().isEmpty()); Assert.assertTrue(info.getTags().isEmpty());

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.logaggregation.filecontroller.ifile; 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.assertTrue;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock; 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. // We can only get the logs/logmeta from the first write.
meta = fileFormat.readAggregatedLogsMeta( meta = fileFormat.readAggregatedLogsMeta(
logRequest); logRequest);
Assert.assertEquals(meta.size(), 1); assertThat(meta.size()).isEqualTo(1);
for (ContainerLogMeta log : meta) { for (ContainerLogMeta log : meta) {
Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getContainerId().equals(containerId.toString()));
Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString()));
@ -319,7 +320,7 @@ public boolean isRollover(final FileContext fc,
fileFormat.closeWriter(); fileFormat.closeWriter();
meta = fileFormat.readAggregatedLogsMeta( meta = fileFormat.readAggregatedLogsMeta(
logRequest); logRequest);
Assert.assertEquals(meta.size(), 2); assertThat(meta.size()).isEqualTo(2);
for (ContainerLogMeta log : meta) { for (ContainerLogMeta log : meta) {
Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getContainerId().equals(containerId.toString()));
Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString()));
@ -347,7 +348,7 @@ public boolean isRollover(final FileContext fc,
Assert.assertTrue(status.length == 2); Assert.assertTrue(status.length == 2);
meta = fileFormat.readAggregatedLogsMeta( meta = fileFormat.readAggregatedLogsMeta(
logRequest); logRequest);
Assert.assertEquals(meta.size(), 3); assertThat(meta.size()).isEqualTo(3);
for (ContainerLogMeta log : meta) { for (ContainerLogMeta log : meta) {
Assert.assertTrue(log.getContainerId().equals(containerId.toString())); Assert.assertTrue(log.getContainerId().equals(containerId.toString()));
Assert.assertTrue(log.getNodeId().equals(nodeId.toString())); Assert.assertTrue(log.getNodeId().equals(nodeId.toString()));

View File

@ -25,6 +25,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; 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,="; String badEnv = "1,,2=a=b,3=a=,4==,5==a,==,c-3=3,=";
environment.clear(); environment.clear();
Apps.setEnvFromInputString(environment, badEnv, File.pathSeparator); Apps.setEnvFromInputString(environment, badEnv, File.pathSeparator);
assertEquals(environment.size(), 0); assertThat(environment).isEmpty();
// Test "=" in the value part // Test "=" in the value part
environment.clear(); environment.clear();

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.yarn.util; 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.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -93,12 +94,12 @@ public void testNodeIdWithDefaultPort() throws URISyntaxException {
NodeId nid; NodeId nid;
nid = ConverterUtils.toNodeIdWithDefaultPort("node:10"); nid = ConverterUtils.toNodeIdWithDefaultPort("node:10");
assertEquals(nid.getPort(), 10); assertThat(nid.getPort()).isEqualTo(10);
assertEquals(nid.getHost(), "node"); assertThat(nid.getHost()).isEqualTo("node");
nid = ConverterUtils.toNodeIdWithDefaultPort("node"); nid = ConverterUtils.toNodeIdWithDefaultPort("node");
assertEquals(nid.getPort(), 0); assertThat(nid.getPort()).isEqualTo(0);
assertEquals(nid.getHost(), "node"); assertThat(nid.getHost()).isEqualTo("node");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.yarn.util; package org.apache.hadoop.yarn.util;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -59,7 +61,7 @@ public void testMapCastToHashMap() {
HashMap<String, String> alternateHashMap = HashMap<String, String> alternateHashMap =
TimelineServiceHelper.mapCastToHashMap(firstTreeMap); TimelineServiceHelper.mapCastToHashMap(firstTreeMap);
Assert.assertEquals(firstTreeMap.size(), alternateHashMap.size()); Assert.assertEquals(firstTreeMap.size(), alternateHashMap.size());
Assert.assertEquals(alternateHashMap.get(key), value); assertThat(alternateHashMap.get(key)).isEqualTo(value);
// Test complicated hashmap be casted correctly // Test complicated hashmap be casted correctly
Map<String, Set<String>> complicatedHashMap = Map<String, Set<String>> complicatedHashMap =

View File

@ -18,6 +18,8 @@
package org.apache.hadoop.yarn.util.resource; package org.apache.hadoop.yarn.util.resource;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes; import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
@ -501,27 +503,25 @@ public void testMultipleOpsForResourcesWithTags() throws Exception {
ResourceInformation.newInstance("yarn.io/test-volume", "", 3)); ResourceInformation.newInstance("yarn.io/test-volume", "", 3));
Resource addedResource = Resources.add(resourceA, resourceB); Resource addedResource = Resources.add(resourceA, resourceB);
Assert.assertEquals(addedResource.getMemorySize(), 5); assertThat(addedResource.getMemorySize()).isEqualTo(5);
Assert.assertEquals(addedResource.getVirtualCores(), 10); assertThat(addedResource.getVirtualCores()).isEqualTo(10);
Assert.assertEquals( assertThat(addedResource.getResourceInformation("resource1").getValue()).
addedResource.getResourceInformation("resource1").getValue(), 8); isEqualTo(8);
// Verify that value of resourceA and resourceB is not added up for // Verify that value of resourceA and resourceB is not added up for
// "yarn.io/test-volume". // "yarn.io/test-volume".
Assert.assertEquals( assertThat(addedResource.getResourceInformation("yarn.io/test-volume").
addedResource.getResourceInformation("yarn.io/test-volume").getValue(), getValue()).isEqualTo(2);
2);
Resource mulResource = Resources.multiplyAndRoundDown(resourceA, 3); Resource mulResource = Resources.multiplyAndRoundDown(resourceA, 3);
Assert.assertEquals(mulResource.getMemorySize(), 6); assertThat(mulResource.getMemorySize()).isEqualTo(6);
Assert.assertEquals(mulResource.getVirtualCores(), 12); assertThat(mulResource.getVirtualCores()).isEqualTo(12);
Assert.assertEquals( assertThat(mulResource.getResourceInformation("resource1").getValue()).
mulResource.getResourceInformation("resource1").getValue(), 15); isEqualTo(15);
// Verify that value of resourceA is not multiplied up for // Verify that value of resourceA is not multiplied up for
// "yarn.io/test-volume". // "yarn.io/test-volume".
Assert.assertEquals( assertThat(mulResource.getResourceInformation("yarn.io/test-volume").
mulResource.getResourceInformation("yarn.io/test-volume").getValue(), getValue()).isEqualTo(2);
2);
} }
} }

View File

@ -73,6 +73,11 @@
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId> <artifactId>hadoop-common</artifactId>

View File

@ -52,6 +52,7 @@
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; 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.AccessMode.MULTI_NODE_MULTI_WRITER;
import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM;
@ -333,8 +334,8 @@ public void testCustomizedAdaptor() throws IOException, YarnException {
// Test getPluginInfo // Test getPluginInfo
GetPluginInfoResponse pluginInfo = GetPluginInfoResponse pluginInfo =
adaptorClient.getPluginInfo(GetPluginInfoRequest.newInstance()); adaptorClient.getPluginInfo(GetPluginInfoRequest.newInstance());
Assert.assertEquals(pluginInfo.getDriverName(), "customized-driver"); assertThat(pluginInfo.getDriverName()).isEqualTo("customized-driver");
Assert.assertEquals(pluginInfo.getVersion(), "1.0"); assertThat(pluginInfo.getVersion()).isEqualTo("1.0");
// Test validateVolumeCapacity // Test validateVolumeCapacity
ValidateVolumeCapabilitiesRequest request = ValidateVolumeCapabilitiesRequest request =
@ -412,8 +413,8 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException {
// Test getPluginInfo // Test getPluginInfo
GetPluginInfoResponse pluginInfo = GetPluginInfoResponse pluginInfo =
client1.getPluginInfo(GetPluginInfoRequest.newInstance()); client1.getPluginInfo(GetPluginInfoRequest.newInstance());
Assert.assertEquals(pluginInfo.getDriverName(), "customized-driver-1"); assertThat(pluginInfo.getDriverName()).isEqualTo("customized-driver-1");
Assert.assertEquals(pluginInfo.getVersion(), "1.0"); assertThat(pluginInfo.getVersion()).isEqualTo("1.0");
// Test validateVolumeCapacity // Test validateVolumeCapacity
ValidateVolumeCapabilitiesRequest request = ValidateVolumeCapabilitiesRequest request =
@ -440,8 +441,8 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException {
driver2Addr.getLocalPort())); driver2Addr.getLocalPort()));
GetPluginInfoResponse pluginInfo2 = GetPluginInfoResponse pluginInfo2 =
client2.getPluginInfo(GetPluginInfoRequest.newInstance()); client2.getPluginInfo(GetPluginInfoRequest.newInstance());
Assert.assertEquals(pluginInfo2.getDriverName(), "customized-driver-2"); assertThat(pluginInfo2.getDriverName()).isEqualTo("customized-driver-2");
Assert.assertEquals(pluginInfo2.getVersion(), "1.0"); assertThat(pluginInfo2.getVersion()).isEqualTo("1.0");
services.stop(); services.stop();
} }

View File

@ -76,6 +76,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- 'mvn dependency:analyze' fails to detect use of this dependency --> <!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
<dependency> <dependency>
<groupId>com.google.inject</groupId> <groupId>com.google.inject</groupId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp; 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.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -678,7 +679,7 @@ public void testContainerLogsForFinishedApps() throws Exception {
.accept(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN)
.get(ClientResponse.class); .get(ClientResponse.class);
responseText = response.getEntity(String.class); responseText = response.getEntity(String.class);
assertEquals(responseText.getBytes().length, fullTextSize); assertThat(responseText.getBytes()).hasSize(fullTextSize);
r = resource(); r = resource();
response = r.path("ws").path("v1") response = r.path("ws").path("v1")
@ -689,7 +690,7 @@ public void testContainerLogsForFinishedApps() throws Exception {
.accept(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN)
.get(ClientResponse.class); .get(ClientResponse.class);
responseText = response.getEntity(String.class); responseText = response.getEntity(String.class);
assertEquals(responseText.getBytes().length, fullTextSize); assertThat(responseText.getBytes()).hasSize(fullTextSize);
} }
@Test(timeout = 10000) @Test(timeout = 10000)
@ -880,8 +881,8 @@ public void testContainerLogsMetaForRunningApps() throws Exception {
List<ContainerLogFileInfo> logMeta = logInfo List<ContainerLogFileInfo> logMeta = logInfo
.getContainerLogsInfo(); .getContainerLogsInfo();
assertTrue(logMeta.size() == 1); assertTrue(logMeta.size() == 1);
assertEquals(logMeta.get(0).getFileName(), fileName); assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName);
assertEquals(logMeta.get(0).getFileSize(), String.valueOf( assertThat(logMeta.get(0).getFileSize()).isEqualTo(String.valueOf(
content.length())); content.length()));
} else { } else {
assertEquals(logInfo.getLogType(), assertEquals(logInfo.getLogType(),
@ -908,11 +909,11 @@ public void testContainerLogsMetaForRunningApps() throws Exception {
List<ContainerLogFileInfo> logMeta = logInfo List<ContainerLogFileInfo> logMeta = logInfo
.getContainerLogsInfo(); .getContainerLogsInfo();
assertTrue(logMeta.size() == 1); assertTrue(logMeta.size() == 1);
assertEquals(logMeta.get(0).getFileName(), fileName); assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName);
assertEquals(logMeta.get(0).getFileSize(), String.valueOf( assertThat(logMeta.get(0).getFileSize()).isEqualTo(String.valueOf(
content.length())); content.length()));
} else { } else {
assertEquals(logInfo.getLogType(), assertThat(logInfo.getLogType()).isEqualTo(
ContainerLogAggregationType.LOCAL.toString()); ContainerLogAggregationType.LOCAL.toString());
} }
} }
@ -946,8 +947,8 @@ public void testContainerLogsMetaForFinishedApps() throws Exception {
List<ContainerLogFileInfo> logMeta = responseText.get(0) List<ContainerLogFileInfo> logMeta = responseText.get(0)
.getContainerLogsInfo(); .getContainerLogsInfo();
assertTrue(logMeta.size() == 1); assertTrue(logMeta.size() == 1);
assertEquals(logMeta.get(0).getFileName(), fileName); assertThat(logMeta.get(0).getFileName()).isEqualTo(fileName);
assertEquals(logMeta.get(0).getFileSize(), assertThat(logMeta.get(0).getFileSize()).isEqualTo(
String.valueOf(content.length())); String.valueOf(content.length()));
} }

View File

@ -95,6 +95,11 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.zookeeper</groupId> <groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId> <artifactId>zookeeper</artifactId>

View File

@ -17,6 +17,8 @@
package org.apache.hadoop.yarn.server.federation.policies.manager; 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.FederationPolicyInitializationContext;
import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.FederationAMRMProxyPolicy; import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.FederationAMRMProxyPolicy;
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException; 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.SubClusterId;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration;
import org.apache.hadoop.yarn.server.federation.utils.FederationPoliciesTestUtil; import org.apache.hadoop.yarn.server.federation.utils.FederationPoliciesTestUtil;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
/** /**
@ -92,10 +93,10 @@ protected static void serializeAndDeserializePolicyManager(
FederationRouterPolicy federationRouterPolicy = FederationRouterPolicy federationRouterPolicy =
wfp2.getRouterPolicy(context, null); wfp2.getRouterPolicy(context, null);
Assert.assertEquals(federationAMRMProxyPolicy.getClass(), assertThat(federationAMRMProxyPolicy).
expAMRMProxyPolicy); isExactlyInstanceOf(expAMRMProxyPolicy);
Assert.assertEquals(federationRouterPolicy.getClass(), expRouterPolicy); assertThat(federationRouterPolicy).isExactlyInstanceOf(expRouterPolicy);
} }
} }

View File

@ -131,6 +131,11 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.google.inject</groupId> <groupId>com.google.inject</groupId>
<artifactId>guice</artifactId> <artifactId>guice</artifactId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.nodemanager; 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.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
@ -306,33 +307,34 @@ public void testStartLocalizer() throws IOException {
.build()); .build());
List<String> result=readMockParams(); List<String> result=readMockParams();
Assert.assertEquals(result.size(), 26); assertThat(result).hasSize(26);
Assert.assertEquals(result.get(0), YarnConfiguration.DEFAULT_NM_NONSECURE_MODE_LOCAL_USER); assertThat(result.get(0)).isEqualTo(YarnConfiguration.
Assert.assertEquals(result.get(1), "test"); DEFAULT_NM_NONSECURE_MODE_LOCAL_USER);
Assert.assertEquals(result.get(2), "0" ); assertThat(result.get(1)).isEqualTo("test");
Assert.assertEquals(result.get(3), "application_0"); assertThat(result.get(2)).isEqualTo("0");
Assert.assertEquals(result.get(4), "12345"); assertThat(result.get(3)).isEqualTo("application_0");
Assert.assertEquals(result.get(5), "/bin/nmPrivateCTokensPath"); assertThat(result.get(4)).isEqualTo("12345");
Assert.assertEquals(result.get(9), "-classpath" ); assertThat(result.get(5)).isEqualTo("/bin/nmPrivateCTokensPath");
Assert.assertEquals(result.get(12), "-Xmx256m" ); assertThat(result.get(9)).isEqualTo("-classpath");
Assert.assertEquals(result.get(13), assertThat(result.get(12)).isEqualTo("-Xmx256m");
assertThat(result.get(13)).isEqualTo(
"-Dlog4j.configuration=container-log4j.properties" ); "-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", String.format("-Dyarn.app.container.log.dir=%s/application_0/12345",
mockExec.getConf().get(YarnConfiguration.NM_LOG_DIRS))); mockExec.getConf().get(YarnConfiguration.NM_LOG_DIRS)));
Assert.assertEquals(result.get(15), assertThat(result.get(15)).isEqualTo(
"-Dyarn.app.container.log.filesize=0"); "-Dyarn.app.container.log.filesize=0");
Assert.assertEquals(result.get(16), "-Dhadoop.root.logger=INFO,CLA"); assertThat(result.get(16)).isEqualTo("-Dhadoop.root.logger=INFO,CLA");
Assert.assertEquals(result.get(17), assertThat(result.get(17)).isEqualTo(
"-Dhadoop.root.logfile=container-localizer-syslog"); "-Dhadoop.root.logfile=container-localizer-syslog");
Assert.assertEquals(result.get(18), assertThat(result.get(18)).isEqualTo("org.apache.hadoop.yarn.server." +
"org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer"); "nodemanager.containermanager.localizer.ContainerLocalizer");
Assert.assertEquals(result.get(19), "test"); assertThat(result.get(19)).isEqualTo("test");
Assert.assertEquals(result.get(20), "application_0"); assertThat(result.get(20)).isEqualTo("application_0");
Assert.assertEquals(result.get(21), "12345"); assertThat(result.get(21)).isEqualTo("12345");
Assert.assertEquals(result.get(22), "localhost"); assertThat(result.get(22)).isEqualTo("localhost");
Assert.assertEquals(result.get(23), "8040"); assertThat(result.get(23)).isEqualTo("8040");
Assert.assertEquals(result.get(24), "nmPrivateCTokensPath"); assertThat(result.get(24)).isEqualTo("nmPrivateCTokensPath");
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.error("Error:"+e.getMessage(),e); LOG.error("Error:"+e.getMessage(),e);

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -302,7 +303,7 @@ public void testApplicationRecovery() throws Exception {
// simulate log aggregation completion // simulate log aggregation completion
app.handle(new ApplicationEvent(app.getAppId(), app.handle(new ApplicationEvent(app.getAppId(),
ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
assertEquals(app.getApplicationState(), ApplicationState.FINISHED); assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED);
app.handle(new ApplicationEvent(app.getAppId(), app.handle(new ApplicationEvent(app.getAppId(),
ApplicationEventType.APPLICATION_LOG_HANDLING_FINISHED)); ApplicationEventType.APPLICATION_LOG_HANDLING_FINISHED));
@ -362,7 +363,7 @@ public void testNMRecoveryForAppFinishedWithLogAggregationFailure()
app.handle(new ApplicationEvent(app.getAppId(), app.handle(new ApplicationEvent(app.getAppId(),
ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
assertEquals(app.getApplicationState(), ApplicationState.FINISHED); assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED);
// application is still in NM context. // application is still in NM context.
assertEquals(1, context.getApplications().size()); assertEquals(1, context.getApplications().size());
@ -386,7 +387,7 @@ public void testNMRecoveryForAppFinishedWithLogAggregationFailure()
// is needed. // is needed.
app.handle(new ApplicationEvent(app.getAppId(), app.handle(new ApplicationEvent(app.getAppId(),
ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP)); ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
assertEquals(app.getApplicationState(), ApplicationState.FINISHED); assertThat(app.getApplicationState()).isEqualTo(ApplicationState.FINISHED);
// simulate log aggregation failed. // simulate log aggregation failed.
app.handle(new ApplicationEvent(app.getAppId(), app.handle(new ApplicationEvent(app.getAppId(),
@ -528,7 +529,8 @@ public void testContainerSchedulerRecovery() throws Exception {
ResourceUtilization utilization = ResourceUtilization utilization =
ResourceUtilization.newInstance(1024, 2048, 1.0F); ResourceUtilization.newInstance(1024, 2048, 1.0F);
assertEquals(cm.getContainerScheduler().getNumRunningContainers(), 1); assertThat(cm.getContainerScheduler().getNumRunningContainers()).
isEqualTo(1);
assertEquals(utilization, assertEquals(utilization,
cm.getContainerScheduler().getCurrentUtilization()); cm.getContainerScheduler().getCurrentUtilization());
@ -544,7 +546,8 @@ public void testContainerSchedulerRecovery() throws Exception {
assertNotNull(app); assertNotNull(app);
waitForNMContainerState(cm, cid, ContainerState.RUNNING); waitForNMContainerState(cm, cid, ContainerState.RUNNING);
assertEquals(cm.getContainerScheduler().getNumRunningContainers(), 1); assertThat(cm.getContainerScheduler().getNumRunningContainers()).
isEqualTo(1);
assertEquals(utilization, assertEquals(utilization,
cm.getContainerScheduler().getCurrentUtilization()); cm.getContainerScheduler().getCurrentUtilization());
cm.stop(); cm.stop();

View File

@ -18,9 +18,11 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher; 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.assumeWindows;
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; 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.ArgumentMatchers.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -124,7 +126,6 @@
import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper; import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper;
import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin; import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin;
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin; import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
import org.hamcrest.CoreMatchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
@ -212,7 +213,7 @@ public void testSpecialCharSymlinks() throws IOException {
= new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir); = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
shexc.execute(); shexc.execute();
assertEquals(shexc.getExitCode(), 0); assertThat(shexc.getExitCode()).isEqualTo(0);
//Capture output from prelaunch.out //Capture output from prelaunch.out
List<String> output = Files.readAllLines(Paths.get(localLogDir.getAbsolutePath(), ContainerLaunch.CONTAINER_PRE_LAUNCH_STDOUT), List<String> 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))); "X", Shell.WINDOWS_MAX_SHELL_LENGTH -callCmd.length() + 1)));
fail("longCommand was expected to throw"); fail("longCommand was expected to throw");
} catch(IOException e) { } catch(IOException e) {
assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); assertThat(e).hasMessageContaining(expectedMessage);
} }
// Composite tests, from parts: less, exact and + // 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()))); org.apache.commons.lang3.StringUtils.repeat("X", 2048 - callCmd.length())));
fail("long commands was expected to throw"); fail("long commands was expected to throw");
} catch(IOException e) { } 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); "A", Shell.WINDOWS_MAX_SHELL_LENGTH - ("@set somekey=").length()) + 1);
fail("long env was expected to throw"); fail("long env was expected to throw");
} catch(IOException e) { } 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))); "X", (Shell.WINDOWS_MAX_SHELL_LENGTH - mkDirCmd.length())/2 +1)));
fail("long mkdir was expected to throw"); fail("long mkdir was expected to throw");
} catch(IOException e) { } catch(IOException e) {
assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage)); assertThat(e).hasMessageContaining(expectedMessage);
} }
} }
@Test (timeout = 10000) @Test (timeout = 10000)
@ -1586,7 +1587,7 @@ public void testWindowsShellScriptBuilderLink() throws IOException {
"Y", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2) + 1)); "Y", (Shell.WINDOWS_MAX_SHELL_LENGTH - linkCmd.length())/2) + 1));
fail("long link was expected to throw"); fail("long link was expected to throw");
} catch(IOException e) { } 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); new String[] { tempFile.getAbsolutePath() }, tmpDir);
shexc.execute(); shexc.execute();
assertEquals(shexc.getExitCode(), 0); assertThat(shexc.getExitCode()).isEqualTo(0);
File directorInfo = File directorInfo =
new File(localLogDir, ContainerExecutor.DIRECTORY_CONTENTS); new File(localLogDir, ContainerExecutor.DIRECTORY_CONTENTS);
File scriptCopy = new File(localLogDir, tempFile.getName()); File scriptCopy = new File(localLogDir, tempFile.getName());

View File

@ -20,6 +20,8 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; 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.conf.Configuration;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.nodemanager.Context; import org.apache.hadoop.yarn.server.nodemanager.Context;
@ -71,7 +73,7 @@ public void testOutboundBandwidthHandler() {
List<ResourceHandler> resourceHandlers = resourceHandlerChain List<ResourceHandler> resourceHandlers = resourceHandlerChain
.getResourceHandlerList(); .getResourceHandlerList();
//Exactly one resource handler in chain //Exactly one resource handler in chain
Assert.assertEquals(resourceHandlers.size(), 1); assertThat(resourceHandlers).hasSize(1);
//Same instance is expected to be in the chain. //Same instance is expected to be in the chain.
Assert.assertTrue(resourceHandlers.get(0) == resourceHandler); Assert.assertTrue(resourceHandlers.get(0) == resourceHandler);
} else { } else {
@ -102,7 +104,7 @@ public void testDiskResourceHandler() throws Exception {
List<ResourceHandler> resourceHandlers = List<ResourceHandler> resourceHandlers =
resourceHandlerChain.getResourceHandlerList(); resourceHandlerChain.getResourceHandlerList();
// Exactly one resource handler in chain // Exactly one resource handler in chain
Assert.assertEquals(resourceHandlers.size(), 1); assertThat(resourceHandlers).hasSize(1);
// Same instance is expected to be in the chain. // Same instance is expected to be in the chain.
Assert.assertTrue(resourceHandlers.get(0) == handler); Assert.assertTrue(resourceHandlers.get(0) == handler);
} else { } else {

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer; 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.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -1325,15 +1326,15 @@ private void doLocalization(ResourceLocalizationService spyService,
// hence its not removed despite ref cnt being 0. // hence its not removed despite ref cnt being 0.
LocalizedResource rsrc1 = tracker.getLocalizedResource(req1); LocalizedResource rsrc1 = tracker.getLocalizedResource(req1);
assertNotNull(rsrc1); assertNotNull(rsrc1);
assertEquals(rsrc1.getState(), ResourceState.LOCALIZED); assertThat(rsrc1.getState()).isEqualTo(ResourceState.LOCALIZED);
assertEquals(rsrc1.getRefCount(), 0); assertThat(rsrc1.getRefCount()).isEqualTo(0);
// Container c1 was killed but this resource is referenced by container c2 // Container c1 was killed but this resource is referenced by container c2
// as well hence its ref cnt is 1. // as well hence its ref cnt is 1.
LocalizedResource rsrc2 = tracker.getLocalizedResource(req2); LocalizedResource rsrc2 = tracker.getLocalizedResource(req2);
assertNotNull(rsrc2); assertNotNull(rsrc2);
assertEquals(rsrc2.getState(), ResourceState.DOWNLOADING); assertThat(rsrc2.getState()).isEqualTo(ResourceState.DOWNLOADING);
assertEquals(rsrc2.getRefCount(), 1); assertThat(rsrc2.getRefCount()).isEqualTo(1);
// As container c1 was killed and this resource was not referenced by any // As container c1 was killed and this resource was not referenced by any
// other container, hence its removed. // other container, hence its removed.

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.nodemanager.containermanager.logaggregation; 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.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -870,7 +871,7 @@ public LogAggregationFileController getLogAggregationFileController(
}; };
checkEvents(appEventHandler, expectedEvents, false, checkEvents(appEventHandler, expectedEvents, false,
"getType", "getApplicationID", "getDiagnostic"); "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 // verify trying to collect logs for containers/apps we don't know about
// doesn't blow up and tear down the NM // doesn't blow up and tear down the NM
logAggregationService.handle(new LogHandlerContainerFinishedEvent( logAggregationService.handle(new LogHandlerContainerFinishedEvent(

View File

@ -39,6 +39,7 @@
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.ArgumentMatchers.anySet;
@ -265,7 +266,7 @@ public void testTopologySchedulingWithPackPolicy() throws Exception {
reset(spyPlugin); reset(spyPlugin);
Set<Device> allocation = spyPlugin.allocateDevices(copyAvailableDevices, Set<Device> allocation = spyPlugin.allocateDevices(copyAvailableDevices,
1, env); 1, env);
Assert.assertEquals(allocation.size(), 1); assertThat(allocation).hasSize(1);
verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet()); verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet());
Assert.assertFalse(spyPlugin.isTopoInitialized()); Assert.assertFalse(spyPlugin.isTopoInitialized());
@ -273,7 +274,7 @@ public void testTopologySchedulingWithPackPolicy() throws Exception {
reset(spyPlugin); reset(spyPlugin);
allocation = spyPlugin.allocateDevices(allDevices, 1, env); allocation = spyPlugin.allocateDevices(allDevices, 1, env);
// ensure no topology scheduling needed // ensure no topology scheduling needed
Assert.assertEquals(allocation.size(), 1); assertThat(allocation).hasSize(1);
verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet()); verify(spyPlugin).basicSchedule(anySet(), anyInt(), anySet());
reset(spyPlugin); reset(spyPlugin);
// Case 2. allocate all available // Case 2. allocate all available
@ -285,13 +286,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception {
int count = 2; int count = 2;
Map<String, Integer> pairToWeight = spyPlugin.getDevicePairToWeight(); Map<String, Integer> pairToWeight = spyPlugin.getDevicePairToWeight();
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin).initCostTable(); verify(spyPlugin).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
Device[] allocatedDevices = Device[] allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// Check weights // Check weights
@ -302,13 +303,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception {
reset(spyPlugin); reset(spyPlugin);
count = 3; count = 3;
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin, times(0)).initCostTable(); verify(spyPlugin, times(0)).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
allocatedDevices = allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// check weights // check weights
@ -327,13 +328,13 @@ public void testTopologySchedulingWithPackPolicy() throws Exception {
iterator.remove(); iterator.remove();
count = 2; count = 2;
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin, times(0)).initCostTable(); verify(spyPlugin, times(0)).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
allocatedDevices = allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// check weights // check weights
@ -377,13 +378,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception {
int count = 2; int count = 2;
Map<String, Integer> pairToWeight = spyPlugin.getDevicePairToWeight(); Map<String, Integer> pairToWeight = spyPlugin.getDevicePairToWeight();
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin).initCostTable(); verify(spyPlugin).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
Device[] allocatedDevices = Device[] allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// Check weights // Check weights
@ -394,13 +395,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception {
reset(spyPlugin); reset(spyPlugin);
count = 3; count = 3;
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin, times(0)).initCostTable(); verify(spyPlugin, times(0)).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
allocatedDevices = allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// check weights // check weights
@ -419,13 +420,13 @@ public void testTopologySchedulingWithSpreadPolicy() throws Exception {
iterator.remove(); iterator.remove();
count = 2; count = 2;
allocation = spyPlugin.allocateDevices(allDevices, count, env); allocation = spyPlugin.allocateDevices(allDevices, count, env);
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
// the costTable should be init and used topology scheduling // the costTable should be init and used topology scheduling
verify(spyPlugin, times(0)).initCostTable(); verify(spyPlugin, times(0)).initCostTable();
Assert.assertTrue(spyPlugin.isTopoInitialized()); Assert.assertTrue(spyPlugin.isTopoInitialized());
verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(), verify(spyPlugin).topologyAwareSchedule(anySet(), anyInt(), anyMap(),
anySet(), anyMap()); anySet(), anyMap());
Assert.assertEquals(allocation.size(), count); assertThat(allocation).hasSize(count);
allocatedDevices = allocatedDevices =
allocation.toArray(new Device[count]); allocation.toArray(new Device[count]);
// check weights // check weights
@ -574,7 +575,7 @@ public void testTopologySchedulingPerformanceWithPackPolicyWithNVLink()
report.readFromFile(); report.readFromFile();
ArrayList<ActualPerformanceReport.DataRecord> dataSet = ArrayList<ActualPerformanceReport.DataRecord> dataSet =
report.getDataSet(); report.getDataSet();
Assert.assertEquals(dataSet.size(), 2952); assertThat(dataSet).hasSize(2952);
String[] allModels = {"alexnet", "resnet50", "vgg16", "inception3"}; String[] allModels = {"alexnet", "resnet50", "vgg16", "inception3"};
int[] batchSizes = {32, 64, 128}; int[] batchSizes = {32, 64, 128};
int[] gpuCounts = {2, 3, 4, 5, 6, 7}; int[] gpuCounts = {2, 3, 4, 5, 6, 7};

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.nodemanager.recovery; 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.fusesource.leveldbjni.JniDBFactory.bytes;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -36,6 +37,7 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -1350,9 +1352,9 @@ public void testUnexpectedKeyDoesntThrowException() throws IOException {
@Test @Test
public void testAMRMProxyStorage() throws IOException { public void testAMRMProxyStorage() throws IOException {
RecoveredAMRMProxyState state = stateStore.loadAMRMProxyState(); RecoveredAMRMProxyState state = stateStore.loadAMRMProxyState();
assertEquals(state.getCurrentMasterKey(), null); assertThat(state.getCurrentMasterKey()).isNull();
assertEquals(state.getNextMasterKey(), null); assertThat(state.getNextMasterKey()).isNull();
assertEquals(state.getAppContexts().size(), 0); assertThat(state.getAppContexts()).isEmpty();
ApplicationId appId1 = ApplicationId.newInstance(1, 1); ApplicationId appId1 = ApplicationId.newInstance(1, 1);
ApplicationId appId2 = ApplicationId.newInstance(1, 2); ApplicationId appId2 = ApplicationId.newInstance(1, 2);
@ -1384,18 +1386,18 @@ public void testAMRMProxyStorage() throws IOException {
state = stateStore.loadAMRMProxyState(); state = stateStore.loadAMRMProxyState();
assertEquals(state.getCurrentMasterKey(), assertEquals(state.getCurrentMasterKey(),
secretManager.getCurrentMasterKeyData().getMasterKey()); secretManager.getCurrentMasterKeyData().getMasterKey());
assertEquals(state.getNextMasterKey(), null); assertThat(state.getNextMasterKey()).isNull();
assertEquals(state.getAppContexts().size(), 2); assertThat(state.getAppContexts()).hasSize(2);
// app1 // app1
Map<String, byte[]> map = state.getAppContexts().get(attemptId1); Map<String, byte[]> map = state.getAppContexts().get(attemptId1);
assertNotEquals(map, null); assertNotEquals(map, null);
assertEquals(map.size(), 2); assertThat(map).hasSize(2);
assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key1), data1));
assertTrue(Arrays.equals(map.get(key2), data2)); assertTrue(Arrays.equals(map.get(key2), data2));
// app2 // app2
map = state.getAppContexts().get(attemptId2); map = state.getAppContexts().get(attemptId2);
assertNotEquals(map, null); assertNotEquals(map, null);
assertEquals(map.size(), 2); assertThat(map).hasSize(2);
assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key1), data1));
assertTrue(Arrays.equals(map.get(key2), data2)); assertTrue(Arrays.equals(map.get(key2), data2));
@ -1414,14 +1416,14 @@ public void testAMRMProxyStorage() throws IOException {
assertEquals(state.getAppContexts().size(), 2); assertEquals(state.getAppContexts().size(), 2);
// app1 // app1
map = state.getAppContexts().get(attemptId1); map = state.getAppContexts().get(attemptId1);
assertNotEquals(map, null); assertThat(map).isNotNull();
assertEquals(map.size(), 2); assertThat(map).hasSize(2);
assertTrue(Arrays.equals(map.get(key1), data1)); assertTrue(Arrays.equals(map.get(key1), data1));
assertTrue(Arrays.equals(map.get(key2), data2)); assertTrue(Arrays.equals(map.get(key2), data2));
// app2 // app2
map = state.getAppContexts().get(attemptId2); map = state.getAppContexts().get(attemptId2);
assertNotEquals(map, null); assertThat(map).isNotNull();
assertEquals(map.size(), 1); assertThat(map).hasSize(1);
assertTrue(Arrays.equals(map.get(key2), data2)); assertTrue(Arrays.equals(map.get(key2), data2));
// Activate next master key and remove all entries of app1 // Activate next master key and remove all entries of app1
@ -1434,12 +1436,12 @@ public void testAMRMProxyStorage() throws IOException {
state = stateStore.loadAMRMProxyState(); state = stateStore.loadAMRMProxyState();
assertEquals(state.getCurrentMasterKey(), assertEquals(state.getCurrentMasterKey(),
secretManager.getCurrentMasterKeyData().getMasterKey()); secretManager.getCurrentMasterKeyData().getMasterKey());
assertEquals(state.getNextMasterKey(), null); assertThat(state.getNextMasterKey()).isNull();
assertEquals(state.getAppContexts().size(), 1); assertThat(state.getAppContexts()).hasSize(1);
// app2 only // app2 only
map = state.getAppContexts().get(attemptId2); map = state.getAppContexts().get(attemptId2);
assertNotEquals(map, null); assertThat(map).isNotNull();
assertEquals(map.size(), 1); assertThat(map).hasSize(1);
assertTrue(Arrays.equals(map.get(key2), data2)); assertTrue(Arrays.equals(map.get(key2), data2));
} finally { } finally {
secretManager.stop(); secretManager.stop();

View File

@ -96,6 +96,7 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -704,7 +705,7 @@ private void testContainerLogs(WebResource r, ContainerId containerId)
List<ContainerLogFileInfo> logMeta = responseList.get(0) List<ContainerLogFileInfo> logMeta = responseList.get(0)
.getContainerLogsInfo(); .getContainerLogsInfo();
assertTrue(logMeta.size() == 1); 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 // now create an aggregated log in Remote File system
File tempLogDir = new File("target", File tempLogDir = new File("target",
@ -724,19 +725,19 @@ private void testContainerLogs(WebResource r, ContainerId containerId)
assertEquals(200, response.getStatus()); assertEquals(200, response.getStatus());
responseList = response.getEntity(new GenericType< responseList = response.getEntity(new GenericType<
List<ContainerLogsInfo>>(){}); List<ContainerLogsInfo>>(){});
assertEquals(responseList.size(), 2); assertThat(responseList).hasSize(2);
for (ContainerLogsInfo logInfo : responseList) { for (ContainerLogsInfo logInfo : responseList) {
if(logInfo.getLogType().equals( if(logInfo.getLogType().equals(
ContainerLogAggregationType.AGGREGATED.toString())) { ContainerLogAggregationType.AGGREGATED.toString())) {
List<ContainerLogFileInfo> meta = logInfo.getContainerLogsInfo(); List<ContainerLogFileInfo> meta = logInfo.getContainerLogsInfo();
assertTrue(meta.size() == 1); assertTrue(meta.size() == 1);
assertEquals(meta.get(0).getFileName(), aggregatedLogFile); assertThat(meta.get(0).getFileName()).isEqualTo(aggregatedLogFile);
} else { } else {
assertEquals(logInfo.getLogType(), assertEquals(logInfo.getLogType(),
ContainerLogAggregationType.LOCAL.toString()); ContainerLogAggregationType.LOCAL.toString());
List<ContainerLogFileInfo> meta = logInfo.getContainerLogsInfo(); List<ContainerLogFileInfo> meta = logInfo.getContainerLogsInfo();
assertTrue(meta.size() == 1); assertTrue(meta.size() == 1);
assertEquals(meta.get(0).getFileName(), filename); assertThat(meta.get(0).getFileName()).isEqualTo(filename);
} }
} }

View File

@ -57,6 +57,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager; 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.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -1788,7 +1789,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() {
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
duration = 30000; duration = 30000;
deadline = sRequest.getReservationDefinition().getDeadline(); deadline = sRequest.getReservationDefinition().getDeadline();
@ -1808,7 +1809,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() {
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
arrival = clock.getTime(); arrival = clock.getTime();
// List reservations, search by end time before the reservation start // List reservations, search by end time before the reservation start
@ -1826,7 +1827,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() {
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
// List reservations, search by very small end time. // List reservations, search by very small end time.
request = ReservationListRequest request = ReservationListRequest
@ -1841,7 +1842,7 @@ public void testListReservationsByTimeIntervalContainingNoReservations() {
// Ensure all reservations are filtered out. // Ensure all reservations are filtered out.
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getReservationAllocationState().size(), 0); assertThat(response.getReservationAllocationState()).isEmpty();
rm.stop(); rm.stop();
} }
@ -2012,7 +2013,7 @@ protected ClientRMService createClientRMService() {
Arrays.asList(node1A))); Arrays.asList(node1A)));
Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll(
Arrays.asList(node1B, node3B))); Arrays.asList(node1B, node3B)));
Assert.assertEquals(labelsToNodes.get(labelY.getName()), null); assertThat(labelsToNodes.get(labelY.getName())).isNull();
rpc.stopProxy(client, conf); rpc.stopProxy(client, conf);
rm.close(); rm.close();
@ -2113,10 +2114,10 @@ protected ClientRMService createClientRMService() {
client.getAttributesToNodes(request); client.getAttributesToNodes(request);
Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs = Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs =
response.getAttributesToNodes(); response.getAttributesToNodes();
Assert.assertEquals(response.getAttributesToNodes().size(), 4); assertThat(response.getAttributesToNodes()).hasSize(4);
Assert.assertEquals(attrs.get(dist.getAttributeKey()).size(), 2); assertThat(attrs.get(dist.getAttributeKey())).hasSize(2);
Assert.assertEquals(attrs.get(os.getAttributeKey()).size(), 1); assertThat(attrs.get(os.getAttributeKey())).hasSize(1);
Assert.assertEquals(attrs.get(gpu.getAttributeKey()).size(), 1); assertThat(attrs.get(gpu.getAttributeKey())).hasSize(1);
Assert.assertTrue(findHostnameAndValInMapping(node1, "3_0_2", Assert.assertTrue(findHostnameAndValInMapping(node1, "3_0_2",
attrs.get(dist.getAttributeKey()))); attrs.get(dist.getAttributeKey())));
Assert.assertTrue(findHostnameAndValInMapping(node2, "3_0_2", Assert.assertTrue(findHostnameAndValInMapping(node2, "3_0_2",
@ -2130,7 +2131,7 @@ protected ClientRMService createClientRMService() {
client.getAttributesToNodes(request2); client.getAttributesToNodes(request2);
Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs2 = Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs2 =
response2.getAttributesToNodes(); response2.getAttributesToNodes();
Assert.assertEquals(attrs2.size(), 1); assertThat(attrs2).hasSize(1);
Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0",
attrs2.get(docker.getAttributeKey()))); attrs2.get(docker.getAttributeKey())));
@ -2141,7 +2142,7 @@ protected ClientRMService createClientRMService() {
client.getAttributesToNodes(request3); client.getAttributesToNodes(request3);
Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs3 = Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs3 =
response3.getAttributesToNodes(); response3.getAttributesToNodes();
Assert.assertEquals(attrs3.size(), 2); assertThat(attrs3).hasSize(2);
Assert.assertTrue(findHostnameAndValInMapping(node1, "windows64", Assert.assertTrue(findHostnameAndValInMapping(node1, "windows64",
attrs3.get(os.getAttributeKey()))); attrs3.get(os.getAttributeKey())));
Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0",

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager; package org.apache.hadoop.yarn.server.resourcemanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
@ -150,7 +151,7 @@ public void testKillAppWhenFailOverHappensDuringApplicationKill()
MockAM am0 = launchAM(app0, rm1, nm1); MockAM am0 = launchAM(app0, rm1, nm1);
// ensure that the app is in running state // ensure that the app is in running state
Assert.assertEquals(app0.getState(), RMAppState.RUNNING); assertThat(app0.getState()).isEqualTo(RMAppState.RUNNING);
// kill the app. // kill the app.
rm1.killApp(app0.getApplicationId()); rm1.killApp(app0.getApplicationId());

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager; 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.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -608,7 +609,7 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager,
Assert.assertEquals(accessList.getAclString(), Assert.assertEquals(accessList.getAclString(),
aclString); aclString);
} else { } else {
Assert.assertEquals(accessList.getAclString(), "*"); assertThat(accessList.getAclString()).isEqualTo("*");
} }
} }
} }

View File

@ -22,6 +22,7 @@
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -381,14 +382,14 @@ public void testHAIDLookup() {
rm = new MockRM(conf); rm = new MockRM(conf);
rm.init(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 //test explicitly lookup HA-ID
configuration.set(YarnConfiguration.RM_HA_ID, RM1_NODE_ID); configuration.set(YarnConfiguration.RM_HA_ID, RM1_NODE_ID);
conf = new YarnConfiguration(configuration); conf = new YarnConfiguration(configuration);
rm = new MockRM(conf); rm = new MockRM(conf);
rm.init(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 //test if RM_HA_ID can not be found
configuration configuration

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager; 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.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
@ -609,7 +610,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception {
MockAM am2 = launchAM(app1, rm1, nm1); MockAM am2 = launchAM(app1, rm1, nm1);
Assert.assertEquals(1, rmAppState.size()); Assert.assertEquals(1, rmAppState.size());
Assert.assertEquals(app1.getState(), RMAppState.RUNNING); assertThat(app1.getState()).isEqualTo(RMAppState.RUNNING);
Assert.assertEquals(app1.getAppAttempts() Assert.assertEquals(app1.getAppAttempts()
.get(app1.getCurrentAppAttempt().getAppAttemptId()) .get(app1.getCurrentAppAttempt().getAppAttemptId())
.getAppAttemptState(), RMAppAttemptState.RUNNING); .getAppAttemptState(), RMAppAttemptState.RUNNING);
@ -665,7 +666,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception {
rmApp = rm3.getRMContext().getRMApps().get(app1.getApplicationId()); rmApp = rm3.getRMContext().getRMApps().get(app1.getApplicationId());
// application should be in ACCEPTED state // application should be in ACCEPTED state
rm3.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); rm3.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
Assert.assertEquals(rmApp.getState(), RMAppState.ACCEPTED); assertThat(rmApp.getState()).isEqualTo(RMAppState.ACCEPTED);
// new attempt should not be started // new attempt should not be started
Assert.assertEquals(3, rmApp.getAppAttempts().size()); Assert.assertEquals(3, rmApp.getAppAttempts().size());
// am1 and am2 attempts should be in FAILED state where as am3 should be // am1 and am2 attempts should be in FAILED state where as am3 should be

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager; 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.api.records.ContainerUpdateType.INCREASE_RESOURCE;
import static org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils.RESOURCE_OUTSIDE_ALLOWED_RANGE; import static org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils.RESOURCE_OUTSIDE_ALLOWED_RANGE;
@ -140,22 +141,22 @@ public void testQueryRMNodes() throws Exception {
List<RMNode> result = RMServerUtils.queryRMNodes(rmContext, List<RMNode> result = RMServerUtils.queryRMNodes(rmContext,
EnumSet.of(NodeState.SHUTDOWN)); EnumSet.of(NodeState.SHUTDOWN));
Assert.assertTrue(result.size() != 0); Assert.assertTrue(result.size() != 0);
Assert.assertEquals(result.get(0), rmNode1); assertThat(result.get(0)).isEqualTo(rmNode1);
when(rmNode1.getState()).thenReturn(NodeState.DECOMMISSIONED); when(rmNode1.getState()).thenReturn(NodeState.DECOMMISSIONED);
result = RMServerUtils.queryRMNodes(rmContext, result = RMServerUtils.queryRMNodes(rmContext,
EnumSet.of(NodeState.DECOMMISSIONED)); EnumSet.of(NodeState.DECOMMISSIONED));
Assert.assertTrue(result.size() != 0); Assert.assertTrue(result.size() != 0);
Assert.assertEquals(result.get(0), rmNode1); assertThat(result.get(0)).isEqualTo(rmNode1);
when(rmNode1.getState()).thenReturn(NodeState.LOST); when(rmNode1.getState()).thenReturn(NodeState.LOST);
result = RMServerUtils.queryRMNodes(rmContext, result = RMServerUtils.queryRMNodes(rmContext,
EnumSet.of(NodeState.LOST)); EnumSet.of(NodeState.LOST));
Assert.assertTrue(result.size() != 0); Assert.assertTrue(result.size() != 0);
Assert.assertEquals(result.get(0), rmNode1); assertThat(result.get(0)).isEqualTo(rmNode1);
when(rmNode1.getState()).thenReturn(NodeState.REBOOTED); when(rmNode1.getState()).thenReturn(NodeState.REBOOTED);
result = RMServerUtils.queryRMNodes(rmContext, result = RMServerUtils.queryRMNodes(rmContext,
EnumSet.of(NodeState.REBOOTED)); EnumSet.of(NodeState.REBOOTED));
Assert.assertTrue(result.size() != 0); Assert.assertTrue(result.size() != 0);
Assert.assertEquals(result.get(0), rmNode1); assertThat(result.get(0)).isEqualTo(rmNode1);
} }
@Test @Test

View File

@ -100,6 +100,8 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; 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.capacity.CapacitySchedulerConfiguration.PREFIX;
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler import static org.apache.hadoop.yarn.server.resourcemanager.scheduler
@ -263,7 +265,8 @@ public void testSchedulerRecovery() throws Exception {
scheduler.getRMContainer(amContainer.getContainerId()))); scheduler.getRMContainer(amContainer.getContainerId())));
assertTrue(schedulerAttempt.getLiveContainers().contains( assertTrue(schedulerAttempt.getLiveContainers().contains(
scheduler.getRMContainer(runningContainer.getContainerId()))); scheduler.getRMContainer(runningContainer.getContainerId())));
assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); assertThat(schedulerAttempt.getCurrentConsumption()).
isEqualTo(usedResources);
// *********** check appSchedulingInfo state *********** // *********** check appSchedulingInfo state ***********
assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId());
@ -421,7 +424,8 @@ public void testDynamicQueueRecovery() throws Exception {
.contains(scheduler.getRMContainer(amContainer.getContainerId()))); .contains(scheduler.getRMContainer(amContainer.getContainerId())));
assertTrue(schedulerAttempt.getLiveContainers() assertTrue(schedulerAttempt.getLiveContainers()
.contains(scheduler.getRMContainer(runningContainer.getContainerId()))); .contains(scheduler.getRMContainer(runningContainer.getContainerId())));
assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); assertThat(schedulerAttempt.getCurrentConsumption()).
isEqualTo(usedResources);
// *********** check appSchedulingInfo state *********** // *********** check appSchedulingInfo state ***********
assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId());
@ -775,8 +779,9 @@ private void verifyAppRecoveryWithWrongQueueConfig(
ApplicationReport report = rm2.getApplicationReport(app.getApplicationId()); ApplicationReport report = rm2.getApplicationReport(app.getApplicationId());
assertEquals(report.getFinalApplicationStatus(), assertEquals(report.getFinalApplicationStatus(),
FinalApplicationStatus.KILLED); FinalApplicationStatus.KILLED);
assertEquals(report.getYarnApplicationState(), YarnApplicationState.KILLED); assertThat(report.getYarnApplicationState()).
assertEquals(report.getDiagnostics(), diagnostics); isEqualTo(YarnApplicationState.KILLED);
assertThat(report.getDiagnostics()).isEqualTo(diagnostics);
//Reload previous state with cloned app sub context object //Reload previous state with cloned app sub context object
RMState newState = memStore2.reloadStateWithClonedAppSubCtxt(state); RMState newState = memStore2.reloadStateWithClonedAppSubCtxt(state);
@ -1730,7 +1735,8 @@ public void testDynamicAutoCreatedQueueRecovery(String user, String queueName)
.contains(scheduler.getRMContainer(amContainer.getContainerId()))); .contains(scheduler.getRMContainer(amContainer.getContainerId())));
assertTrue(schedulerAttempt.getLiveContainers() assertTrue(schedulerAttempt.getLiveContainers()
.contains(scheduler.getRMContainer(runningContainer.getContainerId()))); .contains(scheduler.getRMContainer(runningContainer.getContainerId())));
assertEquals(schedulerAttempt.getCurrentConsumption(), usedResources); assertThat(schedulerAttempt.getCurrentConsumption()).
isEqualTo(usedResources);
// *********** check appSchedulingInfo state *********** // *********** check appSchedulingInfo state ***********
assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId()); assertEquals((1L << 40) + 1L, schedulerAttempt.getNewContainerId());

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.metrics; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -290,7 +291,7 @@ public void testPublishApplicationMetrics() throws Exception {
} else if (event.getEventType().equals( } else if (event.getEventType().equals(
ApplicationMetricsConstants.STATE_UPDATED_EVENT_TYPE)) { ApplicationMetricsConstants.STATE_UPDATED_EVENT_TYPE)) {
hasStateUpdateEvent = true; hasStateUpdateEvent = true;
Assert.assertEquals(event.getTimestamp(), stateUpdateTimeStamp); assertThat(event.getTimestamp()).isEqualTo(stateUpdateTimeStamp);
Assert.assertEquals(YarnApplicationState.RUNNING.toString(), event Assert.assertEquals(YarnApplicationState.RUNNING.toString(), event
.getEventInfo().get( .getEventInfo().get(
ApplicationMetricsConstants.STATE_EVENT_INFO)); ApplicationMetricsConstants.STATE_EVENT_INFO));

View File

@ -27,6 +27,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@ -230,7 +231,8 @@ public void testPreemptionToBalanceWithConfiguredTimeout() throws IOException {
FifoCandidatesSelector pcs = (FifoCandidatesSelector) pc.getKey(); FifoCandidatesSelector pcs = (FifoCandidatesSelector) pc.getKey();
if (pcs.getAllowQueuesBalanceAfterAllQueuesSatisfied() == true) { if (pcs.getAllowQueuesBalanceAfterAllQueuesSatisfied() == true) {
hasFifoSelector = true; hasFifoSelector = true;
assertEquals(pcs.getMaximumKillWaitTimeMs(), FB_MAX_BEFORE_KILL); assertThat(pcs.getMaximumKillWaitTimeMs()).
isEqualTo(FB_MAX_BEFORE_KILL);
} }
} }
} }

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; 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.ArgumentMatchers.any;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@ -139,8 +140,8 @@ public void testRecoverWithMirror() throws Exception {
toAddAttributes); toAddAttributes);
Map<NodeAttribute, AttributeValue> attrs = Map<NodeAttribute, AttributeValue> attrs =
mgr.getAttributesForNode("host0"); mgr.getAttributesForNode("host0");
Assert.assertEquals(attrs.size(), 1); assertThat(attrs).hasSize(1);
Assert.assertEquals(attrs.keySet().toArray()[0], docker); assertThat(attrs.keySet().toArray()[0]).isEqualTo(docker);
mgr.stop(); mgr.stop();
// Start new attribute manager with same path // Start new attribute manager with same path
@ -154,8 +155,8 @@ public void testRecoverWithMirror() throws Exception {
Assert.assertEquals("host1 size", 1, Assert.assertEquals("host1 size", 1,
mgr.getAttributesForNode("host1").size()); mgr.getAttributesForNode("host1").size());
attrs = mgr.getAttributesForNode("host0"); attrs = mgr.getAttributesForNode("host0");
Assert.assertEquals(attrs.size(), 1); assertThat(attrs).hasSize(1);
Assert.assertEquals(attrs.keySet().toArray()[0], docker); assertThat(attrs.keySet().toArray()[0]).isEqualTo(docker);
//------host0---- //------host0----
// current - docker // current - docker
// replace - gpu // replace - gpu
@ -181,8 +182,8 @@ public void testRecoverWithMirror() throws Exception {
Assert.assertEquals("host1 size", 2, Assert.assertEquals("host1 size", 2,
mgr.getAttributesForNode("host1").size()); mgr.getAttributesForNode("host1").size());
attrs = mgr.getAttributesForNode("host0"); attrs = mgr.getAttributesForNode("host0");
Assert.assertEquals(attrs.size(), 1); assertThat(attrs).hasSize(1);
Assert.assertEquals(attrs.keySet().toArray()[0], gpu); assertThat(attrs.keySet().toArray()[0]).isEqualTo(gpu);
attrs = mgr.getAttributesForNode("host1"); attrs = mgr.getAttributesForNode("host1");
Assert.assertTrue(attrs.keySet().contains(docker)); Assert.assertTrue(attrs.keySet().contains(docker));
Assert.assertTrue(attrs.keySet().contains(gpu)); Assert.assertTrue(attrs.keySet().contains(gpu));

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -88,37 +90,37 @@ public void testGetLabelResourceWhenNodeActiveDeactive() throws Exception {
mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"), mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"),
toNodeId("n2"), toSet("p2"), toNodeId("n3"), toSet("p3"))); toNodeId("n2"), toSet("p2"), toNodeId("n3"), toSet("p3")));
Assert.assertEquals(mgr.getResourceByLabel("p1", null), EMPTY_RESOURCE); assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(EMPTY_RESOURCE);
Assert.assertEquals(mgr.getResourceByLabel("p2", null), EMPTY_RESOURCE); assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo(EMPTY_RESOURCE);
Assert.assertEquals(mgr.getResourceByLabel("p3", null), EMPTY_RESOURCE); assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(EMPTY_RESOURCE);
Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null), assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)).
EMPTY_RESOURCE); isEqualTo(EMPTY_RESOURCE);
// active two NM to n1, one large and one small // active two NM to n1, one large and one small
mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE);
mgr.activateNode(NodeId.newInstance("n1", 2), LARGE_NODE); 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)); Resources.add(SMALL_RESOURCE, LARGE_NODE));
// check add labels multiple times shouldn't overwrite // check add labels multiple times shouldn't overwrite
// original attributes on labels like resource // original attributes on labels like resource
mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p4")); mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p4"));
Assert.assertEquals(mgr.getResourceByLabel("p1", null), assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(
Resources.add(SMALL_RESOURCE, LARGE_NODE)); Resources.add(SMALL_RESOURCE, LARGE_NODE));
Assert.assertEquals(mgr.getResourceByLabel("p4", null), EMPTY_RESOURCE); Assert.assertEquals(mgr.getResourceByLabel("p4", null), EMPTY_RESOURCE);
// change the large NM to small, check if resource updated // change the large NM to small, check if resource updated
mgr.updateNodeResource(NodeId.newInstance("n1", 2), SMALL_RESOURCE); 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)); Resources.multiply(SMALL_RESOURCE, 2));
// deactive one NM, and check if resource updated // deactive one NM, and check if resource updated
mgr.deactivateNode(NodeId.newInstance("n1", 1)); 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 // continus deactive, check if resource updated
mgr.deactivateNode(NodeId.newInstance("n1", 2)); 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 // Add two NM to n1 back
mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE); 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, // And remove p1, now the two NM should come to default label,
mgr.removeFromClusterNodeLabels(ImmutableSet.of("p1")); mgr.removeFromClusterNodeLabels(ImmutableSet.of("p1"));
Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null), assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)).
Resources.add(SMALL_RESOURCE, LARGE_NODE)); isEqualTo(Resources.add(SMALL_RESOURCE, LARGE_NODE));
} }
@Test(timeout = 5000) @Test(timeout = 5000)
@ -152,10 +154,10 @@ public void testGetLabelResource() throws Exception {
// change label of n1 to p2 // change label of n1 to p2
mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p2"))); mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p2")));
Assert.assertEquals(mgr.getResourceByLabel("p1", null), EMPTY_RESOURCE); assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(EMPTY_RESOURCE);
Assert.assertEquals(mgr.getResourceByLabel("p2", null), assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
Assert.assertEquals(mgr.getResourceByLabel("p3", null), SMALL_RESOURCE); assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(SMALL_RESOURCE);
// add more labels // add more labels
mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p4", "p5", "p6")); mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p4", "p5", "p6"));
@ -180,17 +182,17 @@ public void testGetLabelResource() throws Exception {
mgr.activateNode(NodeId.newInstance("n9", 1), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("n9", 1), SMALL_RESOURCE);
// check varibles // check varibles
Assert.assertEquals(mgr.getResourceByLabel("p1", null), SMALL_RESOURCE); assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(SMALL_RESOURCE);
Assert.assertEquals(mgr.getResourceByLabel("p2", null), assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 3)); Resources.multiply(SMALL_RESOURCE, 3));
Assert.assertEquals(mgr.getResourceByLabel("p3", null), assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
Assert.assertEquals(mgr.getResourceByLabel("p4", null), assertThat(mgr.getResourceByLabel("p4", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 1)); Resources.multiply(SMALL_RESOURCE, 1));
Assert.assertEquals(mgr.getResourceByLabel("p5", null), assertThat(mgr.getResourceByLabel("p5", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 1));
Assert.assertEquals(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null),
Resources.multiply(SMALL_RESOURCE, 1)); Resources.multiply(SMALL_RESOURCE, 1));
assertThat(mgr.getResourceByLabel(RMNodeLabelsManager.NO_LABEL, null)).
isEqualTo(Resources.multiply(SMALL_RESOURCE, 1));
// change a bunch of nodes -> labels // change a bunch of nodes -> labels
// n4 -> p2 // n4 -> p2
@ -212,17 +214,17 @@ public void testGetLabelResource() throws Exception {
toNodeId("n9"), toSet("p1"))); toNodeId("n9"), toSet("p1")));
// check varibles // check varibles
Assert.assertEquals(mgr.getResourceByLabel("p1", null), assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
Assert.assertEquals(mgr.getResourceByLabel("p2", null), assertThat(mgr.getResourceByLabel("p2", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 3)); Resources.multiply(SMALL_RESOURCE, 3));
Assert.assertEquals(mgr.getResourceByLabel("p3", null), assertThat(mgr.getResourceByLabel("p3", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
Assert.assertEquals(mgr.getResourceByLabel("p4", null), assertThat(mgr.getResourceByLabel("p4", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 0)); Resources.multiply(SMALL_RESOURCE, 0));
Assert.assertEquals(mgr.getResourceByLabel("p5", null), assertThat(mgr.getResourceByLabel("p5", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 0)); Resources.multiply(SMALL_RESOURCE, 0));
Assert.assertEquals(mgr.getResourceByLabel("", null), assertThat(mgr.getResourceByLabel("", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
} }
@ -413,9 +415,9 @@ public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOExc
mgr.activateNode(NodeId.newInstance("n1", 4), SMALL_RESOURCE); mgr.activateNode(NodeId.newInstance("n1", 4), SMALL_RESOURCE);
// check resource of no label, it should be small * 4 // check resource of no label, it should be small * 4
Assert.assertEquals( assertThat(
mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null)).
Resources.multiply(SMALL_RESOURCE, 4)); isEqualTo(Resources.multiply(SMALL_RESOURCE, 4));
// change two of these nodes to p1, check resource of no_label and P1 // change two of these nodes to p1, check resource of no_label and P1
mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1")); mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1"));
@ -423,12 +425,12 @@ public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOExc
toNodeId("n1:2"), toSet("p1"))); toNodeId("n1:2"), toSet("p1")));
// check resource // check resource
Assert.assertEquals( assertThat(
mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null)).
Resources.multiply(SMALL_RESOURCE, 2)); isEqualTo(Resources.multiply(SMALL_RESOURCE, 2));
Assert.assertEquals( assertThat(
mgr.getResourceByLabel("p1", null), mgr.getResourceByLabel("p1", null)).isEqualTo(
Resources.multiply(SMALL_RESOURCE, 2)); Resources.multiply(SMALL_RESOURCE, 2));
} }
@Test(timeout = 5000) @Test(timeout = 5000)

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.recovery; package org.apache.hadoop.yarn.server.resourcemanager.recovery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
@ -125,8 +126,8 @@ public RMStateStore getRMStateStore() throws Exception {
YarnConfiguration.YARN_INTERMEDIATE_DATA_ENCRYPTION, true); YarnConfiguration.YARN_INTERMEDIATE_DATA_ENCRYPTION, true);
} }
this.store = new TestFileSystemRMStore(conf); this.store = new TestFileSystemRMStore(conf);
Assert.assertEquals(store.getNumRetries(), 8); assertThat(store.getNumRetries()).isEqualTo(8);
Assert.assertEquals(store.getRetryInterval(), 900L); assertThat(store.getRetryInterval()).isEqualTo(900L);
Assert.assertTrue(store.fs.getConf() == store.fsConf); Assert.assertTrue(store.fs.getConf() == store.fsConf);
FileSystem previousFs = store.fs; FileSystem previousFs = store.fs;
store.startInternal(); store.startInternal();

View File

@ -76,6 +76,7 @@
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; 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.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -435,14 +436,14 @@ public void testZKRootPathAcls() throws Exception {
rm.getRMContext().getRMAdminService().transitionToActive(req); rm.getRMContext().getRMAdminService().transitionToActive(req);
ZKRMStateStore stateStore = (ZKRMStateStore) rm.getRMContext().getStateStore(); ZKRMStateStore stateStore = (ZKRMStateStore) rm.getRMContext().getStateStore();
List<ACL> acls = stateStore.getACL(rootPath); List<ACL> acls = stateStore.getACL(rootPath);
assertEquals(acls.size(), 2); assertThat(acls).hasSize(2);
// CREATE and DELETE permissions for root node based on RM ID // CREATE and DELETE permissions for root node based on RM ID
verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls); verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls);
verifyZKACL( verifyZKACL(
"world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls); "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls);
acls = stateStore.getACL(parentPath); acls = stateStore.getACL(parentPath);
assertEquals(1, acls.size()); assertThat(acls).hasSize(1);
assertEquals(perm, acls.get(0).getPerms()); assertEquals(perm, acls.get(0).getPerms());
rm.close(); rm.close();
@ -463,7 +464,7 @@ public void testZKRootPathAcls() throws Exception {
rm.start(); rm.start();
rm.getRMContext().getRMAdminService().transitionToActive(req); rm.getRMContext().getRMAdminService().transitionToActive(req);
acls = stateStore.getACL(rootPath); acls = stateStore.getACL(rootPath);
assertEquals(acls.size(), 2); assertThat(acls).hasSize(2);
verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls); verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls);
verifyZKACL( verifyZKACL(
"world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls); "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls);

View File

@ -17,6 +17,7 @@
*******************************************************************************/ *******************************************************************************/
package org.apache.hadoop.yarn.server.resourcemanager.reservation; package org.apache.hadoop.yarn.server.resourcemanager.reservation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.apache.hadoop.yarn.api.records.ReservationAllocationState; import org.apache.hadoop.yarn.api.records.ReservationAllocationState;
@ -49,9 +50,9 @@ public void testConvertAllocationsToReservationInfo() {
.convertAllocationsToReservationInfo( .convertAllocationsToReservationInfo(
Collections.singleton(allocation), true); Collections.singleton(allocation), true);
Assert.assertEquals(infoList.size(), 1); assertThat(infoList).hasSize(1);
Assert.assertEquals(infoList.get(0).getReservationId().toString(), assertThat(infoList.get(0).getReservationId().toString()).isEqualTo(
id.toString()); id.toString());
Assert.assertFalse(infoList.get(0).getResourceAllocationRequests() Assert.assertFalse(infoList.get(0).getResourceAllocationRequests()
.isEmpty()); .isEmpty());
} }
@ -104,7 +105,7 @@ public void testConvertAllocationsToReservationInfoEmptySet() {
.convertAllocationsToReservationInfo( .convertAllocationsToReservationInfo(
Collections.<ReservationAllocation>emptySet(), false); Collections.<ReservationAllocation>emptySet(), false);
Assert.assertEquals(infoList.size(), 0); assertThat(infoList).isEmpty();
} }
private ReservationAllocation createReservationAllocation(long startTime, private ReservationAllocation createReservationAllocation(long startTime,

View File

@ -18,7 +18,8 @@
package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning; 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.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -990,8 +991,9 @@ public void testGetDurationInterval() throws PlanningException {
StageAllocatorLowCostAligned.getDurationInterval(10*step, 30*step, StageAllocatorLowCostAligned.getDurationInterval(10*step, 30*step,
planLoads, planModifications, clusterCapacity, netRLERes, res, step, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
assertEquals(durationInterval.numCanFit(), 4); assertThat(durationInterval.numCanFit()).isEqualTo(4);
assertEquals(durationInterval.getTotalCost(), 0.55, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0.55, within(0.00001));
// 2. // 2.
// currLoad: should start at 20*step, end at 31*step with a null value // 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, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
System.out.println(durationInterval); System.out.println(durationInterval);
assertEquals(durationInterval.numCanFit(), 3); assertThat(durationInterval.numCanFit()).isEqualTo(3);
assertEquals(durationInterval.getTotalCost(), 0.56, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0.56, within(0.00001));
// 3. // 3.
// currLoad: should start at 20*step, end at 30*step with a null value // 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, StageAllocatorLowCostAligned.getDurationInterval(15*step, 30*step,
planLoads, planModifications, clusterCapacity, netRLERes, res, step, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
assertEquals(durationInterval.numCanFit(), 4); assertThat(durationInterval.numCanFit()).isEqualTo(4);
assertEquals(durationInterval.getTotalCost(), 0.55, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0.55, within(0.00001));
// 4. // 4.
// currLoad: should start at 20*step, end at 31*step with a null value // 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, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
System.out.println(durationInterval); System.out.println(durationInterval);
assertEquals(durationInterval.numCanFit(), 3); assertThat(durationInterval.numCanFit()).isEqualTo(3);
assertEquals(durationInterval.getTotalCost(), 0.56, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0.56, within(0.00001));
// 5. // 5.
// currLoad: should only contain one entry at startTime // currLoad: should only contain one entry at startTime
@ -1042,8 +1047,9 @@ public void testGetDurationInterval() throws PlanningException {
planLoads, planModifications, clusterCapacity, netRLERes, res, step, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
System.out.println(durationInterval); System.out.println(durationInterval);
assertEquals(durationInterval.numCanFit(), 8); assertThat(durationInterval.numCanFit()).isEqualTo(8);
assertEquals(durationInterval.getTotalCost(), 0.05, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0.05, within(0.00001));
// 6. // 6.
// currLoad: should start at 39*step, end at 41*step with a null value // 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, planLoads, planModifications, clusterCapacity, netRLERes, res, step,
requestedResources); requestedResources);
System.out.println(durationInterval); System.out.println(durationInterval);
assertEquals(durationInterval.numCanFit(), 0); assertThat(durationInterval.numCanFit()).isEqualTo(0);
assertEquals(durationInterval.getTotalCost(), 0, 0.00001); assertThat(durationInterval.getTotalCost()).
isCloseTo(0, within(0.00001));
} }

View File

@ -105,6 +105,7 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -1278,7 +1279,8 @@ public void testGetAppReport() throws IOException {
assertAppState(RMAppState.NEW, app); assertAppState(RMAppState.NEW, app);
ApplicationReport report = app.createAndGetApplicationReport(null, true); ApplicationReport report = app.createAndGetApplicationReport(null, true);
Assert.assertNotNull(report.getApplicationResourceUsageReport()); 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); report = app.createAndGetApplicationReport("clientuser", true);
Assert.assertNotNull(report.getApplicationResourceUsageReport()); Assert.assertNotNull(report.getApplicationResourceUsageReport());
Assert.assertTrue("bad proxy url for app", Assert.assertTrue("bad proxy url for app",

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -308,14 +309,15 @@ public void testLimitsComputation() throws Exception {
queue.getUserAMResourceLimit()); queue.getUserAMResourceLimit());
Resource amResourceLimit = Resource.newInstance(160 * GB, 1); Resource amResourceLimit = Resource.newInstance(160 * GB, 1);
assertEquals(queue.calculateAndGetAMResourceLimit(), amResourceLimit); assertThat(queue.calculateAndGetAMResourceLimit()).
assertEquals(queue.getUserAMResourceLimit(), isEqualTo(amResourceLimit);
assertThat(queue.getUserAMResourceLimit()).isEqualTo(
Resource.newInstance(80*GB, 1)); Resource.newInstance(80*GB, 1));
// Assert in metrics // Assert in metrics
assertEquals(queue.getMetrics().getAMResourceLimitMB(), assertThat(queue.getMetrics().getAMResourceLimitMB()).isEqualTo(
amResourceLimit.getMemorySize()); amResourceLimit.getMemorySize());
assertEquals(queue.getMetrics().getAMResourceLimitVCores(), assertThat(queue.getMetrics().getAMResourceLimitVCores()).isEqualTo(
amResourceLimit.getVirtualCores()); amResourceLimit.getVirtualCores());
assertEquals( assertEquals(
@ -327,11 +329,11 @@ public void testLimitsComputation() throws Exception {
clusterResource = Resources.createResource(120 * 16 * GB); clusterResource = Resources.createResource(120 * 16 * GB);
root.updateClusterResource(clusterResource, new ResourceLimits( root.updateClusterResource(clusterResource, new ResourceLimits(
clusterResource)); clusterResource));
assertEquals(queue.calculateAndGetAMResourceLimit(), assertThat(queue.calculateAndGetAMResourceLimit()).isEqualTo(
Resource.newInstance(192 * GB, 1)); Resource.newInstance(192 * GB, 1));
assertEquals(queue.getUserAMResourceLimit(), assertThat(queue.getUserAMResourceLimit()).isEqualTo(
Resource.newInstance(96*GB, 1)); Resource.newInstance(96*GB, 1));
assertEquals( assertEquals(
(int)(clusterResource.getMemorySize() * queue.getAbsoluteCapacity()), (int)(clusterResource.getMemorySize() * queue.getAbsoluteCapacity()),
@ -378,11 +380,11 @@ public void testLimitsComputation() throws Exception {
(long) csConf.getMaximumApplicationMasterResourcePerQueuePercent( (long) csConf.getMaximumApplicationMasterResourcePerQueuePercent(
queue.getQueuePath()) queue.getQueuePath())
); );
assertEquals(queue.calculateAndGetAMResourceLimit(), assertThat(queue.calculateAndGetAMResourceLimit()).isEqualTo(
Resource.newInstance(800 * GB, 1)); Resource.newInstance(800 * GB, 1));
assertEquals(queue.getUserAMResourceLimit(), assertThat(queue.getUserAMResourceLimit()).isEqualTo(
Resource.newInstance(400*GB, 1)); Resource.newInstance(400*GB, 1));
// Change the per-queue max applications. // Change the per-queue max applications.
csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications", csConf.setInt(PREFIX + queue.getQueuePath() + ".maximum-applications",

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; 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.mock;
import static org.mockito.Mockito.when; 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 // Now, the first assignment will be for app2 since app2 is of highest
// priority // priority
assertEquals(q.getApplications().size(), 2); assertThat(q.getApplications()).hasSize(2);
assertEquals(q.getApplications().iterator().next() assertThat(q.getApplications().iterator().next().getApplicationAttemptId())
.getApplicationAttemptId(), appAttemptId2); .isEqualTo(appAttemptId2);
rm.stop(); rm.stop();
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; 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;
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_MB;
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_VCORES; 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()); RMNode node1 = rm.getRMContext().getRMNodes().get(nm1.getNodeId());
cs.handle(new NodeUpdateSchedulerEvent(node1)); cs.handle(new NodeUpdateSchedulerEvent(node1));
ContainerId cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 1l); 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); cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 2l);
Assert.assertNull(cs.getRMContainer(cid)); Assert.assertNull(cs.getRMContainer(cid));

View File

@ -22,6 +22,7 @@
import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.resource.Resources;
import org.junit.Test; import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -52,8 +53,10 @@ public void testGetResourceWithPercentage() {
public void testGetResourceWithAbsolute() { public void testGetResourceWithAbsolute() {
ConfigurableResource configurableResource = ConfigurableResource configurableResource =
new ConfigurableResource(Resources.createResource(3072, 3)); new ConfigurableResource(Resources.createResource(3072, 3));
assertEquals(configurableResource.getResource().getMemorySize(), 3072); assertThat(configurableResource.getResource().getMemorySize()).
assertEquals(configurableResource.getResource().getVirtualCores(), 3); isEqualTo(3072);
assertThat(configurableResource.getResource().getVirtualCores()).
isEqualTo(3);
assertEquals( assertEquals(
configurableResource.getResource(clusterResource).getMemorySize(), configurableResource.getResource(clusterResource).getMemorySize(),
@ -62,7 +65,9 @@ public void testGetResourceWithAbsolute() {
configurableResource.getResource(clusterResource).getVirtualCores(), configurableResource.getResource(clusterResource).getVirtualCores(),
3); 3);
assertEquals(configurableResource.getResource(null).getMemorySize(), 3072); assertThat(configurableResource.getResource(null).getMemorySize()).
assertEquals(configurableResource.getResource(null).getVirtualCores(), 3); isEqualTo(3072);
assertThat(configurableResource.getResource(null).getVirtualCores()).
isEqualTo(3);
} }
} }

View File

@ -43,6 +43,7 @@
import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.resource.Resources;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -153,9 +154,10 @@ public void testSortedNodes() throws Exception {
scheduler.handle(nodeEvent2); scheduler.handle(nodeEvent2);
// available resource // available resource
Assert.assertEquals(scheduler.getClusterResource().getMemorySize(), assertThat(scheduler.getClusterResource().getMemorySize()).
16 * 1024); isEqualTo(16 * 1024);
Assert.assertEquals(scheduler.getClusterResource().getVirtualCores(), 16); assertThat(scheduler.getClusterResource().getVirtualCores()).
isEqualTo(16);
// send application request // send application request
ApplicationAttemptId appAttemptId = ApplicationAttemptId appAttemptId =

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair; 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.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -90,8 +91,9 @@ public void testUpdateDemand() {
String queueName = "root.queue1"; String queueName = "root.queue1";
FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null); FSLeafQueue schedulable = new FSLeafQueue(queueName, scheduler, null);
schedulable.setMaxShare(new ConfigurableResource(maxResource)); schedulable.setMaxShare(new ConfigurableResource(maxResource));
assertEquals(schedulable.getMetrics().getMaxApps(), Integer.MAX_VALUE); assertThat(schedulable.getMetrics().getMaxApps()).
assertEquals(schedulable.getMetrics().getSchedulingPolicy(), isEqualTo(Integer.MAX_VALUE);
assertThat(schedulable.getMetrics().getSchedulingPolicy()).isEqualTo(
SchedulingPolicy.DEFAULT_POLICY.getName()); SchedulingPolicy.DEFAULT_POLICY.getName());
FSAppAttempt app = mock(FSAppAttempt.class); FSAppAttempt app = mock(FSAppAttempt.class);
@ -124,8 +126,8 @@ public void test() throws Exception {
resourceManager.start(); resourceManager.start();
scheduler = (FairScheduler) resourceManager.getResourceScheduler(); scheduler = (FairScheduler) resourceManager.getResourceScheduler();
for(FSQueue queue: scheduler.getQueueManager().getQueues()) { for(FSQueue queue: scheduler.getQueueManager().getQueues()) {
assertEquals(queue.getMetrics().getMaxApps(), Integer.MAX_VALUE); assertThat(queue.getMetrics().getMaxApps()).isEqualTo(Integer.MAX_VALUE);
assertEquals(queue.getMetrics().getSchedulingPolicy(), assertThat(queue.getMetrics().getSchedulingPolicy()).isEqualTo(
SchedulingPolicy.DEFAULT_POLICY.getName()); SchedulingPolicy.DEFAULT_POLICY.getName());
} }

View File

@ -114,6 +114,7 @@
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -4623,17 +4624,17 @@ public void testResourceUsageByMoveApp() throws Exception {
FSQueue queue2 = queueMgr.getLeafQueue("parent2.queue2", true); FSQueue queue2 = queueMgr.getLeafQueue("parent2.queue2", true);
FSQueue queue1 = queueMgr.getLeafQueue("parent1.queue1", true); FSQueue queue1 = queueMgr.getLeafQueue("parent1.queue1", true);
Assert.assertEquals(parent2.getResourceUsage().getMemorySize(), 0); assertThat(parent2.getResourceUsage().getMemorySize()).isEqualTo(0);
Assert.assertEquals(queue2.getResourceUsage().getMemorySize(), 0); assertThat(queue2.getResourceUsage().getMemorySize()).isEqualTo(0);
Assert.assertEquals(parent1.getResourceUsage().getMemorySize(), 1 * GB); assertThat(parent1.getResourceUsage().getMemorySize()).isEqualTo(1 * GB);
Assert.assertEquals(queue1.getResourceUsage().getMemorySize(), 1 * GB); assertThat(queue1.getResourceUsage().getMemorySize()).isEqualTo(1 * GB);
scheduler.moveApplication(appAttId.getApplicationId(), "parent2.queue2"); scheduler.moveApplication(appAttId.getApplicationId(), "parent2.queue2");
Assert.assertEquals(parent2.getResourceUsage().getMemorySize(), 1 * GB); assertThat(parent2.getResourceUsage().getMemorySize()).isEqualTo(1 * GB);
Assert.assertEquals(queue2.getResourceUsage().getMemorySize(), 1 * GB); assertThat(queue2.getResourceUsage().getMemorySize()).isEqualTo(1 * GB);
Assert.assertEquals(parent1.getResourceUsage().getMemorySize(), 0); assertThat(parent1.getResourceUsage().getMemorySize()).isEqualTo(0);
Assert.assertEquals(queue1.getResourceUsage().getMemorySize(), 0); assertThat(queue1.getResourceUsage().getMemorySize()).isEqualTo(0);
} }
@Test (expected = YarnException.class) @Test (expected = YarnException.class)
@ -5070,20 +5071,20 @@ public void handle(Event event) {
Resource usedResource = Resource usedResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getAllocatedResource(); .getSchedulerNode(nm_0.getNodeId()).getAllocatedResource();
Assert.assertEquals(usedResource.getMemorySize(), 0); assertThat(usedResource.getMemorySize()).isEqualTo(0);
Assert.assertEquals(usedResource.getVirtualCores(), 0); assertThat(usedResource.getVirtualCores()).isEqualTo(0);
// Check total resource of scheduler node is also changed to 0 GB 0 core // Check total resource of scheduler node is also changed to 0 GB 0 core
Resource totalResource = Resource totalResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getTotalResource(); .getSchedulerNode(nm_0.getNodeId()).getTotalResource();
Assert.assertEquals(totalResource.getMemorySize(), 0 * GB); assertThat(totalResource.getMemorySize()).isEqualTo(0 * GB);
Assert.assertEquals(totalResource.getVirtualCores(), 0); assertThat(totalResource.getVirtualCores()).isEqualTo(0);
// Check the available resource is 0/0 // Check the available resource is 0/0
Resource availableResource = Resource availableResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource(); .getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource();
Assert.assertEquals(availableResource.getMemorySize(), 0); assertThat(availableResource.getMemorySize()).isEqualTo(0);
Assert.assertEquals(availableResource.getVirtualCores(), 0); assertThat(availableResource.getVirtualCores()).isEqualTo(0);
} }
private NodeManager registerNode(String hostName, int containerManagerPort, private NodeManager registerNode(String hostName, int containerManagerPort,
@ -5159,8 +5160,7 @@ public void testContainerAllocationWithContainerIdLeap() throws Exception {
// container will be allocated at node2 // container will be allocated at node2
scheduler.handle(new NodeUpdateSchedulerEvent(node2)); scheduler.handle(new NodeUpdateSchedulerEvent(node2));
assertEquals(scheduler.getSchedulerApp(app2). assertThat(scheduler.getSchedulerApp(app2).getLiveContainers()).hasSize(1);
getLiveContainers().size(), 1);
long maxId = 0; long maxId = 0;
for (RMContainer container : for (RMContainer container :

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo; 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.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -333,7 +334,7 @@ public void testUpdateResourceOnNode() throws Exception {
NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0);
scheduler.handle(nodeEvent1); scheduler.handle(nodeEvent1);
assertEquals(scheduler.getNumClusterNodes(), 1); assertThat(scheduler.getNumClusterNodes()).isEqualTo(1);
Resource newResource = Resources.createResource(1024, 4); Resource newResource = Resources.createResource(1024, 4);
@ -1286,20 +1287,20 @@ public void handle(Event event) {
Resource usedResource = Resource usedResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getAllocatedResource(); .getSchedulerNode(nm_0.getNodeId()).getAllocatedResource();
Assert.assertEquals(usedResource.getMemorySize(), 1 * GB); assertThat(usedResource.getMemorySize()).isEqualTo(1 * GB);
Assert.assertEquals(usedResource.getVirtualCores(), 1); assertThat(usedResource.getVirtualCores()).isEqualTo(1);
// Check total resource of scheduler node is also changed to 1 GB 1 core // Check total resource of scheduler node is also changed to 1 GB 1 core
Resource totalResource = Resource totalResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getTotalResource(); .getSchedulerNode(nm_0.getNodeId()).getTotalResource();
Assert.assertEquals(totalResource.getMemorySize(), 1 * GB); assertThat(totalResource.getMemorySize()).isEqualTo(1 * GB);
Assert.assertEquals(totalResource.getVirtualCores(), 1); assertThat(totalResource.getVirtualCores()).isEqualTo(1);
// Check the available resource is 0/0 // Check the available resource is 0/0
Resource availableResource = Resource availableResource =
resourceManager.getResourceScheduler() resourceManager.getResourceScheduler()
.getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource(); .getSchedulerNode(nm_0.getNodeId()).getUnallocatedResource();
Assert.assertEquals(availableResource.getMemorySize(), 0); assertThat(availableResource.getMemorySize()).isEqualTo(0);
Assert.assertEquals(availableResource.getVirtualCores(), 0); assertThat(availableResource.getVirtualCores()).isEqualTo(0);
} }
private void checkApplicationResourceUsage(int expected, private void checkApplicationResourceUsage(int expected,

View File

@ -25,6 +25,8 @@
import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.Priority;
import static org.assertj.core.api.Assertions.assertThat;
public class TestFifoOrderingPolicy { public class TestFifoOrderingPolicy {
@Test @Test
@ -33,14 +35,14 @@ public void testFifoOrderingPolicy() {
new FifoOrderingPolicy<MockSchedulableEntity>(); new FifoOrderingPolicy<MockSchedulableEntity>();
MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r1 = new MockSchedulableEntity();
MockSchedulableEntity r2 = 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.setSerial(1);
Assert.assertEquals(policy.getComparator().compare(r1, r2), 1); assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(1);
r2.setSerial(2); r2.setSerial(2);
Assert.assertEquals(policy.getComparator().compare(r1, r2), -1); assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(-1);
} }
@Test @Test

View File

@ -23,6 +23,8 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestFifoOrderingPolicyForPendingApps { public class TestFifoOrderingPolicyForPendingApps {
@Test @Test
@ -33,16 +35,16 @@ public void testFifoOrderingPolicyForPendingApps() {
MockSchedulableEntity r1 = new MockSchedulableEntity(); MockSchedulableEntity r1 = new MockSchedulableEntity();
MockSchedulableEntity r2 = 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.setSerial(1);
r1.setRecovering(true); r1.setRecovering(true);
Assert.assertEquals(policy.getComparator().compare(r1, r2), -1); assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(-1);
r1.setRecovering(false); r1.setRecovering(false);
r2.setSerial(2); r2.setSerial(2);
r2.setRecovering(true); r2.setRecovering(true);
Assert.assertEquals(policy.getComparator().compare(r1, r2), 1); assertThat(policy.getComparator().compare(r1, r2)).isEqualTo(1);
} }
/** /**

View File

@ -64,6 +64,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@ -316,13 +317,13 @@ public void testVolumeResourceAllocate() throws Exception {
Assert.assertEquals(1, allocated.size()); Assert.assertEquals(1, allocated.size());
Container alloc = allocated.get(0); Container alloc = allocated.get(0);
Assert.assertEquals(alloc.getResource().getMemorySize(), 1024); assertThat(alloc.getResource().getMemorySize()).isEqualTo(1024);
Assert.assertEquals(alloc.getResource().getVirtualCores(), 1); assertThat(alloc.getResource().getVirtualCores()).isEqualTo(1);
ResourceInformation allocatedVolume = ResourceInformation allocatedVolume =
alloc.getResource().getResourceInformation(VOLUME_RESOURCE_NAME); alloc.getResource().getResourceInformation(VOLUME_RESOURCE_NAME);
Assert.assertNotNull(allocatedVolume); Assert.assertNotNull(allocatedVolume);
Assert.assertEquals(allocatedVolume.getValue(), 1024); assertThat(allocatedVolume.getValue()).isEqualTo(1024);
Assert.assertEquals(allocatedVolume.getUnits(), "Mi"); assertThat(allocatedVolume.getUnits()).isEqualTo("Mi");
rm.stop(); rm.stop();
} }
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.webapp; 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.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -1088,8 +1089,8 @@ private void verifyNodeAllocationTag(JSONObject json,
for (int j=0; j<tagsInfo.length(); j++) { for (int j=0; j<tagsInfo.length(); j++) {
JSONObject tagInfo = tagsInfo.getJSONObject(j); JSONObject tagInfo = tagsInfo.getJSONObject(j);
String expectedTag = it.next(); String expectedTag = it.next();
assertEquals(tagInfo.getString("allocationTag"), expectedTag); assertThat(tagInfo.getString("allocationTag")).isEqualTo(expectedTag);
assertEquals(tagInfo.getLong("allocationsCount"), assertThat(tagInfo.getLong("allocationsCount")).isEqualTo(
expectedTags.get(expectedTag).longValue()); expectedTags.get(expectedTag).longValue());
} }
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.resourcemanager.webapp; 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.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -770,7 +771,7 @@ public void testQueueOnlyRequestListReservation() throws Exception {
return; return;
} }
assertEquals(json.getJSONArray("reservations").length(), 2); assertThat(json.getJSONArray("reservations").length()).isEqualTo(2);
testRDLHelper(json.getJSONArray("reservations").getJSONObject(0)); testRDLHelper(json.getJSONArray("reservations").getJSONObject(0));
testRDLHelper(json.getJSONArray("reservations").getJSONObject(1)); testRDLHelper(json.getJSONArray("reservations").getJSONObject(1));

View File

@ -124,6 +124,11 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>

View File

@ -60,6 +60,7 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
@ -414,7 +415,7 @@ store.new AppLogs(mainTestAppId, mainTestAppDirPath,
TimelineEntities entities = tdm.getEntities("type_1", null, null, null, TimelineEntities entities = tdm.getEntities("type_1", null, null, null,
null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), null, null, null, null, EnumSet.allOf(TimelineReader.Field.class),
UserGroupInformation.getLoginUser()); UserGroupInformation.getLoginUser());
assertEquals(entities.getEntities().size(), 1); assertThat(entities.getEntities()).hasSize(1);
for (TimelineEntity entity : entities.getEntities()) { for (TimelineEntity entity : entities.getEntities()) {
assertEquals((Long) 123L, entity.getStartTime()); assertEquals((Long) 123L, entity.getStartTime());
} }

View File

@ -324,6 +324,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.hbase</groupId> <groupId>org.apache.hbase</groupId>
<artifactId>hbase-testing-util</artifactId> <artifactId>hbase-testing-util</artifactId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.timelineservice.storage.flow; 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.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -119,7 +120,8 @@ public void testWriteNonNumericData() throws Exception {
Cell actualValue = r.getColumnLatestCell( Cell actualValue = r.getColumnLatestCell(
FlowRunColumnFamily.INFO.getBytes(), columnNameBytes); FlowRunColumnFamily.INFO.getBytes(), columnNameBytes);
assertNotNull(CellUtil.cloneValue(actualValue)); assertNotNull(CellUtil.cloneValue(actualValue));
assertEquals(Bytes.toString(CellUtil.cloneValue(actualValue)), value); assertThat(Bytes.toString(CellUtil.cloneValue(actualValue))).
isEqualTo(value);
} }
@Test @Test

View File

@ -131,6 +131,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -42,6 +42,7 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -109,7 +110,7 @@ public void testAggregation() throws Exception {
TimelineEntities testEntities = generateTestEntities(groups, n); TimelineEntities testEntities = generateTestEntities(groups, n);
TimelineEntity resultEntity = TimelineCollector.aggregateEntities( TimelineEntity resultEntity = TimelineCollector.aggregateEntities(
testEntities, "test_result", "TEST_AGGR", true); 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++) { for (int i = 0; i < groups; i++) {
Set<TimelineMetric> metrics = resultEntity.getMetrics(); Set<TimelineMetric> metrics = resultEntity.getMetrics();
@ -130,7 +131,7 @@ public void testAggregation() throws Exception {
TimelineEntities testEntities1 = generateTestEntities(1, n); TimelineEntities testEntities1 = generateTestEntities(1, n);
TimelineEntity resultEntity1 = TimelineCollector.aggregateEntities( TimelineEntity resultEntity1 = TimelineCollector.aggregateEntities(
testEntities1, "test_result", "TEST_AGGR", false); testEntities1, "test_result", "TEST_AGGR", false);
assertEquals(resultEntity1.getMetrics().size(), 3); assertThat(resultEntity1.getMetrics()).hasSize(3);
Set<TimelineMetric> metrics = resultEntity1.getMetrics(); Set<TimelineMetric> metrics = resultEntity1.getMetrics();
for (TimelineMetric m : metrics) { for (TimelineMetric m : metrics) {

View File

@ -74,6 +74,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- 'mvn dependency:analyze' fails to detect use of this dependency --> <!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.webproxy; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -334,7 +335,7 @@ public void testWebAppProxyPassThroughHeaders() throws Exception {
"Access-Control-Request-Headers", "Authorization"); "Access-Control-Request-Headers", "Authorization");
proxyConn.addRequestProperty(UNKNOWN_HEADER, "unknown"); proxyConn.addRequestProperty(UNKNOWN_HEADER, "unknown");
// Verify if four headers mentioned above have been added // Verify if four headers mentioned above have been added
assertEquals(proxyConn.getRequestProperties().size(), 4); assertThat(proxyConn.getRequestProperties()).hasSize(4);
proxyConn.connect(); proxyConn.connect();
assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode());
// Verify if number of headers received by end server is 9. // Verify if number of headers received by end server is 9.

View File

@ -44,6 +44,7 @@
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -163,7 +164,7 @@ public void testFindRedirectUrl() throws Exception {
spy.proxyUriBases.put(rm2, rm2Url); spy.proxyUriBases.put(rm2, rm2Url);
spy.rmUrls = new String[] { rm1, rm2 }; spy.rmUrls = new String[] { rm1, rm2 };
assertEquals(spy.findRedirectUrl(), rm1Url); assertThat(spy.findRedirectUrl()).isEqualTo(rm1Url);
} }
private String startHttpServer() throws Exception { private String startHttpServer() throws Exception {

View File

@ -25,7 +25,7 @@
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap; 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.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -137,7 +137,7 @@ public void testFindRedirectUrl() throws Exception {
assertTrue(spy.isValidUrl(rm1Url)); assertTrue(spy.isValidUrl(rm1Url));
assertFalse(spy.isValidUrl(rm2Url)); assertFalse(spy.isValidUrl(rm2Url));
assertEquals(spy.findRedirectUrl(), rm1Url); assertThat(spy.findRedirectUrl()).isEqualTo(rm1Url);
} }
private String startSecureHttpServer() throws Exception { private String startSecureHttpServer() throws Exception {