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 Part1. #7474

Open
wants to merge 6 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@
import org.apache.hadoop.yarn.server.resourcemanager
.ParameterizedSchedulerTestBase;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collection;

import static org.junit.jupiter.api.Assertions.assertEquals;
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 All @@ -75,18 +76,20 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {

protected static final String YARN_RM = "[email protected]";

public TestYarnClientImpl(SchedulerType type) throws IOException {
super(type);
public void initTestYarnClientImpl(SchedulerType type) throws IOException {
initParameterizedSchedulerTestBase(type);
setup();
}

@Before
public void setup() {
QueueMetrics.clearQueueMetrics();
DefaultMetricsSystem.setMiniClusterMode(true);
}

@Test
public void testStartWithTimelineV15() {
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testStartWithTimelineV15(SchedulerType type) throws IOException {
initTestYarnClientImpl(type);
Configuration conf = getConf();
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 1.5f);
Expand All @@ -96,8 +99,10 @@ public void testStartWithTimelineV15() {
client.stop();
}

@Test
public void testAsyncAPIPollTimeout() {
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testAsyncAPIPollTimeout(SchedulerType type) throws IOException {
initTestYarnClientImpl(type);
testAsyncAPIPollTimeoutHelper(null, false);
testAsyncAPIPollTimeoutHelper(0L, true);
testAsyncAPIPollTimeoutHelper(1L, true);
Expand All @@ -116,16 +121,17 @@ private void testAsyncAPIPollTimeoutHelper(Long valueForTimeout,

client.init(conf);

Assert.assertEquals(
expectedTimeoutEnforcement, client.enforceAsyncAPITimeout());
assertEquals(expectedTimeoutEnforcement, client.enforceAsyncAPITimeout());
} finally {
IOUtils.closeStream(client);
}
}

@Test
public void testBestEffortTimelineDelegationToken()
throws Exception {
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testBestEffortTimelineDelegationToken(SchedulerType type)
throws Exception {
initTestYarnClientImpl(type);
Configuration conf = getConf();
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
Expand All @@ -152,7 +158,7 @@ TimelineClient createTimelineClient() throws IOException, YarnException {
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, false);
client.serviceInit(conf);
client.getTimelineDelegationToken();
Assert.fail("Get delegation token should have thrown an exception");
fail("Get delegation token should have thrown an exception");
} catch (IOException e) {
// Success
}
Expand All @@ -161,9 +167,11 @@ TimelineClient createTimelineClient() throws IOException, YarnException {
// Validates if YarnClientImpl automatically adds HDFS Delegation
// token for Log Aggregation Path in a cluster setup with fs.DefaultFS
// set to LocalFileSystem and Log Aggregation Path set to HDFS.
@Test
public void testAutomaitcLogAggregationDelegationToken()
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testAutomaitcLogAggregationDelegationToken(SchedulerType type)
throws Exception {
initTestYarnClientImpl(type);
Configuration conf = getConf();
SecurityUtil.setAuthenticationMethod(
UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
Expand Down Expand Up @@ -262,10 +270,10 @@ public boolean isSecurityEnabled() {
}
Collection<Token<? extends TokenIdentifier>> dTokens =
credentials.getAllTokens();
Assert.assertEquals("Failed to place token for Log Aggregation Path",
1, dTokens.size());
Assert.assertEquals("Wrong Token for Log Aggregation",
hdfsDT.getKind(), dTokens.iterator().next().getKind());
assertEquals(1, dTokens.size(),
"Failed to place token for Log Aggregation Path");
assertEquals(hdfsDT.getKind(), dTokens.iterator().next().getKind(),
"Wrong Token for Log Aggregation");

} finally {
if (hdfsCluster != null) {
Expand All @@ -274,9 +282,11 @@ public boolean isSecurityEnabled() {
}
}

@Test
public void testAutomaticTimelineDelegationTokenLoading()
throws Exception {
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testAutomaticTimelineDelegationTokenLoading(SchedulerType type)
throws Exception {
initTestYarnClientImpl(type);
Configuration conf = getConf();
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
Expand Down Expand Up @@ -356,16 +366,19 @@ public boolean isSecurityEnabled() {
}
Collection<Token<? extends TokenIdentifier>> dTokens =
credentials.getAllTokens();
Assert.assertEquals(1, dTokens.size());
Assert.assertEquals(dToken, dTokens.iterator().next());
assertEquals(1, dTokens.size());
assertEquals(dToken, dTokens.iterator().next());
}
} finally {
client.stop();
}
}

@Test
public void testParseTimelineDelegationTokenRenewer() {
@ParameterizedTest(name = "{0}")
@MethodSource("getParameters")
public void testParseTimelineDelegationTokenRenewer(SchedulerType type)
throws IOException {
initTestYarnClientImpl(type);
// Client side
YarnClientImpl client = (YarnClientImpl) YarnClient.createYarnClient();
Configuration conf = getConf();
Expand All @@ -376,7 +389,7 @@ public void testParseTimelineDelegationTokenRenewer() {
try {
client.init(conf);
client.start();
Assert.assertEquals("rm/[email protected]", client.timelineDTRenewer);
assertEquals("rm/[email protected]", client.timelineDTRenewer);
} finally {
client.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,18 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;



import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
.allocationfile.AllocationFileQueue;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
.allocationfile.AllocationFileWriter;
import org.junit.After;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterEach;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

@RunWith(Parameterized.class)
public abstract class ParameterizedSchedulerTestBase {
protected final static String TEST_DIR =
new File(System.getProperty("test.build.data", "/tmp")).getAbsolutePath();
Expand All @@ -53,7 +48,6 @@ public enum SchedulerType {
CAPACITY, FAIR
}

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> getParameters() {
return Arrays.stream(SchedulerType.values()).map(
type -> new Object[]{type}).collect(Collectors.toList());
Expand All @@ -68,7 +62,7 @@ public YarnConfiguration getConf() {
}

// Due to parameterization, this gets called before each test method
public ParameterizedSchedulerTestBase(SchedulerType type)
public void initParameterizedSchedulerTestBase(SchedulerType type)
throws IOException {
conf = new YarnConfiguration();

Expand Down Expand Up @@ -113,7 +107,7 @@ protected void configureFairScheduler(YarnConfiguration configuration) {
configuration.setLong(FairSchedulerConfiguration.UPDATE_INTERVAL_MS, 10);
}

@After
@AfterEach
public void tearDown() {
if (schedulerType == SchedulerType.FAIR) {
(new File(FS_ALLOC_FILE)).delete();
Expand All @@ -128,7 +122,7 @@ public SchedulerType getSchedulerType() {
* Return a scheduler configured by {@code YarnConfiguration.RM_SCHEDULER}
*
* <p>The scheduler is configured by
* {@link #ParameterizedSchedulerTestBase(SchedulerType)}.
* {@link ParameterizedSchedulerTestBase}.
* Client test code can obtain the scheduler with this getter method.
* Schedulers supported by this class are {@link FairScheduler} or
* {@link CapacityScheduler}. </p>
Expand Down
Loading