Skip to content

Commit 9f2e340

Browse files
committed
YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part4.
1 parent 65f6567 commit 9f2e340

File tree

68 files changed

+3606
-3525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3606
-3525
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
7070
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
7171
import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator;
72-
import org.junit.jupiter.api.Assertions;
7372
import org.mockito.invocation.InvocationOnMock;
7473
import org.mockito.stubbing.Answer;
7574

@@ -121,8 +120,7 @@ public static void validateReservationQueue(
121120
assertEquals(8192, plan.getTotalCapacity().getMemorySize());
122121
assertTrue(
123122
plan.getReservationAgent() instanceof AlignedPlannerWithGreedy);
124-
Assertions
125-
.assertTrue(plan.getSharingPolicy() instanceof CapacityOverTimePolicy);
123+
assertTrue(plan.getSharingPolicy() instanceof CapacityOverTimePolicy);
126124
}
127125

128126
public static void setupFSAllocationFile(String allocationFile) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestAppSchedulingInfo.java

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.scheduler;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2125
import static org.mockito.Mockito.doReturn;
2226
import static org.mockito.Mockito.mock;
2327
import static org.mockito.Mockito.when;
@@ -36,8 +40,7 @@
3640
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FSLeafQueue;
3741
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.LocalityAppPlacementAllocator;
3842
import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
39-
import org.junit.Assert;
40-
import org.junit.Test;
43+
import org.junit.jupiter.api.Test;
4144

