Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YARN-11262. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part3. #7485

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcem…
…anager Part3.
  • Loading branch information
slfan1989 committed Mar 8, 2025
commit 2b3c0d9385a1b365e542f5d6511fab6c75dee160
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppActivitiesInfo;
import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import org.apache.hadoop.yarn.util.resource.Resources;

Expand Down Expand Up @@ -89,7 +90,7 @@ public class TestActivitiesManager {

private ThreadPoolExecutor threadPoolExecutor;

@Before
@BeforeEach
public void setup() {
rmContext = Mockito.mock(RMContext.class);
Configuration conf = new Configuration();
Expand Down Expand Up @@ -163,12 +164,12 @@ public void testRecordingDifferentNodeActivitiesInMultiThreads()
}
// Check activities for all nodes should be recorded and every node should
// have only one allocation information.
Assert.assertEquals(NUM_NODES,
Assertions.assertEquals(NUM_NODES,
activitiesManager.historyNodeAllocations.size());
for (List<List<NodeAllocation>> nodeAllocationsForThisNode :
activitiesManager.historyNodeAllocations.values()) {
Assert.assertEquals(1, nodeAllocationsForThisNode.size());
Assert.assertEquals(1, nodeAllocationsForThisNode.get(0).size());
Assertions.assertEquals(1, nodeAllocationsForThisNode.size());
Assertions.assertEquals(1, nodeAllocationsForThisNode.get(0).size());
}
}

Expand Down Expand Up @@ -207,7 +208,7 @@ public void testRecordingSchedulerActivitiesForMultiNodesInMultiThreads()
future.get();
}
// Check activities for multi-nodes should be recorded only once
Assert.assertEquals(1, activitiesManager.historyNodeAllocations.size());
Assertions.assertEquals(1, activitiesManager.historyNodeAllocations.size());
}


Expand Down Expand Up @@ -254,13 +255,14 @@ public void testRecordingAppActivitiesInMultiThreads()
Queue<AppAllocation> appAllocations =
activitiesManager.completedAppAllocations
.get(randomApp.getApplicationId());
Assert.assertEquals(nTasks, appAllocations.size());
Assertions.assertEquals(nTasks, appAllocations.size());
for(AppAllocation aa : appAllocations) {
Assert.assertEquals(NUM_NODES, aa.getAllocationAttempts().size());
Assertions.assertEquals(NUM_NODES, aa.getAllocationAttempts().size());
}
}

