YARN-11404. Add junit5 dependency to hadoop-mapreduce-client-app to fix few unit test failure. Contributed by Susheel Gupta

This commit is contained in:
Szilard Nemeth 2023-01-25 15:06:20 +01:00
parent 3b7b79b37a
commit 8eda456d37
52 changed files with 1773 additions and 1624 deletions

View File

@ -99,6 +99,39 @@
<artifactId>hadoop-yarn-server-tests</artifactId> <artifactId>hadoop-yarn-server-tests</artifactId>
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-core</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>

View File

@ -53,10 +53,11 @@
import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.event.Event; import org.apache.hadoop.yarn.event.Event;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -75,7 +76,7 @@ private static void delete(File dir) throws IOException {
fs.delete(p, true); fs.delete(p, true);
} }
@BeforeClass @BeforeAll
public static void setupTestDirs() throws IOException { public static void setupTestDirs() throws IOException {
testWorkDir = new File("target", testWorkDir = new File("target",
TestLocalContainerLauncher.class.getCanonicalName()); TestLocalContainerLauncher.class.getCanonicalName());
@ -89,7 +90,7 @@ public static void setupTestDirs() throws IOException {
} }
} }
@AfterClass @AfterAll
public static void cleanupTestDirs() throws IOException { public static void cleanupTestDirs() throws IOException {
if (testWorkDir != null) { if (testWorkDir != null) {
delete(testWorkDir); delete(testWorkDir);
@ -97,7 +98,8 @@ public static void cleanupTestDirs() throws IOException {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Test(timeout=10000) @Test
@Timeout(10000)
public void testKillJob() throws Exception { public void testKillJob() throws Exception {
JobConf conf = new JobConf(); JobConf conf = new JobConf();
AppContext context = mock(AppContext.class); AppContext context = mock(AppContext.class);
@ -198,8 +200,8 @@ public void testRenameMapOutputForReduce() throws Exception {
final Path mapOut = mrOutputFiles.getOutputFileForWrite(1); final Path mapOut = mrOutputFiles.getOutputFileForWrite(1);
conf.set(MRConfig.LOCAL_DIR, localDirs[1].toString()); conf.set(MRConfig.LOCAL_DIR, localDirs[1].toString());
final Path mapOutIdx = mrOutputFiles.getOutputIndexFileForWrite(1); final Path mapOutIdx = mrOutputFiles.getOutputIndexFileForWrite(1);
Assert.assertNotEquals("Paths must be different!", Assertions.assertNotEquals(mapOut.getParent(), mapOutIdx.getParent(),
mapOut.getParent(), mapOutIdx.getParent()); "Paths must be different!");
// make both dirs part of LOCAL_DIR // make both dirs part of LOCAL_DIR
conf.setStrings(MRConfig.LOCAL_DIR, localDirs); conf.setStrings(MRConfig.LOCAL_DIR, localDirs);

View File

@ -37,8 +37,8 @@
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -87,7 +87,7 @@ public void testFinshingAttemptTimeout()
} }
taskAttemptFinishingMonitor.stop(); taskAttemptFinishingMonitor.stop();
assertTrue("Finishing attempt didn't time out.", eventHandler.timedOut); assertTrue(eventHandler.timedOut, "Finishing attempt didn't time out.");
} }

View File

@ -19,19 +19,18 @@
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -67,14 +66,15 @@
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.util.ControlledClock; import org.apache.hadoop.yarn.util.ControlledClock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
@ -87,7 +87,7 @@
/** /**
* Tests the behavior of TaskAttemptListenerImpl. * Tests the behavior of TaskAttemptListenerImpl.
*/ */
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class TestTaskAttemptListenerImpl { public class TestTaskAttemptListenerImpl {
private static final String ATTEMPT1_ID = private static final String ATTEMPT1_ID =
"attempt_123456789012_0001_m_000001_0"; "attempt_123456789012_0001_m_000001_0";
@ -172,7 +172,7 @@ protected void stopRpcServer() {
} }
} }
@After @AfterEach
public void after() throws IOException { public void after() throws IOException {
if (listener != null) { if (listener != null) {
listener.close(); listener.close();
@ -180,7 +180,8 @@ public void after() throws IOException {
} }
} }
@Test (timeout=5000) @Test
@Timeout(5000)
public void testGetTask() throws IOException { public void testGetTask() throws IOException {
configureMocks(); configureMocks();
startListener(false); startListener(false);
@ -238,7 +239,8 @@ public void testGetTask() throws IOException {
} }
@Test (timeout=5000) @Test
@Timeout(5000)
public void testJVMId() { public void testJVMId() {
JVMId jvmid = new JVMId("test", 1, true, 2); JVMId jvmid = new JVMId("test", 1, true, 2);
@ -247,7 +249,8 @@ public void testJVMId() {
assertEquals(0, jvmid.compareTo(jvmid1)); assertEquals(0, jvmid.compareTo(jvmid1));
} }
@Test (timeout=10000) @Test
@Timeout(10000)
public void testGetMapCompletionEvents() throws IOException { public void testGetMapCompletionEvents() throws IOException {
TaskAttemptCompletionEvent[] empty = {}; TaskAttemptCompletionEvent[] empty = {};
TaskAttemptCompletionEvent[] taskEvents = { TaskAttemptCompletionEvent[] taskEvents = {
@ -257,12 +260,6 @@ public void testGetMapCompletionEvents() throws IOException {
createTce(3, false, TaskAttemptCompletionEventStatus.FAILED) }; createTce(3, false, TaskAttemptCompletionEventStatus.FAILED) };
TaskAttemptCompletionEvent[] mapEvents = { taskEvents[0], taskEvents[2] }; TaskAttemptCompletionEvent[] mapEvents = { taskEvents[0], taskEvents[2] };
Job mockJob = mock(Job.class); Job mockJob = mock(Job.class);
when(mockJob.getTaskAttemptCompletionEvents(0, 100))
.thenReturn(taskEvents);
when(mockJob.getTaskAttemptCompletionEvents(0, 2))
.thenReturn(Arrays.copyOfRange(taskEvents, 0, 2));
when(mockJob.getTaskAttemptCompletionEvents(2, 100))
.thenReturn(Arrays.copyOfRange(taskEvents, 2, 4));
when(mockJob.getMapAttemptCompletionEvents(0, 100)).thenReturn( when(mockJob.getMapAttemptCompletionEvents(0, 100)).thenReturn(
TypeConverter.fromYarn(mapEvents)); TypeConverter.fromYarn(mapEvents));
when(mockJob.getMapAttemptCompletionEvents(0, 2)).thenReturn( when(mockJob.getMapAttemptCompletionEvents(0, 2)).thenReturn(
@ -312,7 +309,8 @@ private static TaskAttemptCompletionEvent createTce(int eventId,
return tce; return tce;
} }
@Test (timeout=10000) @Test
@Timeout(10000)
public void testCommitWindow() throws IOException { public void testCommitWindow() throws IOException {
SystemClock clock = SystemClock.getInstance(); SystemClock clock = SystemClock.getInstance();

View File

@ -21,8 +21,8 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ClusterStorageCapacityExceededException; import org.apache.hadoop.fs.ClusterStorageCapacityExceededException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -36,7 +36,7 @@ public class TestYarnChild {
final static private String KILL_LIMIT_EXCEED_CONF_NAME = final static private String KILL_LIMIT_EXCEED_CONF_NAME =
"mapreduce.job.dfs.storage.capacity.kill-limit-exceed"; "mapreduce.job.dfs.storage.capacity.kill-limit-exceed";
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
task = mock(Task.class); task = mock(Task.class);
umbilical = mock(TaskUmbilicalProtocol.class); umbilical = mock(TaskUmbilicalProtocol.class);

View File

@ -19,8 +19,8 @@
package org.apache.hadoop.mapreduce.jobhistory; package org.apache.hadoop.mapreduce.jobhistory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -40,7 +40,8 @@
import org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl; import org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl;
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent;
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
public class TestEvents { public class TestEvents {
@ -50,9 +51,9 @@ public class TestEvents {
* *
* @throws Exception * @throws Exception
*/ */
@Test(timeout = 10000) @Test
@Timeout(10000)
public void testTaskAttemptFinishedEvent() throws Exception { public void testTaskAttemptFinishedEvent() throws Exception {
JobID jid = new JobID("001", 1); JobID jid = new JobID("001", 1);
TaskID tid = new TaskID(jid, TaskType.REDUCE, 2); TaskID tid = new TaskID(jid, TaskType.REDUCE, 2);
TaskAttemptID taskAttemptId = new TaskAttemptID(tid, 3); TaskAttemptID taskAttemptId = new TaskAttemptID(tid, 3);
@ -79,17 +80,18 @@ public void testTaskAttemptFinishedEvent() throws Exception {
* @throws Exception * @throws Exception
*/ */
@Test(timeout = 10000) @Test
@Timeout(10000)
public void testJobPriorityChange() throws Exception { public void testJobPriorityChange() throws Exception {
org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1); org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1);
JobPriorityChangeEvent test = new JobPriorityChangeEvent(jid, JobPriorityChangeEvent test = new JobPriorityChangeEvent(jid,
JobPriority.LOW); JobPriority.LOW);
assertThat(test.getJobId().toString()).isEqualTo(jid.toString()); assertThat(test.getJobId().toString()).isEqualTo(jid.toString());
assertThat(test.getPriority()).isEqualTo(JobPriority.LOW); assertThat(test.getPriority()).isEqualTo(JobPriority.LOW);
} }
@Test(timeout = 10000) @Test
@Timeout(10000)
public void testJobQueueChange() throws Exception { public void testJobQueueChange() throws Exception {
org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1); org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1);
JobQueueChangeEvent test = new JobQueueChangeEvent(jid, JobQueueChangeEvent test = new JobQueueChangeEvent(jid,
@ -103,14 +105,14 @@ public void testJobQueueChange() throws Exception {
* *
* @throws Exception * @throws Exception
*/ */
@Test(timeout = 10000) @Test
@Timeout(10000)
public void testTaskUpdated() throws Exception { public void testTaskUpdated() throws Exception {
JobID jid = new JobID("001", 1); JobID jid = new JobID("001", 1);
TaskID tid = new TaskID(jid, TaskType.REDUCE, 2); TaskID tid = new TaskID(jid, TaskType.REDUCE, 2);
TaskUpdatedEvent test = new TaskUpdatedEvent(tid, 1234L); TaskUpdatedEvent test = new TaskUpdatedEvent(tid, 1234L);
assertThat(test.getTaskId().toString()).isEqualTo(tid.toString()); assertThat(test.getTaskId().toString()).isEqualTo(tid.toString());
assertThat(test.getFinishTime()).isEqualTo(1234L); assertThat(test.getFinishTime()).isEqualTo(1234L);
} }
/* /*
@ -118,9 +120,9 @@ public void testTaskUpdated() throws Exception {
* instance of HistoryEvent Different HistoryEvent should have a different * instance of HistoryEvent Different HistoryEvent should have a different
* datum. * datum.
*/ */
@Test(timeout = 10000) @Test
@Timeout(10000)
public void testEvents() throws Exception { public void testEvents() throws Exception {
EventReader reader = new EventReader(new DataInputStream( EventReader reader = new EventReader(new DataInputStream(
new ByteArrayInputStream(getEvents()))); new ByteArrayInputStream(getEvents())));
HistoryEvent e = reader.getNextEvent(); HistoryEvent e = reader.getNextEvent();

View File

@ -19,9 +19,9 @@
package org.apache.hadoop.mapreduce.jobhistory; package org.apache.hadoop.mapreduce.jobhistory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@ -81,11 +81,12 @@
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.server.MiniYARNCluster; import org.apache.hadoop.yarn.server.MiniYARNCluster;
import org.apache.hadoop.yarn.server.timeline.TimelineStore; import org.apache.hadoop.yarn.server.timeline.TimelineStore;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito; import org.mockito.Mockito;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -101,7 +102,7 @@ public class TestJobHistoryEventHandler {
private static MiniDFSCluster dfsCluster = null; private static MiniDFSCluster dfsCluster = null;
private static String coreSitePath; private static String coreSitePath;
@BeforeClass @BeforeAll
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
coreSitePath = "." + File.separator + "target" + File.separator + coreSitePath = "." + File.separator + "target" + File.separator +
"test-classes" + File.separator + "core-site.xml"; "test-classes" + File.separator + "core-site.xml";
@ -109,17 +110,18 @@ public static void setUpClass() throws Exception {
dfsCluster = new MiniDFSCluster.Builder(conf).build(); dfsCluster = new MiniDFSCluster.Builder(conf).build();
} }
@AfterClass @AfterAll
public static void cleanUpClass() throws Exception { public static void cleanUpClass() throws Exception {
dfsCluster.shutdown(); dfsCluster.shutdown();
} }
@After @AfterEach
public void cleanTest() throws Exception { public void cleanTest() throws Exception {
new File(coreSitePath).delete(); new File(coreSitePath).delete();
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testFirstFlushOnCompletionEvent() throws Exception { public void testFirstFlushOnCompletionEvent() throws Exception {
TestParams t = new TestParams(); TestParams t = new TestParams();
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -162,7 +164,8 @@ public void testFirstFlushOnCompletionEvent() throws Exception {
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testMaxUnflushedCompletionEvents() throws Exception { public void testMaxUnflushedCompletionEvents() throws Exception {
TestParams t = new TestParams(); TestParams t = new TestParams();
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -207,7 +210,8 @@ public void testMaxUnflushedCompletionEvents() throws Exception {
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testUnflushedTimer() throws Exception { public void testUnflushedTimer() throws Exception {
TestParams t = new TestParams(); TestParams t = new TestParams();
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -238,19 +242,20 @@ public void testUnflushedTimer() throws Exception {
} }
handleNextNEvents(jheh, 9); handleNextNEvents(jheh, 9);
Assert.assertTrue(jheh.getFlushTimerStatus()); Assertions.assertTrue(jheh.getFlushTimerStatus());
verify(mockWriter, times(0)).flush(); verify(mockWriter, times(0)).flush();
Thread.sleep(2 * 4 * 1000l); // 4 seconds should be enough. Just be safe. Thread.sleep(2 * 4 * 1000l); // 4 seconds should be enough. Just be safe.
verify(mockWriter).flush(); verify(mockWriter).flush();
Assert.assertFalse(jheh.getFlushTimerStatus()); Assertions.assertFalse(jheh.getFlushTimerStatus());
} finally { } finally {
jheh.stop(); jheh.stop();
verify(mockWriter).close(); verify(mockWriter).close();
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testBatchedFlushJobEndMultiplier() throws Exception { public void testBatchedFlushJobEndMultiplier() throws Exception {
TestParams t = new TestParams(); TestParams t = new TestParams();
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -295,7 +300,8 @@ public void testBatchedFlushJobEndMultiplier() throws Exception {
} }
// In case of all types of events, process Done files if it's last AM retry // In case of all types of events, process Done files if it's last AM retry
@Test (timeout=50000) @Test
@Timeout(50000)
public void testProcessDoneFilesOnLastAMRetry() throws Exception { public void testProcessDoneFilesOnLastAMRetry() throws Exception {
TestParams t = new TestParams(true); TestParams t = new TestParams(true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -341,7 +347,8 @@ public void testProcessDoneFilesOnLastAMRetry() throws Exception {
} }
// Skip processing Done files in case of ERROR, if it's not last AM retry // Skip processing Done files in case of ERROR, if it's not last AM retry
@Test (timeout=50000) @Test
@Timeout(50000)
public void testProcessDoneFilesNotLastAMRetry() throws Exception { public void testProcessDoneFilesNotLastAMRetry() throws Exception {
TestParams t = new TestParams(false); TestParams t = new TestParams(false);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -421,16 +428,15 @@ public void testPropertyRedactionForJHS() throws Exception {
// load the job_conf.xml in JHS directory and verify property redaction. // load the job_conf.xml in JHS directory and verify property redaction.
Path jhsJobConfFile = getJobConfInIntermediateDoneDir(conf, params.jobId); Path jhsJobConfFile = getJobConfInIntermediateDoneDir(conf, params.jobId);
Assert.assertTrue("The job_conf.xml file is not in the JHS directory", Assertions.assertTrue(FileContext.getFileContext(conf).util().exists(jhsJobConfFile),
FileContext.getFileContext(conf).util().exists(jhsJobConfFile)); "The job_conf.xml file is not in the JHS directory");
Configuration jhsJobConf = new Configuration(); Configuration jhsJobConf = new Configuration();
try (InputStream input = FileSystem.get(conf).open(jhsJobConfFile)) { try (InputStream input = FileSystem.get(conf).open(jhsJobConfFile)) {
jhsJobConf.addResource(input); jhsJobConf.addResource(input);
Assert.assertEquals( Assertions.assertEquals(MRJobConfUtil.REDACTION_REPLACEMENT_VAL,
sensitivePropertyName + " is not redacted in HDFS.", jhsJobConf.get(sensitivePropertyName),
MRJobConfUtil.REDACTION_REPLACEMENT_VAL, sensitivePropertyName + " is not redacted in HDFS.");
jhsJobConf.get(sensitivePropertyName));
} }
} finally { } finally {
jheh.stop(); jheh.stop();
@ -456,7 +462,8 @@ private void purgeHdfsHistoryIntermediateDoneDirectory(Configuration conf)
fs.delete(new Path(intermDoneDirPrefix), true); fs.delete(new Path(intermDoneDirPrefix), true);
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testDefaultFsIsUsedForHistory() throws Exception { public void testDefaultFsIsUsedForHistory() throws Exception {
// Create default configuration pointing to the minicluster // Create default configuration pointing to the minicluster
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -490,11 +497,11 @@ public void testDefaultFsIsUsedForHistory() throws Exception {
// If we got here then event handler worked but we don't know with which // If we got here then event handler worked but we don't know with which
// file system. Now we check that history stuff was written to minicluster // file system. Now we check that history stuff was written to minicluster
FileSystem dfsFileSystem = dfsCluster.getFileSystem(); FileSystem dfsFileSystem = dfsCluster.getFileSystem();
assertTrue("Minicluster contains some history files", assertTrue(dfsFileSystem.globStatus(new Path(t.dfsWorkDir + "/*")).length != 0,
dfsFileSystem.globStatus(new Path(t.dfsWorkDir + "/*")).length != 0); "Minicluster contains some history files");
FileSystem localFileSystem = LocalFileSystem.get(conf); FileSystem localFileSystem = LocalFileSystem.get(conf);
assertFalse("No history directory on non-default file system", assertFalse(localFileSystem.exists(new Path(t.dfsWorkDir)),
localFileSystem.exists(new Path(t.dfsWorkDir))); "No history directory on non-default file system");
} finally { } finally {
jheh.stop(); jheh.stop();
purgeHdfsHistoryIntermediateDoneDirectory(conf); purgeHdfsHistoryIntermediateDoneDirectory(conf);
@ -509,7 +516,7 @@ public void testGetHistoryIntermediateDoneDirForUser() throws IOException {
"/mapred/history/done_intermediate"); "/mapred/history/done_intermediate");
conf.set(MRJobConfig.USER_NAME, System.getProperty("user.name")); conf.set(MRJobConfig.USER_NAME, System.getProperty("user.name"));
String pathStr = JobHistoryUtils.getHistoryIntermediateDoneDirForUser(conf); String pathStr = JobHistoryUtils.getHistoryIntermediateDoneDirForUser(conf);
Assert.assertEquals("/mapred/history/done_intermediate/" + Assertions.assertEquals("/mapred/history/done_intermediate/" +
System.getProperty("user.name"), pathStr); System.getProperty("user.name"), pathStr);
// Test fully qualified path // Test fully qualified path
@ -523,13 +530,14 @@ public void testGetHistoryIntermediateDoneDirForUser() throws IOException {
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
"file:///"); "file:///");
pathStr = JobHistoryUtils.getHistoryIntermediateDoneDirForUser(conf); pathStr = JobHistoryUtils.getHistoryIntermediateDoneDirForUser(conf);
Assert.assertEquals(dfsCluster.getURI().toString() + Assertions.assertEquals(dfsCluster.getURI().toString() +
"/mapred/history/done_intermediate/" + System.getProperty("user.name"), "/mapred/history/done_intermediate/" + System.getProperty("user.name"),
pathStr); pathStr);
} }
// test AMStartedEvent for submitTime and startTime // test AMStartedEvent for submitTime and startTime
@Test (timeout=50000) @Test
@Timeout(50000)
public void testAMStartedEvent() throws Exception { public void testAMStartedEvent() throws Exception {
TestParams t = new TestParams(); TestParams t = new TestParams();
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -571,7 +579,8 @@ public void testAMStartedEvent() throws Exception {
// Have JobHistoryEventHandler handle some events and make sure they get // Have JobHistoryEventHandler handle some events and make sure they get
// stored to the Timeline store // stored to the Timeline store
@Test (timeout=50000) @Test
@Timeout(50000)
public void testTimelineEventHandling() throws Exception { public void testTimelineEventHandling() throws Exception {
TestParams t = new TestParams(RunningAppContext.class, false); TestParams t = new TestParams(RunningAppContext.class, false);
Configuration conf = new YarnConfiguration(); Configuration conf = new YarnConfiguration();
@ -598,13 +607,13 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
TimelineEntities entities = ts.getEntities("MAPREDUCE_JOB", null, null, TimelineEntities entities = ts.getEntities("MAPREDUCE_JOB", null, null,
null, null, null, null, null, null, null); null, null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
TimelineEntity tEntity = entities.getEntities().get(0); TimelineEntity tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.jobId.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.jobId.toString(), tEntity.getEntityId());
Assert.assertEquals(1, tEntity.getEvents().size()); Assertions.assertEquals(1, tEntity.getEvents().size());
Assert.assertEquals(EventType.AM_STARTED.toString(), Assertions.assertEquals(EventType.AM_STARTED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(currentTime - 10, Assertions.assertEquals(currentTime - 10,
tEntity.getEvents().get(0).getTimestamp()); tEntity.getEvents().get(0).getTimestamp());
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -615,17 +624,17 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_JOB", null, null, null, entities = ts.getEntities("MAPREDUCE_JOB", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.jobId.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.jobId.toString(), tEntity.getEntityId());
Assert.assertEquals(2, tEntity.getEvents().size()); Assertions.assertEquals(2, tEntity.getEvents().size());
Assert.assertEquals(EventType.JOB_SUBMITTED.toString(), Assertions.assertEquals(EventType.JOB_SUBMITTED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(EventType.AM_STARTED.toString(), Assertions.assertEquals(EventType.AM_STARTED.toString(),
tEntity.getEvents().get(1).getEventType()); tEntity.getEvents().get(1).getEventType());
Assert.assertEquals(currentTime + 10, Assertions.assertEquals(currentTime + 10,
tEntity.getEvents().get(0).getTimestamp()); tEntity.getEvents().get(0).getTimestamp());
Assert.assertEquals(currentTime - 10, Assertions.assertEquals(currentTime - 10,
tEntity.getEvents().get(1).getTimestamp()); tEntity.getEvents().get(1).getTimestamp());
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -634,21 +643,21 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_JOB", null, null, null, entities = ts.getEntities("MAPREDUCE_JOB", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.jobId.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.jobId.toString(), tEntity.getEntityId());
Assert.assertEquals(3, tEntity.getEvents().size()); Assertions.assertEquals(3, tEntity.getEvents().size());
Assert.assertEquals(EventType.JOB_SUBMITTED.toString(), Assertions.assertEquals(EventType.JOB_SUBMITTED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(EventType.AM_STARTED.toString(), Assertions.assertEquals(EventType.AM_STARTED.toString(),
tEntity.getEvents().get(1).getEventType()); tEntity.getEvents().get(1).getEventType());
Assert.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(), Assertions.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(),
tEntity.getEvents().get(2).getEventType()); tEntity.getEvents().get(2).getEventType());
Assert.assertEquals(currentTime + 10, Assertions.assertEquals(currentTime + 10,
tEntity.getEvents().get(0).getTimestamp()); tEntity.getEvents().get(0).getTimestamp());
Assert.assertEquals(currentTime - 10, Assertions.assertEquals(currentTime - 10,
tEntity.getEvents().get(1).getTimestamp()); tEntity.getEvents().get(1).getTimestamp());
Assert.assertEquals(currentTime - 20, Assertions.assertEquals(currentTime - 20,
tEntity.getEvents().get(2).getTimestamp()); tEntity.getEvents().get(2).getTimestamp());
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -657,25 +666,25 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_JOB", null, null, null, entities = ts.getEntities("MAPREDUCE_JOB", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.jobId.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.jobId.toString(), tEntity.getEntityId());
Assert.assertEquals(4, tEntity.getEvents().size()); Assertions.assertEquals(4, tEntity.getEvents().size());
Assert.assertEquals(EventType.JOB_SUBMITTED.toString(), Assertions.assertEquals(EventType.JOB_SUBMITTED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(EventType.JOB_FINISHED.toString(), Assertions.assertEquals(EventType.JOB_FINISHED.toString(),
tEntity.getEvents().get(1).getEventType()); tEntity.getEvents().get(1).getEventType());
Assert.assertEquals(EventType.AM_STARTED.toString(), Assertions.assertEquals(EventType.AM_STARTED.toString(),
tEntity.getEvents().get(2).getEventType()); tEntity.getEvents().get(2).getEventType());
Assert.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(), Assertions.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(),
tEntity.getEvents().get(3).getEventType()); tEntity.getEvents().get(3).getEventType());
Assert.assertEquals(currentTime + 10, Assertions.assertEquals(currentTime + 10,
tEntity.getEvents().get(0).getTimestamp()); tEntity.getEvents().get(0).getTimestamp());
Assert.assertEquals(currentTime, Assertions.assertEquals(currentTime,
tEntity.getEvents().get(1).getTimestamp()); tEntity.getEvents().get(1).getTimestamp());
Assert.assertEquals(currentTime - 10, Assertions.assertEquals(currentTime - 10,
tEntity.getEvents().get(2).getTimestamp()); tEntity.getEvents().get(2).getTimestamp());
Assert.assertEquals(currentTime - 20, Assertions.assertEquals(currentTime - 20,
tEntity.getEvents().get(3).getTimestamp()); tEntity.getEvents().get(3).getTimestamp());
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -685,29 +694,29 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_JOB", null, null, null, entities = ts.getEntities("MAPREDUCE_JOB", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.jobId.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.jobId.toString(), tEntity.getEntityId());
Assert.assertEquals(5, tEntity.getEvents().size()); Assertions.assertEquals(5, tEntity.getEvents().size());
Assert.assertEquals(EventType.JOB_KILLED.toString(), Assertions.assertEquals(EventType.JOB_KILLED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(EventType.JOB_SUBMITTED.toString(), Assertions.assertEquals(EventType.JOB_SUBMITTED.toString(),
tEntity.getEvents().get(1).getEventType()); tEntity.getEvents().get(1).getEventType());
Assert.assertEquals(EventType.JOB_FINISHED.toString(), Assertions.assertEquals(EventType.JOB_FINISHED.toString(),
tEntity.getEvents().get(2).getEventType()); tEntity.getEvents().get(2).getEventType());
Assert.assertEquals(EventType.AM_STARTED.toString(), Assertions.assertEquals(EventType.AM_STARTED.toString(),
tEntity.getEvents().get(3).getEventType()); tEntity.getEvents().get(3).getEventType());
Assert.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(), Assertions.assertEquals(EventType.JOB_QUEUE_CHANGED.toString(),
tEntity.getEvents().get(4).getEventType()); tEntity.getEvents().get(4).getEventType());
Assert.assertEquals(currentTime + 20, Assertions.assertEquals(currentTime + 20,
tEntity.getEvents().get(0).getTimestamp()); tEntity.getEvents().get(0).getTimestamp());
Assert.assertEquals(currentTime + 10, Assertions.assertEquals(currentTime + 10,
tEntity.getEvents().get(1).getTimestamp()); tEntity.getEvents().get(1).getTimestamp());
Assert.assertEquals(currentTime, Assertions.assertEquals(currentTime,
tEntity.getEvents().get(2).getTimestamp()); tEntity.getEvents().get(2).getTimestamp());
Assert.assertEquals(currentTime - 10, Assertions.assertEquals(currentTime - 10,
tEntity.getEvents().get(3).getTimestamp()); tEntity.getEvents().get(3).getTimestamp());
Assert.assertEquals(currentTime - 20, Assertions.assertEquals(currentTime - 20,
tEntity.getEvents().get(4).getTimestamp()); tEntity.getEvents().get(4).getTimestamp());
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -715,13 +724,13 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_TASK", null, null, null, entities = ts.getEntities("MAPREDUCE_TASK", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.taskID.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.taskID.toString(), tEntity.getEntityId());
Assert.assertEquals(1, tEntity.getEvents().size()); Assertions.assertEquals(1, tEntity.getEvents().size());
Assert.assertEquals(EventType.TASK_STARTED.toString(), Assertions.assertEquals(EventType.TASK_STARTED.toString(),
tEntity.getEvents().get(0).getEventType()); tEntity.getEvents().get(0).getEventType());
Assert.assertEquals(TaskType.MAP.toString(), Assertions.assertEquals(TaskType.MAP.toString(),
tEntity.getEvents().get(0).getEventInfo().get("TASK_TYPE")); tEntity.getEvents().get(0).getEventInfo().get("TASK_TYPE"));
handleEvent(jheh, new JobHistoryEvent(t.jobId, handleEvent(jheh, new JobHistoryEvent(t.jobId,
@ -729,20 +738,21 @@ public void testTimelineEventHandling() throws Exception {
jheh.getDispatcher().await(); jheh.getDispatcher().await();
entities = ts.getEntities("MAPREDUCE_TASK", null, null, null, entities = ts.getEntities("MAPREDUCE_TASK", null, null, null,
null, null, null, null, null, null); null, null, null, null, null, null);
Assert.assertEquals(1, entities.getEntities().size()); Assertions.assertEquals(1, entities.getEntities().size());
tEntity = entities.getEntities().get(0); tEntity = entities.getEntities().get(0);
Assert.assertEquals(t.taskID.toString(), tEntity.getEntityId()); Assertions.assertEquals(t.taskID.toString(), tEntity.getEntityId());
Assert.assertEquals(2, tEntity.getEvents().size()); Assertions.assertEquals(2, tEntity.getEvents().size());
Assert.assertEquals(EventType.TASK_STARTED.toString(), Assertions.assertEquals(EventType.TASK_STARTED.toString(),
tEntity.getEvents().get(1).getEventType()); tEntity.getEvents().get(1).getEventType());
Assert.assertEquals(TaskType.REDUCE.toString(), Assertions.assertEquals(TaskType.REDUCE.toString(),
tEntity.getEvents().get(0).getEventInfo().get("TASK_TYPE")); tEntity.getEvents().get(0).getEventInfo().get("TASK_TYPE"));
Assert.assertEquals(TaskType.MAP.toString(), Assertions.assertEquals(TaskType.MAP.toString(),
tEntity.getEvents().get(1).getEventInfo().get("TASK_TYPE")); tEntity.getEvents().get(1).getEventInfo().get("TASK_TYPE"));
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testCountersToJSON() throws Exception { public void testCountersToJSON() throws Exception {
JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0); JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0);
Counters counters = new Counters(); Counters counters = new Counters();
@ -775,30 +785,31 @@ public void testCountersToJSON() throws Exception {
+ "{\"NAME\":\"MATT_SMITH\",\"DISPLAY_NAME\":\"Matt Smith\",\"VALUE\":" + "{\"NAME\":\"MATT_SMITH\",\"DISPLAY_NAME\":\"Matt Smith\",\"VALUE\":"
+ "11},{\"NAME\":\"PETER_CAPALDI\",\"DISPLAY_NAME\":\"Peter Capaldi\"," + "11},{\"NAME\":\"PETER_CAPALDI\",\"DISPLAY_NAME\":\"Peter Capaldi\","
+ "\"VALUE\":12}]}]"; + "\"VALUE\":12}]}]";
Assert.assertEquals(expected, jsonStr); Assertions.assertEquals(expected, jsonStr);
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testCountersToJSONEmpty() throws Exception { public void testCountersToJSONEmpty() throws Exception {
JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0); JobHistoryEventHandler jheh = new JobHistoryEventHandler(null, 0);
Counters counters = null; Counters counters = null;
JsonNode jsonNode = JobHistoryEventUtils.countersToJSON(counters); JsonNode jsonNode = JobHistoryEventUtils.countersToJSON(counters);
String jsonStr = new ObjectMapper().writeValueAsString(jsonNode); String jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
String expected = "[]"; String expected = "[]";
Assert.assertEquals(expected, jsonStr); Assertions.assertEquals(expected, jsonStr);
counters = new Counters(); counters = new Counters();
jsonNode = JobHistoryEventUtils.countersToJSON(counters); jsonNode = JobHistoryEventUtils.countersToJSON(counters);
jsonStr = new ObjectMapper().writeValueAsString(jsonNode); jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
expected = "[]"; expected = "[]";
Assert.assertEquals(expected, jsonStr); Assertions.assertEquals(expected, jsonStr);
counters.addGroup("DOCTORS", "Incarnations of the Doctor"); counters.addGroup("DOCTORS", "Incarnations of the Doctor");
jsonNode = JobHistoryEventUtils.countersToJSON(counters); jsonNode = JobHistoryEventUtils.countersToJSON(counters);
jsonStr = new ObjectMapper().writeValueAsString(jsonNode); jsonStr = new ObjectMapper().writeValueAsString(jsonNode);
expected = "[{\"NAME\":\"DOCTORS\",\"DISPLAY_NAME\":\"Incarnations of the " expected = "[{\"NAME\":\"DOCTORS\",\"DISPLAY_NAME\":\"Incarnations of the "
+ "Doctor\",\"COUNTERS\":[]}]"; + "Doctor\",\"COUNTERS\":[]}]";
Assert.assertEquals(expected, jsonStr); Assertions.assertEquals(expected, jsonStr);
} }
private void queueEvent(JHEvenHandlerForTest jheh, JobHistoryEvent event) { private void queueEvent(JHEvenHandlerForTest jheh, JobHistoryEvent event) {
@ -912,8 +923,9 @@ public void testSigTermedFunctionality() throws IOException {
} }
jheh.stop(); jheh.stop();
//Make sure events were handled //Make sure events were handled
assertTrue("handleEvent should've been called only 4 times but was " assertTrue(jheh.eventsHandled == 4,
+ jheh.eventsHandled, jheh.eventsHandled == 4); "handleEvent should've been called only 4 times but was "
+ jheh.eventsHandled);
//Create a new jheh because the last stop closed the eventWriter etc. //Create a new jheh because the last stop closed the eventWriter etc.
jheh = new JHEventHandlerForSigtermTest(mockedContext, 0); jheh = new JHEventHandlerForSigtermTest(mockedContext, 0);
@ -934,14 +946,15 @@ public void testSigTermedFunctionality() throws IOException {
} }
jheh.stop(); jheh.stop();
//Make sure events were handled, 4 + 1 finish event //Make sure events were handled, 4 + 1 finish event
assertTrue("handleEvent should've been called only 5 times but was " assertTrue(jheh.eventsHandled == 5, "handleEvent should've been called only 5 times but was "
+ jheh.eventsHandled, jheh.eventsHandled == 5); + jheh.eventsHandled);
assertTrue("Last event handled wasn't JobUnsuccessfulCompletionEvent", assertTrue(jheh.lastEventHandled.getHistoryEvent()
jheh.lastEventHandled.getHistoryEvent() instanceof JobUnsuccessfulCompletionEvent,
instanceof JobUnsuccessfulCompletionEvent); "Last event handled wasn't JobUnsuccessfulCompletionEvent");
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testSetTrackingURLAfterHistoryIsWritten() throws Exception { public void testSetTrackingURLAfterHistoryIsWritten() throws Exception {
TestParams t = new TestParams(true); TestParams t = new TestParams(true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -972,7 +985,8 @@ public void testSetTrackingURLAfterHistoryIsWritten() throws Exception {
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testDontSetTrackingURLIfHistoryWriteFailed() throws Exception { public void testDontSetTrackingURLIfHistoryWriteFailed() throws Exception {
TestParams t = new TestParams(true); TestParams t = new TestParams(true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -1003,7 +1017,8 @@ public void testDontSetTrackingURLIfHistoryWriteFailed() throws Exception {
jheh.stop(); jheh.stop();
} }
} }
@Test (timeout=50000) @Test
@Timeout(50000)
public void testDontSetTrackingURLIfHistoryWriteThrows() throws Exception { public void testDontSetTrackingURLIfHistoryWriteThrows() throws Exception {
TestParams t = new TestParams(true); TestParams t = new TestParams(true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
@ -1039,7 +1054,8 @@ public void testDontSetTrackingURLIfHistoryWriteThrows() throws Exception {
} }
} }
@Test(timeout = 50000) @Test
@Timeout(50000)
public void testJobHistoryFilePermissions() throws Exception { public void testJobHistoryFilePermissions() throws Exception {
TestParams t = new TestParams(true); TestParams t = new TestParams(true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();

View File

@ -19,9 +19,9 @@
package org.apache.hadoop.mapreduce.jobhistory; package org.apache.hadoop.mapreduce.jobhistory;
import org.apache.hadoop.mapreduce.v2.api.records.JobId; import org.apache.hadoop.mapreduce.v2.api.records.JobId;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,7 +34,7 @@ public class TestJobSummary {
LoggerFactory.getLogger(TestJobSummary.class); LoggerFactory.getLogger(TestJobSummary.class);
private JobSummary summary = new JobSummary(); private JobSummary summary = new JobSummary();
@Before @BeforeEach
public void before() { public void before() {
JobId mockJobId = mock(JobId.class); JobId mockJobId = mock(JobId.class);
when(mockJobId.toString()).thenReturn("testJobId"); when(mockJobId.toString()).thenReturn("testJobId");
@ -64,8 +64,8 @@ public void testEscapeJobSummary() {
summary.setJobName("aa\rbb\ncc\r\ndd"); summary.setJobName("aa\rbb\ncc\r\ndd");
String out = summary.getJobSummaryString(); String out = summary.getJobSummaryString();
LOG.info("summary: " + out); LOG.info("summary: " + out);
Assert.assertFalse(out.contains("\r")); Assertions.assertFalse(out.contains("\r"));
Assert.assertFalse(out.contains("\n")); Assertions.assertFalse(out.contains("\n"));
Assert.assertTrue(out.contains("aa\\rbb\\ncc\\r\\ndd")); Assertions.assertTrue(out.contains("aa\\rbb\\ncc\\r\\ndd"));
} }
} }

View File

@ -24,12 +24,12 @@
import org.apache.hadoop.mapreduce.v2.proto.MRProtos; import org.apache.hadoop.mapreduce.v2.proto.MRProtos;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestTaskAttemptReport { public class TestTaskAttemptReport {

View File

@ -24,12 +24,12 @@
import org.apache.hadoop.mapreduce.v2.proto.MRProtos; import org.apache.hadoop.mapreduce.v2.proto.MRProtos;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestTaskReport { public class TestTaskReport {

View File

@ -98,7 +98,7 @@
import org.apache.hadoop.yarn.state.StateMachineFactory; import org.apache.hadoop.yarn.state.StateMachineFactory;
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -326,8 +326,8 @@ public void waitForInternalState(JobImpl job,
iState = job.getInternalState(); iState = job.getInternalState();
} }
LOG.info("Job {} Internal State is : {}", job.getID(), iState); LOG.info("Job {} Internal State is : {}", job.getID(), iState);
Assert.assertEquals("Task Internal state is not correct (timedout)", Assertions.assertEquals(finalState, iState,
finalState, iState); "Task Internal state is not correct (timedout)");
} }
public void waitForInternalState(TaskImpl task, public void waitForInternalState(TaskImpl task,
@ -339,8 +339,8 @@ public void waitForInternalState(TaskImpl task,
iState = task.getInternalState(); iState = task.getInternalState();
} }
LOG.info("Task {} Internal State is : {}", task.getID(), iState); LOG.info("Task {} Internal State is : {}", task.getID(), iState);
Assert.assertEquals("Task Internal state is not correct (timedout)", Assertions.assertEquals(finalState, iState,
finalState, iState); "Task Internal state is not correct (timedout)");
} }
public void waitForInternalState(TaskAttemptImpl attempt, public void waitForInternalState(TaskAttemptImpl attempt,
@ -352,8 +352,8 @@ public void waitForInternalState(TaskAttemptImpl attempt,
iState = attempt.getInternalState(); iState = attempt.getInternalState();
} }
LOG.info("TaskAttempt {} Internal State is : {}", attempt.getID(), iState); LOG.info("TaskAttempt {} Internal State is : {}", attempt.getID(), iState);
Assert.assertEquals("TaskAttempt Internal state is not correct (timedout)", Assertions.assertEquals(finalState, iState,
finalState, iState); "TaskAttempt Internal state is not correct (timedout)");
} }
public void waitForState(TaskAttempt attempt, public void waitForState(TaskAttempt attempt,
@ -367,9 +367,8 @@ public void waitForState(TaskAttempt attempt,
} }
LOG.info("TaskAttempt {} State is : {}", attempt.getID(), LOG.info("TaskAttempt {} State is : {}", attempt.getID(),
report.getTaskAttemptState()); report.getTaskAttemptState());
Assert.assertEquals("TaskAttempt state is not correct (timedout)", Assertions.assertEquals(finalState, report.getTaskAttemptState(),
finalState, "TaskAttempt state is not correct (timedout)");
report.getTaskAttemptState());
} }
public void waitForState(Task task, TaskState finalState) throws Exception { public void waitForState(Task task, TaskState finalState) throws Exception {
@ -381,8 +380,8 @@ public void waitForState(Task task, TaskState finalState) throws Exception {
report = task.getReport(); report = task.getReport();
} }
LOG.info("Task {} State is : {}", task.getID(), report.getTaskState()); LOG.info("Task {} State is : {}", task.getID(), report.getTaskState());
Assert.assertEquals("Task state is not correct (timedout)", finalState, Assertions.assertEquals(finalState, report.getTaskState(),
report.getTaskState()); "Task state is not correct (timedout)");
} }
public void waitForState(Job job, JobState finalState) throws Exception { public void waitForState(Job job, JobState finalState) throws Exception {
@ -394,14 +393,14 @@ public void waitForState(Job job, JobState finalState) throws Exception {
Thread.sleep(WAIT_FOR_STATE_INTERVAL); Thread.sleep(WAIT_FOR_STATE_INTERVAL);
} }
LOG.info("Job {} State is : {}", job.getID(), report.getJobState()); LOG.info("Job {} State is : {}", job.getID(), report.getJobState());
Assert.assertEquals("Job state is not correct (timedout)", finalState, Assertions.assertEquals(finalState, job.getState(),
job.getState()); "Job state is not correct (timedout)");
} }
public void waitForState(Service.STATE finalState) throws Exception { public void waitForState(Service.STATE finalState) throws Exception {
if (finalState == Service.STATE.STOPPED) { if (finalState == Service.STATE.STOPPED) {
Assert.assertTrue("Timeout while waiting for MRApp to stop", Assertions.assertTrue(waitForServiceToStop(20 * 1000),
waitForServiceToStop(20 * 1000)); "Timeout while waiting for MRApp to stop");
} else { } else {
int timeoutSecs = 0; int timeoutSecs = 0;
while (!finalState.equals(getServiceState()) while (!finalState.equals(getServiceState())
@ -409,8 +408,8 @@ public void waitForState(Service.STATE finalState) throws Exception {
Thread.sleep(WAIT_FOR_STATE_INTERVAL); Thread.sleep(WAIT_FOR_STATE_INTERVAL);
} }
LOG.info("MRApp State is : {}", getServiceState()); LOG.info("MRApp State is : {}", getServiceState());
Assert.assertEquals("MRApp state is not correct (timedout)", finalState, Assertions.assertEquals(finalState, getServiceState(),
getServiceState()); "MRApp state is not correct (timedout)");
} }
} }
@ -419,22 +418,23 @@ public void verifyCompleted() {
JobReport jobReport = job.getReport(); JobReport jobReport = job.getReport();
LOG.info("Job start time :{}", jobReport.getStartTime()); LOG.info("Job start time :{}", jobReport.getStartTime());
LOG.info("Job finish time :", jobReport.getFinishTime()); LOG.info("Job finish time :", jobReport.getFinishTime());
Assert.assertTrue("Job start time is not less than finish time", Assertions.assertTrue(jobReport.getStartTime() <= jobReport.getFinishTime(),
jobReport.getStartTime() <= jobReport.getFinishTime()); "Job start time is not less than finish time");
Assert.assertTrue("Job finish time is in future", Assertions.assertTrue(jobReport.getFinishTime() <= System.currentTimeMillis(),
jobReport.getFinishTime() <= System.currentTimeMillis()); "Job finish time is in future");
for (Task task : job.getTasks().values()) { for (Task task : job.getTasks().values()) {
TaskReport taskReport = task.getReport(); TaskReport taskReport = task.getReport();
LOG.info("Task {} start time : {}", task.getID(), LOG.info("Task {} start time : {}", task.getID(),
taskReport.getStartTime()); taskReport.getStartTime());
LOG.info("Task {} finish time : {}", task.getID(), LOG.info("Task {} finish time : {}", task.getID(),
taskReport.getFinishTime()); taskReport.getFinishTime());
Assert.assertTrue("Task start time is not less than finish time", Assertions.assertTrue(taskReport.getStartTime() <= taskReport.getFinishTime(),
taskReport.getStartTime() <= taskReport.getFinishTime()); "Task start time is not less than finish time");
for (TaskAttempt attempt : task.getAttempts().values()) { for (TaskAttempt attempt : task.getAttempts().values()) {
TaskAttemptReport attemptReport = attempt.getReport(); TaskAttemptReport attemptReport = attempt.getReport();
Assert.assertTrue("Attempt start time is not less than finish time", Assertions.assertTrue(attemptReport.getStartTime() <=
attemptReport.getStartTime() <= attemptReport.getFinishTime()); attemptReport.getFinishTime(),
"Attempt start time is not less than finish time");
} }
} }
} }

View File

@ -56,7 +56,8 @@
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.event.Level; import org.slf4j.event.Level;
public class MRAppBenchmark { public class MRAppBenchmark {
@ -196,7 +197,8 @@ public void runOnNextHeartbeat(Runnable callback) {
} }
} }
@Test(timeout = 60000) @Test
@Timeout(60000)
public void benchmark1() throws Exception { public void benchmark1() throws Exception {
int maps = 100; // Adjust for benchmarking. Start with thousands. int maps = 100; // Adjust for benchmarking. Start with thousands.
int reduces = 0; int reduces = 0;
@ -275,7 +277,8 @@ public AllocateResponse allocate(AllocateRequest request)
}); });
} }
@Test(timeout = 60000) @Test
@Timeout(60000)
public void benchmark2() throws Exception { public void benchmark2() throws Exception {
int maps = 100; // Adjust for benchmarking, start with a couple of thousands int maps = 100; // Adjust for benchmarking, start with a couple of thousands
int reduces = 50; int reduces = 50;

View File

@ -21,7 +21,7 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.MRJobConfig;
@ -33,7 +33,7 @@
import org.apache.hadoop.mapreduce.v2.app.job.Job; import org.apache.hadoop.mapreduce.v2.app.job.Job;
import org.apache.hadoop.mapreduce.v2.app.job.Task; import org.apache.hadoop.mapreduce.v2.app.job.Task;
import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt; import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestAMInfos { public class TestAMInfos {
@ -50,7 +50,7 @@ public void testAMInfosWithoutRecoveryEnabled() throws Exception {
long am1StartTime = app.getAllAMInfos().get(0).getStartTime(); long am1StartTime = app.getAllAMInfos().get(0).getStartTime();
Assert.assertEquals("No of tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(), "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
app.waitForState(mapTask, TaskState.RUNNING); app.waitForState(mapTask, TaskState.RUNNING);
@ -71,14 +71,14 @@ public void testAMInfosWithoutRecoveryEnabled() throws Exception {
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(), "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask = it.next(); mapTask = it.next();
// There should be two AMInfos // There should be two AMInfos
List<AMInfo> amInfos = app.getAllAMInfos(); List<AMInfo> amInfos = app.getAllAMInfos();
Assert.assertEquals(2, amInfos.size()); Assertions.assertEquals(2, amInfos.size());
AMInfo amInfoOne = amInfos.get(0); AMInfo amInfoOne = amInfos.get(0);
Assert.assertEquals(am1StartTime, amInfoOne.getStartTime()); Assertions.assertEquals(am1StartTime, amInfoOne.getStartTime());
app.stop(); app.stop();
} }
} }

View File

@ -22,7 +22,7 @@
import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.Priority;
import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.resource.Resources;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -58,8 +58,8 @@
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestCheckpointPreemptionPolicy { public class TestCheckpointPreemptionPolicy {
@ -77,7 +77,7 @@ public class TestCheckpointPreemptionPolicy {
private int minAlloc = 1024; private int minAlloc = 1024;
@Before @BeforeEach
@SuppressWarnings("rawtypes") // mocked generics @SuppressWarnings("rawtypes") // mocked generics
public void setup() { public void setup() {
ApplicationId appId = ApplicationId.newInstance(200, 1); ApplicationId appId = ApplicationId.newInstance(200, 1);

View File

@ -24,7 +24,7 @@
import java.util.Map; import java.util.Map;
import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapred.TaskAttemptListenerImpl; import org.apache.hadoop.mapred.TaskAttemptListenerImpl;
@ -48,7 +48,7 @@
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData; import org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Tests the state machine with respect to Job/Task/TaskAttempt failure * Tests the state machine with respect to Job/Task/TaskAttempt failure
@ -68,20 +68,20 @@ public void testFailTask() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
Map<TaskId,Task> tasks = job.getTasks(); Map<TaskId,Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 1, tasks.size()); Assertions.assertEquals(1, tasks.size(), "Num tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
Assert.assertEquals("Task state not correct", TaskState.SUCCEEDED, Assertions.assertEquals(TaskState.SUCCEEDED, task.getReport().getTaskState(),
task.getReport().getTaskState()); "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = Map<TaskAttemptId, TaskAttempt> attempts =
tasks.values().iterator().next().getAttempts(); tasks.values().iterator().next().getAttempts();
Assert.assertEquals("Num attempts is not correct", 2, attempts.size()); Assertions.assertEquals(2, attempts.size(), "Num attempts is not correct");
//one attempt must be failed //one attempt must be failed
//and another must have succeeded //and another must have succeeded
Iterator<TaskAttempt> it = attempts.values().iterator(); Iterator<TaskAttempt> it = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.FAILED, Assertions.assertEquals(TaskAttemptState.FAILED,
it.next().getReport().getTaskAttemptState()); it.next().getReport().getTaskAttemptState(), "Attempt state not correct");
Assert.assertEquals("Attempt state not correct", TaskAttemptState.SUCCEEDED, Assertions.assertEquals(TaskAttemptState.SUCCEEDED,
it.next().getReport().getTaskAttemptState()); it.next().getReport().getTaskAttemptState(), "Attempt state not correct");
} }
@Test @Test
@ -159,17 +159,17 @@ public void testTimedOutTask() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.FAILED); app.waitForState(job, JobState.FAILED);
Map<TaskId,Task> tasks = job.getTasks(); Map<TaskId,Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 1, tasks.size()); Assertions.assertEquals(1, tasks.size(), "Num tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
Assert.assertEquals("Task state not correct", TaskState.FAILED, Assertions.assertEquals(TaskState.FAILED,
task.getReport().getTaskState()); task.getReport().getTaskState(), "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = Map<TaskAttemptId, TaskAttempt> attempts =
tasks.values().iterator().next().getAttempts(); tasks.values().iterator().next().getAttempts();
Assert.assertEquals("Num attempts is not correct", maxAttempts, Assertions.assertEquals(maxAttempts,
attempts.size()); attempts.size(), "Num attempts is not correct");
for (TaskAttempt attempt : attempts.values()) { for (TaskAttempt attempt : attempts.values()) {
Assert.assertEquals("Attempt state not correct", TaskAttemptState.FAILED, Assertions.assertEquals(TaskAttemptState.FAILED,
attempt.getReport().getTaskAttemptState()); attempt.getReport().getTaskAttemptState(), "Attempt state not correct");
} }
} }
@ -185,13 +185,14 @@ public void testTaskFailWithUnusedContainer() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Map<TaskId, Task> tasks = job.getTasks(); Map<TaskId, Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 1, tasks.size()); Assertions.assertEquals(1, tasks.size(),
"Num tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
app.waitForState(task, TaskState.SCHEDULED); app.waitForState(task, TaskState.SCHEDULED);
Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator() Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator()
.next().getAttempts(); .next().getAttempts();
Assert.assertEquals("Num attempts is not correct", maxAttempts, attempts Assertions.assertEquals(maxAttempts, attempts.size(),
.size()); "Num attempts is not correct");
TaskAttempt attempt = attempts.values().iterator().next(); TaskAttempt attempt = attempts.values().iterator().next();
app.waitForInternalState((TaskAttemptImpl) attempt, app.waitForInternalState((TaskAttemptImpl) attempt,
TaskAttemptStateInternal.ASSIGNED); TaskAttemptStateInternal.ASSIGNED);

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -50,8 +50,8 @@
import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptStatusUpdateEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptStatusUpdateEvent;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestFetchFailure { public class TestFetchFailure {
@ -65,8 +65,8 @@ public void testFetchFailure() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("Num tasks not correct", Assertions.assertEquals(2, job.getTasks().size(),
2, job.getTasks().size()); "Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -97,10 +97,10 @@ public Boolean get() {
TaskAttemptCompletionEvent[] events = TaskAttemptCompletionEvent[] events =
job.getTaskAttemptCompletionEvents(0, 100); job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", Assertions.assertEquals(1, events.length,
1, events.length); "Num completion events not correct");
Assert.assertEquals("Event status not correct", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[0].getStatus()); events[0].getStatus(), "Event status not correct");
// wait for reduce to start running // wait for reduce to start running
app.waitForState(reduceTask, TaskState.RUNNING); app.waitForState(reduceTask, TaskState.RUNNING);
@ -117,11 +117,11 @@ public Boolean get() {
app.waitForState(mapTask, TaskState.RUNNING); app.waitForState(mapTask, TaskState.RUNNING);
//map attempt must have become FAILED //map attempt must have become FAILED
Assert.assertEquals("Map TaskAttempt state not correct", Assertions.assertEquals(TaskAttemptState.FAILED, mapAttempt1.getState(),
TaskAttemptState.FAILED, mapAttempt1.getState()); "Map TaskAttempt state not correct");
Assert.assertEquals("Num attempts in Map Task not correct", Assertions.assertEquals(2, mapTask.getAttempts().size(),
2, mapTask.getAttempts().size()); "Num attempts in Map Task not correct");
Iterator<TaskAttempt> atIt = mapTask.getAttempts().values().iterator(); Iterator<TaskAttempt> atIt = mapTask.getAttempts().values().iterator();
atIt.next(); atIt.next();
@ -144,39 +144,41 @@ public Boolean get() {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
//previous completion event now becomes obsolete //previous completion event now becomes obsolete
Assert.assertEquals("Event status not correct", Assertions.assertEquals(TaskAttemptCompletionEventStatus.OBSOLETE,
TaskAttemptCompletionEventStatus.OBSOLETE, events[0].getStatus()); events[0].getStatus(), "Event status not correct");
events = job.getTaskAttemptCompletionEvents(0, 100); events = job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", Assertions.assertEquals(4, events.length,
4, events.length); "Num completion events not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt1.getID(), events[0].getAttemptId(),
mapAttempt1.getID(), events[0].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt1.getID(), events[1].getAttemptId(),
mapAttempt1.getID(), events[1].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt2.getID(), events[2].getAttemptId(),
mapAttempt2.getID(), events[2].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event redude attempt id not correct", Assertions.assertEquals(reduceAttempt.getID(), events[3].getAttemptId(),
reduceAttempt.getID(), events[3].getAttemptId()); "Event redude attempt id not correct");
Assert.assertEquals("Event status not correct for map attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.OBSOLETE,
TaskAttemptCompletionEventStatus.OBSOLETE, events[0].getStatus()); events[0].getStatus(), "Event status not correct for map attempt1");
Assert.assertEquals("Event status not correct for map attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.FAILED,
TaskAttemptCompletionEventStatus.FAILED, events[1].getStatus()); events[1].getStatus(), "Event status not correct for map attempt1");
Assert.assertEquals("Event status not correct for map attempt2", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[2].getStatus()); events[2].getStatus(), "Event status not correct for map attempt2");
Assert.assertEquals("Event status not correct for reduce attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[3].getStatus()); events[3].getStatus(), "Event status not correct for reduce attempt1");
TaskCompletionEvent mapEvents[] = TaskCompletionEvent mapEvents[] =
job.getMapAttemptCompletionEvents(0, 2); job.getMapAttemptCompletionEvents(0, 2);
TaskCompletionEvent convertedEvents[] = TypeConverter.fromYarn(events); TaskCompletionEvent convertedEvents[] = TypeConverter.fromYarn(events);
Assert.assertEquals("Incorrect number of map events", 2, mapEvents.length); Assertions.assertEquals(2, mapEvents.length,
Assert.assertArrayEquals("Unexpected map events", "Incorrect number of map events");
Arrays.copyOfRange(convertedEvents, 0, 2), mapEvents); Assertions.assertArrayEquals(Arrays.copyOfRange(convertedEvents, 0, 2),
mapEvents, "Unexpected map events");
mapEvents = job.getMapAttemptCompletionEvents(2, 200); mapEvents = job.getMapAttemptCompletionEvents(2, 200);
Assert.assertEquals("Incorrect number of map events", 1, mapEvents.length); Assertions.assertEquals(1, mapEvents.length,
Assert.assertEquals("Unexpected map event", convertedEvents[2], "Incorrect number of map events");
mapEvents[0]); Assertions.assertEquals(convertedEvents[2], mapEvents[0],
"Unexpected map event");
} }
/** /**
@ -197,8 +199,8 @@ public void testFetchFailureWithRecovery() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("Num tasks not correct", Assertions.assertEquals(2, job.getTasks().size(),
2, job.getTasks().size()); "Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -218,10 +220,10 @@ public void testFetchFailureWithRecovery() throws Exception {
TaskAttemptCompletionEvent[] events = TaskAttemptCompletionEvent[] events =
job.getTaskAttemptCompletionEvents(0, 100); job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", Assertions.assertEquals(1, events.length,
1, events.length); "Num completion events not correct");
Assert.assertEquals("Event status not correct", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[0].getStatus()); events[0].getStatus(), "Event status not correct");
// wait for reduce to start running // wait for reduce to start running
app.waitForState(reduceTask, TaskState.RUNNING); app.waitForState(reduceTask, TaskState.RUNNING);
@ -250,8 +252,8 @@ public void testFetchFailureWithRecovery() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("Num tasks not correct", Assertions.assertEquals(2, job.getTasks().size(),
2, job.getTasks().size()); "Num tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask = it.next(); mapTask = it.next();
reduceTask = it.next(); reduceTask = it.next();
@ -277,7 +279,8 @@ public void testFetchFailureWithRecovery() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
events = job.getTaskAttemptCompletionEvents(0, 100); events = job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", 2, events.length); Assertions.assertEquals(2, events.length,
"Num completion events not correct");
} }
@Test @Test
@ -290,8 +293,8 @@ public void testFetchFailureMultipleReduces() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("Num tasks not correct", Assertions.assertEquals(4, job.getTasks().size(),
4, job.getTasks().size()); "Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -313,10 +316,10 @@ public void testFetchFailureMultipleReduces() throws Exception {
TaskAttemptCompletionEvent[] events = TaskAttemptCompletionEvent[] events =
job.getTaskAttemptCompletionEvents(0, 100); job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", Assertions.assertEquals(1, events.length,
1, events.length); "Num completion events not correct");
Assert.assertEquals("Event status not correct", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED, events[0].getStatus(),
TaskAttemptCompletionEventStatus.SUCCEEDED, events[0].getStatus()); "Event status not correct");
// wait for reduce to start running // wait for reduce to start running
app.waitForState(reduceTask, TaskState.RUNNING); app.waitForState(reduceTask, TaskState.RUNNING);
@ -354,16 +357,16 @@ public void testFetchFailureMultipleReduces() throws Exception {
app.waitForState(mapTask, TaskState.RUNNING); app.waitForState(mapTask, TaskState.RUNNING);
//map attempt must have become FAILED //map attempt must have become FAILED
Assert.assertEquals("Map TaskAttempt state not correct", Assertions.assertEquals(TaskAttemptState.FAILED, mapAttempt1.getState(),
TaskAttemptState.FAILED, mapAttempt1.getState()); "Map TaskAttempt state not correct");
assertThat(mapAttempt1.getDiagnostics().get(0)) assertThat(mapAttempt1.getDiagnostics().get(0))
.isEqualTo("Too many fetch failures. Failing the attempt. " .isEqualTo("Too many fetch failures. Failing the attempt. "
+ "Last failure reported by " + "Last failure reported by "
+ reduceAttempt3.getID().toString() + " from host host3"); + reduceAttempt3.getID().toString() + " from host host3");
Assert.assertEquals("Num attempts in Map Task not correct", Assertions.assertEquals(2, mapTask.getAttempts().size(),
2, mapTask.getAttempts().size()); "Num attempts in Map Task not correct");
Iterator<TaskAttempt> atIt = mapTask.getAttempts().values().iterator(); Iterator<TaskAttempt> atIt = mapTask.getAttempts().values().iterator();
atIt.next(); atIt.next();
@ -396,39 +399,40 @@ public void testFetchFailureMultipleReduces() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
//previous completion event now becomes obsolete //previous completion event now becomes obsolete
Assert.assertEquals("Event status not correct", Assertions.assertEquals(TaskAttemptCompletionEventStatus.OBSOLETE, events[0].getStatus(),
TaskAttemptCompletionEventStatus.OBSOLETE, events[0].getStatus()); "Event status not correct");
events = job.getTaskAttemptCompletionEvents(0, 100); events = job.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Num completion events not correct", Assertions.assertEquals(6, events.length,
6, events.length); "Num completion events not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt1.getID(), events[0].getAttemptId(),
mapAttempt1.getID(), events[0].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt1.getID(), events[1].getAttemptId(),
mapAttempt1.getID(), events[1].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event map attempt id not correct", Assertions.assertEquals(mapAttempt2.getID(), events[2].getAttemptId(),
mapAttempt2.getID(), events[2].getAttemptId()); "Event map attempt id not correct");
Assert.assertEquals("Event reduce attempt id not correct", Assertions.assertEquals(reduceAttempt.getID(), events[3].getAttemptId(),
reduceAttempt.getID(), events[3].getAttemptId()); "Event reduce attempt id not correct");
Assert.assertEquals("Event status not correct for map attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.OBSOLETE,
TaskAttemptCompletionEventStatus.OBSOLETE, events[0].getStatus()); events[0].getStatus(), "Event status not correct for map attempt1");
Assert.assertEquals("Event status not correct for map attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.FAILED,
TaskAttemptCompletionEventStatus.FAILED, events[1].getStatus()); events[1].getStatus(), "Event status not correct for map attempt1");
Assert.assertEquals("Event status not correct for map attempt2", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[2].getStatus()); events[2].getStatus(), "Event status not correct for map attempt2");
Assert.assertEquals("Event status not correct for reduce attempt1", Assertions.assertEquals(TaskAttemptCompletionEventStatus.SUCCEEDED,
TaskAttemptCompletionEventStatus.SUCCEEDED, events[3].getStatus()); events[3].getStatus(), "Event status not correct for reduce attempt1");
TaskCompletionEvent mapEvents[] = TaskCompletionEvent mapEvents[] =
job.getMapAttemptCompletionEvents(0, 2); job.getMapAttemptCompletionEvents(0, 2);
TaskCompletionEvent convertedEvents[] = TypeConverter.fromYarn(events); TaskCompletionEvent convertedEvents[] = TypeConverter.fromYarn(events);
Assert.assertEquals("Incorrect number of map events", 2, mapEvents.length); Assertions.assertEquals(2, mapEvents.length,
Assert.assertArrayEquals("Unexpected map events", "Incorrect number of map events");
Arrays.copyOfRange(convertedEvents, 0, 2), mapEvents); Assertions.assertArrayEquals(Arrays.copyOfRange(convertedEvents, 0, 2),
mapEvents, "Unexpected map events");
mapEvents = job.getMapAttemptCompletionEvents(2, 200); mapEvents = job.getMapAttemptCompletionEvents(2, 200);
Assert.assertEquals("Incorrect number of map events", 1, mapEvents.length); Assertions.assertEquals(1, mapEvents.length, "Incorrect number of map events");
Assert.assertEquals("Unexpected map event", convertedEvents[2], Assertions.assertEquals(convertedEvents[2], mapEvents[0],
mapEvents[0]); "Unexpected map event");
} }
private void updateStatus(MRApp app, TaskAttempt attempt, Phase phase) { private void updateStatus(MRApp app, TaskAttempt attempt, Phase phase) {

View File

@ -59,8 +59,8 @@
import org.apache.hadoop.mapreduce.v2.app.rm.RMHeartbeatHandler; import org.apache.hadoop.mapreduce.v2.app.rm.RMHeartbeatHandler;
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Tests job end notification * Tests job end notification
@ -74,18 +74,18 @@ private void testNumRetries(Configuration conf) {
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "0"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "0");
conf.set(MRJobConfig.MR_JOB_END_RETRY_ATTEMPTS, "10"); conf.set(MRJobConfig.MR_JOB_END_RETRY_ATTEMPTS, "10");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected numTries to be 0, but was " + numTries, Assertions.assertTrue(numTries == 0,
numTries == 0 ); "Expected numTries to be 0, but was " + numTries);
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "1"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "1");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected numTries to be 1, but was " + numTries, Assertions.assertTrue(numTries == 1,
numTries == 1 ); "Expected numTries to be 1, but was " + numTries);
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "20"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "20");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected numTries to be 11, but was " + numTries, Assertions.assertTrue(numTries == 11 , "Expected numTries to be 11, but was "
numTries == 11 ); //11 because number of _retries_ is 10 + numTries); //11 because number of _retries_ is 10
} }
//Test maximum retry interval is capped by //Test maximum retry interval is capped by
@ -94,53 +94,53 @@ private void testWaitInterval(Configuration conf) {
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_RETRY_INTERVAL, "5000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_RETRY_INTERVAL, "5000");
conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "1000"); conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "1000");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected waitInterval to be 1000, but was " Assertions.assertTrue(waitInterval == 1000,
+ waitInterval, waitInterval == 1000); "Expected waitInterval to be 1000, but was " + waitInterval);
conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "10000"); conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "10000");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected waitInterval to be 5000, but was " Assertions.assertTrue(waitInterval == 5000,
+ waitInterval, waitInterval == 5000); "Expected waitInterval to be 5000, but was " + waitInterval);
//Test negative numbers are set to default //Test negative numbers are set to default
conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "-10"); conf.set(MRJobConfig.MR_JOB_END_RETRY_INTERVAL, "-10");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected waitInterval to be 5000, but was " Assertions.assertTrue(waitInterval == 5000,
+ waitInterval, waitInterval == 5000); "Expected waitInterval to be 5000, but was " + waitInterval);
} }
private void testTimeout(Configuration conf) { private void testTimeout(Configuration conf) {
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_TIMEOUT, "1000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_TIMEOUT, "1000");
setConf(conf); setConf(conf);
Assert.assertTrue("Expected timeout to be 1000, but was " Assertions.assertTrue(timeout == 1000,
+ timeout, timeout == 1000); "Expected timeout to be 1000, but was " + timeout);
} }
private void testProxyConfiguration(Configuration conf) { private void testProxyConfiguration(Configuration conf) {
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost");
setConf(conf); setConf(conf);
Assert.assertTrue("Proxy shouldn't be set because port wasn't specified", Assertions.assertTrue(proxyToUse.type() == Proxy.Type.DIRECT,
proxyToUse.type() == Proxy.Type.DIRECT); "Proxy shouldn't be set because port wasn't specified");
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost:someport"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost:someport");
setConf(conf); setConf(conf);
Assert.assertTrue("Proxy shouldn't be set because port wasn't numeric", Assertions.assertTrue(proxyToUse.type() == Proxy.Type.DIRECT,
proxyToUse.type() == Proxy.Type.DIRECT); "Proxy shouldn't be set because port wasn't numeric");
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost:1000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "somehost:1000");
setConf(conf); setConf(conf);
Assert.assertEquals("Proxy should have been set but wasn't ", Assertions.assertEquals("HTTP @ somehost:1000", proxyToUse.toString(),
"HTTP @ somehost:1000", proxyToUse.toString()); "Proxy should have been set but wasn't ");
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "socks@somehost:1000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "socks@somehost:1000");
setConf(conf); setConf(conf);
Assert.assertEquals("Proxy should have been socks but wasn't ", Assertions.assertEquals("SOCKS @ somehost:1000", proxyToUse.toString(),
"SOCKS @ somehost:1000", proxyToUse.toString()); "Proxy should have been socks but wasn't ");
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "SOCKS@somehost:1000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "SOCKS@somehost:1000");
setConf(conf); setConf(conf);
Assert.assertEquals("Proxy should have been socks but wasn't ", Assertions.assertEquals("SOCKS @ somehost:1000", proxyToUse.toString(),
"SOCKS @ somehost:1000", proxyToUse.toString()); "Proxy should have been socks but wasn't ");
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "sfafn@somehost:1000"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_PROXY, "sfafn@somehost:1000");
setConf(conf); setConf(conf);
Assert.assertEquals("Proxy should have been http but wasn't ", Assertions.assertEquals("HTTP @ somehost:1000", proxyToUse.toString(),
"HTTP @ somehost:1000", proxyToUse.toString()); "Proxy should have been http but wasn't ");
} }
@ -181,10 +181,10 @@ public void testNotifyRetries() throws InterruptedException {
this.setConf(conf); this.setConf(conf);
this.notify(jobReport); this.notify(jobReport);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
Assert.assertEquals("Only 1 try was expected but was : " Assertions.assertEquals(1, this.notificationCount,
+ this.notificationCount, 1, this.notificationCount); "Only 1 try was expected but was : " + this.notificationCount);
Assert.assertTrue("Should have taken more than 5 seconds it took " Assertions.assertTrue(endTime - startTime > 5000,
+ (endTime - startTime), endTime - startTime > 5000); "Should have taken more than 5 seconds it took " + (endTime - startTime));
conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "3"); conf.set(MRJobConfig.MR_JOB_END_NOTIFICATION_MAX_ATTEMPTS, "3");
conf.set(MRJobConfig.MR_JOB_END_RETRY_ATTEMPTS, "3"); conf.set(MRJobConfig.MR_JOB_END_RETRY_ATTEMPTS, "3");
@ -196,10 +196,10 @@ public void testNotifyRetries() throws InterruptedException {
this.setConf(conf); this.setConf(conf);
this.notify(jobReport); this.notify(jobReport);
endTime = System.currentTimeMillis(); endTime = System.currentTimeMillis();
Assert.assertEquals("Only 3 retries were expected but was : " Assertions.assertEquals(3, this.notificationCount,
+ this.notificationCount, 3, this.notificationCount); "Only 3 retries were expected but was : " + this.notificationCount);
Assert.assertTrue("Should have taken more than 9 seconds it took " Assertions.assertTrue(endTime - startTime > 9000,
+ (endTime - startTime), endTime - startTime > 9000); "Should have taken more than 9 seconds it took " + (endTime - startTime));
} }
@ -222,11 +222,11 @@ private void testNotificationOnLastRetry(boolean withRuntimeException)
doThrow(runtimeException).when(app).stop(); doThrow(runtimeException).when(app).stop();
} }
app.shutDownJob(); app.shutDownJob();
Assert.assertTrue(app.isLastAMRetry()); Assertions.assertTrue(app.isLastAMRetry());
Assert.assertEquals(1, JobEndServlet.calledTimes); Assertions.assertEquals(1, JobEndServlet.calledTimes);
Assert.assertEquals("jobid=" + job.getID() + "&status=SUCCEEDED", Assertions.assertEquals("jobid=" + job.getID() + "&status=SUCCEEDED",
JobEndServlet.requestUri.getQuery()); JobEndServlet.requestUri.getQuery());
Assert.assertEquals(JobState.SUCCEEDED.toString(), Assertions.assertEquals(JobState.SUCCEEDED.toString(),
JobEndServlet.foundJobState); JobEndServlet.foundJobState);
server.stop(); server.stop();
} }
@ -262,10 +262,10 @@ public void testAbsentNotificationOnNotLastRetryUnregistrationFailure()
app.shutDownJob(); app.shutDownJob();
// Not the last AM attempt. So user should that the job is still running. // Not the last AM attempt. So user should that the job is still running.
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertFalse(app.isLastAMRetry()); Assertions.assertFalse(app.isLastAMRetry());
Assert.assertEquals(0, JobEndServlet.calledTimes); Assertions.assertEquals(0, JobEndServlet.calledTimes);
Assert.assertNull(JobEndServlet.requestUri); Assertions.assertNull(JobEndServlet.requestUri);
Assert.assertNull(JobEndServlet.foundJobState); Assertions.assertNull(JobEndServlet.foundJobState);
server.stop(); server.stop();
} }
@ -294,11 +294,11 @@ public void testNotificationOnLastRetryUnregistrationFailure()
// Unregistration fails: isLastAMRetry is recalculated, this is // Unregistration fails: isLastAMRetry is recalculated, this is
///reboot will stop service internally, we don't need to shutdown twice ///reboot will stop service internally, we don't need to shutdown twice
app.waitForServiceToStop(10000); app.waitForServiceToStop(10000);
Assert.assertFalse(app.isLastAMRetry()); Assertions.assertFalse(app.isLastAMRetry());
// Since it's not last retry, JobEndServlet didn't called // Since it's not last retry, JobEndServlet didn't called
Assert.assertEquals(0, JobEndServlet.calledTimes); Assertions.assertEquals(0, JobEndServlet.calledTimes);
Assert.assertNull(JobEndServlet.requestUri); Assertions.assertNull(JobEndServlet.requestUri);
Assert.assertNull(JobEndServlet.foundJobState); Assertions.assertNull(JobEndServlet.foundJobState);
server.stop(); server.stop();
} }
@ -321,7 +321,7 @@ public void testCustomNotifierClass() throws InterruptedException {
this.notify(jobReport); this.notify(jobReport);
final URL urlToNotify = CustomNotifier.urlToNotify; final URL urlToNotify = CustomNotifier.urlToNotify;
Assert.assertEquals("http://example.com?jobId=mock-Id&jobStatus=SUCCEEDED", Assertions.assertEquals("http://example.com?jobId=mock-Id&jobStatus=SUCCEEDED",
urlToNotify.toString()); urlToNotify.toString());
} }

View File

@ -23,7 +23,7 @@
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.apache.hadoop.service.Service; import org.apache.hadoop.service.Service;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.v2.api.records.JobId; import org.apache.hadoop.mapreduce.v2.api.records.JobId;
@ -48,7 +48,7 @@
import org.apache.hadoop.yarn.event.AsyncDispatcher; import org.apache.hadoop.yarn.event.AsyncDispatcher;
import org.apache.hadoop.yarn.event.Dispatcher; import org.apache.hadoop.yarn.event.Dispatcher;
import org.apache.hadoop.yarn.event.Event; import org.apache.hadoop.yarn.event.Event;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Tests the state machine with respect to Job/Task/TaskAttempt kill scenarios. * Tests the state machine with respect to Job/Task/TaskAttempt kill scenarios.
@ -83,18 +83,17 @@ public void testKillJob() throws Exception {
app.waitForState(Service.STATE.STOPPED); app.waitForState(Service.STATE.STOPPED);
Map<TaskId,Task> tasks = job.getTasks(); Map<TaskId,Task> tasks = job.getTasks();
Assert.assertEquals("No of tasks is not correct", 1, Assertions.assertEquals(1, tasks.size(),
tasks.size()); "No of tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
Assert.assertEquals("Task state not correct", TaskState.KILLED, Assertions.assertEquals(TaskState.KILLED,
task.getReport().getTaskState()); task.getReport().getTaskState(), "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = Map<TaskAttemptId, TaskAttempt> attempts =
tasks.values().iterator().next().getAttempts(); tasks.values().iterator().next().getAttempts();
Assert.assertEquals("No of attempts is not correct", 1, Assertions.assertEquals(1, attempts.size(), "No of attempts is not correct");
attempts.size());
Iterator<TaskAttempt> it = attempts.values().iterator(); Iterator<TaskAttempt> it = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.KILLED, Assertions.assertEquals(TaskAttemptState.KILLED,
it.next().getReport().getTaskAttemptState()); it.next().getReport().getTaskAttemptState(), "Attempt state not correct");
} }
@Test @Test
@ -107,8 +106,8 @@ public void testKillTask() throws Exception {
//wait and vailidate for Job to become RUNNING //wait and vailidate for Job to become RUNNING
app.waitForInternalState((JobImpl) job, JobStateInternal.RUNNING); app.waitForInternalState((JobImpl) job, JobStateInternal.RUNNING);
Map<TaskId,Task> tasks = job.getTasks(); Map<TaskId,Task> tasks = job.getTasks();
Assert.assertEquals("No of tasks is not correct", 2, Assertions.assertEquals(2, tasks.size(),
tasks.size()); "No of tasks is not correct");
Iterator<Task> it = tasks.values().iterator(); Iterator<Task> it = tasks.values().iterator();
Task task1 = it.next(); Task task1 = it.next();
Task task2 = it.next(); Task task2 = it.next();
@ -126,23 +125,23 @@ public void testKillTask() throws Exception {
//first Task is killed and second is Succeeded //first Task is killed and second is Succeeded
//Job is succeeded //Job is succeeded
Assert.assertEquals("Task state not correct", TaskState.KILLED, Assertions.assertEquals(TaskState.KILLED, task1.getReport().getTaskState(),
task1.getReport().getTaskState()); "Task state not correct");
Assert.assertEquals("Task state not correct", TaskState.SUCCEEDED, Assertions.assertEquals(TaskState.SUCCEEDED, task2.getReport().getTaskState(),
task2.getReport().getTaskState()); "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = task1.getAttempts(); Map<TaskAttemptId, TaskAttempt> attempts = task1.getAttempts();
Assert.assertEquals("No of attempts is not correct", 1, Assertions.assertEquals(1, attempts.size(),
attempts.size()); "No of attempts is not correct");
Iterator<TaskAttempt> iter = attempts.values().iterator(); Iterator<TaskAttempt> iter = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.KILLED, Assertions.assertEquals(TaskAttemptState.KILLED,
iter.next().getReport().getTaskAttemptState()); iter.next().getReport().getTaskAttemptState(), "Attempt state not correct");
attempts = task2.getAttempts(); attempts = task2.getAttempts();
Assert.assertEquals("No of attempts is not correct", 1, Assertions.assertEquals(1, attempts.size(),
attempts.size()); "No of attempts is not correct");
iter = attempts.values().iterator(); iter = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.SUCCEEDED, Assertions.assertEquals(TaskAttemptState.SUCCEEDED,
iter.next().getReport().getTaskAttemptState()); iter.next().getReport().getTaskAttemptState(), "Attempt state not correct");
} }
@Test @Test
@ -194,7 +193,8 @@ public Dispatcher createDispatcher() {
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
JobId jobId = app.getJobId(); JobId jobId = app.getJobId();
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 2, job.getTasks().size()); Assertions.assertEquals(2, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -232,7 +232,8 @@ public Dispatcher createDispatcher() {
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
JobId jobId = app.getJobId(); JobId jobId = app.getJobId();
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 2, job.getTasks().size()); Assertions.assertEquals(2, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -280,7 +281,8 @@ public Dispatcher createDispatcher() {
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
JobId jobId = app.getJobId(); JobId jobId = app.getJobId();
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 2, job.getTasks().size()); Assertions.assertEquals(2, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask = it.next(); Task mapTask = it.next();
Task reduceTask = it.next(); Task reduceTask = it.next();
@ -370,8 +372,8 @@ public void testKillTaskAttempt() throws Exception {
//wait and vailidate for Job to become RUNNING //wait and vailidate for Job to become RUNNING
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Map<TaskId,Task> tasks = job.getTasks(); Map<TaskId,Task> tasks = job.getTasks();
Assert.assertEquals("No of tasks is not correct", 2, Assertions.assertEquals(2, tasks.size(),
tasks.size()); "No of tasks is not correct");
Iterator<Task> it = tasks.values().iterator(); Iterator<Task> it = tasks.values().iterator();
Task task1 = it.next(); Task task1 = it.next();
Task task2 = it.next(); Task task2 = it.next();
@ -394,26 +396,26 @@ public void testKillTaskAttempt() throws Exception {
//first Task will have two attempts 1st is killed, 2nd Succeeds //first Task will have two attempts 1st is killed, 2nd Succeeds
//both Tasks and Job succeeds //both Tasks and Job succeeds
Assert.assertEquals("Task state not correct", TaskState.SUCCEEDED, Assertions.assertEquals(TaskState.SUCCEEDED,
task1.getReport().getTaskState()); task1.getReport().getTaskState(), "Task state not correct");
Assert.assertEquals("Task state not correct", TaskState.SUCCEEDED, Assertions.assertEquals(TaskState.SUCCEEDED,
task2.getReport().getTaskState()); task2.getReport().getTaskState(), "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = task1.getAttempts(); Map<TaskAttemptId, TaskAttempt> attempts = task1.getAttempts();
Assert.assertEquals("No of attempts is not correct", 2, Assertions.assertEquals(2, attempts.size(),
attempts.size()); "No of attempts is not correct");
Iterator<TaskAttempt> iter = attempts.values().iterator(); Iterator<TaskAttempt> iter = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.KILLED, Assertions.assertEquals(TaskAttemptState.KILLED,
iter.next().getReport().getTaskAttemptState()); iter.next().getReport().getTaskAttemptState(), "Attempt state not correct");
Assert.assertEquals("Attempt state not correct", TaskAttemptState.SUCCEEDED, Assertions.assertEquals(TaskAttemptState.SUCCEEDED,
iter.next().getReport().getTaskAttemptState()); iter.next().getReport().getTaskAttemptState(), "Attempt state not correct");
attempts = task2.getAttempts(); attempts = task2.getAttempts();
Assert.assertEquals("No of attempts is not correct", 1, Assertions.assertEquals(1, attempts.size(),
attempts.size()); "No of attempts is not correct");
iter = attempts.values().iterator(); iter = attempts.values().iterator();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.SUCCEEDED, Assertions.assertEquals(TaskAttemptState.SUCCEEDED,
iter.next().getReport().getTaskAttemptState()); iter.next().getReport().getTaskAttemptState(), "Attempt state not correct");
} }
static class BlockingMRApp extends MRApp { static class BlockingMRApp extends MRApp {

View File

@ -47,7 +47,7 @@
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestKillAMPreemptionPolicy { public class TestKillAMPreemptionPolicy {
private final RecordFactory recordFactory = RecordFactoryProvider private final RecordFactory recordFactory = RecordFactoryProvider

View File

@ -30,7 +30,7 @@
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.MRJobConfig;
@ -68,7 +68,7 @@
import org.apache.hadoop.yarn.event.Dispatcher; import org.apache.hadoop.yarn.event.Dispatcher;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
/** /**
@ -83,7 +83,7 @@ public void testMapReduce() throws Exception {
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertEquals(System.getProperty("user.name"),job.getUserName()); Assertions.assertEquals(System.getProperty("user.name"),job.getUserName());
} }
@Test @Test
@ -106,7 +106,7 @@ public void testCommitPending() throws Exception {
MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true); MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true);
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(), "Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -151,7 +151,7 @@ public void testCompletedMapsForReduceSlowstart() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("Num tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -170,8 +170,8 @@ public void testCompletedMapsForReduceSlowstart() throws Exception {
app.waitForState(task2Attempt, TaskAttemptState.RUNNING); app.waitForState(task2Attempt, TaskAttemptState.RUNNING);
// reduces must be in NEW state // reduces must be in NEW state
Assert.assertEquals("Reduce Task state not correct", Assertions.assertEquals(TaskState.NEW,
TaskState.NEW, reduceTask.getReport().getTaskState()); reduceTask.getReport().getTaskState(), "Reduce Task state not correct");
//send the done signal to the 1st map task //send the done signal to the 1st map task
app.getContext().getEventHandler().handle( app.getContext().getEventHandler().handle(
@ -224,7 +224,8 @@ public void testUpdatedNodes() throws Exception {
final Job job1 = app.submit(conf); final Job job1 = app.submit(conf);
app.waitForState(job1, JobState.RUNNING); app.waitForState(job1, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 4, job1.getTasks().size()); Assertions.assertEquals(4, job1.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job1.getTasks().values().iterator(); Iterator<Task> it = job1.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -239,7 +240,7 @@ public void testUpdatedNodes() throws Exception {
.next(); .next();
NodeId node1 = task1Attempt.getNodeId(); NodeId node1 = task1Attempt.getNodeId();
NodeId node2 = task2Attempt.getNodeId(); NodeId node2 = task2Attempt.getNodeId();
Assert.assertEquals(node1, node2); Assertions.assertEquals(node1, node2);
// send the done signal to the task // send the done signal to the task
app.getContext() app.getContext()
@ -271,8 +272,8 @@ public Boolean get() {
TaskAttemptCompletionEvent[] events = job1.getTaskAttemptCompletionEvents TaskAttemptCompletionEvent[] events = job1.getTaskAttemptCompletionEvents
(0, 100); (0, 100);
Assert.assertEquals("Expecting 2 completion events for success", 2, Assertions.assertEquals(2, events.length,
events.length); "Expecting 2 completion events for success");
// send updated nodes info // send updated nodes info
ArrayList<NodeReport> updatedNodes = new ArrayList<NodeReport>(); ArrayList<NodeReport> updatedNodes = new ArrayList<NodeReport>();
@ -297,8 +298,8 @@ public Boolean get() {
}, checkIntervalMillis, waitForMillis); }, checkIntervalMillis, waitForMillis);
events = job1.getTaskAttemptCompletionEvents(0, 100); events = job1.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Expecting 2 more completion events for killed", 4, Assertions.assertEquals(4, events.length,
events.length); "Expecting 2 more completion events for killed");
// 2 map task attempts which were killed above should be requested from // 2 map task attempts which were killed above should be requested from
// container allocator with the previous map task marked as failed. If // container allocator with the previous map task marked as failed. If
// this happens allocator will request the container for this mapper from // this happens allocator will request the container for this mapper from
@ -335,8 +336,8 @@ public Boolean get() {
}, checkIntervalMillis, waitForMillis); }, checkIntervalMillis, waitForMillis);
events = job1.getTaskAttemptCompletionEvents(0, 100); events = job1.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Expecting 1 more completion events for success", 5, Assertions.assertEquals(5, events.length,
events.length); "Expecting 1 more completion events for success");
// Crash the app again. // Crash the app again.
app.stop(); app.stop();
@ -351,7 +352,8 @@ public Boolean get() {
final Job job2 = app.submit(conf); final Job job2 = app.submit(conf);
app.waitForState(job2, JobState.RUNNING); app.waitForState(job2, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 4, job2.getTasks().size()); Assertions.assertEquals(4, job2.getTasks().size(),
"No of tasks not correct");
it = job2.getTasks().values().iterator(); it = job2.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -372,9 +374,8 @@ public Boolean get() {
}, checkIntervalMillis, waitForMillis); }, checkIntervalMillis, waitForMillis);
events = job2.getTaskAttemptCompletionEvents(0, 100); events = job2.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals( Assertions.assertEquals(2, events.length,
"Expecting 2 completion events for killed & success of map1", 2, "Expecting 2 completion events for killed & success of map1");
events.length);
task2Attempt = mapTask2.getAttempts().values().iterator().next(); task2Attempt = mapTask2.getAttempts().values().iterator().next();
app.getContext() app.getContext()
@ -394,8 +395,8 @@ public Boolean get() {
}, checkIntervalMillis, waitForMillis); }, checkIntervalMillis, waitForMillis);
events = job2.getTaskAttemptCompletionEvents(0, 100); events = job2.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Expecting 1 more completion events for success", 3, Assertions.assertEquals(3, events.length,
events.length); "Expecting 1 more completion events for success");
app.waitForState(reduceTask1, TaskState.RUNNING); app.waitForState(reduceTask1, TaskState.RUNNING);
app.waitForState(reduceTask2, TaskState.RUNNING); app.waitForState(reduceTask2, TaskState.RUNNING);
@ -433,8 +434,8 @@ public Boolean get() {
} }
}, checkIntervalMillis, waitForMillis); }, checkIntervalMillis, waitForMillis);
events = job2.getTaskAttemptCompletionEvents(0, 100); events = job2.getTaskAttemptCompletionEvents(0, 100);
Assert.assertEquals("Expecting 2 more completion events for reduce success", Assertions.assertEquals(5, events.length,
5, events.length); "Expecting 2 more completion events for reduce success");
// job succeeds // job succeeds
app.waitForState(job2, JobState.SUCCEEDED); app.waitForState(job2, JobState.SUCCEEDED);
@ -472,7 +473,8 @@ public void testJobError() throws Exception {
MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true); MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true);
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -493,7 +495,7 @@ public void testJobSuccess() throws Exception {
JobImpl job = (JobImpl) app.submit(new Configuration()); JobImpl job = (JobImpl) app.submit(new Configuration());
app.waitForInternalState(job, JobStateInternal.SUCCEEDED); app.waitForInternalState(job, JobStateInternal.SUCCEEDED);
// AM is not unregistered // AM is not unregistered
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
// imitate that AM is unregistered // imitate that AM is unregistered
app.successfullyUnregistered.set(true); app.successfullyUnregistered.set(true);
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
@ -505,7 +507,8 @@ public void testJobRebootNotLastRetryOnUnregistrationFailure()
MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true); MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true);
Job job = app.submit(new Configuration()); Job job = app.submit(new Configuration());
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -530,7 +533,8 @@ public void testJobRebootOnLastRetryOnUnregistrationFailure()
Configuration conf = new Configuration(); Configuration conf = new Configuration();
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -624,7 +628,7 @@ public void handle(ContainerLauncherEvent event) {
(TaskAttemptImpl) taskAttempts.iterator().next(); (TaskAttemptImpl) taskAttempts.iterator().next();
// Container from RM should pass through to the launcher. Container object // Container from RM should pass through to the launcher. Container object
// should be the same. // should be the same.
Assert.assertTrue(taskAttempt.container Assertions.assertTrue(taskAttempt.container
== containerObtainedByContainerLauncher); == containerObtainedByContainerLauncher);
} }

View File

@ -20,7 +20,7 @@
import java.io.IOException; import java.io.IOException;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.jobhistory.JobHistoryEvent; import org.apache.hadoop.mapreduce.jobhistory.JobHistoryEvent;
@ -35,11 +35,13 @@
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
public class TestMRAppComponentDependencies { public class TestMRAppComponentDependencies {
@Test(timeout = 20000) @Test
@Timeout(20000)
public void testComponentStopOrder() throws Exception { public void testComponentStopOrder() throws Exception {
@SuppressWarnings("resource") @SuppressWarnings("resource")
TestMRApp app = new TestMRApp(1, 1, true, this.getClass().getName(), true); TestMRApp app = new TestMRApp(1, 1, true, this.getClass().getName(), true);
@ -54,8 +56,8 @@ public void testComponentStopOrder() throws Exception {
} }
// assert JobHistoryEventHandlerStopped and then clientServiceStopped // assert JobHistoryEventHandlerStopped and then clientServiceStopped
Assert.assertEquals(1, app.JobHistoryEventHandlerStopped); Assertions.assertEquals(1, app.JobHistoryEventHandlerStopped);
Assert.assertEquals(2, app.clientServiceStopped); Assertions.assertEquals(2, app.clientServiceStopped);
} }
private final class TestMRApp extends MRApp { private final class TestMRApp extends MRApp {

View File

@ -18,9 +18,9 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@ -40,7 +40,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.FileContext;
@ -84,10 +84,11 @@
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.slf4j.event.Level; import org.slf4j.event.Level;
@ -104,7 +105,7 @@ public class TestMRAppMaster {
static String stagingDir = new Path(testDir, "staging").toString(); static String stagingDir = new Path(testDir, "staging").toString();
private static FileContext localFS = null; private static FileContext localFS = null;
@BeforeClass @BeforeAll
public static void setup() throws AccessControlException, public static void setup() throws AccessControlException,
FileNotFoundException, IllegalArgumentException, IOException { FileNotFoundException, IllegalArgumentException, IOException {
//Do not error out if metrics are inited multiple times //Do not error out if metrics are inited multiple times
@ -116,7 +117,7 @@ public static void setup() throws AccessControlException,
new File(testDir.toString()).mkdir(); new File(testDir.toString()).mkdir();
} }
@Before @BeforeEach
public void prepare() throws IOException { public void prepare() throws IOException {
File dir = new File(stagingDir); File dir = new File(stagingDir);
if(dir.exists()) { if(dir.exists()) {
@ -125,7 +126,7 @@ public void prepare() throws IOException {
dir.mkdirs(); dir.mkdirs();
} }
@AfterClass @AfterAll
public static void cleanup() throws IOException { public static void cleanup() throws IOException {
localFS.delete(testDir, true); localFS.delete(testDir, true);
} }
@ -226,8 +227,8 @@ public void testMRAppMasterJobLaunchTime() throws IOException,
"host", -1, -1, System.currentTimeMillis()); "host", -1, -1, System.currentTimeMillis());
MRAppMaster.initAndStartAppMaster(appMaster, conf, userName); MRAppMaster.initAndStartAppMaster(appMaster, conf, userName);
appMaster.stop(); appMaster.stop();
assertTrue("Job launch time should not be negative.", assertTrue(appMaster.jobLaunchTime.get() >= 0,
appMaster.jobLaunchTime.get() >= 0); "Job launch time should not be negative.");
} }
@Test @Test
@ -343,7 +344,8 @@ public void testMRAppMasterMissingStaging() throws IOException,
appMaster.stop(); appMaster.stop();
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testMRAppMasterMaxAppAttempts() throws IOException, public void testMRAppMasterMaxAppAttempts() throws IOException,
InterruptedException { InterruptedException {
// No matter what's the maxAppAttempt or attempt id, the isLastRetry always // No matter what's the maxAppAttempt or attempt id, the isLastRetry always
@ -368,8 +370,8 @@ public void testMRAppMasterMaxAppAttempts() throws IOException,
new MRAppMasterTest(applicationAttemptId, containerId, "host", -1, -1, new MRAppMasterTest(applicationAttemptId, containerId, "host", -1, -1,
System.currentTimeMillis(), false, true); System.currentTimeMillis(), false, true);
MRAppMaster.initAndStartAppMaster(appMaster, conf, userName); MRAppMaster.initAndStartAppMaster(appMaster, conf, userName);
assertEquals("isLastAMRetry is correctly computed.", expectedBools[i], assertEquals(expectedBools[i], appMaster.isLastAMRetry(),
appMaster.isLastAMRetry()); "isLastAMRetry is correctly computed.");
} }
} }
@ -465,37 +467,37 @@ public void testMRAppMasterCredentials() throws Exception {
// Now validate the task credentials // Now validate the task credentials
Credentials appMasterCreds = appMaster.getCredentials(); Credentials appMasterCreds = appMaster.getCredentials();
Assert.assertNotNull(appMasterCreds); Assertions.assertNotNull(appMasterCreds);
Assert.assertEquals(1, appMasterCreds.numberOfSecretKeys()); Assertions.assertEquals(1, appMasterCreds.numberOfSecretKeys());
Assert.assertEquals(1, appMasterCreds.numberOfTokens()); Assertions.assertEquals(1, appMasterCreds.numberOfTokens());
// Validate the tokens - app token should not be present // Validate the tokens - app token should not be present
Token<? extends TokenIdentifier> usedToken = Token<? extends TokenIdentifier> usedToken =
appMasterCreds.getToken(tokenAlias); appMasterCreds.getToken(tokenAlias);
Assert.assertNotNull(usedToken); Assertions.assertNotNull(usedToken);
Assert.assertEquals(storedToken, usedToken); Assertions.assertEquals(storedToken, usedToken);
// Validate the keys // Validate the keys
byte[] usedKey = appMasterCreds.getSecretKey(keyAlias); byte[] usedKey = appMasterCreds.getSecretKey(keyAlias);
Assert.assertNotNull(usedKey); Assertions.assertNotNull(usedKey);
Assert.assertEquals("mySecretKey", new String(usedKey)); Assertions.assertEquals("mySecretKey", new String(usedKey));
// The credentials should also be added to conf so that OuputCommitter can // The credentials should also be added to conf so that OuputCommitter can
// access it - app token should not be present // access it - app token should not be present
Credentials confCredentials = conf.getCredentials(); Credentials confCredentials = conf.getCredentials();
Assert.assertEquals(1, confCredentials.numberOfSecretKeys()); Assertions.assertEquals(1, confCredentials.numberOfSecretKeys());
Assert.assertEquals(1, confCredentials.numberOfTokens()); Assertions.assertEquals(1, confCredentials.numberOfTokens());
Assert.assertEquals(storedToken, confCredentials.getToken(tokenAlias)); Assertions.assertEquals(storedToken, confCredentials.getToken(tokenAlias));
Assert.assertEquals("mySecretKey", Assertions.assertEquals("mySecretKey",
new String(confCredentials.getSecretKey(keyAlias))); new String(confCredentials.getSecretKey(keyAlias)));
// Verify the AM's ugi - app token should be present // Verify the AM's ugi - app token should be present
Credentials ugiCredentials = appMaster.getUgi().getCredentials(); Credentials ugiCredentials = appMaster.getUgi().getCredentials();
Assert.assertEquals(1, ugiCredentials.numberOfSecretKeys()); Assertions.assertEquals(1, ugiCredentials.numberOfSecretKeys());
Assert.assertEquals(2, ugiCredentials.numberOfTokens()); Assertions.assertEquals(2, ugiCredentials.numberOfTokens());
Assert.assertEquals(storedToken, ugiCredentials.getToken(tokenAlias)); Assertions.assertEquals(storedToken, ugiCredentials.getToken(tokenAlias));
Assert.assertEquals(appToken, ugiCredentials.getToken(appTokenService)); Assertions.assertEquals(appToken, ugiCredentials.getToken(appTokenService));
Assert.assertEquals("mySecretKey", Assertions.assertEquals("mySecretKey",
new String(ugiCredentials.getSecretKey(keyAlias))); new String(ugiCredentials.getSecretKey(keyAlias)));
@ -525,10 +527,10 @@ public void testMRAppMasterShutDownJob() throws Exception,
doNothing().when(appMaster).serviceStop(); doNothing().when(appMaster).serviceStop();
// Test normal shutdown. // Test normal shutdown.
appMaster.shutDownJob(); appMaster.shutDownJob();
Assert.assertTrue("Expected shutDownJob to terminate.", Assertions.assertTrue(ExitUtil.terminateCalled(),
ExitUtil.terminateCalled()); "Expected shutDownJob to terminate.");
Assert.assertEquals("Expected shutDownJob to exit with status code of 0.", Assertions.assertEquals(0, ExitUtil.getFirstExitException().status,
0, ExitUtil.getFirstExitException().status); "Expected shutDownJob to exit with status code of 0.");
// Test shutdown with exception. // Test shutdown with exception.
ExitUtil.resetFirstExitException(); ExitUtil.resetFirstExitException();
@ -536,10 +538,10 @@ public void testMRAppMasterShutDownJob() throws Exception,
doThrow(new RuntimeException(msg)) doThrow(new RuntimeException(msg))
.when(appMaster).notifyIsLastAMRetry(anyBoolean()); .when(appMaster).notifyIsLastAMRetry(anyBoolean());
appMaster.shutDownJob(); appMaster.shutDownJob();
assertTrue("Expected message from ExitUtil.ExitException to be " + msg, assertTrue(ExitUtil.getFirstExitException().getMessage().contains(msg),
ExitUtil.getFirstExitException().getMessage().contains(msg)); "Expected message from ExitUtil.ExitException to be " + msg);
Assert.assertEquals("Expected shutDownJob to exit with status code of 1.", Assertions.assertEquals(1, ExitUtil.getFirstExitException().status,
1, ExitUtil.getFirstExitException().status); "Expected shutDownJob to exit with status code of 1.");
} }
private void verifyFailedStatus(MRAppMasterTest appMaster, private void verifyFailedStatus(MRAppMasterTest appMaster,

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException; import java.io.IOException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
@ -26,7 +26,7 @@
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.JobACL; import org.apache.hadoop.mapreduce.JobACL;
@ -70,7 +70,7 @@
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.ipc.YarnRPC; import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestMRClientService { public class TestMRClientService {
@ -82,7 +82,8 @@ public void test() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -116,8 +117,8 @@ public void test() throws Exception {
GetCountersRequest gcRequest = GetCountersRequest gcRequest =
recordFactory.newRecordInstance(GetCountersRequest.class); recordFactory.newRecordInstance(GetCountersRequest.class);
gcRequest.setJobId(job.getID()); gcRequest.setJobId(job.getID());
Assert.assertNotNull("Counters is null", Assertions.assertNotNull(proxy.getCounters(gcRequest).getCounters(),
proxy.getCounters(gcRequest).getCounters()); "Counters is null");
GetJobReportRequest gjrRequest = GetJobReportRequest gjrRequest =
recordFactory.newRecordInstance(GetJobReportRequest.class); recordFactory.newRecordInstance(GetJobReportRequest.class);
@ -131,14 +132,14 @@ public void test() throws Exception {
gtaceRequest.setJobId(job.getID()); gtaceRequest.setJobId(job.getID());
gtaceRequest.setFromEventId(0); gtaceRequest.setFromEventId(0);
gtaceRequest.setMaxEvents(10); gtaceRequest.setMaxEvents(10);
Assert.assertNotNull("TaskCompletionEvents is null", Assertions.assertNotNull(proxy.getTaskAttemptCompletionEvents(gtaceRequest).
proxy.getTaskAttemptCompletionEvents(gtaceRequest).getCompletionEventList()); getCompletionEventList(), "TaskCompletionEvents is null");
GetDiagnosticsRequest gdRequest = GetDiagnosticsRequest gdRequest =
recordFactory.newRecordInstance(GetDiagnosticsRequest.class); recordFactory.newRecordInstance(GetDiagnosticsRequest.class);
gdRequest.setTaskAttemptId(attempt.getID()); gdRequest.setTaskAttemptId(attempt.getID());
Assert.assertNotNull("Diagnostics is null", Assertions.assertNotNull(proxy.getDiagnostics(gdRequest).
proxy.getDiagnostics(gdRequest).getDiagnosticsList()); getDiagnosticsList(), "Diagnostics is null");
GetTaskAttemptReportRequest gtarRequest = GetTaskAttemptReportRequest gtarRequest =
recordFactory.newRecordInstance(GetTaskAttemptReportRequest.class); recordFactory.newRecordInstance(GetTaskAttemptReportRequest.class);
@ -151,31 +152,32 @@ public void test() throws Exception {
GetTaskReportRequest gtrRequest = GetTaskReportRequest gtrRequest =
recordFactory.newRecordInstance(GetTaskReportRequest.class); recordFactory.newRecordInstance(GetTaskReportRequest.class);
gtrRequest.setTaskId(task.getID()); gtrRequest.setTaskId(task.getID());
Assert.assertNotNull("TaskReport is null", Assertions.assertNotNull(proxy.getTaskReport(gtrRequest).getTaskReport(),
proxy.getTaskReport(gtrRequest).getTaskReport()); "TaskReport is null");
GetTaskReportsRequest gtreportsRequest = GetTaskReportsRequest gtreportsRequest =
recordFactory.newRecordInstance(GetTaskReportsRequest.class); recordFactory.newRecordInstance(GetTaskReportsRequest.class);
gtreportsRequest.setJobId(job.getID()); gtreportsRequest.setJobId(job.getID());
gtreportsRequest.setTaskType(TaskType.MAP); gtreportsRequest.setTaskType(TaskType.MAP);
Assert.assertNotNull("TaskReports for map is null", Assertions.assertNotNull(proxy.getTaskReports(gtreportsRequest)
proxy.getTaskReports(gtreportsRequest).getTaskReportList()); .getTaskReportList(), "TaskReports for map is null");
gtreportsRequest = gtreportsRequest =
recordFactory.newRecordInstance(GetTaskReportsRequest.class); recordFactory.newRecordInstance(GetTaskReportsRequest.class);
gtreportsRequest.setJobId(job.getID()); gtreportsRequest.setJobId(job.getID());
gtreportsRequest.setTaskType(TaskType.REDUCE); gtreportsRequest.setTaskType(TaskType.REDUCE);
Assert.assertNotNull("TaskReports for reduce is null", Assertions.assertNotNull(proxy.getTaskReports(gtreportsRequest).getTaskReportList(),
proxy.getTaskReports(gtreportsRequest).getTaskReportList()); "TaskReports for reduce is null");
List<String> diag = proxy.getDiagnostics(gdRequest).getDiagnosticsList(); List<String> diag = proxy.getDiagnostics(gdRequest).getDiagnosticsList();
Assert.assertEquals("Num diagnostics not correct", 1 , diag.size()); Assertions.assertEquals(1 , diag.size(),
Assert.assertEquals("Diag 1 not correct", "Num diagnostics not correct");
diagnostic1, diag.get(0).toString()); Assertions.assertEquals(diagnostic1, diag.get(0).toString(),
"Diag 1 not correct");
TaskReport taskReport = proxy.getTaskReport(gtrRequest).getTaskReport(); TaskReport taskReport = proxy.getTaskReport(gtrRequest).getTaskReport();
Assert.assertEquals("Num diagnostics not correct", 1, Assertions.assertEquals(1, taskReport.getDiagnosticsCount(),
taskReport.getDiagnosticsCount()); "Num diagnostics not correct");
//send the done signal to the task //send the done signal to the task
app.getContext().getEventHandler().handle( app.getContext().getEventHandler().handle(
@ -207,7 +209,8 @@ public void testViewAclOnlyCannotModify() throws Exception {
conf.set(MRJobConfig.JOB_ACL_VIEW_JOB, "viewonlyuser"); conf.set(MRJobConfig.JOB_ACL_VIEW_JOB, "viewonlyuser");
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size()); Assertions.assertEquals(1, job.getTasks().size(),
"Num tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task task = it.next(); Task task = it.next();
app.waitForState(task, TaskState.RUNNING); app.waitForState(task, TaskState.RUNNING);
@ -217,10 +220,10 @@ public void testViewAclOnlyCannotModify() throws Exception {
UserGroupInformation viewOnlyUser = UserGroupInformation viewOnlyUser =
UserGroupInformation.createUserForTesting( UserGroupInformation.createUserForTesting(
"viewonlyuser", new String[] {}); "viewonlyuser", new String[] {});
Assert.assertTrue("viewonlyuser cannot view job", Assertions.assertTrue(job.checkAccess(viewOnlyUser, JobACL.VIEW_JOB),
job.checkAccess(viewOnlyUser, JobACL.VIEW_JOB)); "viewonlyuser cannot view job");
Assert.assertFalse("viewonlyuser can modify job", Assertions.assertFalse(job.checkAccess(viewOnlyUser, JobACL.MODIFY_JOB),
job.checkAccess(viewOnlyUser, JobACL.MODIFY_JOB)); "viewonlyuser can modify job");
MRClientProtocol client = viewOnlyUser.doAs( MRClientProtocol client = viewOnlyUser.doAs(
new PrivilegedExceptionAction<MRClientProtocol>() { new PrivilegedExceptionAction<MRClientProtocol>() {
@Override @Override
@ -273,28 +276,28 @@ public MRClientProtocol run() throws Exception {
} }
private void verifyJobReport(JobReport jr) { private void verifyJobReport(JobReport jr) {
Assert.assertNotNull("JobReport is null", jr); Assertions.assertNotNull(jr, "JobReport is null");
List<AMInfo> amInfos = jr.getAMInfos(); List<AMInfo> amInfos = jr.getAMInfos();
Assert.assertEquals(1, amInfos.size()); Assertions.assertEquals(1, amInfos.size());
Assert.assertEquals(JobState.RUNNING, jr.getJobState()); Assertions.assertEquals(JobState.RUNNING, jr.getJobState());
AMInfo amInfo = amInfos.get(0); AMInfo amInfo = amInfos.get(0);
Assert.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost()); Assertions.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost());
Assert.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort()); Assertions.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort());
Assert.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort()); Assertions.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort());
Assert.assertEquals(1, amInfo.getAppAttemptId().getAttemptId()); Assertions.assertEquals(1, amInfo.getAppAttemptId().getAttemptId());
Assert.assertEquals(1, amInfo.getContainerId().getApplicationAttemptId() Assertions.assertEquals(1, amInfo.getContainerId().getApplicationAttemptId()
.getAttemptId()); .getAttemptId());
Assert.assertTrue(amInfo.getStartTime() > 0); Assertions.assertTrue(amInfo.getStartTime() > 0);
Assert.assertFalse(jr.isUber()); Assertions.assertFalse(jr.isUber());
} }
private void verifyTaskAttemptReport(TaskAttemptReport tar) { private void verifyTaskAttemptReport(TaskAttemptReport tar) {
Assert.assertEquals(TaskAttemptState.RUNNING, tar.getTaskAttemptState()); Assertions.assertEquals(TaskAttemptState.RUNNING, tar.getTaskAttemptState());
Assert.assertNotNull("TaskAttemptReport is null", tar); Assertions.assertNotNull(tar, "TaskAttemptReport is null");
Assert.assertEquals(MRApp.NM_HOST, tar.getNodeManagerHost()); Assertions.assertEquals(MRApp.NM_HOST, tar.getNodeManagerHost());
Assert.assertEquals(MRApp.NM_PORT, tar.getNodeManagerPort()); Assertions.assertEquals(MRApp.NM_PORT, tar.getNodeManagerPort());
Assert.assertEquals(MRApp.NM_HTTP_PORT, tar.getNodeManagerHttpPort()); Assertions.assertEquals(MRApp.NM_HTTP_PORT, tar.getNodeManagerHttpPort());
Assert.assertEquals(1, tar.getContainerId().getApplicationAttemptId() Assertions.assertEquals(1, tar.getContainerId().getApplicationAttemptId()
.getAttemptId()); .getAttemptId());
} }

View File

@ -19,9 +19,9 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -42,7 +42,7 @@
import org.apache.hadoop.mapreduce.util.MRJobConfUtil; import org.apache.hadoop.mapreduce.util.MRJobConfUtil;
import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -107,8 +107,9 @@
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -126,7 +127,7 @@ public class TestRecovery {
private Text val1 = new Text("val1"); private Text val1 = new Text("val1");
private Text val2 = new Text("val2"); private Text val2 = new Text("val2");
@BeforeClass @BeforeAll
public static void setupClass() throws Exception { public static void setupClass() throws Exception {
// setup the test root directory // setup the test root directory
testRootDir = testRootDir =
@ -158,8 +159,8 @@ public void testCrashed() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
long jobStartTime = job.getReport().getStartTime(); long jobStartTime = job.getReport().getStartTime();
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -192,7 +193,7 @@ public void testCrashed() throws Exception {
Thread.sleep(2000); Thread.sleep(2000);
LOG.info("Waiting for next attempt to start"); LOG.info("Waiting for next attempt to start");
} }
Assert.assertEquals(2, mapTask1.getAttempts().size()); Assertions.assertEquals(2, mapTask1.getAttempts().size());
Iterator<TaskAttempt> itr = mapTask1.getAttempts().values().iterator(); Iterator<TaskAttempt> itr = mapTask1.getAttempts().values().iterator();
itr.next(); itr.next();
TaskAttempt task1Attempt2 = itr.next(); TaskAttempt task1Attempt2 = itr.next();
@ -213,7 +214,7 @@ public void testCrashed() throws Exception {
Thread.sleep(2000); Thread.sleep(2000);
LOG.info("Waiting for next attempt to start"); LOG.info("Waiting for next attempt to start");
} }
Assert.assertEquals(3, mapTask1.getAttempts().size()); Assertions.assertEquals(3, mapTask1.getAttempts().size());
itr = mapTask1.getAttempts().values().iterator(); itr = mapTask1.getAttempts().values().iterator();
itr.next(); itr.next();
itr.next(); itr.next();
@ -234,7 +235,7 @@ public void testCrashed() throws Exception {
Thread.sleep(2000); Thread.sleep(2000);
LOG.info("Waiting for next attempt to start"); LOG.info("Waiting for next attempt to start");
} }
Assert.assertEquals(4, mapTask1.getAttempts().size()); Assertions.assertEquals(4, mapTask1.getAttempts().size());
itr = mapTask1.getAttempts().values().iterator(); itr = mapTask1.getAttempts().values().iterator();
itr.next(); itr.next();
itr.next(); itr.next();
@ -272,8 +273,8 @@ public void testCrashed() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -308,29 +309,29 @@ public void testCrashed() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertEquals("Job Start time not correct", Assertions.assertEquals(jobStartTime, job.getReport().getStartTime(),
jobStartTime, job.getReport().getStartTime()); "Job Start time not correct");
Assert.assertEquals("Task Start time not correct", Assertions.assertEquals(task1StartTime, mapTask1.getReport().getStartTime(),
task1StartTime, mapTask1.getReport().getStartTime()); "Task Start time not correct");
Assert.assertEquals("Task Finish time not correct", Assertions.assertEquals(task1FinishTime, mapTask1.getReport().getFinishTime(),
task1FinishTime, mapTask1.getReport().getFinishTime()); "Task Finish time not correct");
Assert.assertEquals(2, job.getAMInfos().size()); Assertions.assertEquals(2, job.getAMInfos().size());
int attemptNum = 1; int attemptNum = 1;
// Verify AMInfo // Verify AMInfo
for (AMInfo amInfo : job.getAMInfos()) { for (AMInfo amInfo : job.getAMInfos()) {
Assert.assertEquals(attemptNum++, amInfo.getAppAttemptId() Assertions.assertEquals(attemptNum++, amInfo.getAppAttemptId()
.getAttemptId()); .getAttemptId());
Assert.assertEquals(amInfo.getAppAttemptId(), amInfo.getContainerId() Assertions.assertEquals(amInfo.getAppAttemptId(), amInfo.getContainerId()
.getApplicationAttemptId()); .getApplicationAttemptId());
Assert.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost()); Assertions.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost());
Assert.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort()); Assertions.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort());
Assert.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort()); Assertions.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort());
} }
long am1StartTimeReal = job.getAMInfos().get(0).getStartTime(); long am1StartTimeReal = job.getAMInfos().get(0).getStartTime();
long am2StartTimeReal = job.getAMInfos().get(1).getStartTime(); long am2StartTimeReal = job.getAMInfos().get(1).getStartTime();
Assert.assertTrue(am1StartTimeReal >= am1StartTimeEst Assertions.assertTrue(am1StartTimeReal >= am1StartTimeEst
&& am1StartTimeReal <= am2StartTimeEst); && am1StartTimeReal <= am2StartTimeEst);
Assert.assertTrue(am2StartTimeReal >= am2StartTimeEst Assertions.assertTrue(am2StartTimeReal >= am2StartTimeEst
&& am2StartTimeReal <= System.currentTimeMillis()); && am2StartTimeReal <= System.currentTimeMillis());
// TODO Add verification of additional data from jobHistory - whatever was // TODO Add verification of additional data from jobHistory - whatever was
// available in the failed attempt should be available here // available in the failed attempt should be available here
@ -371,7 +372,7 @@ public void testCrashOfMapsOnlyJob() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
// all maps would be running // all maps would be running
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -429,7 +430,7 @@ public void testCrashOfMapsOnlyJob() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -516,7 +517,7 @@ public void testRecoverySuccessUsingCustomOutputCommitter() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
// all maps would be running // all maps would be running
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -575,7 +576,7 @@ public void testRecoverySuccessUsingCustomOutputCommitter() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -641,8 +642,9 @@ public void testRecoveryWithSpillEncryption() throws Exception {
app = new MRAppWithHistory(1, 1, false, this.getClass().getName(), false, app = new MRAppWithHistory(1, 1, false, this.getClass().getName(), false,
++runCount); ++runCount);
Job jobAttempt2 = app.submit(conf); Job jobAttempt2 = app.submit(conf);
Assert.assertTrue("Recovery from previous job attempt is processed even " + Assertions.assertTrue(!app.recovered(),
"though intermediate data encryption is enabled.", !app.recovered()); "Recovery from previous job attempt is processed even " +
"though intermediate data encryption is enabled.");
// The map task succeeded from previous job attempt will not be recovered // The map task succeeded from previous job attempt will not be recovered
// because the data spill encryption is enabled. // because the data spill encryption is enabled.
@ -694,7 +696,7 @@ public void testRecoveryFailsUsingCustomOutputCommitter() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
// all maps would be running // all maps would be running
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -753,7 +755,7 @@ public void testRecoveryFailsUsingCustomOutputCommitter() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -813,8 +815,8 @@ public void testMultipleCrashes() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -833,8 +835,8 @@ public void testMultipleCrashes() throws Exception {
app.waitForState(task2Attempt, TaskAttemptState.RUNNING); app.waitForState(task2Attempt, TaskAttemptState.RUNNING);
// reduces must be in NEW state // reduces must be in NEW state
Assert.assertEquals("Reduce Task state not correct", Assertions.assertEquals(TaskState.RUNNING, reduceTask.getReport().getTaskState(),
TaskState.RUNNING, reduceTask.getReport().getTaskState()); "Reduce Task state not correct");
//send the done signal to the 1st map //send the done signal to the 1st map
app.getContext().getEventHandler().handle( app.getContext().getEventHandler().handle(
@ -862,8 +864,8 @@ public void testMultipleCrashes() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -905,8 +907,8 @@ public void testMultipleCrashes() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -940,8 +942,8 @@ public void testOutputRecovery() throws Exception {
conf.set(FileOutputFormat.OUTDIR, outputDir.toString()); conf.set(FileOutputFormat.OUTDIR, outputDir.toString());
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task reduceTask1 = it.next(); Task reduceTask1 = it.next();
@ -966,7 +968,7 @@ public void testOutputRecovery() throws Exception {
app.waitForState(mapTask1, TaskState.SUCCEEDED); app.waitForState(mapTask1, TaskState.SUCCEEDED);
// Verify the shuffle-port // Verify the shuffle-port
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
app.waitForState(reduceTask1, TaskState.RUNNING); app.waitForState(reduceTask1, TaskState.RUNNING);
TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next(); TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next();
@ -998,8 +1000,8 @@ public void testOutputRecovery() throws Exception {
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
reduceTask1 = it.next(); reduceTask1 = it.next();
@ -1010,7 +1012,7 @@ public void testOutputRecovery() throws Exception {
// Verify the shuffle-port after recovery // Verify the shuffle-port after recovery
task1Attempt1 = mapTask1.getAttempts().values().iterator().next(); task1Attempt1 = mapTask1.getAttempts().values().iterator().next();
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
// first reduce will be recovered, no need to send done // first reduce will be recovered, no need to send done
app.waitForState(reduceTask1, TaskState.SUCCEEDED); app.waitForState(reduceTask1, TaskState.SUCCEEDED);
@ -1051,7 +1053,7 @@ public void testPreviousJobOutputCleanedWhenNoRecovery() throws Exception {
conf.set(FileOutputFormat.OUTDIR, outputDir.toString()); conf.set(FileOutputFormat.OUTDIR, outputDir.toString());
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
//stop the app before the job completes. //stop the app before the job completes.
app.stop(); app.stop();
app.close(); app.close();
@ -1061,11 +1063,11 @@ public void testPreviousJobOutputCleanedWhenNoRecovery() throws Exception {
++runCount); ++runCount);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(), "No of tasks not correct");
TestFileOutputCommitter committer = ( TestFileOutputCommitter committer = (
TestFileOutputCommitter) app.getCommitter(); TestFileOutputCommitter) app.getCommitter();
assertTrue("commiter.abortJob() has not been called", assertTrue(committer.isAbortJobCalled(),
committer.isAbortJobCalled()); "commiter.abortJob() has not been called");
app.close(); app.close();
} }
@ -1086,7 +1088,8 @@ public void testPreviousJobIsNotCleanedWhenRecovery()
conf.set(FileOutputFormat.OUTDIR, outputDir.toString()); conf.set(FileOutputFormat.OUTDIR, outputDir.toString());
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(),
"No of tasks not correct");
//stop the app before the job completes. //stop the app before the job completes.
app.stop(); app.stop();
app.close(); app.close();
@ -1096,11 +1099,12 @@ public void testPreviousJobIsNotCleanedWhenRecovery()
++runCount); ++runCount);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", 3, job.getTasks().size()); Assertions.assertEquals(3, job.getTasks().size(),
"No of tasks not correct");
TestFileOutputCommitter committer = ( TestFileOutputCommitter committer = (
TestFileOutputCommitter) app.getCommitter(); TestFileOutputCommitter) app.getCommitter();
assertFalse("commiter.abortJob() has been called", assertFalse(committer.isAbortJobCalled(),
committer.isAbortJobCalled()); "commiter.abortJob() has been called");
app.close(); app.close();
} }
@ -1116,8 +1120,8 @@ public void testOutputRecoveryMapsOnly() throws Exception {
conf.set(FileOutputFormat.OUTDIR, outputDir.toString()); conf.set(FileOutputFormat.OUTDIR, outputDir.toString());
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -1147,7 +1151,7 @@ public void testOutputRecoveryMapsOnly() throws Exception {
app.waitForState(mapTask1, TaskState.SUCCEEDED); app.waitForState(mapTask1, TaskState.SUCCEEDED);
// Verify the shuffle-port // Verify the shuffle-port
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
//stop the app before the job completes. //stop the app before the job completes.
app.stop(); app.stop();
@ -1164,8 +1168,8 @@ public void testOutputRecoveryMapsOnly() throws Exception {
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -1176,7 +1180,7 @@ public void testOutputRecoveryMapsOnly() throws Exception {
// Verify the shuffle-port after recovery // Verify the shuffle-port after recovery
task1Attempt1 = mapTask1.getAttempts().values().iterator().next(); task1Attempt1 = mapTask1.getAttempts().values().iterator().next();
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
app.waitForState(mapTask2, TaskState.RUNNING); app.waitForState(mapTask2, TaskState.RUNNING);
@ -1197,7 +1201,7 @@ public void testOutputRecoveryMapsOnly() throws Exception {
app.waitForState(mapTask2, TaskState.SUCCEEDED); app.waitForState(mapTask2, TaskState.SUCCEEDED);
// Verify the shuffle-port // Verify the shuffle-port
Assert.assertEquals(5467, task2Attempt1.getShufflePort()); Assertions.assertEquals(5467, task2Attempt1.getShufflePort());
app.waitForState(reduceTask1, TaskState.RUNNING); app.waitForState(reduceTask1, TaskState.RUNNING);
TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next(); TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next();
@ -1231,8 +1235,8 @@ public void testRecoveryWithOldCommiter() throws Exception {
conf.set(FileOutputFormat.OUTDIR, outputDir.toString()); conf.set(FileOutputFormat.OUTDIR, outputDir.toString());
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task reduceTask1 = it.next(); Task reduceTask1 = it.next();
@ -1257,7 +1261,7 @@ public void testRecoveryWithOldCommiter() throws Exception {
app.waitForState(mapTask1, TaskState.SUCCEEDED); app.waitForState(mapTask1, TaskState.SUCCEEDED);
// Verify the shuffle-port // Verify the shuffle-port
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
app.waitForState(reduceTask1, TaskState.RUNNING); app.waitForState(reduceTask1, TaskState.RUNNING);
TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next(); TaskAttempt reduce1Attempt1 = reduceTask1.getAttempts().values().iterator().next();
@ -1289,8 +1293,8 @@ public void testRecoveryWithOldCommiter() throws Exception {
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false);
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
reduceTask1 = it.next(); reduceTask1 = it.next();
@ -1301,7 +1305,7 @@ public void testRecoveryWithOldCommiter() throws Exception {
// Verify the shuffle-port after recovery // Verify the shuffle-port after recovery
task1Attempt1 = mapTask1.getAttempts().values().iterator().next(); task1Attempt1 = mapTask1.getAttempts().values().iterator().next();
Assert.assertEquals(5467, task1Attempt1.getShufflePort()); Assertions.assertEquals(5467, task1Attempt1.getShufflePort());
// first reduce will be recovered, no need to send done // first reduce will be recovered, no need to send done
app.waitForState(reduceTask1, TaskState.SUCCEEDED); app.waitForState(reduceTask1, TaskState.SUCCEEDED);
@ -1351,8 +1355,8 @@ public void testSpeculative() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
long jobStartTime = job.getReport().getStartTime(); long jobStartTime = job.getReport().getStartTime();
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
@ -1425,8 +1429,8 @@ public void testSpeculative() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -1462,36 +1466,36 @@ public void testSpeculative() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertEquals("Job Start time not correct", Assertions.assertEquals(jobStartTime, job.getReport().getStartTime(),
jobStartTime, job.getReport().getStartTime()); "Job Start time not correct");
Assert.assertEquals("Task Start time not correct", Assertions.assertEquals(task1StartTime, mapTask1.getReport().getStartTime(),
task1StartTime, mapTask1.getReport().getStartTime()); "Task Start time not correct");
Assert.assertEquals("Task Finish time not correct", Assertions.assertEquals(task1FinishTime, mapTask1.getReport().getFinishTime(),
task1FinishTime, mapTask1.getReport().getFinishTime()); "Task Finish time not correct");
Assert.assertEquals(2, job.getAMInfos().size()); Assertions.assertEquals(2, job.getAMInfos().size());
int attemptNum = 1; int attemptNum = 1;
// Verify AMInfo // Verify AMInfo
for (AMInfo amInfo : job.getAMInfos()) { for (AMInfo amInfo : job.getAMInfos()) {
Assert.assertEquals(attemptNum++, amInfo.getAppAttemptId() Assertions.assertEquals(attemptNum++, amInfo.getAppAttemptId()
.getAttemptId()); .getAttemptId());
Assert.assertEquals(amInfo.getAppAttemptId(), amInfo.getContainerId() Assertions.assertEquals(amInfo.getAppAttemptId(), amInfo.getContainerId()
.getApplicationAttemptId()); .getApplicationAttemptId());
Assert.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost()); Assertions.assertEquals(MRApp.NM_HOST, amInfo.getNodeManagerHost());
Assert.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort()); Assertions.assertEquals(MRApp.NM_PORT, amInfo.getNodeManagerPort());
Assert.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort()); Assertions.assertEquals(MRApp.NM_HTTP_PORT, amInfo.getNodeManagerHttpPort());
} }
long am1StartTimeReal = job.getAMInfos().get(0).getStartTime(); long am1StartTimeReal = job.getAMInfos().get(0).getStartTime();
long am2StartTimeReal = job.getAMInfos().get(1).getStartTime(); long am2StartTimeReal = job.getAMInfos().get(1).getStartTime();
Assert.assertTrue(am1StartTimeReal >= am1StartTimeEst Assertions.assertTrue(am1StartTimeReal >= am1StartTimeEst
&& am1StartTimeReal <= am2StartTimeEst); && am1StartTimeReal <= am2StartTimeEst);
Assert.assertTrue(am2StartTimeReal >= am2StartTimeEst Assertions.assertTrue(am2StartTimeReal >= am2StartTimeEst
&& am2StartTimeReal <= System.currentTimeMillis()); && am2StartTimeReal <= System.currentTimeMillis());
} }
@Test(timeout=30000) @Test
@Timeout(30000)
public void testRecoveryWithoutShuffleSecret() throws Exception { public void testRecoveryWithoutShuffleSecret() throws Exception {
int runCount = 0; int runCount = 0;
MRApp app = new MRAppNoShuffleSecret(2, 1, false, MRApp app = new MRAppNoShuffleSecret(2, 1, false,
this.getClass().getName(), true, ++runCount); this.getClass().getName(), true, ++runCount);
@ -1503,8 +1507,8 @@ public void testRecoveryWithoutShuffleSecret() throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
Iterator<Task> it = job.getTasks().values().iterator(); Iterator<Task> it = job.getTasks().values().iterator();
Task mapTask1 = it.next(); Task mapTask1 = it.next();
Task mapTask2 = it.next(); Task mapTask2 = it.next();
@ -1550,8 +1554,8 @@ public void testRecoveryWithoutShuffleSecret() throws Exception {
job = app.submit(conf); job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
//all maps would be running //all maps would be running
Assert.assertEquals("No of tasks not correct", Assertions.assertEquals(3, job.getTasks().size(),
3, job.getTasks().size()); "No of tasks not correct");
it = job.getTasks().values().iterator(); it = job.getTasks().values().iterator();
mapTask1 = it.next(); mapTask1 = it.next();
mapTask2 = it.next(); mapTask2 = it.next();
@ -1890,16 +1894,16 @@ private void recoveryChecker(MapTaskImpl checkTask, TaskState finalState,
ArgumentCaptor<Event> arg, List<EventType> expectedJobHistoryEvents, ArgumentCaptor<Event> arg, List<EventType> expectedJobHistoryEvents,
long expectedMapLaunches, long expectedFailedMaps) { long expectedMapLaunches, long expectedFailedMaps) {
assertEquals("Final State of Task", finalState, checkTask.getState()); assertEquals(finalState, checkTask.getState(), "Final State of Task");
Map<TaskAttemptId, TaskAttempt> recoveredAttempts = Map<TaskAttemptId, TaskAttempt> recoveredAttempts =
checkTask.getAttempts(); checkTask.getAttempts();
assertEquals("Expected Number of Task Attempts", assertEquals(finalAttemptStates.size(), recoveredAttempts.size(),
finalAttemptStates.size(), recoveredAttempts.size()); "Expected Number of Task Attempts");
for (TaskAttemptID taID : finalAttemptStates.keySet()) { for (TaskAttemptID taID : finalAttemptStates.keySet()) {
assertEquals("Expected Task Attempt State", assertEquals(finalAttemptStates.get(taID),
finalAttemptStates.get(taID), recoveredAttempts.get(TypeConverter.toYarn(taID)).getState(),
recoveredAttempts.get(TypeConverter.toYarn(taID)).getState()); "Expected Task Attempt State");
} }
Iterator<Event> ie = arg.getAllValues().iterator(); Iterator<Event> ie = arg.getAllValues().iterator();
@ -1947,12 +1951,12 @@ private void recoveryChecker(MapTaskImpl checkTask, TaskState finalState,
} }
} }
assertTrue(jobTaskEventReceived || (finalState == TaskState.RUNNING)); assertTrue(jobTaskEventReceived || (finalState == TaskState.RUNNING));
assertEquals("Did not process all expected JobHistoryEvents", assertEquals(0, expectedJobHistoryEvents.size(),
0, expectedJobHistoryEvents.size()); "Did not process all expected JobHistoryEvents");
assertEquals("Expected Map Launches", assertEquals(expectedMapLaunches, totalLaunchedMaps,
expectedMapLaunches, totalLaunchedMaps); "Expected Map Launches");
assertEquals("Expected Failed Maps", assertEquals(expectedFailedMaps, totalFailedMaps,
expectedFailedMaps, totalFailedMaps); "Expected Failed Maps");
} }
private MapTaskImpl getMockMapTask(long clusterTimestamp, EventHandler eh) { private MapTaskImpl getMockMapTask(long clusterTimestamp, EventHandler eh) {

View File

@ -78,8 +78,8 @@
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.ControlledClock; import org.apache.hadoop.yarn.util.ControlledClock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -152,16 +152,16 @@ public class TestRuntimeEstimators {
conf.setDouble(MRJobConfig.SPECULATIVECAP_TOTAL_TASKS, 0.001); conf.setDouble(MRJobConfig.SPECULATIVECAP_TOTAL_TASKS, 0.001);
conf.setInt(MRJobConfig.SPECULATIVE_MINIMUM_ALLOWED_TASKS, 5); conf.setInt(MRJobConfig.SPECULATIVE_MINIMUM_ALLOWED_TASKS, 5);
speculator = new DefaultSpeculator(conf, myAppContext, estimator, clock); speculator = new DefaultSpeculator(conf, myAppContext, estimator, clock);
Assert.assertEquals("wrong SPECULATIVE_RETRY_AFTER_NO_SPECULATE value", Assertions.assertEquals(500L, speculator.getSoonestRetryAfterNoSpeculate(),
500L, speculator.getSoonestRetryAfterNoSpeculate()); "wrong SPECULATIVE_RETRY_AFTER_NO_SPECULATE value");
Assert.assertEquals("wrong SPECULATIVE_RETRY_AFTER_SPECULATE value", Assertions.assertEquals(5000L, speculator.getSoonestRetryAfterSpeculate(),
5000L, speculator.getSoonestRetryAfterSpeculate()); "wrong SPECULATIVE_RETRY_AFTER_SPECULATE value");
assertThat(speculator.getProportionRunningTasksSpeculatable()) assertThat(speculator.getProportionRunningTasksSpeculatable())
.isCloseTo(0.1, offset(0.00001)); .isCloseTo(0.1, offset(0.00001));
assertThat(speculator.getProportionTotalTasksSpeculatable()) assertThat(speculator.getProportionTotalTasksSpeculatable())
.isCloseTo(0.001, offset(0.00001)); .isCloseTo(0.001, offset(0.00001));
Assert.assertEquals("wrong SPECULATIVE_MINIMUM_ALLOWED_TASKS value", Assertions.assertEquals(5, speculator.getMinimumAllowedSpeculativeTasks(),
5, speculator.getMinimumAllowedSpeculativeTasks()); "wrong SPECULATIVE_MINIMUM_ALLOWED_TASKS value");
dispatcher.register(Speculator.EventType.class, speculator); dispatcher.register(Speculator.EventType.class, speculator);
@ -244,8 +244,8 @@ public class TestRuntimeEstimators {
} }
} }
Assert.assertEquals("We got the wrong number of successful speculations.", Assertions.assertEquals(expectedSpeculations, successfulSpeculations.get(),
expectedSpeculations, successfulSpeculations.get()); "We got the wrong number of successful speculations.");
} }
@Test @Test
@ -279,8 +279,8 @@ public void handle(TaskEvent event) {
TaskId taskID = event.getTaskID(); TaskId taskID = event.getTaskID();
Task task = myJob.getTask(taskID); Task task = myJob.getTask(taskID);
Assert.assertEquals Assertions.assertEquals
("Wrong type event", TaskEventType.T_ADD_SPEC_ATTEMPT, event.getType()); (TaskEventType.T_ADD_SPEC_ATTEMPT, event.getType(), "Wrong type event");
System.out.println("SpeculationRequestEventHandler.handle adds a speculation task for " + taskID); System.out.println("SpeculationRequestEventHandler.handle adds a speculation task for " + taskID);

View File

@ -18,8 +18,8 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -61,9 +61,10 @@
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
/** /**
@ -78,7 +79,7 @@ public class TestStagingCleanup {
private final static RecordFactory recordFactory = RecordFactoryProvider. private final static RecordFactory recordFactory = RecordFactoryProvider.
getRecordFactory(null); getRecordFactory(null);
@After @AfterEach
public void tearDown() { public void tearDown() {
conf.setBoolean(MRJobConfig.PRESERVE_FAILED_TASK_FILES, false); conf.setBoolean(MRJobConfig.PRESERVE_FAILED_TASK_FILES, false);
} }
@ -135,7 +136,7 @@ public void testDeletionofStaging() throws IOException {
JobId jobid = recordFactory.newRecordInstance(JobId.class); JobId jobid = recordFactory.newRecordInstance(JobId.class);
jobid.setAppId(appId); jobid.setAppId(appId);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -146,7 +147,8 @@ public void testDeletionofStaging() throws IOException {
verify(fs).delete(stagingJobPath, true); verify(fs).delete(stagingJobPath, true);
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testNoDeletionofStagingOnReboot() throws IOException { public void testNoDeletionofStagingOnReboot() throws IOException {
conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir); conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir);
fs = mock(FileSystem.class); fs = mock(FileSystem.class);
@ -158,7 +160,7 @@ public void testNoDeletionofStagingOnReboot() throws IOException {
0); 0);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.REBOOT, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.REBOOT, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -197,7 +199,8 @@ public void testDeletionofStagingOnReboot() throws IOException {
verify(fs).delete(stagingJobPath, true); verify(fs).delete(stagingJobPath, true);
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testDeletionofStagingOnKill() throws IOException { public void testDeletionofStagingOnKill() throws IOException {
conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir); conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir);
fs = mock(FileSystem.class); fs = mock(FileSystem.class);
@ -242,13 +245,14 @@ public void testDeletionofStagingOnKillLastTry() throws IOException {
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc); //no retry MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc); //no retry
appMaster.init(conf); appMaster.init(conf);
assertTrue("appMaster.isLastAMRetry() is false", appMaster.isLastAMRetry()); assertTrue(appMaster.isLastAMRetry(),
"appMaster.isLastAMRetry() is false");
//simulate the process being killed //simulate the process being killed
MRAppMaster.MRAppMasterShutdownHook hook = MRAppMaster.MRAppMasterShutdownHook hook =
new MRAppMaster.MRAppMasterShutdownHook(appMaster); new MRAppMaster.MRAppMasterShutdownHook(appMaster);
hook.run(); hook.run();
assertTrue("MRAppMaster isn't stopped", assertTrue(appMaster.isInState(Service.STATE.STOPPED),
appMaster.isInState(Service.STATE.STOPPED)); "MRAppMaster isn't stopped");
verify(fs).delete(stagingJobPath, true); verify(fs).delete(stagingJobPath, true);
} }
@ -270,7 +274,7 @@ public void testByPreserveFailedStaging() throws IOException {
JobId jobid = recordFactory.newRecordInstance(JobId.class); JobId jobid = recordFactory.newRecordInstance(JobId.class);
jobid.setAppId(appId); jobid.setAppId(appId);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.FAILED, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.FAILED, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -298,7 +302,7 @@ public void testPreservePatternMatchedStaging() throws IOException {
JobId jobid = recordFactory.newRecordInstance(JobId.class); JobId jobid = recordFactory.newRecordInstance(JobId.class);
jobid.setAppId(appId); jobid.setAppId(appId);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -324,7 +328,7 @@ public void testNotPreserveNotPatternMatchedStaging() throws IOException {
JobId jobid = recordFactory.newRecordInstance(JobId.class); JobId jobid = recordFactory.newRecordInstance(JobId.class);
jobid.setAppId(appId); jobid.setAppId(appId);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -355,7 +359,7 @@ public void testPreservePatternMatchedAndFailedStaging() throws IOException {
JobId jobid = recordFactory.newRecordInstance(JobId.class); JobId jobid = recordFactory.newRecordInstance(JobId.class);
jobid.setAppId(appId); jobid.setAppId(appId);
ContainerAllocator mockAlloc = mock(ContainerAllocator.class); ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1); Assertions.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc,
JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS); JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
appMaster.init(conf); appMaster.init(conf);
@ -583,7 +587,8 @@ public void runOnNextHeartbeat(Runnable callback) {
}; };
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testStagingCleanupOrder() throws Exception { public void testStagingCleanupOrder() throws Exception {
MRAppTestCleanup app = new MRAppTestCleanup(1, 1, true, MRAppTestCleanup app = new MRAppTestCleanup(1, 1, true,
this.getClass().getName(), true); this.getClass().getName(), true);
@ -598,7 +603,7 @@ public void testStagingCleanupOrder() throws Exception {
} }
// assert ContainerAllocatorStopped and then tagingDirCleanedup // assert ContainerAllocatorStopped and then tagingDirCleanedup
Assert.assertEquals(1, app.ContainerAllocatorStopped); Assertions.assertEquals(1, app.ContainerAllocatorStopped);
Assert.assertEquals(2, app.stagingDirCleanedup); Assertions.assertEquals(2, app.stagingDirCleanedup);
} }
} }

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -40,8 +40,8 @@
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.ControlledClock; import org.apache.hadoop.yarn.util.ControlledClock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -214,11 +214,11 @@ public void testTaskUnregistered() throws Exception {
JobId jobId = MRBuilderUtils.newJobId(appId, 4); JobId jobId = MRBuilderUtils.newJobId(appId, 4);
TaskId tid = MRBuilderUtils.newTaskId(jobId, 3, TaskType.MAP); TaskId tid = MRBuilderUtils.newTaskId(jobId, 3, TaskType.MAP);
final TaskAttemptId taid = MRBuilderUtils.newTaskAttemptId(tid, 2); final TaskAttemptId taid = MRBuilderUtils.newTaskAttemptId(tid, 2);
Assert.assertFalse(hb.hasRecentlyUnregistered(taid)); Assertions.assertFalse(hb.hasRecentlyUnregistered(taid));
hb.register(taid); hb.register(taid);
Assert.assertFalse(hb.hasRecentlyUnregistered(taid)); Assertions.assertFalse(hb.hasRecentlyUnregistered(taid));
hb.unregister(taid); hb.unregister(taid);
Assert.assertTrue(hb.hasRecentlyUnregistered(taid)); Assertions.assertTrue(hb.hasRecentlyUnregistered(taid));
long unregisterTimeout = conf.getLong(MRJobConfig.TASK_EXIT_TIMEOUT, long unregisterTimeout = conf.getLong(MRJobConfig.TASK_EXIT_TIMEOUT,
MRJobConfig.TASK_EXIT_TIMEOUT_DEFAULT); MRJobConfig.TASK_EXIT_TIMEOUT_DEFAULT);
clock.setTime(unregisterTimeout + 1); clock.setTime(unregisterTimeout + 1);
@ -260,7 +260,7 @@ private static void verifyTaskTimeoutConfig(final Configuration conf,
new TaskHeartbeatHandler(null, SystemClock.getInstance(), 1); new TaskHeartbeatHandler(null, SystemClock.getInstance(), 1);
hb.init(conf); hb.init(conf);
Assert.assertTrue("The value of the task timeout is incorrect.", Assertions.assertTrue(hb.getTaskTimeOut() == expectedTimeout,
hb.getTaskTimeOut() == expectedTimeout); "The value of the task timeout is incorrect.");
} }
} }

View File

@ -27,7 +27,7 @@
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.mapreduce.JobContext;
@ -39,7 +39,7 @@
import org.apache.hadoop.yarn.event.AsyncDispatcher; import org.apache.hadoop.yarn.event.AsyncDispatcher;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.File; import java.io.File;
@ -62,9 +62,9 @@
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestCommitterEventHandler { public class TestCommitterEventHandler {
public static class WaitForItHandler implements EventHandler<Event> { public static class WaitForItHandler implements EventHandler<Event> {
@ -95,13 +95,13 @@ public synchronized Event getAndClearEvent() throws InterruptedException {
static String stagingDir = "target/test-staging/"; static String stagingDir = "target/test-staging/";
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
File dir = new File(stagingDir); File dir = new File(stagingDir);
stagingDir = dir.getAbsolutePath(); stagingDir = dir.getAbsolutePath();
} }
@Before @BeforeEach
public void cleanup() throws IOException { public void cleanup() throws IOException {
File dir = new File(stagingDir); File dir = new File(stagingDir);
if(dir.exists()) { if(dir.exists()) {
@ -146,11 +146,11 @@ public void testCommitWindow() throws Exception {
Thread.sleep(10); Thread.sleep(10);
timeToWaitMs -= 10; timeToWaitMs -= 10;
} }
Assert.assertEquals("committer did not register a heartbeat callback", Assertions.assertEquals(1, rmhh.getNumCallbacks(),
1, rmhh.getNumCallbacks()); "committer did not register a heartbeat callback");
verify(committer, never()).commitJob(any(JobContext.class)); verify(committer, never()).commitJob(any(JobContext.class));
Assert.assertEquals("committer should not have committed", Assertions.assertEquals(0, jeh.numCommitCompletedEvents,
0, jeh.numCommitCompletedEvents); "committer should not have committed");
// set a fresh heartbeat and verify commit completes // set a fresh heartbeat and verify commit completes
rmhh.setLastHeartbeatTime(clock.getTime()); rmhh.setLastHeartbeatTime(clock.getTime());
@ -159,8 +159,8 @@ public void testCommitWindow() throws Exception {
Thread.sleep(10); Thread.sleep(10);
timeToWaitMs -= 10; timeToWaitMs -= 10;
} }
Assert.assertEquals("committer did not complete commit after RM hearbeat", Assertions.assertEquals(1, jeh.numCommitCompletedEvents,
1, jeh.numCommitCompletedEvents); "committer did not complete commit after RM hearbeat");
verify(committer, times(1)).commitJob(any()); verify(committer, times(1)).commitJob(any());
//Clean up so we can try to commit again (Don't do this at home) //Clean up so we can try to commit again (Don't do this at home)
@ -174,8 +174,8 @@ public void testCommitWindow() throws Exception {
Thread.sleep(10); Thread.sleep(10);
timeToWaitMs -= 10; timeToWaitMs -= 10;
} }
Assert.assertEquals("committer did not commit", Assertions.assertEquals(2, jeh.numCommitCompletedEvents,
2, jeh.numCommitCompletedEvents); "committer did not commit");
verify(committer, times(2)).commitJob(any()); verify(committer, times(2)).commitJob(any());
ceh.stop(); ceh.stop();
@ -262,9 +262,9 @@ public void testBasic() throws Exception {
assertNotNull(e); assertNotNull(e);
assertTrue(e instanceof JobCommitCompletedEvent); assertTrue(e instanceof JobCommitCompletedEvent);
FileSystem fs = FileSystem.get(conf); FileSystem fs = FileSystem.get(conf);
assertTrue(startCommitFile.toString(), fs.exists(startCommitFile)); assertTrue(fs.exists(startCommitFile), startCommitFile.toString());
assertTrue(endCommitSuccessFile.toString(), fs.exists(endCommitSuccessFile)); assertTrue(fs.exists(endCommitSuccessFile), endCommitSuccessFile.toString());
assertFalse(endCommitFailureFile.toString(), fs.exists(endCommitFailureFile)); assertFalse(fs.exists(endCommitFailureFile), endCommitFailureFile.toString());
verify(mockCommitter).commitJob(any(JobContext.class)); verify(mockCommitter).commitJob(any(JobContext.class));
} finally { } finally {
handler.stop(); handler.stop();

View File

@ -105,10 +105,11 @@
import org.apache.hadoop.yarn.state.StateMachineFactory; import org.apache.hadoop.yarn.state.StateMachineFactory;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -120,13 +121,13 @@ public class TestJobImpl {
static String stagingDir = "target/test-staging/"; static String stagingDir = "target/test-staging/";
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
File dir = new File(stagingDir); File dir = new File(stagingDir);
stagingDir = dir.getAbsolutePath(); stagingDir = dir.getAbsolutePath();
} }
@Before @BeforeEach
public void cleanup() throws IOException { public void cleanup() throws IOException {
File dir = new File(stagingDir); File dir = new File(stagingDir);
if(dir.exists()) { if(dir.exists()) {
@ -169,13 +170,14 @@ public void testJobNoTasks() {
dispatcher.stop(); dispatcher.stop();
commitHandler.stop(); commitHandler.stop();
try { try {
Assert.assertTrue(jseHandler.getAssertValue()); Assertions.assertTrue(jseHandler.getAssertValue());
} catch (InterruptedException e) { } catch (InterruptedException e) {
Assert.fail("Workflow related attributes are not tested properly"); Assertions.fail("Workflow related attributes are not tested properly");
} }
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testCommitJobFailsJob() throws Exception { public void testCommitJobFailsJob() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -200,7 +202,8 @@ public void testCommitJobFailsJob() throws Exception {
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testCheckJobCompleteSuccess() throws Exception { public void testCheckJobCompleteSuccess() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -252,7 +255,8 @@ public void testCheckJobCompleteSuccess() throws Exception {
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testRebootedDuringSetup() throws Exception { public void testRebootedDuringSetup() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -289,13 +293,14 @@ public synchronized void setupJob(JobContext jobContext)
assertJobState(job, JobStateInternal.REBOOT); assertJobState(job, JobStateInternal.REBOOT);
// return the external state as RUNNING since otherwise JobClient will // return the external state as RUNNING since otherwise JobClient will
// exit when it polls the AM for job state // exit when it polls the AM for job state
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
dispatcher.stop(); dispatcher.stop();
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testRebootedDuringCommit() throws Exception { public void testRebootedDuringCommit() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -321,15 +326,16 @@ public void testRebootedDuringCommit() throws Exception {
job.handle(new JobEvent(job.getID(), JobEventType.JOB_AM_REBOOT)); job.handle(new JobEvent(job.getID(), JobEventType.JOB_AM_REBOOT));
assertJobState(job, JobStateInternal.REBOOT); assertJobState(job, JobStateInternal.REBOOT);
// return the external state as ERROR since this is last retry. // return the external state as ERROR since this is last retry.
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true); when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true);
Assert.assertEquals(JobState.ERROR, job.getState()); Assertions.assertEquals(JobState.ERROR, job.getState());
dispatcher.stop(); dispatcher.stop();
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testKilledDuringSetup() throws Exception { public void testKilledDuringSetup() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -366,7 +372,8 @@ public synchronized void setupJob(JobContext jobContext)
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testKilledDuringCommit() throws Exception { public void testKilledDuringCommit() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -423,7 +430,8 @@ public void testAbortJobCalledAfterKillingTasks() throws IOException {
dispatcher.stop(); dispatcher.stop();
} }
@Test (timeout=10000) @Test
@Timeout(10000)
public void testFailAbortDoesntHang() throws IOException { public void testFailAbortDoesntHang() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -461,7 +469,8 @@ public void testFailAbortDoesntHang() throws IOException {
dispatcher.stop(); dispatcher.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testKilledDuringFailAbort() throws Exception { public void testKilledDuringFailAbort() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -503,7 +512,8 @@ public synchronized void abortJob(JobContext jobContext, State state)
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testKilledDuringKillAbort() throws Exception { public void testKilledDuringKillAbort() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -546,7 +556,8 @@ public synchronized void abortJob(JobContext jobContext, State state)
commitHandler.stop(); commitHandler.stop();
} }
@Test(timeout=20000) @Test
@Timeout(20000)
public void testUnusableNodeTransition() throws Exception { public void testUnusableNodeTransition() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
@ -599,7 +610,7 @@ public void handle(TaskAttemptEvent event) {
job.handle(new JobTaskAttemptCompletedEvent(tce)); job.handle(new JobTaskAttemptCompletedEvent(tce));
// complete the task itself // complete the task itself
job.handle(new JobTaskEvent(taskId, TaskState.SUCCEEDED)); job.handle(new JobTaskEvent(taskId, TaskState.SUCCEEDED));
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
} }
} }
@ -699,13 +710,13 @@ public void handle(TaskEvent event) {
* much value. Instead, we validate the T_KILL events. * much value. Instead, we validate the T_KILL events.
*/ */
if (killMappers) { if (killMappers) {
Assert.assertEquals("Number of killed events", 2, killedEvents.size()); Assertions.assertEquals(2, killedEvents.size(), "Number of killed events");
Assert.assertEquals("AttemptID", "task_1234567890000_0001_m_000000", Assertions.assertEquals("task_1234567890000_0001_m_000000",
killedEvents.get(0).getTaskID().toString()); killedEvents.get(0).getTaskID().toString(), "AttemptID");
Assert.assertEquals("AttemptID", "task_1234567890000_0001_m_000001", Assertions.assertEquals("task_1234567890000_0001_m_000001",
killedEvents.get(1).getTaskID().toString()); killedEvents.get(1).getTaskID().toString(), "AttemptID");
} else { } else {
Assert.assertEquals("Number of killed events", 0, killedEvents.size()); Assertions.assertEquals(0, killedEvents.size(), "Number of killed events");
} }
} }
@ -738,8 +749,8 @@ public void testCheckAccess() {
// Verify access // Verify access
JobImpl job1 = new JobImpl(jobId, null, conf1, null, null, null, null, null, JobImpl job1 = new JobImpl(jobId, null, conf1, null, null, null, null, null,
null, null, null, true, user1, 0, null, null, null, null); null, null, null, true, user1, 0, null, null, null, null);
Assert.assertTrue(job1.checkAccess(ugi1, JobACL.VIEW_JOB)); Assertions.assertTrue(job1.checkAccess(ugi1, JobACL.VIEW_JOB));
Assert.assertFalse(job1.checkAccess(ugi2, JobACL.VIEW_JOB)); Assertions.assertFalse(job1.checkAccess(ugi2, JobACL.VIEW_JOB));
// Setup configuration access to the user1 (owner) and user2 // Setup configuration access to the user1 (owner) and user2
Configuration conf2 = new Configuration(); Configuration conf2 = new Configuration();
@ -749,8 +760,8 @@ public void testCheckAccess() {
// Verify access // Verify access
JobImpl job2 = new JobImpl(jobId, null, conf2, null, null, null, null, null, JobImpl job2 = new JobImpl(jobId, null, conf2, null, null, null, null, null,
null, null, null, true, user1, 0, null, null, null, null); null, null, null, true, user1, 0, null, null, null, null);
Assert.assertTrue(job2.checkAccess(ugi1, JobACL.VIEW_JOB)); Assertions.assertTrue(job2.checkAccess(ugi1, JobACL.VIEW_JOB));
Assert.assertTrue(job2.checkAccess(ugi2, JobACL.VIEW_JOB)); Assertions.assertTrue(job2.checkAccess(ugi2, JobACL.VIEW_JOB));
// Setup configuration access with security enabled and access to all // Setup configuration access with security enabled and access to all
Configuration conf3 = new Configuration(); Configuration conf3 = new Configuration();
@ -760,8 +771,8 @@ public void testCheckAccess() {
// Verify access // Verify access
JobImpl job3 = new JobImpl(jobId, null, conf3, null, null, null, null, null, JobImpl job3 = new JobImpl(jobId, null, conf3, null, null, null, null, null,
null, null, null, true, user1, 0, null, null, null, null); null, null, null, true, user1, 0, null, null, null, null);
Assert.assertTrue(job3.checkAccess(ugi1, JobACL.VIEW_JOB)); Assertions.assertTrue(job3.checkAccess(ugi1, JobACL.VIEW_JOB));
Assert.assertTrue(job3.checkAccess(ugi2, JobACL.VIEW_JOB)); Assertions.assertTrue(job3.checkAccess(ugi2, JobACL.VIEW_JOB));
// Setup configuration access without security enabled // Setup configuration access without security enabled
Configuration conf4 = new Configuration(); Configuration conf4 = new Configuration();
@ -771,8 +782,8 @@ public void testCheckAccess() {
// Verify access // Verify access
JobImpl job4 = new JobImpl(jobId, null, conf4, null, null, null, null, null, JobImpl job4 = new JobImpl(jobId, null, conf4, null, null, null, null, null,
null, null, null, true, user1, 0, null, null, null, null); null, null, null, true, user1, 0, null, null, null, null);
Assert.assertTrue(job4.checkAccess(ugi1, JobACL.VIEW_JOB)); Assertions.assertTrue(job4.checkAccess(ugi1, JobACL.VIEW_JOB));
Assert.assertTrue(job4.checkAccess(ugi2, JobACL.VIEW_JOB)); Assertions.assertTrue(job4.checkAccess(ugi2, JobACL.VIEW_JOB));
// Setup configuration access without security enabled // Setup configuration access without security enabled
Configuration conf5 = new Configuration(); Configuration conf5 = new Configuration();
@ -782,8 +793,8 @@ public void testCheckAccess() {
// Verify access // Verify access
JobImpl job5 = new JobImpl(jobId, null, conf5, null, null, null, null, null, JobImpl job5 = new JobImpl(jobId, null, conf5, null, null, null, null, null,
null, null, null, true, user1, 0, null, null, null, null); null, null, null, true, user1, 0, null, null, null, null);
Assert.assertTrue(job5.checkAccess(ugi1, null)); Assertions.assertTrue(job5.checkAccess(ugi1, null));
Assert.assertTrue(job5.checkAccess(ugi2, null)); Assertions.assertTrue(job5.checkAccess(ugi2, null));
} }
@Test @Test
@ -804,8 +815,8 @@ null, mock(JobTokenSecretManager.class), null,
mrAppMetrics, null, true, null, 0, null, mockContext, null, null); mrAppMetrics, null, true, null, 0, null, mockContext, null, null);
job.handle(diagUpdateEvent); job.handle(diagUpdateEvent);
String diagnostics = job.getReport().getDiagnostics(); String diagnostics = job.getReport().getDiagnostics();
Assert.assertNotNull(diagnostics); Assertions.assertNotNull(diagnostics);
Assert.assertTrue(diagnostics.contains(diagMsg)); Assertions.assertTrue(diagnostics.contains(diagMsg));
job = new JobImpl(jobId, Records job = new JobImpl(jobId, Records
.newRecord(ApplicationAttemptId.class), new Configuration(), .newRecord(ApplicationAttemptId.class), new Configuration(),
@ -816,8 +827,8 @@ null, mock(JobTokenSecretManager.class), null,
job.handle(new JobEvent(jobId, JobEventType.JOB_KILL)); job.handle(new JobEvent(jobId, JobEventType.JOB_KILL));
job.handle(diagUpdateEvent); job.handle(diagUpdateEvent);
diagnostics = job.getReport().getDiagnostics(); diagnostics = job.getReport().getDiagnostics();
Assert.assertNotNull(diagnostics); Assertions.assertNotNull(diagnostics);
Assert.assertTrue(diagnostics.contains(diagMsg)); Assertions.assertTrue(diagnostics.contains(diagMsg));
} }
@Test @Test
@ -826,13 +837,13 @@ public void testUberDecision() throws Exception {
// with default values, no of maps is 2 // with default values, no of maps is 2
Configuration conf = new Configuration(); Configuration conf = new Configuration();
boolean isUber = testUberDecision(conf); boolean isUber = testUberDecision(conf);
Assert.assertFalse(isUber); Assertions.assertFalse(isUber);
// enable uber mode, no of maps is 2 // enable uber mode, no of maps is 2
conf = new Configuration(); conf = new Configuration();
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true);
isUber = testUberDecision(conf); isUber = testUberDecision(conf);
Assert.assertTrue(isUber); Assertions.assertTrue(isUber);
// enable uber mode, no of maps is 2, no of reduces is 1 and uber task max // enable uber mode, no of maps is 2, no of reduces is 1 and uber task max
// reduces is 0 // reduces is 0
@ -841,7 +852,7 @@ public void testUberDecision() throws Exception {
conf.setInt(MRJobConfig.JOB_UBERTASK_MAXREDUCES, 0); conf.setInt(MRJobConfig.JOB_UBERTASK_MAXREDUCES, 0);
conf.setInt(MRJobConfig.NUM_REDUCES, 1); conf.setInt(MRJobConfig.NUM_REDUCES, 1);
isUber = testUberDecision(conf); isUber = testUberDecision(conf);
Assert.assertFalse(isUber); Assertions.assertFalse(isUber);
// enable uber mode, no of maps is 2, no of reduces is 1 and uber task max // enable uber mode, no of maps is 2, no of reduces is 1 and uber task max
// reduces is 1 // reduces is 1
@ -850,14 +861,14 @@ public void testUberDecision() throws Exception {
conf.setInt(MRJobConfig.JOB_UBERTASK_MAXREDUCES, 1); conf.setInt(MRJobConfig.JOB_UBERTASK_MAXREDUCES, 1);
conf.setInt(MRJobConfig.NUM_REDUCES, 1); conf.setInt(MRJobConfig.NUM_REDUCES, 1);
isUber = testUberDecision(conf); isUber = testUberDecision(conf);
Assert.assertTrue(isUber); Assertions.assertTrue(isUber);
// enable uber mode, no of maps is 2 and uber task max maps is 0 // enable uber mode, no of maps is 2 and uber task max maps is 0
conf = new Configuration(); conf = new Configuration();
conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true); conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true);
conf.setInt(MRJobConfig.JOB_UBERTASK_MAXMAPS, 1); conf.setInt(MRJobConfig.JOB_UBERTASK_MAXMAPS, 1);
isUber = testUberDecision(conf); isUber = testUberDecision(conf);
Assert.assertFalse(isUber); Assertions.assertFalse(isUber);
// enable uber mode of 0 reducer no matter how much memory assigned to reducer // enable uber mode of 0 reducer no matter how much memory assigned to reducer
conf = new Configuration(); conf = new Configuration();
@ -866,7 +877,7 @@ public void testUberDecision() throws Exception {
conf.setInt(MRJobConfig.REDUCE_MEMORY_MB, 2048); conf.setInt(MRJobConfig.REDUCE_MEMORY_MB, 2048);
conf.setInt(MRJobConfig.REDUCE_CPU_VCORES, 10); conf.setInt(MRJobConfig.REDUCE_CPU_VCORES, 10);
isUber = testUberDecision(conf); isUber = testUberDecision(conf);
Assert.assertTrue(isUber); Assertions.assertTrue(isUber);
} }
private boolean testUberDecision(Configuration conf) { private boolean testUberDecision(Configuration conf) {
@ -931,9 +942,9 @@ public void testTransitionsAtFailed() throws IOException {
assertJobState(job, JobStateInternal.FAILED); assertJobState(job, JobStateInternal.FAILED);
job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_FETCH_FAILURE)); job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_FETCH_FAILURE));
assertJobState(job, JobStateInternal.FAILED); assertJobState(job, JobStateInternal.FAILED);
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true); when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true);
Assert.assertEquals(JobState.FAILED, job.getState()); Assertions.assertEquals(JobState.FAILED, job.getState());
dispatcher.stop(); dispatcher.stop();
commitHandler.stop(); commitHandler.stop();
@ -960,12 +971,12 @@ protected TaskSplitMetaInfo[] createSplits(JobImpl job, JobId jobId) {
JobEvent mockJobEvent = mock(JobEvent.class); JobEvent mockJobEvent = mock(JobEvent.class);
JobStateInternal jobSI = initTransition.transition(job, mockJobEvent); JobStateInternal jobSI = initTransition.transition(job, mockJobEvent);
Assert.assertTrue("When init fails, return value from InitTransition.transition should equal NEW.", Assertions.assertTrue(jobSI.equals(JobStateInternal.NEW),
jobSI.equals(JobStateInternal.NEW)); "When init fails, return value from InitTransition.transition should equal NEW.");
Assert.assertTrue("Job diagnostics should contain YarnRuntimeException", Assertions.assertTrue(job.getDiagnostics().toString().contains("YarnRuntimeException"),
job.getDiagnostics().toString().contains("YarnRuntimeException")); "Job diagnostics should contain YarnRuntimeException");
Assert.assertTrue("Job diagnostics should contain " + EXCEPTIONMSG, Assertions.assertTrue(job.getDiagnostics().toString().contains(EXCEPTIONMSG),
job.getDiagnostics().toString().contains(EXCEPTIONMSG)); "Job diagnostics should contain " + EXCEPTIONMSG);
} }
@Test @Test
@ -986,7 +997,7 @@ public void testJobPriorityUpdate() throws Exception {
assertJobState(job, JobStateInternal.SETUP); assertJobState(job, JobStateInternal.SETUP);
// Update priority of job to 5, and it will be updated // Update priority of job to 5, and it will be updated
job.setJobPriority(submittedPriority); job.setJobPriority(submittedPriority);
Assert.assertEquals(submittedPriority, job.getReport().getJobPriority()); Assertions.assertEquals(submittedPriority, job.getReport().getJobPriority());
job.handle(new JobSetupCompletedEvent(jobId)); job.handle(new JobSetupCompletedEvent(jobId));
assertJobState(job, JobStateInternal.RUNNING); assertJobState(job, JobStateInternal.RUNNING);
@ -996,10 +1007,10 @@ public void testJobPriorityUpdate() throws Exception {
job.setJobPriority(updatedPriority); job.setJobPriority(updatedPriority);
assertJobState(job, JobStateInternal.RUNNING); assertJobState(job, JobStateInternal.RUNNING);
Priority jobPriority = job.getReport().getJobPriority(); Priority jobPriority = job.getReport().getJobPriority();
Assert.assertNotNull(jobPriority); Assertions.assertNotNull(jobPriority);
// Verify whether changed priority is same as what is set in Job. // Verify whether changed priority is same as what is set in Job.
Assert.assertEquals(updatedPriority, jobPriority); Assertions.assertEquals(updatedPriority, jobPriority);
} }
@Test @Test
@ -1013,14 +1024,14 @@ public void testCleanupSharedCacheUploadPolicies() {
filePolicies.put("file1", true); filePolicies.put("file1", true);
filePolicies.put("jar1", true); filePolicies.put("jar1", true);
Job.setFileSharedCacheUploadPolicies(config, filePolicies); Job.setFileSharedCacheUploadPolicies(config, filePolicies);
Assert.assertEquals( Assertions.assertEquals(
2, Job.getArchiveSharedCacheUploadPolicies(config).size()); 2, Job.getArchiveSharedCacheUploadPolicies(config).size());
Assert.assertEquals( Assertions.assertEquals(
2, Job.getFileSharedCacheUploadPolicies(config).size()); 2, Job.getFileSharedCacheUploadPolicies(config).size());
JobImpl.cleanupSharedCacheUploadPolicies(config); JobImpl.cleanupSharedCacheUploadPolicies(config);
Assert.assertEquals( Assertions.assertEquals(
0, Job.getArchiveSharedCacheUploadPolicies(config).size()); 0, Job.getArchiveSharedCacheUploadPolicies(config).size());
Assert.assertEquals( Assertions.assertEquals(
0, Job.getFileSharedCacheUploadPolicies(config).size()); 0, Job.getFileSharedCacheUploadPolicies(config).size());
} }
@ -1088,14 +1099,14 @@ private static void completeJobTasks(JobImpl job) {
job.handle(new JobTaskEvent( job.handle(new JobTaskEvent(
MRBuilderUtils.newTaskId(job.getID(), 1, TaskType.MAP), MRBuilderUtils.newTaskId(job.getID(), 1, TaskType.MAP),
TaskState.SUCCEEDED)); TaskState.SUCCEEDED));
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
} }
int numReduces = job.getTotalReduces(); int numReduces = job.getTotalReduces();
for (int i = 0; i < numReduces; ++i) { for (int i = 0; i < numReduces; ++i) {
job.handle(new JobTaskEvent( job.handle(new JobTaskEvent(
MRBuilderUtils.newTaskId(job.getID(), 1, TaskType.MAP), MRBuilderUtils.newTaskId(job.getID(), 1, TaskType.MAP),
TaskState.SUCCEEDED)); TaskState.SUCCEEDED));
Assert.assertEquals(JobState.RUNNING, job.getState()); Assertions.assertEquals(JobState.RUNNING, job.getState());
} }
} }
@ -1109,7 +1120,7 @@ private static void assertJobState(JobImpl job, JobStateInternal state) {
break; break;
} }
} }
Assert.assertEquals(state, job.getInternalState()); Assertions.assertEquals(state, job.getInternalState());
} }
private void createSpiedMapTasks(Map<NodeReport, TaskId> private void createSpiedMapTasks(Map<NodeReport, TaskId>

View File

@ -22,7 +22,7 @@
import java.util.Map; import java.util.Map;
import org.apache.hadoop.mapreduce.TaskType; import org.apache.hadoop.mapreduce.TaskType;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.JobConf;
@ -37,7 +37,8 @@
import org.apache.hadoop.mapreduce.v2.app.launcher.ContainerRemoteLaunchEvent; import org.apache.hadoop.mapreduce.v2.app.launcher.ContainerRemoteLaunchEvent;
import org.apache.hadoop.mapreduce.v2.util.MRApps; import org.apache.hadoop.mapreduce.v2.util.MRApps;
import org.apache.hadoop.yarn.api.records.ContainerLaunchContext; import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -46,9 +47,9 @@ public class TestMapReduceChildJVM {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(TestMapReduceChildJVM.class); LoggerFactory.getLogger(TestMapReduceChildJVM.class);
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testCommandLine() throws Exception { public void testCommandLine() throws Exception {
MyMRApp app = new MyMRApp(1, 0, true, this.getClass().getName(), true); MyMRApp app = new MyMRApp(1, 0, true, this.getClass().getName(), true);
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true); conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
@ -56,7 +57,7 @@ public void testCommandLine() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertEquals( Assertions.assertEquals(
"[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" + "[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" +
" -Djava.net.preferIPv4Stack=true" + " -Djava.net.preferIPv4Stack=true" +
" -Dhadoop.metrics.log.level=WARN " + " -Dhadoop.metrics.log.level=WARN " +
@ -72,23 +73,25 @@ public void testCommandLine() throws Exception {
" 1><LOG_DIR>/stdout" + " 1><LOG_DIR>/stdout" +
" 2><LOG_DIR>/stderr ]", app.launchCmdList.get(0)); " 2><LOG_DIR>/stderr ]", app.launchCmdList.get(0));
Assert.assertTrue("HADOOP_ROOT_LOGGER not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER"),
app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER")); "HADOOP_ROOT_LOGGER not set for job");
Assert.assertEquals("INFO,console", Assertions.assertEquals("INFO,console",
app.cmdEnvironment.get("HADOOP_ROOT_LOGGER")); app.cmdEnvironment.get("HADOOP_ROOT_LOGGER"));
Assert.assertTrue("HADOOP_CLIENT_OPTS not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS"),
app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS")); "HADOOP_CLIENT_OPTS not set for job");
Assert.assertEquals("", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS")); Assertions.assertEquals("", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS"));
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testReduceCommandLineWithSeparateShuffle() throws Exception { public void testReduceCommandLineWithSeparateShuffle() throws Exception {
final Configuration conf = new Configuration(); final Configuration conf = new Configuration();
conf.setBoolean(MRJobConfig.REDUCE_SEPARATE_SHUFFLE_LOG, true); conf.setBoolean(MRJobConfig.REDUCE_SEPARATE_SHUFFLE_LOG, true);
testReduceCommandLine(conf); testReduceCommandLine(conf);
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testReduceCommandLineWithSeparateCRLAShuffle() throws Exception { public void testReduceCommandLineWithSeparateCRLAShuffle() throws Exception {
final Configuration conf = new Configuration(); final Configuration conf = new Configuration();
conf.setBoolean(MRJobConfig.REDUCE_SEPARATE_SHUFFLE_LOG, true); conf.setBoolean(MRJobConfig.REDUCE_SEPARATE_SHUFFLE_LOG, true);
@ -97,7 +100,8 @@ public void testReduceCommandLineWithSeparateCRLAShuffle() throws Exception {
testReduceCommandLine(conf); testReduceCommandLine(conf);
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testReduceCommandLine() throws Exception { public void testReduceCommandLine() throws Exception {
final Configuration conf = new Configuration(); final Configuration conf = new Configuration();
testReduceCommandLine(conf); testReduceCommandLine(conf);
@ -119,7 +123,7 @@ private void testReduceCommandLine(Configuration conf)
? "shuffleCRLA" ? "shuffleCRLA"
: "shuffleCLA"; : "shuffleCLA";
Assert.assertEquals( Assertions.assertEquals(
"[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" + "[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" +
" -Djava.net.preferIPv4Stack=true" + " -Djava.net.preferIPv4Stack=true" +
" -Dhadoop.metrics.log.level=WARN " + " -Dhadoop.metrics.log.level=WARN " +
@ -139,16 +143,17 @@ private void testReduceCommandLine(Configuration conf)
" 1><LOG_DIR>/stdout" + " 1><LOG_DIR>/stdout" +
" 2><LOG_DIR>/stderr ]", app.launchCmdList.get(0)); " 2><LOG_DIR>/stderr ]", app.launchCmdList.get(0));
Assert.assertTrue("HADOOP_ROOT_LOGGER not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER"),
app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER")); "HADOOP_ROOT_LOGGER not set for job");
Assert.assertEquals("INFO,console", Assertions.assertEquals("INFO,console",
app.cmdEnvironment.get("HADOOP_ROOT_LOGGER")); app.cmdEnvironment.get("HADOOP_ROOT_LOGGER"));
Assert.assertTrue("HADOOP_CLIENT_OPTS not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS"),
app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS")); "HADOOP_CLIENT_OPTS not set for job");
Assert.assertEquals("", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS")); Assertions.assertEquals("", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS"));
} }
@Test (timeout = 30000) @Test
@Timeout(30000)
public void testCommandLineWithLog4JConifg() throws Exception { public void testCommandLineWithLog4JConifg() throws Exception {
MyMRApp app = new MyMRApp(1, 0, true, this.getClass().getName(), true); MyMRApp app = new MyMRApp(1, 0, true, this.getClass().getName(), true);
@ -161,7 +166,7 @@ public void testCommandLineWithLog4JConifg() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertEquals( Assertions.assertEquals(
"[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" + "[" + MRApps.crossPlatformify("JAVA_HOME") + "/bin/java" +
" -Djava.net.preferIPv4Stack=true" + " -Djava.net.preferIPv4Stack=true" +
" -Dhadoop.metrics.log.level=WARN " + " -Dhadoop.metrics.log.level=WARN " +
@ -203,10 +208,10 @@ private void testAutoHeapSize(int mapMb, int redMb, String xmxArg)
MRJobConfig.DEFAULT_HEAP_MEMORY_MB_RATIO); MRJobConfig.DEFAULT_HEAP_MEMORY_MB_RATIO);
// Verify map and reduce java opts are not set by default // Verify map and reduce java opts are not set by default
Assert.assertNull("Default map java opts!", Assertions.assertNull(conf.get(MRJobConfig.MAP_JAVA_OPTS),
conf.get(MRJobConfig.MAP_JAVA_OPTS)); "Default map java opts!");
Assert.assertNull("Default reduce java opts!", Assertions.assertNull(conf.get(MRJobConfig.REDUCE_JAVA_OPTS),
conf.get(MRJobConfig.REDUCE_JAVA_OPTS)); "Default reduce java opts!");
// Set the memory-mbs and java-opts // Set the memory-mbs and java-opts
if (mapMb > 0) { if (mapMb > 0) {
conf.setInt(MRJobConfig.MAP_MEMORY_MB, mapMb); conf.setInt(MRJobConfig.MAP_MEMORY_MB, mapMb);
@ -242,8 +247,8 @@ private void testAutoHeapSize(int mapMb, int redMb, String xmxArg)
: MRJobConfig.REDUCE_JAVA_OPTS); : MRJobConfig.REDUCE_JAVA_OPTS);
heapMb = JobConf.parseMaximumHeapSizeMB(javaOpts); heapMb = JobConf.parseMaximumHeapSizeMB(javaOpts);
} }
Assert.assertEquals("Incorrect heapsize in the command opts", Assertions.assertEquals(heapMb, JobConf.parseMaximumHeapSizeMB(cmd),
heapMb, JobConf.parseMaximumHeapSizeMB(cmd)); "Incorrect heapsize in the command opts");
} }
} }
@ -288,13 +293,13 @@ public void testEnvironmentVariables() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertTrue("HADOOP_ROOT_LOGGER not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER"),
app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER")); "HADOOP_ROOT_LOGGER not set for job");
Assert.assertEquals("WARN,console", Assertions.assertEquals("WARN,console",
app.cmdEnvironment.get("HADOOP_ROOT_LOGGER")); app.cmdEnvironment.get("HADOOP_ROOT_LOGGER"));
Assert.assertTrue("HADOOP_CLIENT_OPTS not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS"),
app.cmdEnvironment.containsKey("HADOOP_CLIENT_OPTS")); "HADOOP_CLIENT_OPTS not set for job");
Assert.assertEquals("test", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS")); Assertions.assertEquals("test", app.cmdEnvironment.get("HADOOP_CLIENT_OPTS"));
// Try one more. // Try one more.
app = new MyMRApp(1, 0, true, this.getClass().getName(), true); app = new MyMRApp(1, 0, true, this.getClass().getName(), true);
@ -304,9 +309,9 @@ public void testEnvironmentVariables() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertTrue("HADOOP_ROOT_LOGGER not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER"),
app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER")); "HADOOP_ROOT_LOGGER not set for job");
Assert.assertEquals("trace", Assertions.assertEquals("trace",
app.cmdEnvironment.get("HADOOP_ROOT_LOGGER")); app.cmdEnvironment.get("HADOOP_ROOT_LOGGER"));
// Try one using the mapreduce.task.env.var=value syntax // Try one using the mapreduce.task.env.var=value syntax
@ -318,9 +323,9 @@ public void testEnvironmentVariables() throws Exception {
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();
Assert.assertTrue("HADOOP_ROOT_LOGGER not set for job", Assertions.assertTrue(app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER"),
app.cmdEnvironment.containsKey("HADOOP_ROOT_LOGGER")); "HADOOP_ROOT_LOGGER not set for job");
Assert.assertEquals("DEBUG,console", Assertions.assertEquals("DEBUG,console",
app.cmdEnvironment.get("HADOOP_ROOT_LOGGER")); app.cmdEnvironment.get("HADOOP_ROOT_LOGGER"));
} }
} }

View File

@ -53,8 +53,8 @@
import org.apache.hadoop.yarn.server.api.ApplicationInitializationContext; import org.apache.hadoop.yarn.server.api.ApplicationInitializationContext;
import org.apache.hadoop.yarn.server.api.ApplicationTerminationContext; import org.apache.hadoop.yarn.server.api.ApplicationTerminationContext;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
public class TestShuffleProvider { public class TestShuffleProvider {
@ -110,9 +110,12 @@ public void testShuffleProviders() throws Exception {
credentials); credentials);
Map<String, ByteBuffer> serviceDataMap = launchCtx.getServiceData(); Map<String, ByteBuffer> serviceDataMap = launchCtx.getServiceData();
Assert.assertNotNull("TestShuffleHandler1 is missing", serviceDataMap.get(TestShuffleHandler1.MAPREDUCE_TEST_SHUFFLE_SERVICEID)); Assertions.assertNotNull(serviceDataMap.get(TestShuffleHandler1.MAPREDUCE_TEST_SHUFFLE_SERVICEID),
Assert.assertNotNull("TestShuffleHandler2 is missing", serviceDataMap.get(TestShuffleHandler2.MAPREDUCE_TEST_SHUFFLE_SERVICEID)); "TestShuffleHandler1 is missing");
Assert.assertTrue("mismatch number of services in map", serviceDataMap.size() == 3); // 2 that we entered + 1 for the built-in shuffle-provider Assertions.assertNotNull(serviceDataMap.get(TestShuffleHandler2.MAPREDUCE_TEST_SHUFFLE_SERVICEID),
"TestShuffleHandler2 is missing");
Assertions.assertTrue(serviceDataMap.size() == 3,
"mismatch number of services in map"); // 2 that we entered + 1 for the built-in shuffle-provider
} }
static public class StubbedFS extends RawLocalFileSystem { static public class StubbedFS extends RawLocalFileSystem {

View File

@ -20,9 +20,10 @@
import static org.apache.hadoop.test.GenericTestUtils.waitFor; import static org.apache.hadoop.test.GenericTestUtils.waitFor;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@ -41,10 +42,10 @@
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptFailEvent;
import org.apache.hadoop.yarn.util.resource.CustomResourceTypesConfigurationProvider; import org.apache.hadoop.yarn.util.resource.CustomResourceTypesConfigurationProvider;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -111,7 +112,7 @@
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LoggingEvent;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
@ -151,17 +152,17 @@ private List<LoggingEvent> getLogEvents() {
} }
} }
@BeforeClass @BeforeAll
public static void setupBeforeClass() { public static void setupBeforeClass() {
ResourceUtils.resetResourceTypes(new Configuration()); ResourceUtils.resetResourceTypes(new Configuration());
} }
@Before @BeforeEach
public void before() { public void before() {
TaskAttemptImpl.RESOURCE_REQUEST_CACHE.clear(); TaskAttemptImpl.RESOURCE_REQUEST_CACHE.clear();
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
ResourceUtils.resetResourceTypes(new Configuration()); ResourceUtils.resetResourceTypes(new Configuration());
} }
@ -289,7 +290,7 @@ public void testSingleRackRequest() throws Exception {
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class); ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(2)).handle(arg.capture()); verify(eventHandler, times(2)).handle(arg.capture());
if (!(arg.getAllValues().get(1) instanceof ContainerRequestEvent)) { if (!(arg.getAllValues().get(1) instanceof ContainerRequestEvent)) {
Assert.fail("Second Event not of type ContainerRequestEvent"); Assertions.fail("Second Event not of type ContainerRequestEvent");
} }
ContainerRequestEvent cre = ContainerRequestEvent cre =
(ContainerRequestEvent) arg.getAllValues().get(1); (ContainerRequestEvent) arg.getAllValues().get(1);
@ -323,7 +324,7 @@ public void testHostResolveAttempt() throws Exception {
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class); ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(2)).handle(arg.capture()); verify(eventHandler, times(2)).handle(arg.capture());
if (!(arg.getAllValues().get(1) instanceof ContainerRequestEvent)) { if (!(arg.getAllValues().get(1) instanceof ContainerRequestEvent)) {
Assert.fail("Second Event not of type ContainerRequestEvent"); Assertions.fail("Second Event not of type ContainerRequestEvent");
} }
Map<String, Boolean> expected = new HashMap<String, Boolean>(); Map<String, Boolean> expected = new HashMap<String, Boolean>();
expected.put("host1", true); expected.put("host1", true);
@ -361,16 +362,16 @@ public void verifyMillisCounters(Resource containerResource,
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Map<TaskId, Task> tasks = job.getTasks(); Map<TaskId, Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 2, tasks.size()); Assertions.assertEquals(2, tasks.size(), "Num tasks is not correct");
Iterator<Task> taskIter = tasks.values().iterator(); Iterator<Task> taskIter = tasks.values().iterator();
Task mTask = taskIter.next(); Task mTask = taskIter.next();
app.waitForState(mTask, TaskState.RUNNING); app.waitForState(mTask, TaskState.RUNNING);
Task rTask = taskIter.next(); Task rTask = taskIter.next();
app.waitForState(rTask, TaskState.RUNNING); app.waitForState(rTask, TaskState.RUNNING);
Map<TaskAttemptId, TaskAttempt> mAttempts = mTask.getAttempts(); Map<TaskAttemptId, TaskAttempt> mAttempts = mTask.getAttempts();
Assert.assertEquals("Num attempts is not correct", 1, mAttempts.size()); Assertions.assertEquals(1, mAttempts.size(), "Num attempts is not correct");
Map<TaskAttemptId, TaskAttempt> rAttempts = rTask.getAttempts(); Map<TaskAttemptId, TaskAttempt> rAttempts = rTask.getAttempts();
Assert.assertEquals("Num attempts is not correct", 1, rAttempts.size()); Assertions.assertEquals(1, rAttempts.size(), "Num attempts is not correct");
TaskAttempt mta = mAttempts.values().iterator().next(); TaskAttempt mta = mAttempts.values().iterator().next();
TaskAttempt rta = rAttempts.values().iterator().next(); TaskAttempt rta = rAttempts.values().iterator().next();
app.waitForState(mta, TaskAttemptState.RUNNING); app.waitForState(mta, TaskAttemptState.RUNNING);
@ -392,21 +393,21 @@ public void verifyMillisCounters(Resource containerResource,
int memoryMb = (int) containerResource.getMemorySize(); int memoryMb = (int) containerResource.getMemorySize();
int vcores = containerResource.getVirtualCores(); int vcores = containerResource.getVirtualCores();
Assert.assertEquals((int) Math.ceil((float) memoryMb / minContainerSize), Assertions.assertEquals((int) Math.ceil((float) memoryMb / minContainerSize),
counters.findCounter(JobCounter.SLOTS_MILLIS_MAPS).getValue()); counters.findCounter(JobCounter.SLOTS_MILLIS_MAPS).getValue());
Assert.assertEquals((int) Math.ceil((float) memoryMb / minContainerSize), Assertions.assertEquals((int) Math.ceil((float) memoryMb / minContainerSize),
counters.findCounter(JobCounter.SLOTS_MILLIS_REDUCES).getValue()); counters.findCounter(JobCounter.SLOTS_MILLIS_REDUCES).getValue());
Assert.assertEquals(1, Assertions.assertEquals(1,
counters.findCounter(JobCounter.MILLIS_MAPS).getValue()); counters.findCounter(JobCounter.MILLIS_MAPS).getValue());
Assert.assertEquals(1, Assertions.assertEquals(1,
counters.findCounter(JobCounter.MILLIS_REDUCES).getValue()); counters.findCounter(JobCounter.MILLIS_REDUCES).getValue());
Assert.assertEquals(memoryMb, Assertions.assertEquals(memoryMb,
counters.findCounter(JobCounter.MB_MILLIS_MAPS).getValue()); counters.findCounter(JobCounter.MB_MILLIS_MAPS).getValue());
Assert.assertEquals(memoryMb, Assertions.assertEquals(memoryMb,
counters.findCounter(JobCounter.MB_MILLIS_REDUCES).getValue()); counters.findCounter(JobCounter.MB_MILLIS_REDUCES).getValue());
Assert.assertEquals(vcores, Assertions.assertEquals(vcores,
counters.findCounter(JobCounter.VCORES_MILLIS_MAPS).getValue()); counters.findCounter(JobCounter.VCORES_MILLIS_MAPS).getValue());
Assert.assertEquals(vcores, Assertions.assertEquals(vcores,
counters.findCounter(JobCounter.VCORES_MILLIS_REDUCES).getValue()); counters.findCounter(JobCounter.VCORES_MILLIS_REDUCES).getValue());
} }
@ -452,23 +453,25 @@ private void testMRAppHistory(MRApp app) throws Exception {
app.waitForState(job, JobState.FAILED); app.waitForState(job, JobState.FAILED);
Map<TaskId, Task> tasks = job.getTasks(); Map<TaskId, Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 1, tasks.size()); Assertions.assertEquals(1, tasks.size(),
"Num tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
Assert.assertEquals("Task state not correct", TaskState.FAILED, task Assertions.assertEquals(TaskState.FAILED, task.getReport().getTaskState(),
.getReport().getTaskState()); "Task state not correct");
Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator().next() Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator().next()
.getAttempts(); .getAttempts();
Assert.assertEquals("Num attempts is not correct", 4, attempts.size()); Assertions.assertEquals(4, attempts.size(),
"Num attempts is not correct");
Iterator<TaskAttempt> it = attempts.values().iterator(); Iterator<TaskAttempt> it = attempts.values().iterator();
TaskAttemptReport report = it.next().getReport(); TaskAttemptReport report = it.next().getReport();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.FAILED, Assertions.assertEquals(TaskAttemptState.FAILED, report.getTaskAttemptState(),
report.getTaskAttemptState()); "Attempt state not correct");
Assert.assertEquals("Diagnostic Information is not Correct", Assertions.assertEquals("Test Diagnostic Event", report.getDiagnosticInfo(),
"Test Diagnostic Event", report.getDiagnosticInfo()); "Diagnostic Information is not Correct");
report = it.next().getReport(); report = it.next().getReport();
Assert.assertEquals("Attempt state not correct", TaskAttemptState.FAILED, Assertions.assertEquals(TaskAttemptState.FAILED, report.getTaskAttemptState(),
report.getTaskAttemptState()); "Attempt state not correct ");
} }
private void testTaskAttemptAssignedFailHistory private void testTaskAttemptAssignedFailHistory
@ -477,8 +480,8 @@ private void testMRAppHistory(MRApp app) throws Exception {
Job job = app.submit(conf); Job job = app.submit(conf);
app.waitForState(job, JobState.FAILED); app.waitForState(job, JobState.FAILED);
Map<TaskId, Task> tasks = job.getTasks(); Map<TaskId, Task> tasks = job.getTasks();
Assert.assertTrue("No Ta Started JH Event", app.getTaStartJHEvent()); Assertions.assertTrue(app.getTaStartJHEvent(), "No Ta Started JH Event");
Assert.assertTrue("No Ta Failed JH Event", app.getTaFailedJHEvent()); Assertions.assertTrue(app.getTaFailedJHEvent(), "No Ta Failed JH Event");
} }
private void testTaskAttemptAssignedKilledHistory private void testTaskAttemptAssignedKilledHistory
@ -518,8 +521,8 @@ public void handle(JobHistoryEvent event) {
if (event.getType() == org.apache.hadoop.mapreduce.jobhistory.EventType.MAP_ATTEMPT_FAILED) { if (event.getType() == org.apache.hadoop.mapreduce.jobhistory.EventType.MAP_ATTEMPT_FAILED) {
TaskAttemptUnsuccessfulCompletion datum = (TaskAttemptUnsuccessfulCompletion) event TaskAttemptUnsuccessfulCompletion datum = (TaskAttemptUnsuccessfulCompletion) event
.getHistoryEvent().getDatum(); .getHistoryEvent().getDatum();
Assert.assertEquals("Diagnostic Information is not Correct", Assertions.assertEquals("Test Diagnostic Event", datum.get(8).toString(),
"Test Diagnostic Event", datum.get(8).toString()); "Diagnostic Information is not Correct");
} }
} }
}; };
@ -638,8 +641,8 @@ public void testLaunchFailedWhileKilling() throws Exception {
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_CONTAINER_LAUNCH_FAILED)); TaskAttemptEventType.TA_CONTAINER_LAUNCH_FAILED));
assertFalse(eventHandler.internalError); assertFalse(eventHandler.internalError);
assertEquals("Task attempt is not assigned on the local node", assertEquals(Locality.NODE_LOCAL, taImpl.getLocality(),
Locality.NODE_LOCAL, taImpl.getLocality()); "Task attempt is not assigned on the local node");
} }
@Test @Test
@ -695,10 +698,10 @@ public void testContainerCleanedWhileRunning() throws Exception {
.isEqualTo(TaskAttemptState.RUNNING); .isEqualTo(TaskAttemptState.RUNNING);
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_CONTAINER_CLEANED)); TaskAttemptEventType.TA_CONTAINER_CLEANED));
assertFalse("InternalError occurred trying to handle TA_CONTAINER_CLEANED", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_CONTAINER_CLEANED");
assertEquals("Task attempt is not assigned on the local rack", assertEquals(Locality.RACK_LOCAL, taImpl.getLocality(),
Locality.RACK_LOCAL, taImpl.getLocality()); "Task attempt is not assigned on the local rack");
} }
@Test @Test
@ -757,10 +760,10 @@ public void testContainerCleanedWhileCommitting() throws Exception {
.isEqualTo(TaskAttemptState.COMMIT_PENDING); .isEqualTo(TaskAttemptState.COMMIT_PENDING);
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_CONTAINER_CLEANED)); TaskAttemptEventType.TA_CONTAINER_CLEANED));
assertFalse("InternalError occurred trying to handle TA_CONTAINER_CLEANED", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_CONTAINER_CLEANED");
assertEquals("Task attempt is assigned locally", Locality.OFF_SWITCH, assertEquals(Locality.OFF_SWITCH,taImpl.getLocality(),
taImpl.getLocality()); "Task attempt is assigned locally");
} }
@Test @Test
@ -832,8 +835,8 @@ public void testDoubleTooManyFetchFailure() throws Exception {
assertThat(taImpl.getState()) assertThat(taImpl.getState())
.withFailMessage("Task attempt is not in FAILED state, still") .withFailMessage("Task attempt is not in FAILED state, still")
.isEqualTo(TaskAttemptState.FAILED); .isEqualTo(TaskAttemptState.FAILED);
assertFalse("InternalError occurred trying to handle TA_CONTAINER_CLEANED", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_CONTAINER_CLEANED");
} }
@ -883,16 +886,15 @@ public void testAppDiagnosticEventOnUnassignedTask() {
TaskAttemptEventType.TA_SCHEDULE)); TaskAttemptEventType.TA_SCHEDULE));
taImpl.handle(new TaskAttemptDiagnosticsUpdateEvent(attemptId, taImpl.handle(new TaskAttemptDiagnosticsUpdateEvent(attemptId,
"Task got killed")); "Task got killed"));
assertFalse( assertFalse(eventHandler.internalError,
"InternalError occurred trying to handle TA_DIAGNOSTICS_UPDATE on assigned task", "InternalError occurred trying to handle TA_DIAGNOSTICS_UPDATE on assigned task");
eventHandler.internalError);
try { try {
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_KILL)); TaskAttemptEventType.TA_KILL));
Assert.assertTrue("No exception on UNASSIGNED STATE KILL event", true); Assertions.assertTrue(true, "No exception on UNASSIGNED STATE KILL event");
} catch (Exception e) { } catch (Exception e) {
Assert.assertFalse( Assertions.assertFalse(true,
"Exception not expected for UNASSIGNED STATE KILL event", true); "Exception not expected for UNASSIGNED STATE KILL event");
} }
} }
@ -962,8 +964,8 @@ public void testTooManyFetchFailureAfterKill() throws Exception {
assertThat(taImpl.getState()) assertThat(taImpl.getState())
.withFailMessage("Task attempt is not in KILLED state, still") .withFailMessage("Task attempt is not in KILLED state, still")
.isEqualTo(TaskAttemptState.KILLED); .isEqualTo(TaskAttemptState.KILLED);
assertFalse("InternalError occurred trying to handle TA_CONTAINER_CLEANED", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_CONTAINER_CLEANED");
} }
@Test @Test
@ -1009,9 +1011,8 @@ public void testAppDiagnosticEventOnNewTask() {
when(container.getNodeHttpAddress()).thenReturn("localhost:0"); when(container.getNodeHttpAddress()).thenReturn("localhost:0");
taImpl.handle(new TaskAttemptDiagnosticsUpdateEvent(attemptId, taImpl.handle(new TaskAttemptDiagnosticsUpdateEvent(attemptId,
"Task got killed")); "Task got killed"));
assertFalse( assertFalse(eventHandler.internalError,
"InternalError occurred trying to handle TA_DIAGNOSTICS_UPDATE on assigned task", "InternalError occurred trying to handle TA_DIAGNOSTICS_UPDATE on assigned task");
eventHandler.internalError);
} }
@Test @Test
@ -1072,8 +1073,8 @@ public void testFetchFailureAttemptFinishTime() throws Exception{
.withFailMessage("Task attempt is not in SUCCEEDED state") .withFailMessage("Task attempt is not in SUCCEEDED state")
.isEqualTo(TaskAttemptState.SUCCEEDED); .isEqualTo(TaskAttemptState.SUCCEEDED);
assertTrue("Task Attempt finish time is not greater than 0", assertTrue(taImpl.getFinishTime() > 0,
taImpl.getFinishTime() > 0); "Task Attempt finish time is not greater than 0");
Long finishTime = taImpl.getFinishTime(); Long finishTime = taImpl.getFinishTime();
Thread.sleep(5); Thread.sleep(5);
@ -1084,9 +1085,9 @@ public void testFetchFailureAttemptFinishTime() throws Exception{
.withFailMessage("Task attempt is not in FAILED state") .withFailMessage("Task attempt is not in FAILED state")
.isEqualTo(TaskAttemptState.FAILED); .isEqualTo(TaskAttemptState.FAILED);
assertEquals("After TA_TOO_MANY_FETCH_FAILURE," assertEquals(finishTime, Long.valueOf(taImpl.getFinishTime()),
+ " Task attempt finish time is not the same ", "After TA_TOO_MANY_FETCH_FAILURE,"
finishTime, Long.valueOf(taImpl.getFinishTime())); + " Task attempt finish time is not the same ");
} }
private void containerKillBeforeAssignment(boolean scheduleAttempt) private void containerKillBeforeAssignment(boolean scheduleAttempt)
@ -1114,7 +1115,7 @@ private void containerKillBeforeAssignment(boolean scheduleAttempt)
assertThat(taImpl.getInternalState()) assertThat(taImpl.getInternalState())
.withFailMessage("Task attempt's internal state is not KILLED") .withFailMessage("Task attempt's internal state is not KILLED")
.isEqualTo(TaskAttemptStateInternal.KILLED); .isEqualTo(TaskAttemptStateInternal.KILLED);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
TaskEvent event = eventHandler.lastTaskEvent; TaskEvent event = eventHandler.lastTaskEvent;
assertEquals(TaskEventType.T_ATTEMPT_KILLED, event.getType()); assertEquals(TaskEventType.T_ATTEMPT_KILLED, event.getType());
// In NEW state, new map attempt should not be rescheduled. // In NEW state, new map attempt should not be rescheduled.
@ -1238,8 +1239,8 @@ public void testContainerKillWhileRunning() throws Exception {
.isEqualTo(TaskAttemptState.RUNNING); .isEqualTo(TaskAttemptState.RUNNING);
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_KILL)); TaskAttemptEventType.TA_KILL));
assertFalse("InternalError occurred trying to handle TA_KILL", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_KILL");
assertThat(taImpl.getInternalState()) assertThat(taImpl.getInternalState())
.withFailMessage("Task should be in KILL_CONTAINER_CLEANUP state") .withFailMessage("Task should be in KILL_CONTAINER_CLEANUP state")
.isEqualTo(TaskAttemptStateInternal.KILL_CONTAINER_CLEANUP); .isEqualTo(TaskAttemptStateInternal.KILL_CONTAINER_CLEANUP);
@ -1301,8 +1302,8 @@ public void testContainerKillWhileCommitPending() throws Exception {
.isEqualTo(TaskAttemptStateInternal.COMMIT_PENDING); .isEqualTo(TaskAttemptStateInternal.COMMIT_PENDING);
taImpl.handle(new TaskAttemptEvent(attemptId, taImpl.handle(new TaskAttemptEvent(attemptId,
TaskAttemptEventType.TA_KILL)); TaskAttemptEventType.TA_KILL));
assertFalse("InternalError occurred trying to handle TA_KILL", assertFalse(eventHandler.internalError,
eventHandler.internalError); "InternalError occurred trying to handle TA_KILL");
assertThat(taImpl.getInternalState()) assertThat(taImpl.getInternalState())
.withFailMessage("Task should be in KILL_CONTAINER_CLEANUP state") .withFailMessage("Task should be in KILL_CONTAINER_CLEANUP state")
.isEqualTo(TaskAttemptStateInternal.KILL_CONTAINER_CLEANUP); .isEqualTo(TaskAttemptStateInternal.KILL_CONTAINER_CLEANUP);
@ -1348,7 +1349,7 @@ public void testKillMapTaskWhileSuccessFinishing() throws Exception {
.withFailMessage("Task attempt is not in KILLED state") .withFailMessage("Task attempt is not in KILLED state")
.isEqualTo(TaskAttemptState.KILLED); .isEqualTo(TaskAttemptState.KILLED);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1359,32 +1360,30 @@ public void testKillMapOnlyTaskWhileSuccessFinishing() throws Exception {
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_DONE)); TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt is not in SUCCEEDED state", assertEquals(TaskAttemptState.SUCCEEDED, taImpl.getState(),
TaskAttemptState.SUCCEEDED, taImpl.getState()); "Task attempt is not in SUCCEEDED state");
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER,
"SUCCESS_FINISHING_CONTAINER", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER, "SUCCESS_FINISHING_CONTAINER");
taImpl.getInternalState());
// If the map only task is killed when it is in SUCCESS_FINISHING_CONTAINER // If the map only task is killed when it is in SUCCESS_FINISHING_CONTAINER
// state, the state will move to SUCCESS_CONTAINER_CLEANUP // state, the state will move to SUCCESS_CONTAINER_CLEANUP
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_KILL)); TaskAttemptEventType.TA_KILL));
assertEquals("Task attempt is not in SUCCEEDED state", assertEquals(TaskAttemptState.SUCCEEDED, taImpl.getState(),
TaskAttemptState.SUCCEEDED, taImpl.getState()); "Task attempt is not in SUCCEEDED state");
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP,
"SUCCESS_CONTAINER_CLEANUP", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP, "SUCCESS_CONTAINER_CLEANUP");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_CONTAINER_CLEANED)); TaskAttemptEventType.TA_CONTAINER_CLEANED));
assertEquals("Task attempt is not in SUCCEEDED state", assertEquals(TaskAttemptState.SUCCEEDED, taImpl.getState(),
TaskAttemptState.SUCCEEDED, taImpl.getState()); "Task attempt is not in SUCCEEDED state");
assertEquals("Task attempt's internal state is not SUCCEEDED state", assertEquals(TaskAttemptStateInternal.SUCCEEDED, taImpl.getInternalState(),
TaskAttemptStateInternal.SUCCEEDED, taImpl.getInternalState()); "Task attempt's internal state is not SUCCEEDED state");
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1414,7 +1413,7 @@ public void testKillMapTaskAfterSuccess() throws Exception {
assertThat(taImpl.getInternalState()) assertThat(taImpl.getInternalState())
.withFailMessage("Task attempt's internal state is not KILLED") .withFailMessage("Task attempt's internal state is not KILLED")
.isEqualTo(TaskAttemptStateInternal.KILLED); .isEqualTo(TaskAttemptStateInternal.KILLED);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
TaskEvent event = eventHandler.lastTaskEvent; TaskEvent event = eventHandler.lastTaskEvent;
assertEquals(TaskEventType.T_ATTEMPT_KILLED, event.getType()); assertEquals(TaskEventType.T_ATTEMPT_KILLED, event.getType());
// Send an attempt killed event to TaskImpl forwarding the same reschedule // Send an attempt killed event to TaskImpl forwarding the same reschedule
@ -1430,22 +1429,21 @@ public void testKillMapOnlyTaskAfterSuccess() throws Exception {
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_DONE)); TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt is not in SUCCEEDED state", assertEquals(TaskAttemptState.SUCCEEDED, taImpl.getState(),
TaskAttemptState.SUCCEEDED, taImpl.getState()); "Task attempt is not in SUCCEEDED state");
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER,
"SUCCESS_FINISHING_CONTAINER", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER, "SUCCESS_FINISHING_CONTAINER");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_CONTAINER_CLEANED)); TaskAttemptEventType.TA_CONTAINER_CLEANED));
// Succeeded // Succeeded
taImpl.handle(new TaskAttemptKillEvent(taImpl.getID(),"", true)); taImpl.handle(new TaskAttemptKillEvent(taImpl.getID(),"", true));
assertEquals("Task attempt is not in SUCCEEDED state", assertEquals(TaskAttemptState.SUCCEEDED, taImpl.getState(),
TaskAttemptState.SUCCEEDED, taImpl.getState()); "Task attempt is not in SUCCEEDED state");
assertEquals("Task attempt's internal state is not SUCCEEDED", assertEquals(TaskAttemptStateInternal.SUCCEEDED, taImpl.getInternalState(),
TaskAttemptStateInternal.SUCCEEDED, taImpl.getInternalState()); "Task attempt's internal state is not SUCCEEDED");
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
TaskEvent event = eventHandler.lastTaskEvent; TaskEvent event = eventHandler.lastTaskEvent;
assertEquals(TaskEventType.T_ATTEMPT_SUCCEEDED, event.getType()); assertEquals(TaskEventType.T_ATTEMPT_SUCCEEDED, event.getType());
} }
@ -1498,7 +1496,7 @@ public void testKillMapTaskWhileFailFinishing() throws Exception {
.withFailMessage("Task attempt is not in FAILED state") .withFailMessage("Task attempt is not in FAILED state")
.isEqualTo(TaskAttemptState.FAILED); .isEqualTo(TaskAttemptState.FAILED);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1531,7 +1529,7 @@ public void testFailMapTaskByClient() throws Exception {
.withFailMessage("Task attempt is not in FAILED state") .withFailMessage("Task attempt is not in FAILED state")
.isEqualTo(TaskAttemptState.FAILED); .isEqualTo(TaskAttemptState.FAILED);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1561,7 +1559,7 @@ public void testTaskAttemptDiagnosticEventOnFinishing() throws Exception {
"SUCCESS_FINISHING_CONTAINER") "SUCCESS_FINISHING_CONTAINER")
.isEqualTo(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER); .isEqualTo(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1592,7 +1590,7 @@ public void testTimeoutWhileSuccessFinishing() throws Exception {
"SUCCESS_CONTAINER_CLEANUP") "SUCCESS_CONTAINER_CLEANUP")
.isEqualTo(TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP); .isEqualTo(TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1619,7 +1617,7 @@ public void testTimeoutWhileFailFinishing() throws Exception {
"FAIL_CONTAINER_CLEANUP") "FAIL_CONTAINER_CLEANUP")
.isEqualTo(TaskAttemptStateInternal.FAIL_CONTAINER_CLEANUP); .isEqualTo(TaskAttemptStateInternal.FAIL_CONTAINER_CLEANUP);
assertFalse("InternalError occurred", eventHandler.internalError); assertFalse(eventHandler.internalError, "InternalError occurred");
} }
@Test @Test
@ -1636,8 +1634,8 @@ public void testMapperCustomResourceTypes() {
ResourceInformation resourceInfo = ResourceInformation resourceInfo =
getResourceInfoFromContainerRequest(taImpl, eventHandler). getResourceInfoFromContainerRequest(taImpl, eventHandler).
getResourceInformation(CUSTOM_RESOURCE_NAME); getResourceInformation(CUSTOM_RESOURCE_NAME);
assertEquals("Expecting the default unit (G)", assertEquals("G", resourceInfo.getUnits(),
"G", resourceInfo.getUnits()); "Expecting the default unit (G)");
assertEquals(7L, resourceInfo.getValue()); assertEquals(7L, resourceInfo.getValue());
} }
@ -1654,8 +1652,8 @@ public void testReducerCustomResourceTypes() {
ResourceInformation resourceInfo = ResourceInformation resourceInfo =
getResourceInfoFromContainerRequest(taImpl, eventHandler). getResourceInfoFromContainerRequest(taImpl, eventHandler).
getResourceInformation(CUSTOM_RESOURCE_NAME); getResourceInformation(CUSTOM_RESOURCE_NAME);
assertEquals("Expecting the specified unit (m)", assertEquals("m", resourceInfo.getUnits(),
"m", resourceInfo.getUnits()); "Expecting the specified unit (m)");
assertEquals(3L, resourceInfo.getValue()); assertEquals(3L, resourceInfo.getValue());
} }
@ -1752,8 +1750,9 @@ public void testReducerMemoryRequestOverriding() {
} }
} }
@Test(expected=IllegalArgumentException.class) @Test
public void testReducerMemoryRequestMultipleName() { public void testReducerMemoryRequestMultipleName() {
assertThrows(IllegalArgumentException.class, () -> {
EventHandler eventHandler = mock(EventHandler.class); EventHandler eventHandler = mock(EventHandler.class);
Clock clock = SystemClock.getInstance(); Clock clock = SystemClock.getInstance();
JobConf jobConf = new JobConf(); JobConf jobConf = new JobConf();
@ -1764,6 +1763,7 @@ public void testReducerMemoryRequestMultipleName() {
"3Gi"); "3Gi");
} }
createReduceTaskAttemptImplForTest(eventHandler, clock, jobConf); createReduceTaskAttemptImplForTest(eventHandler, clock, jobConf);
});
} }
@Test @Test
@ -1853,14 +1853,16 @@ private Resource getResourceInfoFromContainerRequest(
containerRequestEvents.add((ContainerRequestEvent) e); containerRequestEvents.add((ContainerRequestEvent) e);
} }
} }
assertEquals("Expected one ContainerRequestEvent after scheduling " assertEquals(1, containerRequestEvents.size(),
+ "task attempt", 1, containerRequestEvents.size()); "Expected one ContainerRequestEvent after scheduling "
+ "task attempt");
return containerRequestEvents.get(0).getCapability(); return containerRequestEvents.get(0).getCapability();
} }
@Test(expected=IllegalArgumentException.class) @Test
public void testReducerCustomResourceTypeWithInvalidUnit() { public void testReducerCustomResourceTypeWithInvalidUnit() {
assertThrows(IllegalArgumentException.class, () -> {
initResourceTypes(); initResourceTypes();
EventHandler eventHandler = mock(EventHandler.class); EventHandler eventHandler = mock(EventHandler.class);
Clock clock = SystemClock.getInstance(); Clock clock = SystemClock.getInstance();
@ -1868,6 +1870,7 @@ public void testReducerCustomResourceTypeWithInvalidUnit() {
jobConf.set(MRJobConfig.REDUCE_RESOURCE_TYPE_PREFIX jobConf.set(MRJobConfig.REDUCE_RESOURCE_TYPE_PREFIX
+ CUSTOM_RESOURCE_NAME, "3z"); + CUSTOM_RESOURCE_NAME, "3z");
createReduceTaskAttemptImplForTest(eventHandler, clock, jobConf); createReduceTaskAttemptImplForTest(eventHandler, clock, jobConf);
});
} }
@Test @Test
@ -1882,22 +1885,19 @@ public void testKillingTaskWhenContainerCleanup() {
// move in two steps to the desired state (cannot get there directly) // move in two steps to the desired state (cannot get there directly)
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_DONE)); TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER,
"SUCCESS_FINISHING_CONTAINER", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER, "SUCCESS_FINISHING_CONTAINER");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_TIMED_OUT)); TaskAttemptEventType.TA_TIMED_OUT));
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP,
"SUCCESS_CONTAINER_CLEANUP", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP, "SUCCESS_CONTAINER_CLEANUP");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptKillEvent(mapTAId, "", true)); taImpl.handle(new TaskAttemptKillEvent(mapTAId, "", true));
assertEquals("Task attempt is not in KILLED state", assertEquals(TaskAttemptState.KILLED,
TaskAttemptState.KILLED, taImpl.getState(), "Task attempt is not in KILLED state");
taImpl.getState());
} }
@Test @Test
@ -1912,24 +1912,21 @@ public void testTooManyFetchFailureWhileContainerCleanup() {
// move in two steps to the desired state (cannot get there directly) // move in two steps to the desired state (cannot get there directly)
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_DONE)); TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER,
"SUCCESS_FINISHING_CONTAINER", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER, "SUCCESS_FINISHING_CONTAINER");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_TIMED_OUT)); TaskAttemptEventType.TA_TIMED_OUT));
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP,
"SUCCESS_CONTAINER_CLEANUP", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_CONTAINER_CLEANUP, "SUCCESS_CONTAINER_CLEANUP");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptTooManyFetchFailureEvent(taImpl.getID(), taImpl.handle(new TaskAttemptTooManyFetchFailureEvent(taImpl.getID(),
reduceTAId, "Host")); reduceTAId, "Host"));
assertEquals("Task attempt is not in FAILED state", assertEquals(TaskAttemptState.FAILED,
TaskAttemptState.FAILED, taImpl.getState(), "Task attempt is not in FAILED state");
taImpl.getState()); assertFalse(eventHandler.internalError, "InternalError occurred");
assertFalse("InternalError occurred", eventHandler.internalError);
} }
private void initResourceTypes() { private void initResourceTypes() {
@ -1951,17 +1948,15 @@ public void testTooManyFetchFailureWhileSuccessFinishing() throws Exception {
taImpl.handle(new TaskAttemptEvent(taImpl.getID(), taImpl.handle(new TaskAttemptEvent(taImpl.getID(),
TaskAttemptEventType.TA_DONE)); TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt's internal state is not " + assertEquals(TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER,
"SUCCESS_FINISHING_CONTAINER", taImpl.getInternalState(), "Task attempt's internal state is not " +
TaskAttemptStateInternal.SUCCESS_FINISHING_CONTAINER, "SUCCESS_FINISHING_CONTAINER");
taImpl.getInternalState());
taImpl.handle(new TaskAttemptTooManyFetchFailureEvent(taImpl.getID(), taImpl.handle(new TaskAttemptTooManyFetchFailureEvent(taImpl.getID(),
reduceTAId, "Host")); reduceTAId, "Host"));
assertEquals("Task attempt is not in FAILED state", assertEquals(TaskAttemptState.FAILED,
TaskAttemptState.FAILED, taImpl.getState(), "Task attempt is not in FAILED state");
taImpl.getState()); assertFalse(eventHandler.internalError, "InternalError occurred");
assertFalse("InternalError occurred", eventHandler.internalError);
} }
private void setupTaskAttemptFinishingMonitor( private void setupTaskAttemptFinishingMonitor(

View File

@ -27,8 +27,8 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
@ -58,12 +58,12 @@
import org.apache.hadoop.yarn.api.records.ContainerLaunchContext; import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.Test; import org.junit.jupiter.api.Test;
@SuppressWarnings({"rawtypes"}) @SuppressWarnings({"rawtypes"})
public class TestTaskAttemptContainerRequest { public class TestTaskAttemptContainerRequest {
@After @AfterEach
public void cleanup() { public void cleanup() {
UserGroupInformation.reset(); UserGroupInformation.reset();
} }
@ -114,7 +114,8 @@ public void testAttemptContainerRequest() throws Exception {
mock(WrappedJvmID.class), taListener, mock(WrappedJvmID.class), taListener,
credentials); credentials);
Assert.assertEquals("ACLs mismatch", acls, launchCtx.getApplicationACLs()); Assertions.assertEquals(acls, launchCtx.getApplicationACLs(),
"ACLs mismatch");
Credentials launchCredentials = new Credentials(); Credentials launchCredentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer(); DataInputByteBuffer dibb = new DataInputByteBuffer();
@ -125,17 +126,18 @@ public void testAttemptContainerRequest() throws Exception {
for (Token<? extends TokenIdentifier> token : credentials.getAllTokens()) { for (Token<? extends TokenIdentifier> token : credentials.getAllTokens()) {
Token<? extends TokenIdentifier> launchToken = Token<? extends TokenIdentifier> launchToken =
launchCredentials.getToken(token.getService()); launchCredentials.getToken(token.getService());
Assert.assertNotNull("Token " + token.getService() + " is missing", Assertions.assertNotNull(launchToken,
launchToken); "Token " + token.getService() + " is missing");
Assert.assertEquals("Token " + token.getService() + " mismatch", Assertions.assertEquals(token, launchToken,
token, launchToken); "Token " + token.getService() + " mismatch");
} }
// verify the secret key is in the launch context // verify the secret key is in the launch context
Assert.assertNotNull("Secret key missing", Assertions.assertNotNull(launchCredentials.getSecretKey(SECRET_KEY_ALIAS),
launchCredentials.getSecretKey(SECRET_KEY_ALIAS)); "Secret key missing");
Assert.assertTrue("Secret key mismatch", Arrays.equals(SECRET_KEY, Assertions.assertTrue(Arrays.equals(SECRET_KEY,
launchCredentials.getSecretKey(SECRET_KEY_ALIAS))); launchCredentials.getSecretKey(SECRET_KEY_ALIAS)),
"Secret key mismatch");
} }
static public class StubbedFS extends RawLocalFileSystem { static public class StubbedFS extends RawLocalFileSystem {

View File

@ -17,10 +17,10 @@
*/ */
package org.apache.hadoop.mapreduce.v2.app.job.impl; package org.apache.hadoop.mapreduce.v2.app.job.impl;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -65,9 +65,9 @@
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.apache.hadoop.yarn.util.SystemClock; import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -234,7 +234,7 @@ public boolean isMapTask() {
} }
@Before @BeforeEach
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setup() { public void setup() {
dispatcher = new InlineDispatcher(); dispatcher = new InlineDispatcher();
@ -273,7 +273,7 @@ private MockTaskImpl createMockTask(TaskType taskType) {
startCount, metrics, appContext, taskType); startCount, metrics, appContext, taskType);
} }
@After @AfterEach
public void teardown() { public void teardown() {
taskAttempts.clear(); taskAttempts.clear();
} }
@ -587,10 +587,10 @@ public void testFailureDuringTaskAttemptCommit() {
mockTask.handle(new TaskTAttemptEvent(getLastAttempt().getAttemptId(), mockTask.handle(new TaskTAttemptEvent(getLastAttempt().getAttemptId(),
TaskEventType.T_ATTEMPT_SUCCEEDED)); TaskEventType.T_ATTEMPT_SUCCEEDED));
assertFalse("First attempt should not commit", assertFalse(mockTask.canCommit(taskAttempts.get(0).getAttemptId()),
mockTask.canCommit(taskAttempts.get(0).getAttemptId())); "First attempt should not commit");
assertTrue("Second attempt should commit", assertTrue(mockTask.canCommit(getLastAttempt().getAttemptId()),
mockTask.canCommit(getLastAttempt().getAttemptId())); "Second attempt should commit");
assertTaskSucceededState(); assertTaskSucceededState();
} }
@ -879,7 +879,8 @@ protected int getMaxAttempts() {
baseAttempt.setProgress(1.0f); baseAttempt.setProgress(1.0f);
Counters taskCounters = mockTask.getCounters(); Counters taskCounters = mockTask.getCounters();
assertEquals("wrong counters for task", specAttemptCounters, taskCounters); assertEquals(specAttemptCounters, taskCounters,
"wrong counters for task");
} }
public static class MockTaskAttemptEventHandler implements EventHandler { public static class MockTaskAttemptEventHandler implements EventHandler {

View File

@ -44,7 +44,7 @@
import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationResponse; import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationResponse;
import org.apache.hadoop.yarn.api.protocolrecords.RestartContainerResponse; import org.apache.hadoop.yarn.api.protocolrecords.RestartContainerResponse;
import org.apache.hadoop.yarn.api.protocolrecords.RollbackResponse; import org.apache.hadoop.yarn.api.protocolrecords.RollbackResponse;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.ipc.Server; import org.apache.hadoop.ipc.Server;
@ -93,7 +93,8 @@
import org.apache.hadoop.yarn.server.api.records.MasterKey; import org.apache.hadoop.yarn.server.api.records.MasterKey;
import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM; import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -107,9 +108,9 @@ public class TestContainerLauncher {
static final Logger LOG = static final Logger LOG =
LoggerFactory.getLogger(TestContainerLauncher.class); LoggerFactory.getLogger(TestContainerLauncher.class);
@Test (timeout = 10000) @Test
@Timeout(10000)
public void testPoolSize() throws InterruptedException { public void testPoolSize() throws InterruptedException {
ApplicationId appId = ApplicationId.newInstance(12345, 67); ApplicationId appId = ApplicationId.newInstance(12345, 67);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
appId, 3); appId, 3);
@ -127,10 +128,10 @@ public void testPoolSize() throws InterruptedException {
// No events yet // No events yet
assertThat(containerLauncher.initialPoolSize).isEqualTo( assertThat(containerLauncher.initialPoolSize).isEqualTo(
MRJobConfig.DEFAULT_MR_AM_CONTAINERLAUNCHER_THREADPOOL_INITIAL_SIZE); MRJobConfig.DEFAULT_MR_AM_CONTAINERLAUNCHER_THREADPOOL_INITIAL_SIZE);
Assert.assertEquals(0, threadPool.getPoolSize()); Assertions.assertEquals(0, threadPool.getPoolSize());
Assert.assertEquals(containerLauncher.initialPoolSize, Assertions.assertEquals(containerLauncher.initialPoolSize,
threadPool.getCorePoolSize()); threadPool.getCorePoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
containerLauncher.expectedCorePoolSize = containerLauncher.initialPoolSize; containerLauncher.expectedCorePoolSize = containerLauncher.initialPoolSize;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -141,8 +142,8 @@ public void testPoolSize() throws InterruptedException {
ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH)); ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH));
} }
waitForEvents(containerLauncher, 10); waitForEvents(containerLauncher, 10);
Assert.assertEquals(10, threadPool.getPoolSize()); Assertions.assertEquals(10, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
// Same set of hosts, so no change // Same set of hosts, so no change
containerLauncher.finishEventHandling = true; containerLauncher.finishEventHandling = true;
@ -153,7 +154,7 @@ public void testPoolSize() throws InterruptedException {
+ ". Timeout is " + timeOut); + ". Timeout is " + timeOut);
Thread.sleep(1000); Thread.sleep(1000);
} }
Assert.assertEquals(10, containerLauncher.numEventsProcessed.get()); Assertions.assertEquals(10, containerLauncher.numEventsProcessed.get());
containerLauncher.finishEventHandling = false; containerLauncher.finishEventHandling = false;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ContainerId containerId = ContainerId.newContainerId(appAttemptId, ContainerId containerId = ContainerId.newContainerId(appAttemptId,
@ -165,8 +166,8 @@ public void testPoolSize() throws InterruptedException {
ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH)); ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH));
} }
waitForEvents(containerLauncher, 20); waitForEvents(containerLauncher, 20);
Assert.assertEquals(10, threadPool.getPoolSize()); Assertions.assertEquals(10, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
// Different hosts, there should be an increase in core-thread-pool size to // Different hosts, there should be an increase in core-thread-pool size to
// 21(11hosts+10buffer) // 21(11hosts+10buffer)
@ -179,8 +180,8 @@ public void testPoolSize() throws InterruptedException {
containerId, "host11:1234", null, containerId, "host11:1234", null,
ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH)); ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH));
waitForEvents(containerLauncher, 21); waitForEvents(containerLauncher, 21);
Assert.assertEquals(11, threadPool.getPoolSize()); Assertions.assertEquals(11, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
containerLauncher.stop(); containerLauncher.stop();
@ -194,7 +195,8 @@ public void testPoolSize() throws InterruptedException {
assertThat(containerLauncher.initialPoolSize).isEqualTo(20); assertThat(containerLauncher.initialPoolSize).isEqualTo(20);
} }
@Test(timeout = 5000) @Test
@Timeout(5000)
public void testPoolLimits() throws InterruptedException { public void testPoolLimits() throws InterruptedException {
ApplicationId appId = ApplicationId.newInstance(12345, 67); ApplicationId appId = ApplicationId.newInstance(12345, 67);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
@ -222,8 +224,8 @@ public void testPoolLimits() throws InterruptedException {
ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH)); ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH));
} }
waitForEvents(containerLauncher, 10); waitForEvents(containerLauncher, 10);
Assert.assertEquals(10, threadPool.getPoolSize()); Assertions.assertEquals(10, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
// 4 more different hosts, but thread pool size should be capped at 12 // 4 more different hosts, but thread pool size should be capped at 12
containerLauncher.expectedCorePoolSize = 12 ; containerLauncher.expectedCorePoolSize = 12 ;
@ -233,14 +235,14 @@ public void testPoolLimits() throws InterruptedException {
ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH)); ContainerLauncher.EventType.CONTAINER_REMOTE_LAUNCH));
} }
waitForEvents(containerLauncher, 12); waitForEvents(containerLauncher, 12);
Assert.assertEquals(12, threadPool.getPoolSize()); Assertions.assertEquals(12, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
// Make some threads ideal so that remaining events are also done. // Make some threads ideal so that remaining events are also done.
containerLauncher.finishEventHandling = true; containerLauncher.finishEventHandling = true;
waitForEvents(containerLauncher, 14); waitForEvents(containerLauncher, 14);
Assert.assertEquals(12, threadPool.getPoolSize()); Assertions.assertEquals(12, threadPool.getPoolSize());
Assert.assertNull(containerLauncher.foundErrors); Assertions.assertNull(containerLauncher.foundErrors);
containerLauncher.stop(); containerLauncher.stop();
} }
@ -254,13 +256,13 @@ private void waitForEvents(CustomContainerLauncher containerLauncher,
+ ". It is now " + containerLauncher.numEventsProcessing.get()); + ". It is now " + containerLauncher.numEventsProcessing.get());
Thread.sleep(1000); Thread.sleep(1000);
} }
Assert.assertEquals(expectedNumEvents, Assertions.assertEquals(expectedNumEvents,
containerLauncher.numEventsProcessing.get()); containerLauncher.numEventsProcessing.get());
} }
@Test(timeout = 15000) @Test
@Timeout(15000)
public void testSlowNM() throws Exception { public void testSlowNM() throws Exception {
conf = new Configuration(); conf = new Configuration();
int maxAttempts = 1; int maxAttempts = 1;
conf.setInt(MRJobConfig.MAP_MAX_ATTEMPTS, maxAttempts); conf.setInt(MRJobConfig.MAP_MAX_ATTEMPTS, maxAttempts);
@ -290,15 +292,16 @@ public void testSlowNM() throws Exception {
app.waitForState(job, JobState.RUNNING); app.waitForState(job, JobState.RUNNING);
Map<TaskId, Task> tasks = job.getTasks(); Map<TaskId, Task> tasks = job.getTasks();
Assert.assertEquals("Num tasks is not correct", 1, tasks.size()); Assertions.assertEquals(1, tasks.size(),
"Num tasks is not correct");
Task task = tasks.values().iterator().next(); Task task = tasks.values().iterator().next();
app.waitForState(task, TaskState.SCHEDULED); app.waitForState(task, TaskState.SCHEDULED);
Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator() Map<TaskAttemptId, TaskAttempt> attempts = tasks.values().iterator()
.next().getAttempts(); .next().getAttempts();
Assert.assertEquals("Num attempts is not correct", maxAttempts, Assertions.assertEquals(maxAttempts, attempts.size(),
attempts.size()); "Num attempts is not correct");
TaskAttempt attempt = attempts.values().iterator().next(); TaskAttempt attempt = attempts.values().iterator().next();
app.waitForInternalState((TaskAttemptImpl) attempt, app.waitForInternalState((TaskAttemptImpl) attempt,
@ -309,9 +312,9 @@ public void testSlowNM() throws Exception {
String diagnostics = attempt.getDiagnostics().toString(); String diagnostics = attempt.getDiagnostics().toString();
LOG.info("attempt.getDiagnostics: " + diagnostics); LOG.info("attempt.getDiagnostics: " + diagnostics);
Assert.assertTrue(diagnostics.contains("Container launch failed for " Assertions.assertTrue(diagnostics.contains("Container launch failed for "
+ "container_0_0000_01_000000 : ")); + "container_0_0000_01_000000 : "));
Assert Assertions
.assertTrue(diagnostics .assertTrue(diagnostics
.contains("java.net.SocketTimeoutException: 3000 millis timeout while waiting for channel")); .contains("java.net.SocketTimeoutException: 3000 millis timeout while waiting for channel"));
@ -440,7 +443,7 @@ public StartContainersResponse startContainers(StartContainersRequest requests)
MRApp.newContainerTokenIdentifier(request.getContainerToken()); MRApp.newContainerTokenIdentifier(request.getContainerToken());
// Validate that the container is what RM is giving. // Validate that the container is what RM is giving.
Assert.assertEquals(MRApp.NM_HOST + ":" + MRApp.NM_PORT, Assertions.assertEquals(MRApp.NM_HOST + ":" + MRApp.NM_PORT,
containerTokenIdentifier.getNmHostAddress()); containerTokenIdentifier.getNmHostAddress());
StartContainersResponse response = recordFactory StartContainersResponse response = recordFactory

View File

@ -79,8 +79,9 @@
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier; import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -94,7 +95,7 @@ public class TestContainerLauncherImpl {
private Map<String, ByteBuffer> serviceResponse = private Map<String, ByteBuffer> serviceResponse =
new HashMap<String, ByteBuffer>(); new HashMap<String, ByteBuffer>();
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
serviceResponse.clear(); serviceResponse.clear();
serviceResponse.put(ShuffleHandler.MAPREDUCE_SHUFFLE_SERVICEID, serviceResponse.put(ShuffleHandler.MAPREDUCE_SHUFFLE_SERVICEID,
@ -168,7 +169,8 @@ public static TaskAttemptId makeTaskAttemptId(long ts, int appId, int taskId,
return MRBuilderUtils.newTaskAttemptId(tID, id); return MRBuilderUtils.newTaskAttemptId(tID, id);
} }
@Test(timeout = 5000) @Test
@Timeout(5000)
public void testHandle() throws Exception { public void testHandle() throws Exception {
LOG.info("STARTING testHandle"); LOG.info("STARTING testHandle");
AppContext mockContext = mock(AppContext.class); AppContext mockContext = mock(AppContext.class);
@ -226,7 +228,8 @@ public void testHandle() throws Exception {
} }
} }
@Test(timeout = 5000) @Test
@Timeout(5000)
public void testOutOfOrder() throws Exception { public void testOutOfOrder() throws Exception {
LOG.info("STARTING testOutOfOrder"); LOG.info("STARTING testOutOfOrder");
AppContext mockContext = mock(AppContext.class); AppContext mockContext = mock(AppContext.class);
@ -300,7 +303,8 @@ public void testOutOfOrder() throws Exception {
} }
} }
@Test(timeout = 5000) @Test
@Timeout(5000)
public void testMyShutdown() throws Exception { public void testMyShutdown() throws Exception {
LOG.info("in test Shutdown"); LOG.info("in test Shutdown");
@ -352,7 +356,8 @@ public void testMyShutdown() throws Exception {
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@Test(timeout = 5000) @Test
@Timeout(5000)
public void testContainerCleaned() throws Exception { public void testContainerCleaned() throws Exception {
LOG.info("STARTING testContainerCleaned"); LOG.info("STARTING testContainerCleaned");

View File

@ -69,8 +69,8 @@
import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.ipc.RPCUtil;
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.resource.Resources;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
public class TestLocalContainerAllocator { public class TestLocalContainerAllocator {
@ -90,7 +90,7 @@ public void testRMConnectionRetry() throws Exception {
lca.start(); lca.start();
try { try {
lca.heartbeat(); lca.heartbeat();
Assert.fail("heartbeat was supposed to throw"); Assertions.fail("heartbeat was supposed to throw");
} catch (YarnException e) { } catch (YarnException e) {
// YarnException is expected // YarnException is expected
} finally { } finally {
@ -104,7 +104,7 @@ public void testRMConnectionRetry() throws Exception {
lca.start(); lca.start();
try { try {
lca.heartbeat(); lca.heartbeat();
Assert.fail("heartbeat was supposed to throw"); Assertions.fail("heartbeat was supposed to throw");
} catch (YarnRuntimeException e) { } catch (YarnRuntimeException e) {
// YarnRuntimeException is expected // YarnRuntimeException is expected
} finally { } finally {
@ -172,14 +172,13 @@ public Void run() throws Exception {
} }
} }
Assert.assertEquals("too many AMRM tokens", 1, tokenCount); Assertions.assertEquals(1, tokenCount, "too many AMRM tokens");
Assert.assertArrayEquals("token identifier not updated", Assertions.assertArrayEquals(newToken.getIdentifier(), ugiToken.getIdentifier(),
newToken.getIdentifier(), ugiToken.getIdentifier()); "token identifier not updated");
Assert.assertArrayEquals("token password not updated", Assertions.assertArrayEquals(newToken.getPassword(), ugiToken.getPassword(),
newToken.getPassword(), ugiToken.getPassword()); "token password not updated");
Assert.assertEquals("AMRM token service not updated", Assertions.assertEquals(new Text(ClientRMProxy.getAMRMTokenService(conf)),
new Text(ClientRMProxy.getAMRMTokenService(conf)), ugiToken.getService(), "AMRM token service not updated");
ugiToken.getService());
} }
@Test @Test
@ -202,7 +201,7 @@ public void testAllocatedContainerResourceIsNotNull() {
verify(eventHandler, times(1)).handle(containerAssignedCaptor.capture()); verify(eventHandler, times(1)).handle(containerAssignedCaptor.capture());
Container container = containerAssignedCaptor.getValue().getContainer(); Container container = containerAssignedCaptor.getValue().getContainer();
Resource containerResource = container.getResource(); Resource containerResource = container.getResource();
Assert.assertNotNull(containerResource); Assertions.assertNotNull(containerResource);
assertThat(containerResource.getMemorySize()).isEqualTo(0); assertThat(containerResource.getMemorySize()).isEqualTo(0);
assertThat(containerResource.getVirtualCores()).isEqualTo(0); assertThat(containerResource.getVirtualCores()).isEqualTo(0);
} }
@ -282,8 +281,8 @@ public FinishApplicationMasterResponse finishApplicationMaster(
@Override @Override
public AllocateResponse allocate(AllocateRequest request) public AllocateResponse allocate(AllocateRequest request)
throws YarnException, IOException { throws YarnException, IOException {
Assert.assertEquals("response ID mismatch", Assertions.assertEquals(responseId, request.getResponseId(),
responseId, request.getResponseId()); "response ID mismatch");
++responseId; ++responseId;
org.apache.hadoop.yarn.api.records.Token yarnToken = null; org.apache.hadoop.yarn.api.records.Token yarnToken = null;
if (amToken != null) { if (amToken != null) {

View File

@ -25,19 +25,20 @@
import static org.apache.hadoop.test.MetricsAsserts.*; import static org.apache.hadoop.test.MetricsAsserts.*;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class TestMRAppMetrics { public class TestMRAppMetrics {
@After @AfterEach
public void tearDown() { public void tearDown() {
DefaultMetricsSystem.shutdown(); DefaultMetricsSystem.shutdown();
} }
@Test public void testNames() { @Test
public void testNames() {
Job job = mock(Job.class); Job job = mock(Job.class);
Task mapTask = mock(Task.class); Task mapTask = mock(Task.class);
when(mapTask.getType()).thenReturn(TaskType.MAP); when(mapTask.getType()).thenReturn(TaskType.MAP);

View File

@ -23,7 +23,8 @@
import org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable; import org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.AllocatorRunnable;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.Clock;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@ -45,7 +46,8 @@ protected void heartbeat() throws Exception {
} }
} }
@Test(timeout = 2000) @Test
@Timeout(2000)
public void testRMContainerAllocatorExceptionIsHandled() throws Exception { public void testRMContainerAllocatorExceptionIsHandled() throws Exception {
ClientService mockClientService = mock(ClientService.class); ClientService mockClientService = mock(ClientService.class);
AppContext mockContext = mock(AppContext.class); AppContext mockContext = mock(AppContext.class);
@ -66,7 +68,8 @@ public void testRMContainerAllocatorExceptionIsHandled() throws Exception {
testRunnable.run(); testRunnable.run();
} }
@Test(timeout = 2000) @Test
@Timeout(2000)
public void testRMContainerAllocatorYarnRuntimeExceptionIsHandled() public void testRMContainerAllocatorYarnRuntimeExceptionIsHandled()
throws Exception { throws Exception {
ClientService mockClientService = mock(ClientService.class); ClientService mockClientService = mock(ClientService.class);

View File

@ -19,8 +19,8 @@
package org.apache.hadoop.mapreduce.v2.app.rm; package org.apache.hadoop.mapreduce.v2.app.rm;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.EnumSet; import java.util.EnumSet;
@ -59,17 +59,17 @@ private void verifyDifferentResourceTypes(Resource clusterAvailableResources,
Resource nonZeroResource, int expectedNumberOfContainersForMemoryOnly, Resource nonZeroResource, int expectedNumberOfContainersForMemoryOnly,
int expectedNumberOfContainersOverall) { int expectedNumberOfContainersOverall) {
Assert.assertEquals("Incorrect number of available containers for Memory", Assertions.assertEquals(expectedNumberOfContainersForMemoryOnly,
expectedNumberOfContainersForMemoryOnly,
ResourceCalculatorUtils.computeAvailableContainers( ResourceCalculatorUtils.computeAvailableContainers(
clusterAvailableResources, nonZeroResource, clusterAvailableResources, nonZeroResource,
EnumSet.of(SchedulerResourceTypes.MEMORY))); EnumSet.of(SchedulerResourceTypes.MEMORY)),
"Incorrect number of available containers for Memory");
Assert.assertEquals("Incorrect number of available containers overall", Assertions.assertEquals(expectedNumberOfContainersOverall,
expectedNumberOfContainersOverall,
ResourceCalculatorUtils.computeAvailableContainers( ResourceCalculatorUtils.computeAvailableContainers(
clusterAvailableResources, nonZeroResource, clusterAvailableResources, nonZeroResource,
EnumSet.of(SchedulerResourceTypes.CPU, EnumSet.of(SchedulerResourceTypes.CPU,
SchedulerResourceTypes.MEMORY))); SchedulerResourceTypes.MEMORY)),
"Incorrect number of available containers overall");
} }
} }

View File

@ -18,8 +18,8 @@
package org.apache.hadoop.mapreduce.v2.app.speculate; package org.apache.hadoop.mapreduce.v2.app.speculate;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TestDataStatistics { public class TestDataStatistics {
@ -28,21 +28,21 @@ public class TestDataStatistics {
@Test @Test
public void testEmptyDataStatistics() throws Exception { public void testEmptyDataStatistics() throws Exception {
DataStatistics statistics = new DataStatistics(); DataStatistics statistics = new DataStatistics();
Assert.assertEquals(0, statistics.count(), TOL); Assertions.assertEquals(0, statistics.count(), TOL);
Assert.assertEquals(0, statistics.mean(), TOL); Assertions.assertEquals(0, statistics.mean(), TOL);
Assert.assertEquals(0, statistics.var(), TOL); Assertions.assertEquals(0, statistics.var(), TOL);
Assert.assertEquals(0, statistics.std(), TOL); Assertions.assertEquals(0, statistics.std(), TOL);
Assert.assertEquals(0, statistics.outlier(1.0f), TOL); Assertions.assertEquals(0, statistics.outlier(1.0f), TOL);
} }
@Test @Test
public void testSingleEntryDataStatistics() throws Exception { public void testSingleEntryDataStatistics() throws Exception {
DataStatistics statistics = new DataStatistics(17.29); DataStatistics statistics = new DataStatistics(17.29);
Assert.assertEquals(1, statistics.count(), TOL); Assertions.assertEquals(1, statistics.count(), TOL);
Assert.assertEquals(17.29, statistics.mean(), TOL); Assertions.assertEquals(17.29, statistics.mean(), TOL);
Assert.assertEquals(0, statistics.var(), TOL); Assertions.assertEquals(0, statistics.var(), TOL);
Assert.assertEquals(0, statistics.std(), TOL); Assertions.assertEquals(0, statistics.std(), TOL);
Assert.assertEquals(17.29, statistics.outlier(1.0f), TOL); Assertions.assertEquals(17.29, statistics.outlier(1.0f), TOL);
} }
@Test @Test
@ -50,24 +50,24 @@ public void testMutiEntryDataStatistics() throws Exception {
DataStatistics statistics = new DataStatistics(); DataStatistics statistics = new DataStatistics();
statistics.add(17); statistics.add(17);
statistics.add(29); statistics.add(29);
Assert.assertEquals(2, statistics.count(), TOL); Assertions.assertEquals(2, statistics.count(), TOL);
Assert.assertEquals(23.0, statistics.mean(), TOL); Assertions.assertEquals(23.0, statistics.mean(), TOL);
Assert.assertEquals(36.0, statistics.var(), TOL); Assertions.assertEquals(36.0, statistics.var(), TOL);
Assert.assertEquals(6.0, statistics.std(), TOL); Assertions.assertEquals(6.0, statistics.std(), TOL);
Assert.assertEquals(29.0, statistics.outlier(1.0f), TOL); Assertions.assertEquals(29.0, statistics.outlier(1.0f), TOL);
} }
@Test @Test
public void testUpdateStatistics() throws Exception { public void testUpdateStatistics() throws Exception {
DataStatistics statistics = new DataStatistics(17); DataStatistics statistics = new DataStatistics(17);
statistics.add(29); statistics.add(29);
Assert.assertEquals(2, statistics.count(), TOL); Assertions.assertEquals(2, statistics.count(), TOL);
Assert.assertEquals(23.0, statistics.mean(), TOL); Assertions.assertEquals(23.0, statistics.mean(), TOL);
Assert.assertEquals(36.0, statistics.var(), TOL); Assertions.assertEquals(36.0, statistics.var(), TOL);
statistics.updateStatistics(17, 29); statistics.updateStatistics(17, 29);
Assert.assertEquals(2, statistics.count(), TOL); Assertions.assertEquals(2, statistics.count(), TOL);
Assert.assertEquals(29.0, statistics.mean(), TOL); Assertions.assertEquals(29.0, statistics.mean(), TOL);
Assert.assertEquals(0.0, statistics.var(), TOL); Assertions.assertEquals(0.0, statistics.var(), TOL);
} }
} }

View File

@ -21,8 +21,8 @@
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.yarn.util.ControlledClock; import org.apache.hadoop.yarn.util.ControlledClock;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Testing the statistical model of simple exponential estimator. * Testing the statistical model of simple exponential estimator.
@ -100,21 +100,21 @@ private int zeroTestSimpleExponentialForecast() {
@Test @Test
public void testSimpleExponentialForecastLinearInc() throws Exception { public void testSimpleExponentialForecastLinearInc() throws Exception {
int res = incTestSimpleExponentialForecast(); int res = incTestSimpleExponentialForecast();
Assert.assertEquals("We got the wrong estimate from simple exponential.", Assertions.assertEquals(res, 0,
res, 0); "We got the wrong estimate from simple exponential.");
} }
@Test @Test
public void testSimpleExponentialForecastLinearDec() throws Exception { public void testSimpleExponentialForecastLinearDec() throws Exception {
int res = decTestSimpleExponentialForecast(); int res = decTestSimpleExponentialForecast();
Assert.assertEquals("We got the wrong estimate from simple exponential.", Assertions.assertEquals(res, 0,
res, 0); "We got the wrong estimate from simple exponential.");
} }
@Test @Test
public void testSimpleExponentialForecastZeros() throws Exception { public void testSimpleExponentialForecastZeros() throws Exception {
int res = zeroTestSimpleExponentialForecast(); int res = zeroTestSimpleExponentialForecast();
Assert.assertEquals("We got the wrong estimate from simple exponential.", Assertions.assertEquals(res, 0,
res, 0); "We got the wrong estimate from simple exponential.");
} }
} }

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.apache.hadoop.mapreduce.v2.app.webapp.AMParams.APP_ID; import static org.apache.hadoop.mapreduce.v2.app.webapp.AMParams.APP_ID;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -39,7 +39,7 @@
import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.MRJobConfig;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.http.HttpConfig.Policy; import org.apache.hadoop.http.HttpConfig.Policy;
@ -65,14 +65,17 @@
import org.apache.hadoop.yarn.webapp.test.WebAppTests; import org.apache.hadoop.yarn.webapp.test.WebAppTests;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.apache.hadoop.thirdparty.com.google.common.net.HttpHeaders; import org.apache.hadoop.thirdparty.com.google.common.net.HttpHeaders;
import com.google.inject.Injector; import com.google.inject.Injector;
import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
@ExtendWith(SystemStubsExtension.class)
public class TestAMWebApp { public class TestAMWebApp {
private static final File TEST_DIR = new File( private static final File TEST_DIR = new File(
@ -80,12 +83,13 @@ public class TestAMWebApp {
System.getProperty("java.io.tmpdir")), System.getProperty("java.io.tmpdir")),
TestAMWebApp.class.getName()); TestAMWebApp.class.getName());
@After @AfterEach
public void tearDown() { public void tearDown() {
TEST_DIR.delete(); TEST_DIR.delete();
} }
@Test public void testAppControllerIndex() { @Test
public void testAppControllerIndex() {
AppContext ctx = new MockAppContext(0, 1, 1, 1); AppContext ctx = new MockAppContext(0, 1, 1, 1);
Injector injector = WebAppTests.createMockInjector(AppContext.class, ctx); Injector injector = WebAppTests.createMockInjector(AppContext.class, ctx);
AppController controller = injector.getInstance(AppController.class); AppController controller = injector.getInstance(AppController.class);
@ -93,25 +97,29 @@ public void tearDown() {
assertEquals(ctx.getApplicationID().toString(), controller.get(APP_ID,"")); assertEquals(ctx.getApplicationID().toString(), controller.get(APP_ID,""));
} }
@Test public void testAppView() { @Test
public void testAppView() {
WebAppTests.testPage(AppView.class, AppContext.class, new MockAppContext(0, 1, 1, 1)); WebAppTests.testPage(AppView.class, AppContext.class, new MockAppContext(0, 1, 1, 1));
} }
@Test public void testJobView() { @Test
public void testJobView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Map<String, String> params = getJobParams(appContext); Map<String, String> params = getJobParams(appContext);
WebAppTests.testPage(JobPage.class, AppContext.class, appContext, params); WebAppTests.testPage(JobPage.class, AppContext.class, appContext, params);
} }
@Test public void testTasksView() { @Test
public void testTasksView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Map<String, String> params = getTaskParams(appContext); Map<String, String> params = getTaskParams(appContext);
WebAppTests.testPage(TasksPage.class, AppContext.class, appContext, params); WebAppTests.testPage(TasksPage.class, AppContext.class, appContext, params);
} }
@Test public void testTaskView() { @Test
public void testTaskView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Map<String, String> params = getTaskParams(appContext); Map<String, String> params = getTaskParams(appContext);
App app = new App(appContext); App app = new App(appContext);
@ -138,19 +146,22 @@ public static Map<String, String> getTaskParams(AppContext appContext) {
return params; return params;
} }
@Test public void testConfView() { @Test
public void testConfView() {
WebAppTests.testPage(JobConfPage.class, AppContext.class, WebAppTests.testPage(JobConfPage.class, AppContext.class,
new MockAppContext(0, 1, 1, 1)); new MockAppContext(0, 1, 1, 1));
} }
@Test public void testCountersView() { @Test
public void testCountersView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Map<String, String> params = getJobParams(appContext); Map<String, String> params = getJobParams(appContext);
WebAppTests.testPage(CountersPage.class, AppContext.class, WebAppTests.testPage(CountersPage.class, AppContext.class,
appContext, params); appContext, params);
} }
@Test public void testSingleCounterView() { @Test
public void testSingleCounterView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Job job = appContext.getAllJobs().values().iterator().next(); Job job = appContext.getAllJobs().values().iterator().next();
// add a failed task to the job without any counters // add a failed task to the job without any counters
@ -165,14 +176,16 @@ public static Map<String, String> getTaskParams(AppContext appContext) {
appContext, params); appContext, params);
} }
@Test public void testTaskCountersView() { @Test
public void testTaskCountersView() {
AppContext appContext = new MockAppContext(0, 1, 1, 1); AppContext appContext = new MockAppContext(0, 1, 1, 1);
Map<String, String> params = getTaskParams(appContext); Map<String, String> params = getTaskParams(appContext);
WebAppTests.testPage(CountersPage.class, AppContext.class, WebAppTests.testPage(CountersPage.class, AppContext.class,
appContext, params); appContext, params);
} }
@Test public void testSingleTaskCounterView() { @Test
public void testSingleTaskCounterView() {
AppContext appContext = new MockAppContext(0, 1, 1, 2); AppContext appContext = new MockAppContext(0, 1, 1, 2);
Map<String, String> params = getTaskParams(appContext); Map<String, String> params = getTaskParams(appContext);
params.put(AMParams.COUNTER_GROUP, params.put(AMParams.COUNTER_GROUP,
@ -213,7 +226,7 @@ protected ClientService createClientService(AppContext context) {
InputStream in = conn.getInputStream(); InputStream in = conn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyBytes(in, out, 1024); IOUtils.copyBytes(in, out, 1024);
Assert.assertTrue(out.toString().contains("MapReduce Application")); Assertions.assertTrue(out.toString().contains("MapReduce Application"));
// https:// is not accessible. // https:// is not accessible.
URL httpsUrl = new URL("https://" + hostPort); URL httpsUrl = new URL("https://" + hostPort);
@ -221,7 +234,7 @@ protected ClientService createClientService(AppContext context) {
HttpURLConnection httpsConn = HttpURLConnection httpsConn =
(HttpURLConnection) httpsUrl.openConnection(); (HttpURLConnection) httpsUrl.openConnection();
httpsConn.getInputStream(); httpsConn.getInputStream();
Assert.fail("https:// is not accessible, expected to fail"); Assertions.fail("https:// is not accessible, expected to fail");
} catch (SSLException e) { } catch (SSLException e) {
// expected // expected
} }
@ -230,9 +243,8 @@ protected ClientService createClientService(AppContext context) {
app.verifyCompleted(); app.verifyCompleted();
} }
@Rule @SystemStub
public final EnvironmentVariables environmentVariables public EnvironmentVariables environmentVariables;
= new EnvironmentVariables();
@Test @Test
public void testMRWebAppSSLEnabled() throws Exception { public void testMRWebAppSSLEnabled() throws Exception {
@ -270,7 +282,7 @@ protected ClientService createClientService(AppContext context) {
InputStream in = httpsConn.getInputStream(); InputStream in = httpsConn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyBytes(in, out, 1024); IOUtils.copyBytes(in, out, 1024);
Assert.assertTrue(out.toString().contains("MapReduce Application")); Assertions.assertTrue(out.toString().contains("MapReduce Application"));
// http:// is not accessible. // http:// is not accessible.
URL httpUrl = new URL("http://" + hostPort); URL httpUrl = new URL("http://" + hostPort);
@ -278,7 +290,7 @@ protected ClientService createClientService(AppContext context) {
HttpURLConnection httpConn = HttpURLConnection httpConn =
(HttpURLConnection) httpUrl.openConnection(); (HttpURLConnection) httpUrl.openConnection();
httpConn.getResponseCode(); httpConn.getResponseCode();
Assert.fail("http:// is not accessible, expected to fail"); Assertions.fail("http:// is not accessible, expected to fail");
} catch (SocketException e) { } catch (SocketException e) {
// expected // expected
} }
@ -337,7 +349,7 @@ protected ClientService createClientService(AppContext context) {
InputStream in = httpsConn.getInputStream(); InputStream in = httpsConn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyBytes(in, out, 1024); IOUtils.copyBytes(in, out, 1024);
Assert.assertTrue(out.toString().contains("MapReduce Application")); Assertions.assertTrue(out.toString().contains("MapReduce Application"));
// Try with wrong client cert // Try with wrong client cert
KeyPair otherClientKeyPair = KeyStoreTestUtil.generateKeyPair("RSA"); KeyPair otherClientKeyPair = KeyStoreTestUtil.generateKeyPair("RSA");
@ -349,7 +361,7 @@ protected ClientService createClientService(AppContext context) {
HttpURLConnection httpConn = HttpURLConnection httpConn =
(HttpURLConnection) httpsUrl.openConnection(); (HttpURLConnection) httpsUrl.openConnection();
httpConn.getResponseCode(); httpConn.getResponseCode();
Assert.fail("Wrong client certificate, expected to fail"); Assertions.fail("Wrong client certificate, expected to fail");
} catch (SSLException e) { } catch (SSLException e) {
// expected // expected
} }
@ -404,9 +416,9 @@ protected ClientService createClientService(AppContext context) {
String expectedURL = scheme + conf.get(YarnConfiguration.PROXY_ADDRESS) String expectedURL = scheme + conf.get(YarnConfiguration.PROXY_ADDRESS)
+ ProxyUriUtils.getPath(app.getAppID(), "/mapreduce", true); + ProxyUriUtils.getPath(app.getAppID(), "/mapreduce", true);
Assert.assertEquals(expectedURL, Assertions.assertEquals(expectedURL,
conn.getHeaderField(HttpHeaders.LOCATION)); conn.getHeaderField(HttpHeaders.LOCATION));
Assert.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, Assertions.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,
conn.getResponseCode()); conn.getResponseCode());
app.waitForState(job, JobState.SUCCEEDED); app.waitForState(job, JobState.SUCCEEDED);
app.verifyCompleted(); app.verifyCompleted();

View File

@ -19,9 +19,9 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.StringReader; import java.io.StringReader;
import java.util.Set; import java.util.Set;
@ -43,8 +43,8 @@
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -93,7 +93,7 @@ protected void configureServlets() {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -117,7 +117,7 @@ public void testAM() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -129,7 +129,7 @@ public void testAMSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -141,7 +141,7 @@ public void testAMDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -165,7 +165,7 @@ public void testInfo() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -178,7 +178,7 @@ public void testInfoSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -190,7 +190,7 @@ public void testInfoDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyAMInfo(json.getJSONObject("info"), appContext); verifyAMInfo(json.getJSONObject("info"), appContext);
} }
@ -264,7 +264,7 @@ public void testBlacklistedNodes() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
verifyBlacklistedNodesInfo(json, appContext); verifyBlacklistedNodesInfo(json, appContext);
} }
@ -282,7 +282,7 @@ public void testBlacklistedNodesXML() throws Exception {
public void verifyAMInfo(JSONObject info, AppContext ctx) public void verifyAMInfo(JSONObject info, AppContext ctx)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 5, info.length()); assertEquals(5, info.length(), "incorrect number of elements");
verifyAMInfoGeneric(ctx, info.getString("appId"), info.getString("user"), verifyAMInfoGeneric(ctx, info.getString("appId"), info.getString("user"),
info.getString("name"), info.getLong("startedOn"), info.getString("name"), info.getLong("startedOn"),
@ -297,7 +297,7 @@ public void verifyAMInfoXML(String xml, AppContext ctx)
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList nodes = dom.getElementsByTagName("info"); NodeList nodes = dom.getElementsByTagName("info");
assertEquals("incorrect number of elements", 1, nodes.getLength()); assertEquals(1, nodes.getLength(), "incorrect number of elements");
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
@ -320,8 +320,8 @@ public void verifyAMInfoGeneric(AppContext ctx, String id, String user,
WebServicesTestUtils.checkStringMatch("name", ctx.getApplicationName(), WebServicesTestUtils.checkStringMatch("name", ctx.getApplicationName(),
name); name);
assertEquals("startedOn incorrect", ctx.getStartTime(), startedOn); assertEquals(ctx.getStartTime(), startedOn, "startedOn incorrect");
assertTrue("elapsedTime not greater then 0", (elapsedTime > 0)); assertTrue((elapsedTime > 0), "elapsedTime not greater then 0");
} }
@ -342,11 +342,11 @@ public void verifyBlacklistedNodesInfoXML(String xml, AppContext ctx)
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList infonodes = dom.getElementsByTagName("blacklistednodesinfo"); NodeList infonodes = dom.getElementsByTagName("blacklistednodesinfo");
assertEquals("incorrect number of elements", 1, infonodes.getLength()); assertEquals(1, infonodes.getLength(), "incorrect number of elements");
NodeList nodes = dom.getElementsByTagName("blacklistedNodes"); NodeList nodes = dom.getElementsByTagName("blacklistedNodes");
Set<String> blacklistedNodes = ctx.getBlacklistedNodes(); Set<String> blacklistedNodes = ctx.getBlacklistedNodes();
assertEquals("incorrect number of elements", blacklistedNodes.size(), assertEquals(blacklistedNodes.size(),
nodes.getLength()); nodes.getLength(), "incorrect number of elements");
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
assertTrue( assertTrue(

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.StringReader; import java.io.StringReader;
import java.util.Enumeration; import java.util.Enumeration;
@ -50,8 +50,8 @@
import org.apache.hadoop.yarn.webapp.JerseyTestBase; import org.apache.hadoop.yarn.webapp.JerseyTestBase;
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils; import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -118,7 +118,7 @@ protected Properties getConfiguration(String configPrefix,
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -157,7 +157,7 @@ public void testGetTaskAttemptIdState() throws Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
assertEquals(att.getState().toString(), json.get("state")); assertEquals(att.getState().toString(), json.get("state"));
} }
} }
@ -226,7 +226,8 @@ public void testPutTaskAttemptIdState() throws Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(),
"incorrect number of elements");
assertEquals(TaskAttemptState.KILLED.toString(), json.get("state")); assertEquals(TaskAttemptState.KILLED.toString(), json.get("state"));
} }
} }

View File

@ -19,11 +19,11 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.StringReader; import java.io.StringReader;
import java.util.List; import java.util.List;
@ -52,8 +52,8 @@
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -101,7 +101,7 @@ protected void configureServlets() {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -199,7 +199,7 @@ public void testTaskAttemptsXML() throws JSONException, Exception {
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList attempts = dom.getElementsByTagName("taskAttempts"); NodeList attempts = dom.getElementsByTagName("taskAttempts");
assertEquals("incorrect number of elements", 1, attempts.getLength()); assertEquals(1, attempts.getLength(), "incorrect number of elements");
NodeList nodes = dom.getElementsByTagName("taskAttempt"); NodeList nodes = dom.getElementsByTagName("taskAttempt");
verifyAMTaskAttemptsXML(nodes, task); verifyAMTaskAttemptsXML(nodes, task);
@ -229,7 +229,7 @@ public void testTaskAttemptId() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("taskAttempt"); JSONObject info = json.getJSONObject("taskAttempt");
verifyAMTaskAttempt(info, att, task.getType()); verifyAMTaskAttempt(info, att, task.getType());
} }
@ -259,7 +259,7 @@ public void testTaskAttemptIdSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("taskAttempt"); JSONObject info = json.getJSONObject("taskAttempt");
verifyAMTaskAttempt(info, att, task.getType()); verifyAMTaskAttempt(info, att, task.getType());
} }
@ -288,7 +288,7 @@ public void testTaskAttemptIdDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("taskAttempt"); JSONObject info = json.getJSONObject("taskAttempt");
verifyAMTaskAttempt(info, att, task.getType()); verifyAMTaskAttempt(info, att, task.getType());
} }
@ -391,7 +391,7 @@ private void testTaskAttemptIdErrorGeneric(String attid, String error)
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -434,9 +434,9 @@ public void verifyAMTaskAttemptXML(Element element, TaskAttempt att,
public void verifyAMTaskAttempt(JSONObject info, TaskAttempt att, public void verifyAMTaskAttempt(JSONObject info, TaskAttempt att,
TaskType ttype) throws JSONException { TaskType ttype) throws JSONException {
if (ttype == TaskType.REDUCE) { if (ttype == TaskType.REDUCE) {
assertEquals("incorrect number of elements", 17, info.length()); assertEquals(17, info.length(), "incorrect number of elements");
} else { } else {
assertEquals("incorrect number of elements", 12, info.length()); assertEquals(12, info.length(), "incorrect number of elements");
} }
verifyTaskAttemptGeneric(att, ttype, info.getString("id"), verifyTaskAttemptGeneric(att, ttype, info.getString("id"),
@ -455,9 +455,9 @@ public void verifyAMTaskAttempt(JSONObject info, TaskAttempt att,
public void verifyAMTaskAttempts(JSONObject json, Task task) public void verifyAMTaskAttempts(JSONObject json, Task task)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject attempts = json.getJSONObject("taskAttempts"); JSONObject attempts = json.getJSONObject("taskAttempts");
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONArray arr = attempts.getJSONArray("taskAttempt"); JSONArray arr = attempts.getJSONArray("taskAttempt");
for (TaskAttempt att : task.getAttempts().values()) { for (TaskAttempt att : task.getAttempts().values()) {
TaskAttemptId id = att.getID(); TaskAttemptId id = att.getID();
@ -471,13 +471,13 @@ public void verifyAMTaskAttempts(JSONObject json, Task task)
verifyAMTaskAttempt(info, att, task.getType()); verifyAMTaskAttempt(info, att, task.getType());
} }
} }
assertTrue("task attempt with id: " + attid assertTrue(found, "task attempt with id: " + attid
+ " not in web service output", found); + " not in web service output");
} }
} }
public void verifyAMTaskAttemptsXML(NodeList nodes, Task task) { public void verifyAMTaskAttemptsXML(NodeList nodes, Task task) {
assertEquals("incorrect number of elements", 1, nodes.getLength()); assertEquals(1, nodes.getLength(), "incorrect number of elements");
for (TaskAttempt att : task.getAttempts().values()) { for (TaskAttempt att : task.getAttempts().values()) {
TaskAttemptId id = att.getID(); TaskAttemptId id = att.getID();
@ -485,15 +485,14 @@ public void verifyAMTaskAttemptsXML(NodeList nodes, Task task) {
Boolean found = false; Boolean found = false;
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
assertFalse("task attempt should not contain any attributes, it can lead to incorrect JSON marshaling", assertFalse(element.hasAttributes(), "task attempt should not contain any attributes, it can lead to incorrect JSON marshaling");
element.hasAttributes());
if (attid.matches(WebServicesTestUtils.getXmlString(element, "id"))) { if (attid.matches(WebServicesTestUtils.getXmlString(element, "id"))) {
found = true; found = true;
verifyAMTaskAttemptXML(element, att, task.getType()); verifyAMTaskAttemptXML(element, att, task.getType());
} }
} }
assertTrue("task with id: " + attid + " not in web service output", found); assertTrue(found, "task with id: " + attid + " not in web service output");
} }
} }
@ -528,26 +527,26 @@ public void verifyTaskAttemptGeneric(TaskAttempt ta, TaskType ttype,
ta.getAssignedContainerID().toString(), ta.getAssignedContainerID().toString(),
assignedContainerId); assignedContainerId);
assertEquals("startTime wrong", ta.getLaunchTime(), startTime); assertEquals(ta.getLaunchTime(), startTime, "startTime wrong");
assertEquals("finishTime wrong", ta.getFinishTime(), finishTime); assertEquals(ta.getFinishTime(), finishTime, "finishTime wrong");
assertEquals("elapsedTime wrong", finishTime - startTime, elapsedTime); assertEquals(finishTime - startTime, elapsedTime, "elapsedTime wrong");
assertEquals("progress wrong", ta.getProgress() * 100, progress, 1e-3f); assertEquals(ta.getProgress() * 100, progress, 1e-3f, "progress wrong");
} }
public void verifyReduceTaskAttemptGeneric(TaskAttempt ta, public void verifyReduceTaskAttemptGeneric(TaskAttempt ta,
long shuffleFinishTime, long mergeFinishTime, long elapsedShuffleTime, long shuffleFinishTime, long mergeFinishTime, long elapsedShuffleTime,
long elapsedMergeTime, long elapsedReduceTime) { long elapsedMergeTime, long elapsedReduceTime) {
assertEquals("shuffleFinishTime wrong", ta.getShuffleFinishTime(), assertEquals(ta.getShuffleFinishTime(),
shuffleFinishTime); shuffleFinishTime, "shuffleFinishTime wrong");
assertEquals("mergeFinishTime wrong", ta.getSortFinishTime(), assertEquals(ta.getSortFinishTime(),
mergeFinishTime); mergeFinishTime, "mergeFinishTime wrong");
assertEquals("elapsedShuffleTime wrong", assertEquals(ta.getShuffleFinishTime() - ta.getLaunchTime(), elapsedShuffleTime,
ta.getShuffleFinishTime() - ta.getLaunchTime(), elapsedShuffleTime); "elapsedShuffleTime wrong");
assertEquals("elapsedMergeTime wrong", assertEquals(ta.getSortFinishTime() - ta.getShuffleFinishTime(), elapsedMergeTime,
ta.getSortFinishTime() - ta.getShuffleFinishTime(), elapsedMergeTime); "elapsedMergeTime wrong");
assertEquals("elapsedReduceTime wrong", assertEquals(ta.getFinishTime() - ta.getSortFinishTime(), elapsedReduceTime,
ta.getFinishTime() - ta.getSortFinishTime(), elapsedReduceTime); "elapsedReduceTime wrong");
} }
@Test @Test
@ -572,7 +571,7 @@ public void testTaskAttemptIdCounters() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " assertEquals(MediaType.APPLICATION_JSON_TYPE + "; "
+ JettyUtils.UTF_8, response.getType().toString()); + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobTaskAttemptCounters"); JSONObject info = json.getJSONObject("jobTaskAttemptCounters");
verifyAMJobTaskAttemptCounters(info, att); verifyAMJobTaskAttemptCounters(info, att);
} }
@ -617,7 +616,7 @@ public void testTaskAttemptIdXMLCounters() throws JSONException, Exception {
public void verifyAMJobTaskAttemptCounters(JSONObject info, TaskAttempt att) public void verifyAMJobTaskAttemptCounters(JSONObject info, TaskAttempt att)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 2, info.length()); assertEquals(2, info.length(), "incorrect number of elements");
WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()), WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()),
info.getString("id")); info.getString("id"));
@ -628,15 +627,15 @@ public void verifyAMJobTaskAttemptCounters(JSONObject info, TaskAttempt att)
for (int i = 0; i < counterGroups.length(); i++) { for (int i = 0; i < counterGroups.length(); i++) {
JSONObject counterGroup = counterGroups.getJSONObject(i); JSONObject counterGroup = counterGroups.getJSONObject(i);
String name = counterGroup.getString("counterGroupName"); String name = counterGroup.getString("counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
JSONArray counters = counterGroup.getJSONArray("counter"); JSONArray counters = counterGroup.getJSONArray("counter");
for (int j = 0; j < counters.length(); j++) { for (int j = 0; j < counters.length(); j++) {
JSONObject counter = counters.getJSONObject(j); JSONObject counter = counters.getJSONObject(j);
String counterName = counter.getString("name"); String counterName = counter.getString("name");
assertTrue("name not set", assertTrue((counterName != null && !counterName.isEmpty()),
(counterName != null && !counterName.isEmpty())); "name not set");
long value = counter.getLong("value"); long value = counter.getLong("value");
assertTrue("value >= 0", value >= 0); assertTrue(value >= 0, "value >= 0");
} }
} }
} }
@ -654,20 +653,19 @@ public void verifyAMTaskCountersXML(NodeList nodes, TaskAttempt att) {
for (int j = 0; j < groups.getLength(); j++) { for (int j = 0; j < groups.getLength(); j++) {
Element counters = (Element) groups.item(j); Element counters = (Element) groups.item(j);
assertNotNull("should have counters in the web service info", counters); assertNotNull(counters, "should have counters in the web service info");
String name = WebServicesTestUtils.getXmlString(counters, String name = WebServicesTestUtils.getXmlString(counters,
"counterGroupName"); "counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
NodeList counterArr = counters.getElementsByTagName("counter"); NodeList counterArr = counters.getElementsByTagName("counter");
for (int z = 0; z < counterArr.getLength(); z++) { for (int z = 0; z < counterArr.getLength(); z++) {
Element counter = (Element) counterArr.item(z); Element counter = (Element) counterArr.item(z);
String counterName = WebServicesTestUtils.getXmlString(counter, String counterName = WebServicesTestUtils.getXmlString(counter,
"name"); "name");
assertTrue("counter name not set", assertTrue((counterName != null && !counterName.isEmpty()), "counter name not set");
(counterName != null && !counterName.isEmpty()));
long value = WebServicesTestUtils.getXmlLong(counter, "value"); long value = WebServicesTestUtils.getXmlLong(counter, "value");
assertTrue("value not >= 0", value >= 0); assertTrue(value >= 0, "value not >= 0");
} }
} }

View File

@ -18,10 +18,10 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -52,9 +52,9 @@
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.AfterClass; import org.junit.jupiter.api.Test;
import org.junit.Before; import org.junit.jupiter.api.AfterAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -126,7 +126,7 @@ protected void configureServlets() {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -135,7 +135,7 @@ public void setUp() throws Exception {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@AfterClass @AfterAll
static public void stop() { static public void stop() {
FileUtil.fullyDelete(testConfDir); FileUtil.fullyDelete(testConfDir);
} }
@ -161,7 +161,7 @@ public void testJobConf() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("conf"); JSONObject info = json.getJSONObject("conf");
verifyAMJobConf(info, jobsMap.get(id)); verifyAMJobConf(info, jobsMap.get(id));
} }
@ -180,7 +180,7 @@ public void testJobConfSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("conf"); JSONObject info = json.getJSONObject("conf");
verifyAMJobConf(info, jobsMap.get(id)); verifyAMJobConf(info, jobsMap.get(id));
} }
@ -198,7 +198,7 @@ public void testJobConfDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("conf"); JSONObject info = json.getJSONObject("conf");
verifyAMJobConf(info, jobsMap.get(id)); verifyAMJobConf(info, jobsMap.get(id));
} }
@ -229,7 +229,7 @@ public void testJobConfXML() throws JSONException, Exception {
public void verifyAMJobConf(JSONObject info, Job job) throws JSONException { public void verifyAMJobConf(JSONObject info, Job job) throws JSONException {
assertEquals("incorrect number of elements", 2, info.length()); assertEquals(2, info.length(), "incorrect number of elements");
WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(), WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
info.getString("path")); info.getString("path"));
@ -240,14 +240,14 @@ public void verifyAMJobConf(JSONObject info, Job job) throws JSONException {
JSONObject prop = properties.getJSONObject(i); JSONObject prop = properties.getJSONObject(i);
String name = prop.getString("name"); String name = prop.getString("name");
String value = prop.getString("value"); String value = prop.getString("value");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
assertTrue("value not set", (value != null && !value.isEmpty())); assertTrue((value != null && !value.isEmpty()), "value not set");
} }
} }
public void verifyAMJobConfXML(NodeList nodes, Job job) { public void verifyAMJobConfXML(NodeList nodes, Job job) {
assertEquals("incorrect number of elements", 1, nodes.getLength()); assertEquals(1, nodes.getLength(), "incorrect number of elements");
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
@ -260,11 +260,11 @@ public void verifyAMJobConfXML(NodeList nodes, Job job) {
for (int j = 0; j < properties.getLength(); j++) { for (int j = 0; j < properties.getLength(); j++) {
Element property = (Element) properties.item(j); Element property = (Element) properties.item(j);
assertNotNull("should have counters in the web service info", property); assertNotNull(property, "should have counters in the web service info");
String name = WebServicesTestUtils.getXmlString(property, "name"); String name = WebServicesTestUtils.getXmlString(property, "name");
String value = WebServicesTestUtils.getXmlString(property, "value"); String value = WebServicesTestUtils.getXmlString(property, "value");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
assertTrue("name not set", (value != null && !value.isEmpty())); assertTrue((value != null && !value.isEmpty()), "name not set");
} }
} }
} }

