Skip to content

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

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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import static org.junit.jupiter.api.Assertions.assertTrue;


public abstract class RMHATestBase extends ClientBaseWithFixes{
Expand All @@ -57,7 +58,7 @@ public abstract class RMHATestBase extends ClientBaseWithFixes{
Configuration confForRM1;
Configuration confForRM2;

@Before
@BeforeEach
public void setup() throws Exception {
configuration.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
configuration.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2");
Expand All @@ -83,7 +84,7 @@ public void setup() throws Exception {
confForRM2.set(YarnConfiguration.RM_HA_ID, "rm2");
}

@After
@AfterEach
public void teardown() {
if (rm1 != null) {
rm1.stop();
Expand Down Expand Up @@ -197,26 +198,26 @@ protected boolean isFinalState(RMAppState state) {
protected void explicitFailover() throws IOException {
rm1.adminService.transitionToStandby(requestInfo);
rm2.adminService.transitionToActive(requestInfo);
Assert.assertTrue(rm1.getRMContext().getHAServiceState()
assertTrue(rm1.getRMContext().getHAServiceState()
== HAServiceState.STANDBY);
Assert.assertTrue(rm2.getRMContext().getHAServiceState()
assertTrue(rm2.getRMContext().getHAServiceState()
== HAServiceState.ACTIVE);
}

protected void startRMs(MockRM rm1, Configuration confForRM1, MockRM rm2,
Configuration confForRM2) throws IOException {
rm1.init(confForRM1);
rm1.start();
Assert.assertTrue(rm1.getRMContext().getHAServiceState()
assertTrue(rm1.getRMContext().getHAServiceState()
== HAServiceState.STANDBY);

rm2.init(confForRM2);
rm2.start();
Assert.assertTrue(rm2.getRMContext().getHAServiceState()
assertTrue(rm2.getRMContext().getHAServiceState()
== HAServiceState.STANDBY);

rm1.adminService.transitionToActive(requestInfo);
Assert.assertTrue(rm1.getRMContext().getHAServiceState()
assertTrue(rm1.getRMContext().getHAServiceState()
== HAServiceState.ACTIVE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
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.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;

Expand All @@ -41,16 +43,17 @@
import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
import org.apache.hadoop.yarn.server.resourcemanager.security.RMDelegationTokenSecretManager;
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;


public class TestKillApplicationWithRMHA extends RMHATestBase{

public static final Logger LOG = LoggerFactory
.getLogger(TestKillApplicationWithRMHA.class);

@Test (timeout = 20000)
@Test
@Timeout(value = 20)
public void testKillAppWhenFailoverHappensAtNewState()
throws Exception {
// create a customized RMAppManager
Expand Down Expand Up @@ -92,12 +95,13 @@ public void testKillAppWhenFailoverHappensAtNewState()
failOverAndKillApp(app0.getApplicationId(), RMAppState.NEW);
fail("Should get an exception here");
} catch (ApplicationNotFoundException ex) {
Assert.assertTrue(ex.getMessage().contains(
assertTrue(ex.getMessage().contains(
"Trying to kill an absent application " + app0.getApplicationId()));
}
}

@Test (timeout = 20000)
@Test
@Timeout(value = 20)
public void testKillAppWhenFailoverHappensAtRunningState()
throws Exception {
startRMs();
Expand All @@ -120,7 +124,8 @@ public void testKillAppWhenFailoverHappensAtRunningState()
RMAppAttemptState.RUNNING, RMAppState.ACCEPTED);
}

@Test (timeout = 20000)
@Test
@Timeout(value = 20)
public void testKillAppWhenFailoverHappensAtFinalState()
throws Exception {
startRMs();
Expand Down Expand Up @@ -148,7 +153,8 @@ public void testKillAppWhenFailoverHappensAtFinalState()
RMAppAttemptState.KILLED, RMAppState.KILLED);
}

@Test (timeout = 20000)
@Test
@Timeout(value = 20)
public void testKillAppWhenFailOverHappensDuringApplicationKill()
throws Exception {
// create a customized ClientRMService
Expand Down Expand Up @@ -182,22 +188,22 @@ private void failOverAndKillApp(ApplicationId appId,
ApplicationAttemptId appAttemptId, RMAppState initialRMAppState,
RMAppAttemptState initialRMAppAttemptState,
RMAppState expectedAppStateBeforeKillApp) throws Exception {
Assert.assertEquals(initialRMAppState,
assertEquals(initialRMAppState,
rm1.getRMContext().getRMApps().get(appId).getState());
Assert.assertEquals(initialRMAppAttemptState, rm1.getRMContext()
assertEquals(initialRMAppAttemptState, rm1.getRMContext()
.getRMApps().get(appId).getAppAttempts().get(appAttemptId).getState());
explicitFailover();
Assert.assertEquals(expectedAppStateBeforeKillApp,
assertEquals(expectedAppStateBeforeKillApp,
rm2.getRMContext().getRMApps().get(appId).getState());
killApplication(rm2, appId, appAttemptId, initialRMAppState);
}

private void failOverAndKillApp(ApplicationId appId,
RMAppState initialRMAppState) throws Exception {
Assert.assertEquals(initialRMAppState,
assertEquals(initialRMAppState,
rm1.getRMContext().getRMApps().get(appId).getState());
explicitFailover();
Assert.assertTrue(rm2.getRMContext().getRMApps().get(appId) == null);
assertTrue(rm2.getRMContext().getRMApps().get(appId) == null);
killApplication(rm2, appId, null, initialRMAppState);
}

Expand Down Expand Up @@ -259,15 +265,14 @@ private void killApplication(MockRM rm, ApplicationId appId,
ApplicationAttemptId appAttemptId, RMAppState rmAppState)
throws Exception {
KillApplicationResponse response = rm.killApp(appId);
Assert
.assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState));
assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState));
RMApp loadedApp0 =
rm.getRMContext().getRMApps().get(appId);
rm.waitForState(appId, RMAppState.KILLED);
if (appAttemptId != null) {
rm.waitForState(appAttemptId, RMAppAttemptState.KILLED);
}
// no new attempt is created.
Assert.assertEquals(1, loadedApp0.getAppAttempts().size());
assertEquals(1, loadedApp0.getAppAttempts().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import org.apache.hadoop.service.ServiceStateException;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -65,7 +66,7 @@ private enum SyncTestType {
STANDBY_TIMING
}

@Before
@BeforeEach
public void setup() throws IOException {
conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
Expand Down Expand Up @@ -94,7 +95,8 @@ public void setup() throws IOException {
*
* The test times out if there is a deadlock.
*/
@Test (timeout = 10000)
@Test
@Timeout(value = 10)
public void testDeadlockShutdownBecomeActive() throws InterruptedException {
MockRM rm = new MockRMWithElector(conf, 1000);
rm.start();
Expand Down Expand Up @@ -320,9 +322,9 @@ public void testFailureToConnectToZookeeper() throws Exception {
new ActiveStandbyElectorBasedElectorService(rm);
try {
ees.init(myConf);
Assert.fail("expect failure to connect to Zookeeper");
fail("expect failure to connect to Zookeeper");
} catch (ServiceStateException sse) {
Assert.assertTrue(sse.getMessage().contains("ConnectionLoss"));
assertTrue(sse.getMessage().contains("ConnectionLoss"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAsyncScheduling;
import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestRMHAForAsyncScheduler extends RMHATestBase {
private TestCapacitySchedulerAsyncScheduling.NMHeartbeatThread
nmHeartbeatThread = null;

@Before
@BeforeEach
@Override
public void setup() throws Exception {
super.setup();
Expand Down Expand Up @@ -82,7 +86,8 @@ private void pauseNMHeartbeat() {
}
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception {
// start two RMs, and transit rm1 to active, rm2 to standby
startRMs();
Expand Down Expand Up @@ -114,9 +119,9 @@ public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception {
HAServiceProtocol.RequestSource.REQUEST_BY_USER);
rm2.adminService.transitionToStandby(requestInfo);
rm1.adminService.transitionToActive(requestInfo);
Assert.assertTrue(rm2.getRMContext().getHAServiceState()
assertTrue(rm2.getRMContext().getHAServiceState()
== HAServiceProtocol.HAServiceState.STANDBY);
Assert.assertTrue(rm1.getRMContext().getHAServiceState()
assertTrue(rm1.getRMContext().getHAServiceState()
== HAServiceProtocol.HAServiceState.ACTIVE);
// check async schedule threads
checkAsyncSchedulerThreads(Thread.currentThread());
Expand All @@ -136,7 +141,8 @@ public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception {
rm2.stop();
}

@Test(timeout = 30000)
@Test
@Timeout(value = 30)
public void testAsyncScheduleThreadExit() throws Exception {
// start two RMs, and transit rm1 to active, rm2 to standby
startRMs();
Expand Down Expand Up @@ -241,10 +247,10 @@ private void checkAsyncSchedulerThreads(Thread currentThread){
}
}
}
Assert.assertEquals(1, numResourceCommitterService);
Assert.assertEquals(1, numAsyncScheduleThread);
Assert.assertNotNull(asyncScheduleThread);
Assert.assertNotNull(resourceCommitterService);
assertEquals(1, numResourceCommitterService);
assertEquals(1, numAsyncScheduleThread);
assertNotNull(asyncScheduleThread);
assertNotNull(resourceCommitterService);
}

}
Loading