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 Part2. #7484

Open
wants to merge 4 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 @@ -30,14 +30,14 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
import org.apache.hadoop.yarn.util.Records;
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 java.io.IOException;
import java.util.Collections;

import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -55,7 +55,7 @@ public class TestAppNameMappingPlacementRule {

private YarnConfiguration conf = new YarnConfiguration();

@Before
@BeforeEach
public void setup() {
conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
Expand Down Expand Up @@ -108,7 +108,7 @@ private void verifyQueueMapping(QueueMapping queueMapping,
asc.setApplicationName(appName);
ApplicationPlacementContext ctx = engine.getPlacementForApp(asc,
user);
Assert.assertEquals(expectedQueue,
assertEquals(expectedQueue,
ctx != null ? ctx.getQueue() : inputQueue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

package org.apache.hadoop.yarn.server.resourcemanager.placement;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT_REPLACEMENT;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.ROOT_QUEUE;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.assureRoot;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.cleanName;
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.isValidQueueName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests of the utility methods from {@link FairQueuePlacementUtils}.
Expand All @@ -50,27 +50,27 @@ public void testCleanName() {
final String unTrimmed = " .invalid. "; // not really a valid queue

String cleaned = cleanName(clean);
assertEquals("Name was changed and it should not", clean, cleaned);
assertEquals(clean, cleaned, "Name was changed and it should not");
cleaned = cleanName(dotted);
assertFalse("Cleaned name contains dots and it should not",
cleaned.contains(DOT));
assertFalse(cleaned.contains(DOT),
"Cleaned name contains dots and it should not");
cleaned = cleanName(multiDot);
assertFalse("Cleaned name contains dots and it should not",
cleaned.contains(DOT));
assertNotEquals("Multi dot failed: wrong replacements found",
cleaned.indexOf(DOT_REPLACEMENT),
cleaned.lastIndexOf(DOT_REPLACEMENT));
assertFalse(cleaned.contains(DOT),
"Cleaned name contains dots and it should not");
assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT),
cleaned.lastIndexOf(DOT_REPLACEMENT),
"Multi dot failed: wrong replacements found");
cleaned = cleanName(seqDot);
assertFalse("Cleaned name contains dots and it should not",
cleaned.contains(DOT));
assertNotEquals("Sequential dot failed: wrong replacements found",
cleaned.indexOf(DOT_REPLACEMENT),
cleaned.lastIndexOf(DOT_REPLACEMENT));
assertFalse(cleaned.contains(DOT),
"Cleaned name contains dots and it should not");
assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT),
cleaned.lastIndexOf(DOT_REPLACEMENT),
"Sequential dot failed: wrong replacements found");
cleaned = cleanName(unTrimmed);
assertTrue("Trimming start failed: space not removed or dot not replaced",
cleaned.startsWith(DOT_REPLACEMENT));
assertTrue("Trimming end failed: space not removed or dot not replaced",
cleaned.endsWith(DOT_REPLACEMENT));
assertTrue(cleaned.startsWith(DOT_REPLACEMENT),
"Trimming start failed: space not removed or dot not replaced");
assertTrue(cleaned.endsWith(DOT_REPLACEMENT),
"Trimming end failed: space not removed or dot not replaced");
}

@Test
Expand All @@ -82,23 +82,22 @@ public void testAssureRoot() {
final String alreadyRoot = "root.base";

String rooted = assureRoot(queueName);
assertTrue("Queue should have root prefix (base)",
rooted.startsWith(ROOT_QUEUE + DOT));
assertTrue(rooted.startsWith(ROOT_QUEUE + DOT),
"Queue should have root prefix (base)");
rooted = assureRoot(rootOnly);
assertEquals("'root' queue should not have root prefix (root)",
rootOnly, rooted);
assertEquals(rootOnly, rooted,
"'root' queue should not have root prefix (root)");
rooted = assureRoot(rootNoDot);
assertTrue("Queue should have root prefix (rootbase)",
rooted.startsWith(ROOT_QUEUE + DOT));
assertEquals("'root' queue base was replaced and not prefixed", 5,
rooted.lastIndexOf(ROOT_QUEUE));
assertTrue(rooted.startsWith(ROOT_QUEUE + DOT),
"Queue should have root prefix (rootbase)");
assertEquals(5, rooted.lastIndexOf(ROOT_QUEUE),
"'root' queue base was replaced and not prefixed");
rooted = assureRoot(alreadyRoot);
assertEquals("Root prefixed queue changed and it should not (root.base)",
rooted, alreadyRoot);
assertNull("Null queue did not return null queue",
assureRoot(null));
assertEquals("Empty queue did not return empty name", "",
assureRoot(""));
assertEquals(rooted, alreadyRoot,
"Root prefixed queue changed and it should not (root.base)");
assertNull(assureRoot(null), "Null queue did not return null queue");
assertEquals("", assureRoot(""),
"Empty queue did not return empty name");
}

@Test
Expand All @@ -113,25 +112,24 @@ public void testIsValidQueueName() {
final String endSpace = "invalid ";
final String unicodeSpace = "\u00A0invalid";

assertFalse("'null' queue was not marked as invalid",
isValidQueueName(null));
assertTrue("empty queue was not tagged valid", isValidQueueName(""));
assertTrue("Simple queue name was not tagged valid (valid)",
isValidQueueName(valid));
assertTrue("Root only queue was not tagged valid (root)",
isValidQueueName(rootOnly));
assertTrue("Root prefixed queue was not tagged valid (root.valid)",
isValidQueueName(validRooted));
assertFalse("Queue starting with dot was not tagged invalid (.invalid)",
isValidQueueName(startDot));
assertFalse("Queue ending with dot was not tagged invalid (invalid.)",
isValidQueueName(endDot));
assertFalse("Queue starting with space was not tagged invalid ( invalid)",
isValidQueueName(startSpace));
assertFalse("Queue ending with space was not tagged invalid (invalid )",
isValidQueueName(endSpace));
assertFalse(isValidQueueName(null), "'null' queue was not marked as invalid");
assertTrue(isValidQueueName(""), "empty queue was not tagged valid");
assertTrue(isValidQueueName(valid),
"Simple queue name was not tagged valid (valid)");
assertTrue(isValidQueueName(rootOnly),
"Root only queue was not tagged valid (root)");
assertTrue(isValidQueueName(validRooted),
"Root prefixed queue was not tagged valid (root.valid)");
assertFalse(isValidQueueName(startDot),
"Queue starting with dot was not tagged invalid (.invalid)");
assertFalse(isValidQueueName(endDot),
"Queue ending with dot was not tagged invalid (invalid.)");
assertFalse(isValidQueueName(startSpace),
"Queue starting with space was not tagged invalid ( invalid)");
assertFalse(isValidQueueName(endSpace),
"Queue ending with space was not tagged invalid (invalid )");
// just one for sanity check extensive tests are in the scheduler utils
assertFalse("Queue with unicode space was not tagged as invalid (unicode)",
isValidQueueName(unicodeSpace));
assertFalse(isValidQueueName(unicodeSpace),
"Queue with unicode space was not tagged as invalid (unicode)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

package org.apache.hadoop.yarn.server.resourcemanager.placement;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test for the {@link PlacementFactory}.
Expand All @@ -34,10 +35,12 @@ public class TestPlacementFactory {
*
* @throws ClassNotFoundException
*/
@Test(expected = ClassNotFoundException.class)
@Test
public void testGetNonExistRuleText() throws ClassNotFoundException {
final String nonExist = "my.placement.Rule";
PlacementFactory.getPlacementRule(nonExist, null);
assertThrows(ClassNotFoundException.class, ()->{
final String nonExist = "my.placement.Rule";
PlacementFactory.getPlacementRule(nonExist, null);
});
}

/**
Expand All @@ -53,8 +56,8 @@ public void testGetExistRuleText() {
} catch (ClassNotFoundException cnfe) {
fail("Class should have been found");
}
assertNotNull("Rule object is null", rule);
assertEquals("Names not equal", rule.getName(), exists);
assertNotNull(rule, "Rule object is null");
assertEquals(rule.getName(), exists, "Names not equal");
}

/**
Expand All @@ -65,11 +68,11 @@ public void testGetExistRuleText() {
public void testGetRuleClass() {
PlacementRule rule = PlacementFactory.getPlacementRule(
DefaultPlacementRule.class, null);
assertNotNull("Rule object is null", rule);
assertNotNull(rule, "Rule object is null");
// Should take anything as the second object: ignores unknown types in the
// default implementation.
rule = PlacementFactory.getPlacementRule(
DefaultPlacementRule.class, "");
assertNotNull("Rule object is null", rule);
assertNotNull(rule, "Rule object is null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
import org.apache.hadoop.yarn.util.Records;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

public class TestPlacementManager {

Expand All @@ -56,7 +58,7 @@ private String getQueueMapping(String parentQueue, String leafQueue) {
return parentQueue + DOT + leafQueue;
}

@Before
@BeforeEach
public void setup() {
conf = new CapacitySchedulerConfiguration();
setupQueueConfiguration(conf);
Expand Down Expand Up @@ -96,8 +98,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception {
asc.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME);
asc.setApplicationName(APP_NAME);

Assert.assertNull("Placement should be null",
pm.placeApplication(asc, USER2));
assertNull(pm.placeApplication(asc, USER2), "Placement should be null");
QueueMapping queueMappingEntity = QueueMapping.QueueMappingBuilder.create()
.type(MappingType.APPLICATION)
.source(APP_NAME)
Expand All @@ -112,7 +113,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception {
queuePlacementRules.add(anRule);
pm.updateRules(queuePlacementRules);
ApplicationPlacementContext pc = pm.placeApplication(asc, USER2);
Assert.assertNotNull(pc);
assertNotNull(pc);
}

@Test
Expand All @@ -135,13 +136,13 @@ public void testPlacementRuleUpdationOrder() throws Exception {

// As we are setting placement rule, It shouldn't update default
// placement rule ie user-group. Number of placement rules should be 1.
Assert.assertEquals(1, pm.getPlacementRules().size());
assertEquals(1, pm.getPlacementRules().size());
// Verifying if placement rule set is same as the one we configured
Assert.assertEquals(ugRule.getName(),
assertEquals(ugRule.getName(),
pm.getPlacementRules().get(0).getName());
}

@After
@AfterEach
public void tearDown() {
if (null != mockRM) {
mockRM.stop();
Expand Down
Loading