View File

@ -20,10 +20,10 @@
import static org.apache.hadoop.yarn.util.StringHelper.ujoin; import static org.apache.hadoop.yarn.util.StringHelper.ujoin;
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.StringReader; import java.io.StringReader;
import java.util.List; import java.util.List;
@ -54,8 +54,8 @@
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -103,7 +103,7 @@ protected void configureServlets() {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -128,7 +128,7 @@ public void testJobs() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject jobs = json.getJSONObject("jobs"); JSONObject jobs = json.getJSONObject("jobs");
JSONArray arr = jobs.getJSONArray("job"); JSONArray arr = jobs.getJSONArray("job");
JSONObject info = arr.getJSONObject(0); JSONObject info = arr.getJSONObject(0);
@ -146,7 +146,7 @@ public void testJobsSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject jobs = json.getJSONObject("jobs"); JSONObject jobs = json.getJSONObject("jobs");
JSONArray arr = jobs.getJSONArray("job"); JSONArray arr = jobs.getJSONArray("job");
JSONObject info = arr.getJSONObject(0); JSONObject info = arr.getJSONObject(0);
@ -163,7 +163,7 @@ public void testJobsDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject jobs = json.getJSONObject("jobs"); JSONObject jobs = json.getJSONObject("jobs");
JSONArray arr = jobs.getJSONArray("job"); JSONArray arr = jobs.getJSONArray("job");
JSONObject info = arr.getJSONObject(0); JSONObject info = arr.getJSONObject(0);
@ -187,9 +187,9 @@ public void testJobsXML() throws Exception {
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList jobs = dom.getElementsByTagName("jobs"); NodeList jobs = dom.getElementsByTagName("jobs");
assertEquals("incorrect number of elements", 1, jobs.getLength()); assertEquals(1, jobs.getLength(), "incorrect number of elements");
NodeList job = dom.getElementsByTagName("job"); NodeList job = dom.getElementsByTagName("job");
assertEquals("incorrect number of elements", 1, job.getLength()); assertEquals(1, job.getLength(), "incorrect number of elements");
verifyAMJobXML(job, appContext); verifyAMJobXML(job, appContext);
} }
@ -207,7 +207,7 @@ public void testJobId() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("job"); JSONObject info = json.getJSONObject("job");
verifyAMJob(info, jobsMap.get(id)); verifyAMJob(info, jobsMap.get(id));
} }
@ -227,7 +227,7 @@ public void testJobIdSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("job"); JSONObject info = json.getJSONObject("job");
verifyAMJob(info, jobsMap.get(id)); verifyAMJob(info, jobsMap.get(id));
} }
@ -245,7 +245,7 @@ public void testJobIdDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("job"); JSONObject info = json.getJSONObject("job");
verifyAMJob(info, jobsMap.get(id)); verifyAMJob(info, jobsMap.get(id));
} }
@ -267,7 +267,7 @@ public void testJobIdNonExist() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -295,7 +295,7 @@ public void testJobIdInvalid() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -319,7 +319,7 @@ public void testJobIdInvalidDefault() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -383,7 +383,7 @@ public void testJobIdInvalidBogus() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -425,7 +425,7 @@ public void testJobIdXML() throws Exception {
public void verifyAMJob(JSONObject info, Job job) throws JSONException { public void verifyAMJob(JSONObject info, Job job) throws JSONException {
assertEquals("incorrect number of elements", 31, info.length()); assertEquals(31, info.length(), "incorrect number of elements");
// everyone access fields // everyone access fields
verifyAMJobGeneric(job, info.getString("id"), info.getString("user"), verifyAMJobGeneric(job, info.getString("id"), info.getString("user"),
@ -476,8 +476,8 @@ public void verifyAMJob(JSONObject info, Job job) throws JSONException {
} else { } else {
fail("should have acls in the web service info"); fail("should have acls in the web service info");
} }
assertTrue("acl: " + expectName + " not found in webservice output", assertTrue(found,
found); "acl: " + expectName + " not found in webservice output");
} }
} }
@ -485,14 +485,14 @@ public void verifyAMJob(JSONObject info, Job job) throws JSONException {
public void verifyAMJobXML(NodeList nodes, AppContext appContext) { public void verifyAMJobXML(NodeList nodes, AppContext appContext) {
assertEquals("incorrect number of elements", 1, nodes.getLength()); assertEquals(1, nodes.getLength(), "incorrect number of elements");
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
Job job = appContext.getJob(MRApps.toJobID(WebServicesTestUtils Job job = appContext.getJob(MRApps.toJobID(WebServicesTestUtils
.getXmlString(element, "id"))); .getXmlString(element, "id")));
assertNotNull("Job not found - output incorrect", job); assertNotNull(job, "Job not found - output incorrect");
verifyAMJobGeneric(job, WebServicesTestUtils.getXmlString(element, "id"), verifyAMJobGeneric(job, WebServicesTestUtils.getXmlString(element, "id"),
WebServicesTestUtils.getXmlString(element, "user"), WebServicesTestUtils.getXmlString(element, "user"),
@ -551,8 +551,8 @@ public void verifyAMJobXML(NodeList nodes, AppContext appContext) {
} else { } else {
fail("should have acls in the web service info"); fail("should have acls in the web service info");
} }
assertTrue("acl: " + expectName + " not found in webservice output", assertTrue(found,
found); "acl: " + expectName + " not found in webservice output");
} }
} }
} }
@ -572,21 +572,21 @@ public void verifyAMJobGeneric(Job job, String id, String user, String name,
WebServicesTestUtils.checkStringMatch("state", job.getState().toString(), WebServicesTestUtils.checkStringMatch("state", job.getState().toString(),
state); state);
assertEquals("startTime incorrect", report.getStartTime(), startTime); assertEquals(report.getStartTime(), startTime, "startTime incorrect");
assertEquals("finishTime incorrect", report.getFinishTime(), finishTime); assertEquals(report.getFinishTime(), finishTime, "finishTime incorrect");
assertEquals("elapsedTime incorrect", assertEquals(Times.elapsed(report.getStartTime(), report.getFinishTime()),
Times.elapsed(report.getStartTime(), report.getFinishTime()), elapsedTime, "elapsedTime incorrect");
elapsedTime); assertEquals(job.getTotalMaps(), mapsTotal, "mapsTotal incorrect");
assertEquals("mapsTotal incorrect", job.getTotalMaps(), mapsTotal); assertEquals(job.getCompletedMaps(), mapsCompleted,
assertEquals("mapsCompleted incorrect", job.getCompletedMaps(), "mapsCompleted incorrect");
mapsCompleted); assertEquals(job.getTotalReduces(), reducesTotal,
assertEquals("reducesTotal incorrect", job.getTotalReduces(), reducesTotal); "reducesTotal incorrect");
assertEquals("reducesCompleted incorrect", job.getCompletedReduces(), assertEquals(job.getCompletedReduces(), reducesCompleted,
reducesCompleted); "reducesCompleted incorrect");
assertEquals("mapProgress incorrect", report.getMapProgress() * 100, assertEquals(report.getMapProgress() * 100, mapProgress, 0,
mapProgress, 0); "mapProgress incorrect");
assertEquals("reduceProgress incorrect", report.getReduceProgress() * 100, assertEquals(report.getReduceProgress() * 100, reduceProgress, 0,
reduceProgress, 0); "reduceProgress incorrect");
} }
public void verifyAMJobGenericSecure(Job job, int mapsPending, public void verifyAMJobGenericSecure(Job job, int mapsPending,
@ -609,28 +609,27 @@ public void verifyAMJobGenericSecure(Job job, int mapsPending,
WebServicesTestUtils.checkStringMatch("diagnostics", diagString, WebServicesTestUtils.checkStringMatch("diagnostics", diagString,
diagnostics); diagnostics);
assertEquals("isUber incorrect", job.isUber(), uberized); assertEquals(job.isUber(), uberized, "isUber incorrect");
// unfortunately the following fields are all calculated in JobInfo // unfortunately the following fields are all calculated in JobInfo
// so not easily accessible without doing all the calculations again. // so not easily accessible without doing all the calculations again.
// For now just make sure they are present. // For now just make sure they are present.
assertTrue("mapsPending not >= 0", mapsPending >= 0); assertTrue(mapsPending >= 0, "mapsPending not >= 0");
assertTrue("mapsRunning not >= 0", mapsRunning >= 0); assertTrue(mapsRunning >= 0, "mapsRunning not >= 0");
assertTrue("reducesPending not >= 0", reducesPending >= 0); assertTrue(reducesPending >= 0, "reducesPending not >= 0");
assertTrue("reducesRunning not >= 0", reducesRunning >= 0); assertTrue(reducesRunning >= 0, "reducesRunning not >= 0");
assertTrue("newReduceAttempts not >= 0", newReduceAttempts >= 0); assertTrue(newReduceAttempts >= 0, "newReduceAttempts not >= 0");
assertTrue("runningReduceAttempts not >= 0", runningReduceAttempts >= 0); assertTrue(runningReduceAttempts >= 0, "runningReduceAttempts not >= 0");
assertTrue("failedReduceAttempts not >= 0", failedReduceAttempts >= 0); assertTrue(failedReduceAttempts >= 0, "failedReduceAttempts not >= 0");
assertTrue("killedReduceAttempts not >= 0", killedReduceAttempts >= 0); assertTrue(killedReduceAttempts >= 0, "killedReduceAttempts not >= 0");
assertTrue("successfulReduceAttempts not >= 0", assertTrue(successfulReduceAttempts >= 0, "successfulReduceAttempts not >= 0");
successfulReduceAttempts >= 0);
assertTrue("newMapAttempts not >= 0", newMapAttempts >= 0); assertTrue(newMapAttempts >= 0, "newMapAttempts not >= 0");
assertTrue("runningMapAttempts not >= 0", runningMapAttempts >= 0); assertTrue(runningMapAttempts >= 0, "runningMapAttempts not >= 0");
assertTrue("failedMapAttempts not >= 0", failedMapAttempts >= 0); assertTrue(failedMapAttempts >= 0, "failedMapAttempts not >= 0");
assertTrue("killedMapAttempts not >= 0", killedMapAttempts >= 0); assertTrue(killedMapAttempts >= 0, "killedMapAttempts not >= 0");
assertTrue("successfulMapAttempts not >= 0", successfulMapAttempts >= 0); assertTrue(successfulMapAttempts >= 0, "successfulMapAttempts not >= 0");
} }
@ -647,7 +646,8 @@ public void testJobCounters() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(),
"incorrect number of elements");
JSONObject info = json.getJSONObject("jobCounters"); JSONObject info = json.getJSONObject("jobCounters");
verifyAMJobCounters(info, jobsMap.get(id)); verifyAMJobCounters(info, jobsMap.get(id));
} }
@ -666,7 +666,8 @@ public void testJobCountersSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(),
"incorrect number of elements");
JSONObject info = json.getJSONObject("jobCounters"); JSONObject info = json.getJSONObject("jobCounters");
verifyAMJobCounters(info, jobsMap.get(id)); verifyAMJobCounters(info, jobsMap.get(id));
} }
@ -684,7 +685,8 @@ public void testJobCountersDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(),
"incorrect number of elements");
JSONObject info = json.getJSONObject("jobCounters"); JSONObject info = json.getJSONObject("jobCounters");
verifyAMJobCounters(info, jobsMap.get(id)); verifyAMJobCounters(info, jobsMap.get(id));
} }
@ -716,7 +718,8 @@ public void testJobCountersXML() throws Exception {
public void verifyAMJobCounters(JSONObject info, Job job) public void verifyAMJobCounters(JSONObject info, Job job)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 2, info.length()); assertEquals(2, info.length(),
"incorrect number of elements");
WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()), WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()),
info.getString("id")); info.getString("id"));
@ -726,22 +729,22 @@ public void verifyAMJobCounters(JSONObject info, Job job)
for (int i = 0; i < counterGroups.length(); i++) { for (int i = 0; i < counterGroups.length(); i++) {
JSONObject counterGroup = counterGroups.getJSONObject(i); JSONObject counterGroup = counterGroups.getJSONObject(i);
String name = counterGroup.getString("counterGroupName"); String name = counterGroup.getString("counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
JSONArray counters = counterGroup.getJSONArray("counter"); JSONArray counters = counterGroup.getJSONArray("counter");
for (int j = 0; j < counters.length(); j++) { for (int j = 0; j < counters.length(); j++) {
JSONObject counter = counters.getJSONObject(j); JSONObject counter = counters.getJSONObject(j);
String counterName = counter.getString("name"); String counterName = counter.getString("name");
assertTrue("counter name not set", assertTrue((counterName != null && !counterName.isEmpty()),
(counterName != null && !counterName.isEmpty())); "counter name not set");
long mapValue = counter.getLong("mapCounterValue"); long mapValue = counter.getLong("mapCounterValue");
assertTrue("mapCounterValue >= 0", mapValue >= 0); assertTrue(mapValue >= 0, "mapCounterValue >= 0");
long reduceValue = counter.getLong("reduceCounterValue"); long reduceValue = counter.getLong("reduceCounterValue");
assertTrue("reduceCounterValue >= 0", reduceValue >= 0); assertTrue(reduceValue >= 0, "reduceCounterValue >= 0");
long totalValue = counter.getLong("totalCounterValue"); long totalValue = counter.getLong("totalCounterValue");
assertTrue("totalCounterValue >= 0", totalValue >= 0); assertTrue(totalValue >= 0, "totalCounterValue >= 0");
} }
} }
@ -752,7 +755,7 @@ public void verifyAMJobCountersXML(NodeList nodes, Job job) {
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
assertNotNull("Job not found - output incorrect", job); assertNotNull(job, "Job not found - output incorrect");
WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()), WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()),
WebServicesTestUtils.getXmlString(element, "id")); WebServicesTestUtils.getXmlString(element, "id"));
@ -762,29 +765,30 @@ public void verifyAMJobCountersXML(NodeList nodes, Job job) {
for (int j = 0; j < groups.getLength(); j++) { for (int j = 0; j < groups.getLength(); j++) {
Element counters = (Element) groups.item(j); Element counters = (Element) groups.item(j);
assertNotNull("should have counters in the web service info", counters); assertNotNull(counters,
"should have counters in the web service info");
String name = WebServicesTestUtils.getXmlString(counters, String name = WebServicesTestUtils.getXmlString(counters,
"counterGroupName"); "counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
NodeList counterArr = counters.getElementsByTagName("counter"); NodeList counterArr = counters.getElementsByTagName("counter");
for (int z = 0; z < counterArr.getLength(); z++) { for (int z = 0; z < counterArr.getLength(); z++) {
Element counter = (Element) counterArr.item(z); Element counter = (Element) counterArr.item(z);
String counterName = WebServicesTestUtils.getXmlString(counter, String counterName = WebServicesTestUtils.getXmlString(counter,
"name"); "name");
assertTrue("counter name not set", assertTrue((counterName != null && !counterName.isEmpty()),
(counterName != null && !counterName.isEmpty())); "counter name not set");
long mapValue = WebServicesTestUtils.getXmlLong(counter, long mapValue = WebServicesTestUtils.getXmlLong(counter,
"mapCounterValue"); "mapCounterValue");
assertTrue("mapCounterValue not >= 0", mapValue >= 0); assertTrue(mapValue >= 0, "mapCounterValue not >= 0");
long reduceValue = WebServicesTestUtils.getXmlLong(counter, long reduceValue = WebServicesTestUtils.getXmlLong(counter,
"reduceCounterValue"); "reduceCounterValue");
assertTrue("reduceCounterValue >= 0", reduceValue >= 0); assertTrue(reduceValue >= 0, "reduceCounterValue >= 0");
long totalValue = WebServicesTestUtils.getXmlLong(counter, long totalValue = WebServicesTestUtils.getXmlLong(counter,
"totalCounterValue"); "totalCounterValue");
assertTrue("totalCounterValue >= 0", totalValue >= 0); assertTrue(totalValue >= 0, "totalCounterValue >= 0");
} }
} }
} }
@ -803,7 +807,7 @@ public void testJobAttempts() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobAttempts"); JSONObject info = json.getJSONObject("jobAttempts");
verifyJobAttempts(info, jobsMap.get(id)); verifyJobAttempts(info, jobsMap.get(id));
} }
@ -822,7 +826,7 @@ public void testJobAttemptsSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobAttempts"); JSONObject info = json.getJSONObject("jobAttempts");
verifyJobAttempts(info, jobsMap.get(id)); verifyJobAttempts(info, jobsMap.get(id));
} }
@ -841,7 +845,7 @@ public void testJobAttemptsDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobAttempts"); JSONObject info = json.getJSONObject("jobAttempts");
verifyJobAttempts(info, jobsMap.get(id)); verifyJobAttempts(info, jobsMap.get(id));
} }
@ -866,7 +870,8 @@ public void testJobAttemptsXML() throws Exception {
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList attempts = dom.getElementsByTagName("jobAttempts"); NodeList attempts = dom.getElementsByTagName("jobAttempts");
assertEquals("incorrect number of elements", 1, attempts.getLength()); assertEquals(1, attempts.getLength(),
"incorrect number of elements");
NodeList info = dom.getElementsByTagName("jobAttempt"); NodeList info = dom.getElementsByTagName("jobAttempt");
verifyJobAttemptsXML(info, jobsMap.get(id)); verifyJobAttemptsXML(info, jobsMap.get(id));
} }
@ -876,7 +881,8 @@ public void verifyJobAttempts(JSONObject info, Job job)
throws JSONException { throws JSONException {
JSONArray attempts = info.getJSONArray("jobAttempt"); JSONArray attempts = info.getJSONArray("jobAttempt");
assertEquals("incorrect number of elements", 2, attempts.length()); assertEquals(2, attempts.length(),
"incorrect number of elements");
for (int i = 0; i < attempts.length(); i++) { for (int i = 0; i < attempts.length(); i++) {
JSONObject attempt = attempts.getJSONObject(i); JSONObject attempt = attempts.getJSONObject(i);
verifyJobAttemptsGeneric(job, attempt.getString("nodeHttpAddress"), verifyJobAttemptsGeneric(job, attempt.getString("nodeHttpAddress"),
@ -888,7 +894,8 @@ public void verifyJobAttempts(JSONObject info, Job job)
public void verifyJobAttemptsXML(NodeList nodes, Job job) { public void verifyJobAttemptsXML(NodeList nodes, Job job) {
assertEquals("incorrect number of elements", 2, nodes.getLength()); assertEquals(2, nodes.getLength(),
"incorrect number of elements");
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i); Element element = (Element) nodes.item(i);
verifyJobAttemptsGeneric(job, verifyJobAttemptsGeneric(job,
@ -914,17 +921,17 @@ public void verifyJobAttemptsGeneric(Job job, String nodeHttpAddress,
+ nmHttpPort, nodeHttpAddress); + nmHttpPort, nodeHttpAddress);
WebServicesTestUtils.checkStringMatch("nodeId", WebServicesTestUtils.checkStringMatch("nodeId",
NodeId.newInstance(nmHost, nmPort).toString(), nodeId); NodeId.newInstance(nmHost, nmPort).toString(), nodeId);
assertTrue("startime not greater than 0", startTime > 0); assertTrue(startTime > 0, "startime not greater than 0");
WebServicesTestUtils.checkStringMatch("containerId", amInfo WebServicesTestUtils.checkStringMatch("containerId", amInfo
.getContainerId().toString(), containerId); .getContainerId().toString(), containerId);
String localLogsLink =ujoin("node", "containerlogs", containerId, String localLogsLink =ujoin("node", "containerlogs", containerId,
job.getUserName()); job.getUserName());
assertTrue("logsLink", logsLink.contains(localLogsLink)); assertTrue(logsLink.contains(localLogsLink), "logsLink");
} }
} }
assertTrue("attempt: " + id + " was not found", attemptFound); assertTrue(attemptFound, "attempt: " + id + " was not found");
} }
} }