@Test (timeout = 30000)
@Test
@Timeout(value = 30)
public void testAppActivitiesTTL() throws Exception {
long cleanupIntervalMs = 100;
long appActivitiesTTL = 1000;
Expand Down Expand Up @@ -295,19 +297,20 @@ public void testAppActivitiesTTL() throws Exception {
AppActivitiesInfo appActivitiesInfo = newActivitiesManager
.getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1,
false, 3);
Assert.assertEquals(numActivities,
Assertions.assertEquals(numActivities,
appActivitiesInfo.getAllocations().size());
// sleep until all app activities expired
Thread.sleep(cleanupIntervalMs + appActivitiesTTL);
// there should be no remaining app activities
appActivitiesInfo = newActivitiesManager
.getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1,
false, 3);
Assert.assertEquals(0,
Assertions.assertEquals(0,
appActivitiesInfo.getAllocations().size());
}

@Test (timeout = 30000)
@Test
@Timeout(value = 30)
public void testAppActivitiesPerformance() {
// start recording activities for first app
SchedulerApplicationAttempt app = apps.get(0);
Expand Down Expand Up @@ -343,12 +346,12 @@ public void testAppActivitiesPerformance() {
AppActivitiesInfo appActivitiesInfo = activitiesManager
.getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1,
false, 100);
Assert.assertEquals(numActivities,
Assertions.assertEquals(numActivities,
appActivitiesInfo.getAllocations().size());
Assert.assertEquals(1,
Assertions.assertEquals(1,
appActivitiesInfo.getAllocations().get(0).getChildren()
.size());
Assert.assertEquals(numNodes,
Assertions.assertEquals(numNodes,
appActivitiesInfo.getAllocations().get(0).getChildren()
.get(0).getChildren().size());
return null;
Expand All @@ -361,15 +364,15 @@ public void testAppActivitiesPerformance() {
AppActivitiesInfo appActivitiesInfo = activitiesManager
.getAppActivitiesInfo(app.getApplicationId(), null, null,
RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, false, 100);
Assert.assertEquals(numActivities,
Assertions.assertEquals(numActivities,
appActivitiesInfo.getAllocations().size());
Assert.assertEquals(1,
Assertions.assertEquals(1,
appActivitiesInfo.getAllocations().get(0).getChildren()
.size());
Assert.assertEquals(1,
Assertions.assertEquals(1,
appActivitiesInfo.getAllocations().get(0).getChildren()
.get(0).getChildren().size());
Assert.assertEquals(numNodes,
Assertions.assertEquals(numNodes,
appActivitiesInfo.getAllocations().get(0).getChildren()
.get(0).getChildren().get(0).getNodeIds().size());
return null;
Expand All @@ -382,14 +385,14 @@ public void testAppActivitiesPerformance() {
AppActivitiesInfo appActivitiesInfo = activitiesManager
.getAppActivitiesInfo(app.getApplicationId(), null, null,
RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, true, 100);
Assert.assertEquals(1, appActivitiesInfo.getAllocations().size());
Assert.assertEquals(1,
Assertions.assertEquals(1, appActivitiesInfo.getAllocations().size());
Assertions.assertEquals(1,
appActivitiesInfo.getAllocations().get(0).getChildren()
.size());
Assert.assertEquals(1,
Assertions.assertEquals(1,
appActivitiesInfo.getAllocations().get(0).getChildren()
.get(0).getChildren().size());
Assert.assertEquals(numNodes,
Assertions.assertEquals(numNodes,
appActivitiesInfo.getAllocations().get(0).getChildren()
.get(0).getChildren().get(0).getNodeIds().size());
return null;
Expand All @@ -398,7 +401,8 @@ public void testAppActivitiesPerformance() {
testingTimes);
}

@Test (timeout = 10000)
@Test
@Timeout(value = 10)
public void testAppActivitiesMaxQueueLengthUpdate()
throws TimeoutException, InterruptedException {
Configuration conf = new Configuration();
Expand Down Expand Up @@ -427,14 +431,14 @@ public void testAppActivitiesMaxQueueLengthUpdate()
.thenReturn(numAsyncSchedulerThreads);
ActivitiesManager newActivitiesManager =
new ActivitiesManager(mockRMContext);
Assert.assertEquals(1,
Assertions.assertEquals(1,
newActivitiesManager.getAppActivitiesMaxQueueLength());
newActivitiesManager.init(conf);
newActivitiesManager.start();
GenericTestUtils.waitFor(
() -> newActivitiesManager.getAppActivitiesMaxQueueLength()
== numNodes * numAsyncSchedulerThreads, 100, 3000);
Assert.assertEquals(15,
Assertions.assertEquals(15,
newActivitiesManager.getAppActivitiesMaxQueueLength());
/*
* Test for HB-driven scheduling with multi-node placement disabled
Expand All @@ -443,7 +447,7 @@ public void testAppActivitiesMaxQueueLengthUpdate()
GenericTestUtils.waitFor(
() -> newActivitiesManager.getAppActivitiesMaxQueueLength()
== numNodes * 1.2, 100, 3000);
Assert.assertEquals(6,
Assertions.assertEquals(6,
newActivitiesManager.getAppActivitiesMaxQueueLength());
/*
* Test for scheduling with multi-node placement enabled
Expand All @@ -452,7 +456,7 @@ public void testAppActivitiesMaxQueueLengthUpdate()
GenericTestUtils.waitFor(
() -> newActivitiesManager.getAppActivitiesMaxQueueLength()
== configuredAppActivitiesMaxQueueLength, 100, 3000);
Assert.assertEquals(1,
Assertions.assertEquals(1,
newActivitiesManager.getAppActivitiesMaxQueueLength());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode;
import org.apache.hadoop.yarn.util.Clock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -49,7 +49,7 @@ public class CapacitySchedulerPreemptionTestBase {

Clock clock;

@Before
@BeforeEach
void setUp() throws Exception {
conf = new CapacitySchedulerConfiguration();
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
Expand Down Expand Up @@ -106,7 +106,7 @@ public void waitNumberOfLiveContainersFromApp(FiCaSchedulerApp app,
waitNum++;
}

Assert.fail();
Assertions.fail();
}

public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app,
Expand All @@ -122,7 +122,7 @@ public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app,
waitNum++;
}

Assert.fail();
Assertions.fail();
}

public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node,
Expand All @@ -144,7 +144,7 @@ public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node,
waitNum++;
}

Assert.fail(
Assertions.fail(
"Check #live-container-on-node-from-app, actual=" + total + " expected="
+ expected);
}
Expand All @@ -160,6 +160,6 @@ public void checkNumberOfPreemptionCandidateFromApp(
}
}

Assert.assertEquals(expected, total);
Assertions.assertEquals(expected, total);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;

Expand All @@ -52,7 +52,7 @@ public class CapacitySchedulerQueueCalculationTestBase {
protected CapacitySchedulerConfiguration csConf;
protected NullRMNodeLabelsManager mgr;

@Before
@BeforeEach
public void setUp() throws Exception {
csConf = new CapacitySchedulerConfiguration();
csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.jupiter.api.Assertions;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public final class CapacitySchedulerQueueHelpers {

Expand Down Expand Up @@ -386,18 +386,18 @@ public static void checkQueueStructureCapacities(CapacityScheduler cs,
CSQueue rootQueue = cs.getRootQueue();
for (Map.Entry<String, ExpectedCapacities> entry : capacities.entrySet()) {
CSQueue queue = findQueue(rootQueue, entry.getKey());
Assert.assertNotNull(queue);
Assertions.assertNotNull(queue);
assertQueueCapacities(queue, entry.getValue());
}
}

public static void assertQueueCapacities(CSQueue q, ExpectedCapacities capacities) {
final float epsilon = 1e-4f;
assertEquals("capacity", capacities.getCapacity(), q.getCapacity(), epsilon);
assertEquals("absolute capacity", capacities.getAbsCapacity(),
q.getAbsoluteCapacity(), epsilon);
assertEquals("maximum capacity", 1.0f, q.getMaximumCapacity(), epsilon);
assertEquals("absolute maximum capacity", 1.0f, q.getAbsoluteMaximumCapacity(), epsilon);
assertEquals(capacities.getCapacity(), q.getCapacity(), epsilon, "capacity");
assertEquals(capacities.getAbsCapacity(),
q.getAbsoluteCapacity(), epsilon, "absolute capacity");
assertEquals(1.0f, q.getMaximumCapacity(), epsilon, "maximum capacity");
assertEquals(1.0f, q.getAbsoluteMaximumCapacity(), epsilon, "absolute maximum capacity");
}

public static CSQueue findQueue(CSQueue root, String queuePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import org.apache.hadoop.yarn.server.resourcemanager.security.AppPriorityACLsManager;
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;

import java.io.IOException;
import java.util.Set;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static void checkPendingResource(MockRM rm, String queueName, int memory,
String label) {
CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
CSQueue queue = cs.getQueue(queueName);
Assert.assertEquals(
Assertions.assertEquals(
memory,
queue.getQueueResourceUsage()
.getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label)
Expand All @@ -96,7 +96,7 @@ public static void checkPendingResourceGreaterThanZero(MockRM rm, String queueNa
String label) {
CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
CSQueue queue = cs.getQueue(queueName);
Assert.assertTrue(queue.getQueueResourceUsage()
Assertions.assertTrue(queue.getQueueResourceUsage()
.getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label)
.getMemorySize() > 0);
}
Expand Down Expand Up @@ -230,11 +230,11 @@ public static NodeManager registerNode(ResourceManager rm, String hostName,
}

public static void checkApplicationResourceUsage(int expected, Application application) {
Assert.assertEquals(expected, application.getUsedResources().getMemorySize());
Assertions.assertEquals(expected, application.getUsedResources().getMemorySize());
}

public static void checkNodeResourceUsage(int expected, NodeManager node) {
Assert.assertEquals(expected, node.getUsed().getMemorySize());
Assertions.assertEquals(expected, node.getUsed().getMemorySize());
node.checkResourceUsage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueResourceQuotas;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -141,7 +141,7 @@ public void withResourceSupplier(
BiFunction<QueueResourceQuotas, String, Resource> assertion, String messageInfo) {
CSQueue queue = cs.getQueue(queuePath.getFullPath());
if (queue == null) {
Assert.fail("Queue " + queuePath + " is not found");
Assertions.fail("Queue " + queuePath + " is not found");
}

assertionType = messageInfo;
Expand All @@ -152,7 +152,7 @@ public void withCapacitySupplier(
BiFunction<QueueCapacities, String, Float> assertion, String messageInfo) {
CSQueue queue = cs.getQueue(queuePath.getFullPath());
if (queue == null) {
Assert.fail("Queue " + queuePath + " is not found");
Assertions.fail("Queue " + queuePath + " is not found");
}
assertionType = messageInfo;
valueSupplier = () -> assertion.apply(queue.getQueueCapacities(), label);
Expand Down Expand Up @@ -187,14 +187,14 @@ public void finishAssertion() {
String errorMessage = String.format(RESOURCE_ASSERTION_ERROR_MESSAGE,
assertion.assertionType, assertionEntry.getKey(),
assertion.expectedResource.toString(), assertion.label);
Assert.assertEquals(errorMessage, assertion.expectedResource,
assertion.resourceSupplier.get());
Assertions.assertEquals(assertion.expectedResource,
assertion.resourceSupplier.get(), errorMessage);
} else {
String errorMessage = String.format(ASSERTION_ERROR_MESSAGE,
assertion.assertionType, assertionEntry.getKey(), assertion.expectedValue,
assertion.label);
Assert.assertEquals(errorMessage, assertion.expectedValue,
assertion.valueSupplier.get(), EPSILON);
Assertions.assertEquals(assertion.expectedValue,
assertion.valueSupplier.get(), EPSILON, errorMessage);
}
}
}
Expand Down
Loading