Skip to content

Commit

Permalink
YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcem…
Browse files Browse the repository at this point in the history
…anager Part6.
  • Loading branch information
slfan1989 committed Mar 9, 2025
1 parent 126c3d4 commit e96f2f3
Show file tree
Hide file tree
Showing 55 changed files with 2,698 additions and 2,517 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

public abstract class ACLsTestBase {

Expand Down Expand Up @@ -65,7 +65,7 @@ public abstract class ACLsTestBase {
YarnRPC rpc;
InetSocketAddress rmAddress;

@Before
@BeforeEach
public void setup() throws InterruptedException, IOException {
conf = createConfiguration();
rpc = YarnRPC.create(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
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 java.util.ArrayList;
import java.util.Collections;
Expand All @@ -66,7 +67,7 @@
import static java.lang.Thread.sleep;
import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB;
import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Base class for Application Master test classes.
Expand Down Expand Up @@ -122,14 +123,15 @@ private void requestResources(MockAM am, long memory, int vCores,
.build()), null);
}

@Before
@BeforeEach
public void setup() {
conf = new YarnConfiguration();
conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class,
ResourceScheduler.class);
}

@Test(timeout = 3000000)
@Test
@Timeout(value = 3000)
public void testRMIdentifierOnContainerAllocation() throws Exception {
MockRM rm = new MockRM(conf);
rm.start();
Expand Down Expand Up @@ -163,12 +165,13 @@ public void testRMIdentifierOnContainerAllocation() throws Exception {
ContainerTokenIdentifier tokenId =
BuilderUtils.newContainerTokenIdentifier(allocatedContainer
.getContainerToken());
Assert.assertEquals(MockRM.getClusterTimeStamp(),
Assertions.assertEquals(MockRM.getClusterTimeStamp(),
tokenId.getRMIdentifier());
rm.stop();
}

@Test(timeout = 3000000)
@Test
@Timeout(value = 3000)
public void testAllocateResponseIdOverflow() throws Exception {
MockRM rm = new MockRM(conf);

Expand All @@ -188,21 +191,22 @@ public void testAllocateResponseIdOverflow() throws Exception {
am1.registerAppAttempt();

// Set the last responseId to be Integer.MAX_VALUE
Assert.assertTrue(am1.setApplicationLastResponseId(Integer.MAX_VALUE));
Assertions.assertTrue(am1.setApplicationLastResponseId(Integer.MAX_VALUE));

// Both allocate should succeed
am1.schedule(); // send allocate with responseId = Integer.MAX_VALUE
Assert.assertEquals(0, am1.getResponseId());
Assertions.assertEquals(0, am1.getResponseId());

am1.schedule(); // send allocate with responseId = 0
Assert.assertEquals(1, am1.getResponseId());
Assertions.assertEquals(1, am1.getResponseId());

} finally {
rm.stop();
}
}

@Test(timeout=600000)
@Test
@Timeout(value = 600)
public void testInvalidContainerReleaseRequest() throws Exception {
MockRM rm = new MockRM(conf);

Expand Down Expand Up @@ -232,7 +236,7 @@ public void testInvalidContainerReleaseRequest() throws Exception {
alloc1Response = am1.schedule();
}

Assert.assertTrue(alloc1Response.getAllocatedContainers().size() > 0);
Assertions.assertTrue(alloc1Response.getAllocatedContainers().size() > 0);

RMApp app2 = MockRMAppSubmitter.submitWithMemory(1024, rm);

Expand All @@ -252,14 +256,15 @@ public void testInvalidContainerReleaseRequest() throws Exception {
sb.append(cId.toString());
sb.append(" not belonging to this application attempt : ");
sb.append(attempt2.getAppAttemptId().toString());
Assert.assertTrue(e.getMessage().contains(sb.toString()));
Assertions.assertTrue(e.getMessage().contains(sb.toString()));
}
} finally {
rm.stop();
}
}

@Test(timeout=1200000)
@Test
@Timeout(value = 1200)
public void testProgressFilter() throws Exception{
MockRM rm = new MockRM(conf);
rm.start();
Expand Down Expand Up @@ -324,7 +329,8 @@ public void testProgressFilter() throws Exception{
}
}

@Test(timeout=1200000)
@Test
@Timeout(value = 1200)
public void testFinishApplicationMasterBeforeRegistering() throws Exception {
MockRM rm = new MockRM(conf);

Expand All @@ -342,9 +348,9 @@ public void testFinishApplicationMasterBeforeRegistering() throws Exception {
am1.unregisterAppAttempt(req, false);
fail("ApplicationMasterNotRegisteredException should be thrown");
} catch (ApplicationMasterNotRegisteredException e) {
Assert.assertNotNull(e);
Assert.assertNotNull(e.getMessage());
Assert.assertTrue(e.getMessage().contains(
Assertions.assertNotNull(e);
Assertions.assertNotNull(e.getMessage());
Assertions.assertTrue(e.getMessage().contains(
"Application Master is trying to unregister before registering for:"
));
} catch (Exception e) {
Expand All @@ -361,7 +367,8 @@ public void testFinishApplicationMasterBeforeRegistering() throws Exception {
}
}

@Test(timeout = 1200000)
@Test
@Timeout(value = 1200)
public void testRepeatedFinishApplicationMaster() throws Exception {

CountingDispatcher dispatcher = new CountingDispatcher();
Expand All @@ -387,8 +394,8 @@ protected Dispatcher createDispatcher() {
am1.unregisterAppAttempt(req, false);
}
rm.drainEvents();
Assert.assertEquals("Expecting only one event", 1,
dispatcher.getEventCount());
Assertions.assertEquals(1
, dispatcher.getEventCount(), "Expecting only one event");
} finally {
rm.stop();
}
Expand All @@ -412,7 +419,8 @@ public int getEventCount() {
}
}

@Test(timeout = 3000000)
@Test
@Timeout(value = 3000)
public void testResourceTypes() throws Exception {
HashMap<YarnConfiguration,
EnumSet<YarnServiceProtos.SchedulerResourceTypes>> driver =
Expand Down Expand Up @@ -464,12 +472,13 @@ public void testResourceTypes() throws Exception {
EnumSet<YarnServiceProtos.SchedulerResourceTypes> types =
resp.getSchedulerResourceTypes();
LOG.info("types = " + types.toString());
Assert.assertEquals(expectedValue, types);
Assertions.assertEquals(expectedValue, types);
rm.stop();
}
}

@Test(timeout=1200000)
@Test
@Timeout(value = 1200)
public void testAllocateAfterUnregister() throws Exception {
MockRM rm = new MockRM(conf);
rm.start();
Expand All @@ -495,10 +504,11 @@ public void testAllocateAfterUnregister() throws Exception {
nm1.nodeHeartbeat(true);
rm.drainEvents();
alloc1Response = am1.schedule();
Assert.assertEquals(0, alloc1Response.getAllocatedContainers().size());
Assertions.assertEquals(0, alloc1Response.getAllocatedContainers().size());
}

@Test(timeout = 300000)
@Test
@Timeout(value = 300)
public void testUpdateTrackingUrl() throws Exception {
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
ResourceScheduler.class);
Expand All @@ -514,7 +524,7 @@ public void testUpdateTrackingUrl() throws Exception {
RMAppAttempt attempt1 = app1.getCurrentAppAttempt();
MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
am1.registerAppAttempt();
Assert.assertEquals("N/A", rm.getRMContext().getRMApps().get(
Assertions.assertEquals("N/A", rm.getRMContext().getRMApps().get(
app1.getApplicationId()).getOriginalTrackingUrl());

AllocateRequestPBImpl allocateRequest = new AllocateRequestPBImpl();
Expand All @@ -526,17 +536,18 @@ public void testUpdateTrackingUrl() throws Exception {
// wait until RMAppAttemptEventType.STATUS_UPDATE is handled
rm.drainEvents();

Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get(
Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get(
app1.getApplicationId()).getOriginalTrackingUrl());

// Send it again
am1.allocate(allocateRequest);
Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get(
Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get(
app1.getApplicationId()).getOriginalTrackingUrl());
rm.stop();
}

@Test(timeout = 300000)
@Test
@Timeout(value = 300)
public void testValidateRequestCapacityAgainstMinMaxAllocation()
throws Exception {
Map<String, ResourceInformation> riMap =
Expand Down Expand Up @@ -582,7 +593,7 @@ public void testValidateRequestCapacityAgainstMinMaxAllocation()
} catch (InvalidResourceRequestException e) {
exception = true;
}
Assert.assertTrue(exception);
Assertions.assertTrue(exception);

exception = false;
try {
Expand All @@ -595,12 +606,13 @@ public void testValidateRequestCapacityAgainstMinMaxAllocation()
} catch (InvalidResourceRequestException e) {
exception = true;
}
Assert.assertTrue(exception);
Assertions.assertTrue(exception);

rm.close();
}

@Test(timeout = 300000)
@Test
@Timeout(value = 300)
public void testRequestCapacityMinMaxAllocationForResourceTypes()
throws Exception {
Map<String, ResourceInformation> riMap = initializeMandatoryResources();
Expand Down Expand Up @@ -637,25 +649,25 @@ public void testRequestCapacityMinMaxAllocationForResourceTypes()
RMApp app1 = MockRMAppSubmitter.submit(rm, data);
MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);

Assert.assertEquals(Resource.newInstance(GB, 1),
Assertions.assertEquals(Resource.newInstance(GB, 1),
getResourceUsageForQueue(rm, getDefaultQueueName()));

// Request memory > allowed
try {
requestResources(am1, 9 * GB, 1, ImmutableMap.of());
Assert.fail("Should throw InvalidResourceRequestException");
Assertions.fail("Should throw InvalidResourceRequestException");
} catch (InvalidResourceRequestException ignored) {}

try {
// Request vcores > allowed
requestResources(am1, GB, 18, ImmutableMap.of());
Assert.fail("Should throw InvalidResourceRequestException");
Assertions.fail("Should throw InvalidResourceRequestException");
} catch (InvalidResourceRequestException ignored) {}

try {
// Request custom resource 'res_1' > allowed
requestResources(am1, GB, 2, ImmutableMap.of(CUSTOM_RES, 100));
Assert.fail("Should throw InvalidResourceRequestException");
Assertions.fail("Should throw InvalidResourceRequestException");
} catch (InvalidResourceRequestException ignored) {}

rm.close();
Expand Down
Loading

0 comments on commit e96f2f3

Please sign in to comment.