View File

@ -19,10 +19,10 @@
package org.apache.hadoop.mapreduce.v2.app.webapp; package org.apache.hadoop.mapreduce.v2.app.webapp;
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.StringReader; import java.io.StringReader;
import java.util.Map; import java.util.Map;
@ -50,8 +50,8 @@
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -99,7 +99,7 @@ protected void configureServlets() {
Guice.createInjector(new WebServletModule())); Guice.createInjector(new WebServletModule()));
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -127,10 +127,10 @@ public void testTasks() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject tasks = json.getJSONObject("tasks"); JSONObject tasks = json.getJSONObject("tasks");
JSONArray arr = tasks.getJSONArray("task"); JSONArray arr = tasks.getJSONArray("task");
assertEquals("incorrect number of elements", 2, arr.length()); assertEquals(2, arr.length(), "incorrect number of elements");
verifyAMTask(arr, jobsMap.get(id), null); verifyAMTask(arr, jobsMap.get(id), null);
} }
@ -147,10 +147,10 @@ public void testTasksDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject tasks = json.getJSONObject("tasks"); JSONObject tasks = json.getJSONObject("tasks");
JSONArray arr = tasks.getJSONArray("task"); JSONArray arr = tasks.getJSONArray("task");
assertEquals("incorrect number of elements", 2, arr.length()); assertEquals(2, arr.length(), "incorrect number of elements");
verifyAMTask(arr, jobsMap.get(id), null); verifyAMTask(arr, jobsMap.get(id), null);
} }
@ -168,10 +168,10 @@ public void testTasksSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject tasks = json.getJSONObject("tasks"); JSONObject tasks = json.getJSONObject("tasks");
JSONArray arr = tasks.getJSONArray("task"); JSONArray arr = tasks.getJSONArray("task");
assertEquals("incorrect number of elements", 2, arr.length()); assertEquals(2, arr.length(), "incorrect number of elements");
verifyAMTask(arr, jobsMap.get(id), null); verifyAMTask(arr, jobsMap.get(id), null);
} }
@ -196,7 +196,7 @@ public void testTasksXML() throws JSONException, Exception {
is.setCharacterStream(new StringReader(xml)); is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is); Document dom = db.parse(is);
NodeList tasks = dom.getElementsByTagName("tasks"); NodeList tasks = dom.getElementsByTagName("tasks");
assertEquals("incorrect number of elements", 1, tasks.getLength()); assertEquals(1, tasks.getLength(), "incorrect number of elements");
NodeList task = dom.getElementsByTagName("task"); NodeList task = dom.getElementsByTagName("task");
verifyAMTaskXML(task, jobsMap.get(id)); verifyAMTaskXML(task, jobsMap.get(id));
} }
@ -215,10 +215,10 @@ public void testTasksQueryMap() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject tasks = json.getJSONObject("tasks"); JSONObject tasks = json.getJSONObject("tasks");
JSONArray arr = tasks.getJSONArray("task"); JSONArray arr = tasks.getJSONArray("task");
assertEquals("incorrect number of elements", 1, arr.length()); assertEquals(1, arr.length(), "incorrect number of elements");
verifyAMTask(arr, jobsMap.get(id), type); verifyAMTask(arr, jobsMap.get(id), type);
} }
} }
@ -236,10 +236,10 @@ public void testTasksQueryReduce() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject tasks = json.getJSONObject("tasks"); JSONObject tasks = json.getJSONObject("tasks");
JSONArray arr = tasks.getJSONArray("task"); JSONArray arr = tasks.getJSONArray("task");
assertEquals("incorrect number of elements", 1, arr.length()); assertEquals(1, arr.length(), "incorrect number of elements");
verifyAMTask(arr, jobsMap.get(id), type); verifyAMTask(arr, jobsMap.get(id), type);
} }
} }
@ -265,7 +265,7 @@ public void testTasksQueryInvalid() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -294,7 +294,7 @@ public void testTaskId() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("task"); JSONObject info = json.getJSONObject("task");
verifyAMSingleTask(info, task); verifyAMSingleTask(info, task);
} }
@ -316,7 +316,7 @@ public void testTaskIdSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("task"); JSONObject info = json.getJSONObject("task");
verifyAMSingleTask(info, task); verifyAMSingleTask(info, task);
} }
@ -338,7 +338,7 @@ public void testTaskIdDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("task"); JSONObject info = json.getJSONObject("task");
verifyAMSingleTask(info, task); verifyAMSingleTask(info, task);
} }
@ -363,7 +363,7 @@ public void testTaskIdBogus() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -398,7 +398,7 @@ public void testTaskIdNonExist() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -431,7 +431,7 @@ public void testTaskIdInvalid() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -466,7 +466,7 @@ public void testTaskIdInvalid2() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -501,7 +501,7 @@ public void testTaskIdInvalid3() throws JSONException, Exception {
response.getType().toString()); response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class); JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException"); JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length()); assertEquals(3, exception.length(), "incorrect number of elements");
String message = exception.getString("message"); String message = exception.getString("message");
String type = exception.getString("exception"); String type = exception.getString("exception");
String classname = exception.getString("javaClassName"); String classname = exception.getString("javaClassName");
@ -550,7 +550,7 @@ public void testTaskIdXML() throws JSONException, Exception {
public void verifyAMSingleTask(JSONObject info, Task task) public void verifyAMSingleTask(JSONObject info, Task task)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 9, info.length()); assertEquals(9, info.length(), "incorrect number of elements");
verifyTaskGeneric(task, info.getString("id"), info.getString("state"), verifyTaskGeneric(task, info.getString("id"), info.getString("state"),
info.getString("type"), info.getString("successfulAttempt"), info.getString("type"), info.getString("successfulAttempt"),
@ -574,7 +574,7 @@ public void verifyAMTask(JSONArray arr, Job job, String type)
verifyAMSingleTask(info, task); verifyAMSingleTask(info, task);
} }
} }
assertTrue("task with id: " + tid + " not in web service output", found); assertTrue(found, "task with id: " + tid + " not in web service output");
} }
} }
} }
@ -593,12 +593,12 @@ public void verifyTaskGeneric(Task task, String id, String state,
WebServicesTestUtils.checkStringMatch("state", report.getTaskState() WebServicesTestUtils.checkStringMatch("state", report.getTaskState()
.toString(), state); .toString(), state);
// not easily checked without duplicating logic, just make sure its here // not easily checked without duplicating logic, just make sure its here
assertNotNull("successfulAttempt null", successfulAttempt); assertNotNull(successfulAttempt, "successfulAttempt null");
assertEquals("startTime wrong", report.getStartTime(), startTime); assertEquals(report.getStartTime(), startTime, "startTime wrong");
assertEquals("finishTime wrong", report.getFinishTime(), finishTime); assertEquals(report.getFinishTime(), finishTime, "finishTime wrong");
assertEquals("elapsedTime wrong", finishTime - startTime, elapsedTime); assertEquals(finishTime - startTime, elapsedTime, "elapsedTime wrong");
assertEquals("progress wrong", report.getProgress() * 100, progress, 1e-3f); assertEquals(report.getProgress() * 100, progress, 1e-3f, "progress wrong");
assertEquals("status wrong", report.getStatus(), status); assertEquals(report.getStatus(), status, "status wrong");
} }
public void verifyAMSingleTaskXML(Element element, Task task) { public void verifyAMSingleTaskXML(Element element, Task task) {
@ -615,7 +615,7 @@ public void verifyAMSingleTaskXML(Element element, Task task) {
public void verifyAMTaskXML(NodeList nodes, Job job) { public void verifyAMTaskXML(NodeList nodes, Job job) {
assertEquals("incorrect number of elements", 2, nodes.getLength()); assertEquals(2, nodes.getLength(), "incorrect number of elements");
for (Task task : job.getTasks().values()) { for (Task task : job.getTasks().values()) {
TaskId id = task.getID(); TaskId id = task.getID();
@ -629,7 +629,7 @@ public void verifyAMTaskXML(NodeList nodes, Job job) {
verifyAMSingleTaskXML(element, task); verifyAMSingleTaskXML(element, task);
} }
} }
assertTrue("task with id: " + tid + " not in web service output", found); assertTrue(found, "task with id: " + tid + " not in web service output");
} }
} }
@ -648,7 +648,7 @@ public void testTaskIdCounters() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobTaskCounters"); JSONObject info = json.getJSONObject("jobTaskCounters");
verifyAMJobTaskCounters(info, task); verifyAMJobTaskCounters(info, task);
} }
@ -670,7 +670,7 @@ public void testTaskIdCountersSlash() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobTaskCounters"); JSONObject info = json.getJSONObject("jobTaskCounters");
verifyAMJobTaskCounters(info, task); verifyAMJobTaskCounters(info, task);
} }
@ -692,7 +692,7 @@ public void testTaskIdCountersDefault() throws JSONException, Exception {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString()); response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class); JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length()); assertEquals(1, json.length(), "incorrect number of elements");
JSONObject info = json.getJSONObject("jobTaskCounters"); JSONObject info = json.getJSONObject("jobTaskCounters");
verifyAMJobTaskCounters(info, task); verifyAMJobTaskCounters(info, task);
} }
@ -728,7 +728,7 @@ public void testJobTaskCountersXML() throws Exception {
public void verifyAMJobTaskCounters(JSONObject info, Task task) public void verifyAMJobTaskCounters(JSONObject info, Task task)
throws JSONException { throws JSONException {
assertEquals("incorrect number of elements", 2, info.length()); assertEquals(2, info.length(), "incorrect number of elements");
WebServicesTestUtils.checkStringMatch("id", MRApps.toString(task.getID()), WebServicesTestUtils.checkStringMatch("id", MRApps.toString(task.getID()),
info.getString("id")); info.getString("id"));
@ -738,15 +738,14 @@ public void verifyAMJobTaskCounters(JSONObject info, Task task)
for (int i = 0; i < counterGroups.length(); i++) { for (int i = 0; i < counterGroups.length(); i++) {
JSONObject counterGroup = counterGroups.getJSONObject(i); JSONObject counterGroup = counterGroups.getJSONObject(i);
String name = counterGroup.getString("counterGroupName"); String name = counterGroup.getString("counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
JSONArray counters = counterGroup.getJSONArray("counter"); JSONArray counters = counterGroup.getJSONArray("counter");
for (int j = 0; j < counters.length(); j++) { for (int j = 0; j < counters.length(); j++) {
JSONObject counter = counters.getJSONObject(j); JSONObject counter = counters.getJSONObject(j);
String counterName = counter.getString("name"); String counterName = counter.getString("name");
assertTrue("name not set", assertTrue((counterName != null && !counterName.isEmpty()), "name not set");
(counterName != null && !counterName.isEmpty()));
long value = counter.getLong("value"); long value = counter.getLong("value");
assertTrue("value >= 0", value >= 0); assertTrue(value >= 0, "value >= 0");
} }
} }
} }
@ -765,20 +764,20 @@ public void verifyAMTaskCountersXML(NodeList nodes, Task task) {
for (int j = 0; j < groups.getLength(); j++) { for (int j = 0; j < groups.getLength(); j++) {
Element counters = (Element) groups.item(j); Element counters = (Element) groups.item(j);
assertNotNull("should have counters in the web service info", counters); assertNotNull(counters, "should have counters in the web service info");
String name = WebServicesTestUtils.getXmlString(counters, String name = WebServicesTestUtils.getXmlString(counters,
"counterGroupName"); "counterGroupName");
assertTrue("name not set", (name != null && !name.isEmpty())); assertTrue((name != null && !name.isEmpty()), "name not set");
NodeList counterArr = counters.getElementsByTagName("counter"); NodeList counterArr = counters.getElementsByTagName("counter");
for (int z = 0; z < counterArr.getLength(); z++) { for (int z = 0; z < counterArr.getLength(); z++) {
Element counter = (Element) counterArr.item(z); Element counter = (Element) counterArr.item(z);
String counterName = WebServicesTestUtils.getXmlString(counter, String counterName = WebServicesTestUtils.getXmlString(counter,
"name"); "name");
assertTrue("counter name not set", assertTrue((counterName != null && !counterName.isEmpty()),
(counterName != null && !counterName.isEmpty())); "counter name not set");
long value = WebServicesTestUtils.getXmlLong(counter, "value"); long value = WebServicesTestUtils.getXmlLong(counter, "value");
assertTrue("value not >= 0", value >= 0); assertTrue(value >= 0, "value not >= 0");
} }
} }

View File

@ -37,8 +37,8 @@
import org.apache.hadoop.yarn.webapp.Controller.RequestContext; import org.apache.hadoop.yarn.webapp.Controller.RequestContext;
import org.apache.hadoop.yarn.webapp.MimeType; import org.apache.hadoop.yarn.webapp.MimeType;
import org.apache.hadoop.yarn.webapp.ResponseInfo; import org.apache.hadoop.yarn.webapp.ResponseInfo;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class TestAppController { public class TestAppController {
@ -48,7 +48,7 @@ public class TestAppController {
private Job job; private Job job;
private static final String taskId = "task_01_01_m_01"; private static final String taskId = "task_01_01_m_01";
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
AppContext context = mock(AppContext.class); AppContext context = mock(AppContext.class);
when(context.getApplicationID()).thenReturn( when(context.getApplicationID()).thenReturn(

View File

@ -26,7 +26,7 @@
import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.MRJobConfig;
import org.apache.hadoop.mapreduce.util.MRJobConfUtil; import org.apache.hadoop.mapreduce.util.MRJobConfUtil;
import org.apache.hadoop.yarn.webapp.View; import org.apache.hadoop.yarn.webapp.View;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.v2.api.records.JobId; import org.apache.hadoop.mapreduce.v2.api.records.JobId;
@ -52,7 +52,7 @@
import org.apache.hadoop.yarn.webapp.view.HtmlBlock.Block; import org.apache.hadoop.yarn.webapp.view.HtmlBlock.Block;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
public class TestBlocks { public class TestBlocks {
private ByteArrayOutputStream data = new ByteArrayOutputStream(); private ByteArrayOutputStream data = new ByteArrayOutputStream();