4245
public class TestAppSchedulingInfo {
4346

@@ -57,32 +60,32 @@ public void testBacklistChanged() {
5760

5861
appSchedulingInfo.updatePlacesBlacklistedByApp(new ArrayList<String>(),
5962
new ArrayList<String>());
60-
Assert.assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
63+
assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
6164

6265
ArrayList<String> blacklistAdditions = new ArrayList<String>();
6366
blacklistAdditions.add("node1");
6467
blacklistAdditions.add("node2");
6568
appSchedulingInfo.updatePlacesBlacklistedByApp(blacklistAdditions,
6669
new ArrayList<String>());
67-
Assert.assertTrue(appSchedulingInfo.getAndResetBlacklistChanged());
70+
assertTrue(appSchedulingInfo.getAndResetBlacklistChanged());
6871

6972
blacklistAdditions.clear();
7073
blacklistAdditions.add("node1");
7174
appSchedulingInfo.updatePlacesBlacklistedByApp(blacklistAdditions,
7275
new ArrayList<String>());
73-
Assert.assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
76+
assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
7477

7578
ArrayList<String> blacklistRemovals = new ArrayList<String>();
7679
blacklistRemovals.add("node1");
7780
appSchedulingInfo.updatePlacesBlacklistedByApp(new ArrayList<String>(),
7881
blacklistRemovals);
7982
appSchedulingInfo.updatePlacesBlacklistedByApp(new ArrayList<String>(),
8083
blacklistRemovals);
81-
Assert.assertTrue(appSchedulingInfo.getAndResetBlacklistChanged());
84+
assertTrue(appSchedulingInfo.getAndResetBlacklistChanged());
8285

8386
appSchedulingInfo.updatePlacesBlacklistedByApp(new ArrayList<String>(),
8487
blacklistRemovals);
85-
Assert.assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
88+
assertFalse(appSchedulingInfo.getAndResetBlacklistChanged());
8689
}
8790

8891
@Test
@@ -96,23 +99,23 @@ public void testSchedulerRequestKeyOrdering() {
9699
ts.add(TestUtils.toSchedulerKey(Priority.newInstance(2), 6));
97100
Iterator<SchedulerRequestKey> iter = ts.iterator();
98101
SchedulerRequestKey sk = iter.next();
99-
Assert.assertEquals(0, sk.getPriority().getPriority());
100-
Assert.assertEquals(3, sk.getAllocationRequestId());
102+
assertEquals(0, sk.getPriority().getPriority());
103+
assertEquals(3, sk.getAllocationRequestId());
101104
sk = iter.next();
102-
Assert.assertEquals(0, sk.getPriority().getPriority());
103-
Assert.assertEquals(4, sk.getAllocationRequestId());
105+
assertEquals(0, sk.getPriority().getPriority());
106+
assertEquals(4, sk.getAllocationRequestId());
104107
sk = iter.next();
105-
Assert.assertEquals(1, sk.getPriority().getPriority());
106-
Assert.assertEquals(1, sk.getAllocationRequestId());
108+
assertEquals(1, sk.getPriority().getPriority());
109+
assertEquals(1, sk.getAllocationRequestId());
107110
sk = iter.next();
108-
Assert.assertEquals(1, sk.getPriority().getPriority());
109-
Assert.assertEquals(2, sk.getAllocationRequestId());
111+
assertEquals(1, sk.getPriority().getPriority());
112+
assertEquals(2, sk.getAllocationRequestId());
110113
sk = iter.next();
111-
Assert.assertEquals(2, sk.getPriority().getPriority());
112-
Assert.assertEquals(5, sk.getAllocationRequestId());
114+
assertEquals(2, sk.getPriority().getPriority());
115+
assertEquals(5, sk.getAllocationRequestId());
113116
sk = iter.next();
114-
Assert.assertEquals(2, sk.getPriority().getPriority());
115-
Assert.assertEquals(6, sk.getAllocationRequestId());
117+
assertEquals(2, sk.getPriority().getPriority());
118+
assertEquals(6, sk.getAllocationRequestId());
116119
}
117120

118121
@Test
@@ -128,7 +131,7 @@ public void testSchedulerKeyAccounting() {
128131
AppSchedulingInfo info = new AppSchedulingInfo(
129132
appAttemptId, "test", queue, mock(ActiveUsersManager.class), 0,
130133
new ResourceUsage(), new HashMap<>(), rmContext, false);
131-
Assert.assertEquals(0, info.getSchedulerKeys().size());
134+
assertEquals(0, info.getSchedulerKeys().size());
132135

133136
Priority pri1 = Priority.newInstance(1);
134137
ResourceRequest req1 = ResourceRequest.newInstance(pri1,
@@ -142,16 +145,16 @@ public void testSchedulerKeyAccounting() {
142145
info.updateResourceRequests(reqs, false);
143146
ArrayList<SchedulerRequestKey> keys =
144147
new ArrayList<>(info.getSchedulerKeys());
145-
Assert.assertEquals(2, keys.size());
146-
Assert.assertEquals(SchedulerRequestKey.create(req1), keys.get(0));
147-
Assert.assertEquals(SchedulerRequestKey.create(req2), keys.get(1));
148+
assertEquals(2, keys.size());
149+
assertEquals(SchedulerRequestKey.create(req1), keys.get(0));
150+
assertEquals(SchedulerRequestKey.create(req2), keys.get(1));
148151

149152
// iterate to verify no ConcurrentModificationException
150153
for (SchedulerRequestKey schedulerKey : info.getSchedulerKeys()) {
151154
info.allocate(NodeType.OFF_SWITCH, null, schedulerKey, null);
152155
}
153-
Assert.assertEquals(1, info.getSchedulerKeys().size());
154-
Assert.assertEquals(SchedulerRequestKey.create(req2),
156+
assertEquals(1, info.getSchedulerKeys().size());
157+
assertEquals(SchedulerRequestKey.create(req2),
155158
info.getSchedulerKeys().iterator().next());
156159

157160
req2 = ResourceRequest.newInstance(pri2,
@@ -161,22 +164,22 @@ public void testSchedulerKeyAccounting() {
161164
info.updateResourceRequests(reqs, false);
162165
info.allocate(NodeType.OFF_SWITCH, null, SchedulerRequestKey.create(req2),
163166
null);
164-
Assert.assertEquals(0, info.getSchedulerKeys().size());
167+
assertEquals(0, info.getSchedulerKeys().size());
165168

166169
req1 = ResourceRequest.newInstance(pri1,
167170
ResourceRequest.ANY, Resource.newInstance(1024, 1), 5);
168171
reqs.clear();
169172
reqs.add(req1);
170173
info.updateResourceRequests(reqs, false);
171-
Assert.assertEquals(1, info.getSchedulerKeys().size());
172-
Assert.assertEquals(SchedulerRequestKey.create(req1),
174+
assertEquals(1, info.getSchedulerKeys().size());
175+
assertEquals(SchedulerRequestKey.create(req1),
173176
info.getSchedulerKeys().iterator().next());
174177
req1 = ResourceRequest.newInstance(pri1,
175178
ResourceRequest.ANY, Resource.newInstance(1024, 1), 0);
176179
reqs.clear();
177180
reqs.add(req1);
178181
info.updateResourceRequests(reqs, false);
179-
Assert.assertEquals(0, info.getSchedulerKeys().size());
182+
assertEquals(0, info.getSchedulerKeys().size());
180183
}
181184

182185
@Test
@@ -193,17 +196,17 @@ public void testApplicationPlacementType() {
193196
AppSchedulingInfo info = new AppSchedulingInfo(appAttemptId, "test", queue,
194197
mock(ActiveUsersManager.class), 0, new ResourceUsage(), new HashMap<>(),
195198
rmContext, false);
196-
Assert.assertEquals(info.getApplicationSchedulingEnvs(), new HashMap<>());
199+
assertEquals(info.getApplicationSchedulingEnvs(), new HashMap<>());
197200
// This should return null as nothing is set in the conf.
198-
Assert.assertNull(info.getDefaultResourceRequestAppPlacementType());
201+
assertNull(info.getDefaultResourceRequestAppPlacementType());
199202
conf = new Configuration();
200203
conf.set(YarnConfiguration.APPLICATION_PLACEMENT_TYPE_CLASS,
201204
DEFAULT_APPLICATION_PLACEMENT_TYPE_CLASS);
202205
when(rmContext.getYarnConfiguration()).thenReturn(conf);
203206
info = new AppSchedulingInfo(appAttemptId, "test", queue,
204207
mock(ActiveUsersManager.class), 0, new ResourceUsage(), new HashMap<>(),
205208
rmContext, false);
206-
Assert.assertEquals(info.getDefaultResourceRequestAppPlacementType(),
209+
assertEquals(info.getDefaultResourceRequestAppPlacementType(),
207210
DEFAULT_APPLICATION_PLACEMENT_TYPE_CLASS);
208211
}
209212

@@ -223,7 +226,7 @@ public void testApplicationPlacementTypeNotConfigured() {
223226
mock(ActiveUsersManager.class), 0, new ResourceUsage(),
224227
applicationSchedulingEnvs, rmContext, false);
225228
// This should be set from applicationSchedulingEnvs
226-
Assert.assertEquals(info.getDefaultResourceRequestAppPlacementType(),
229+
assertEquals(info.getDefaultResourceRequestAppPlacementType(),
227230
LocalityAppPlacementAllocator.class.getName());
228231
}
229232
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestClusterNodeTracker.java

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FSSchedulerNode;
3131
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
3232

33-
import org.junit.After;
34-
import org.junit.Before;
35-
import org.junit.Test;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
3636

37-
import static org.junit.Assert.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertEquals;
3838

3939
/**
4040
* Test class to verify ClusterNodeTracker. Using FSSchedulerNode without
@@ -44,13 +44,13 @@ public class TestClusterNodeTracker {
4444
private ClusterNodeTracker<FSSchedulerNode> nodeTracker;
4545
private ClusterMetrics metrics;
4646

47-
@Before
47+
@BeforeEach
4848
public void setup() {
4949
metrics = ClusterMetrics.getMetrics();
5050
nodeTracker = new ClusterNodeTracker<>();
5151
}
5252

53-
@After
53+
@AfterEach
5454
public void teardown() {
5555
ClusterMetrics.destroy();
5656
}
@@ -67,33 +67,33 @@ private void addEight4x4Nodes() {
6767
@Test
6868
public void testGetNodeCount() {
6969
addEight4x4Nodes();
70-
assertEquals("Incorrect number of nodes in the cluster",
71-
8, nodeTracker.nodeCount());
70+
assertEquals(8, nodeTracker.nodeCount(),
71+
"Incorrect number of nodes in the cluster");
7272

73-
assertEquals("Incorrect number of nodes in each rack",
74-
4, nodeTracker.nodeCount("rack0"));
73+
assertEquals(4, nodeTracker.nodeCount("rack0"),
74+
"Incorrect number of nodes in each rack");
7575
}
7676

7777
@Test
7878
public void testIncrCapability() {
7979
addEight4x4Nodes();
80-
assertEquals("Cluster Capability Memory incorrect",
81-
metrics.getCapabilityMB(), (4096 * 8));
82-
assertEquals("Cluster Capability Vcores incorrect",
83-
metrics.getCapabilityVirtualCores(), 4 * 8);
80+
assertEquals(metrics.getCapabilityMB(), (4096 * 8),
81+
"Cluster Capability Memory incorrect");
82+
assertEquals(metrics.getCapabilityVirtualCores(), 4 * 8,
83+
"Cluster Capability Vcores incorrect");
8484
}
8585

8686
@Test
8787
public void testGetNodesForResourceName() throws Exception {
8888
addEight4x4Nodes();
89-
assertEquals("Incorrect number of nodes matching ANY",
90-
8, nodeTracker.getNodesByResourceName(ResourceRequest.ANY).size());
89+
assertEquals(8, nodeTracker.getNodesByResourceName(ResourceRequest.ANY).size(),
90+
"Incorrect number of nodes matching ANY");
9191

92-
assertEquals("Incorrect number of nodes matching rack",
93-
4, nodeTracker.getNodesByResourceName("rack0").size());
92+
assertEquals(4, nodeTracker.getNodesByResourceName("rack0").size(),
93+
"Incorrect number of nodes matching rack");
9494

95-
assertEquals("Incorrect number of nodes matching node",
96-
1, nodeTracker.getNodesByResourceName("host0").size());
95+
assertEquals(1, nodeTracker.getNodesByResourceName("host0").size(),
96+
"Incorrect number of nodes matching node");
9797
}
9898

9999
@Test
@@ -113,8 +113,9 @@ public void testMaxAllowedAllocation() {
113113

114114
Resource result = nodeTracker.getMaxAllowedAllocation();
115115

116-
assertEquals("With no nodes added, the ClusterNodeTracker did not return "
117-
+ "the configured max allocation", maximum, result);
116+
assertEquals(maximum, result,
117+
"With no nodes added, the ClusterNodeTracker did not return "
118+
+ "the configured max allocation");
118119

119120
List<RMNode> smallNodes =
120121
MockNodes.newNodes(1, 1, Resource.newInstance(1024, 2,
@@ -133,72 +134,70 @@ public void testMaxAllowedAllocation() {
133134

134135
result = nodeTracker.getMaxAllowedAllocation();
135136

136-
assertEquals("With a single node added, the ClusterNodeTracker did not "
137-
+ "return that node's resources as the maximum allocation",
138-
mediumNodes.get(0).getTotalCapability(), result);
137+
assertEquals(mediumNodes.get(0).getTotalCapability(), result,
138+
"With a single node added, the ClusterNodeTracker did not "
139+
+ "return that node's resources as the maximum allocation");
139140

140141
nodeTracker.addNode(smallNode);
141142

142143
result = nodeTracker.getMaxAllowedAllocation();
143144

144-
assertEquals("With two nodes added, the ClusterNodeTracker did not "
145+
assertEquals(Resource.newInstance(4096, 2, Collections.singletonMap("test1", 4L)),
146+
result, "With two nodes added, the ClusterNodeTracker did not "
145147
+ "return a the maximum allocation that was the max of their aggregate "
146-
+ "resources",
147-
Resource.newInstance(4096, 2, Collections.singletonMap("test1", 4L)),
148-
result);
148+
+ "resources");
149149

150150
nodeTracker.removeNode(smallNode.getNodeID());
151151

152152
result = nodeTracker.getMaxAllowedAllocation();
153153

154-
assertEquals("After removing a node, the ClusterNodeTracker did not "
155-
+ "recalculate the adjusted maximum allocation correctly",
156-
mediumNodes.get(0).getTotalCapability(), result);
154+
assertEquals(mediumNodes.get(0).getTotalCapability(), result,
155+
"After removing a node, the ClusterNodeTracker did not "
156+
+ "recalculate the adjusted maximum allocation correctly");
157157

158158
nodeTracker.addNode(largeNode);
159159

160160
result = nodeTracker.getMaxAllowedAllocation();
161161

162-
assertEquals("With two nodes added, the ClusterNodeTracker did not "
162+
assertEquals(Resource.newInstance(10240, 4, Collections.singletonMap("test1", 2L)),
163+
result, "With two nodes added, the ClusterNodeTracker did not "
163164
+ "return a the maximum allocation that was the max of their aggregate "
164-
+ "resources",
165-
Resource.newInstance(10240, 4, Collections.singletonMap("test1", 2L)),
166-
result);
165+
+ "resources");
167166

168167
nodeTracker.removeNode(largeNode.getNodeID());
169168

170169
result = nodeTracker.getMaxAllowedAllocation();
171170

172-
assertEquals("After removing a node, the ClusterNodeTracker did not "
173-
+ "recalculate the adjusted maximum allocation correctly",
174-
mediumNodes.get(0).getTotalCapability(), result);
171+
assertEquals(mediumNodes.get(0).getTotalCapability(), result,
172+
"After removing a node, the ClusterNodeTracker did not "
173+
+ "recalculate the adjusted maximum allocation correctly");
175174

176175
nodeTracker.removeNode(mediumNode.getNodeID());
177176

178177
result = nodeTracker.getMaxAllowedAllocation();
179178

180-
assertEquals("After removing all nodes, the ClusterNodeTracker did not "
181-
+ "return the configured maximum allocation", maximum, result);
179+
assertEquals(maximum, result,
180+
"After removing all nodes, the ClusterNodeTracker did not "
181+
+ "return the configured maximum allocation");
182182

183183
nodeTracker.addNode(smallNode);
184184
nodeTracker.addNode(mediumNode);
185185
nodeTracker.addNode(largeNode);
186186

187187
result = nodeTracker.getMaxAllowedAllocation();
188188

189-
assertEquals("With three nodes added, the ClusterNodeTracker did not "
189+
assertEquals(Resource.newInstance(10240, 4, Collections.singletonMap("test1", 4L)),
190+
result, "With three nodes added, the ClusterNodeTracker did not "
190191
+ "return a the maximum allocation that was the max of their aggregate "
191-
+ "resources",
192-
Resource.newInstance(10240, 4, Collections.singletonMap("test1", 4L)),
193-
result);
192+
+ "resources");
194193

195194
nodeTracker.removeNode(smallNode.getNodeID());
196195
nodeTracker.removeNode(mediumNode.getNodeID());
197196
nodeTracker.removeNode(largeNode.getNodeID());
198197

199198
result = nodeTracker.getMaxAllowedAllocation();
200199

201-
assertEquals("After removing all nodes, the ClusterNodeTracker did not "
202-
+ "return the configured maximum allocation", maximum, result);
200+
assertEquals(maximum, result, "After removing all nodes, the ClusterNodeTracker did not "
201+
+ "return the configured maximum allocation");
203202
}
204203
}

0 commit comments

Comments
 (0)