8000 MAPREDUCE-7414. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-hs by ashutoshcipher · Pull Request #5022 · apache/hadoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MAPREDUCE-7414. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-hs #5022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@
<artifactId>assertj-core</artifactId>
<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.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,38 @@
import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
import org.apache.hadoop.mapreduce.v2.api.records.TaskReport;
import org.apache.hadoop.mapreduce.v2.hs.CompletedTask;
import org.junit.Test;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestCompletedTask{

@Test (timeout=5000)
public void testTaskStartTimes() {

TaskId taskId = mock(TaskId.class);
@Test
@Timeout(5000)
void testTaskStartTimes() {

TaskId taskId = mock(TaskId.class);
TaskInfo taskInfo = mock(TaskInfo.class);
Map<TaskAttemptID, TaskAttemptInfo> taskAttempts
= new TreeMap<TaskAttemptID, TaskAttemptInfo>();
= new TreeMap<TaskAttemptID, TaskAttemptInfo>();

TaskAttemptID id = new TaskAttemptID("0", 0, TaskType.MAP, 0, 0);
TaskAttemptInfo info = mock(TaskAttemptInfo.class);
when(info.getAttemptId()).thenReturn(id);
when(info.getStartTime()).thenReturn(10l);
taskAttempts.put(id, info);

id = new TaskAttemptID("1", 0, TaskType.MAP, 1, 1);
info = mock(TaskAttemptInfo.class);
when(info.getAttemptId()).thenReturn(id);
when(info.getStartTime()).thenReturn(20l);
taskAttempts.put(id, info);


when(taskInfo.getAllTaskAttempts()).thenReturn(taskAttempts);
CompletedTask task = new CompletedTask(taskId, taskInfo);
TaskReport report = task.getReport();
Expand All @@ -66,30 +71,32 @@ public void testTaskStartTimes() {
// attempy launch times
assertTrue(report.getStartTime() == 10);
}

/**
* test some methods of CompletedTaskAttempt
*/
@Test (timeout=5000)
public void testCompletedTaskAttempt(){

TaskAttemptInfo attemptInfo= mock(TaskAttemptInfo.class);
@Test
@Timeout(5000)
void testCompletedTaskAttempt() {

TaskAttemptInfo attemptInfo = mock(TaskAttemptInfo.class);
when(attemptInfo.getRackname()).thenReturn("Rackname");
when(attemptInfo.getShuffleFinishTime()).thenReturn(11L);
when(attemptInfo.getSortFinishTime()).thenReturn(12L);
when(attemptInfo.getShufflePort()).thenReturn(10);
JobID jobId= new JobID("12345",0);
TaskID taskId =new TaskID(jobId,TaskType.REDUCE, 0);
TaskAttemptID taskAttemptId= new TaskAttemptID(taskId, 0);

JobID jobId = new JobID("12345", 0);
TaskID taskId = new TaskID(jobId, TaskType.REDUCE, 0);
TaskAttemptID taskAttemptId = new TaskAttemptID(taskId, 0);
when(attemptInfo.getAttemptId()).thenReturn(taskAttemptId);
CompletedTaskAttempt taskAttemt= new CompletedTaskAttempt(null,attemptInfo);
assertEquals( "Rackname", taskAttemt.getNodeRackName());
assertEquals( Phase.CLEANUP, taskAttemt.getPhase());


CompletedTaskAttempt taskAttemt = new CompletedTaskAttempt(null, attemptInfo);
assertEquals("Rackname", taskAttemt.getNodeRackName());
assertEquals(Phase.CLEANUP, taskAttemt.getPhase());
assertTrue( taskAttemt.isFinished());
assertEquals( 11L, taskAttemt.getShuffleFinishTime());
assertEquals( 12L, taskAttemt.getSortFinishTime());
assertEquals( 10, taskAttemt.getShufflePort());
assertEquals(11L, taskAttemt.getShuffleFinishTime());
assertEquals(12L, taskAttemt.getSortFinishTime());
assertEquals(10, taskAttemt.getShufflePort());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.ControlledClock;
import org.apache.hadoop.yarn.util.SystemClock;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.rules.TestName;

import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestHistoryFileManager {
private static MiniDFSCluster dfsCluster = null;
Expand All @@ -64,7 +66,7 @@ public class TestHistoryFileManager {
@Rule
public TestName name = new TestName();

@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
coreSitePath = "." + File.separator + "target" + File.separator +
"test-classes" + File.separator + "core-site.xml";
Expand All @@ -77,13 +79,13 @@ public static void setUpClass() throws Exception {
dfsCluster2 = new MiniDFSCluster.Builder(conf2).build();
}

@AfterClass
@AfterAll
public static void cleanUpClass() throws Exception {
dfsCluster.shutdown();
dfsCluster2.shutdown();
}

@After
@AfterEach
public void cleanTest() throws Exception {
new File(coreSitePath).delete();
dfsCluster.getFileSystem().setSafeMode(
Expand All @@ -106,26 +108,26 @@ private void testTryCreateHistoryDirs(Configuration conf, boolean expected)
conf.set(JHAdminConfig.MR_HISTORY_INTERMEDIATE_DONE_DIR, getIntermediateDoneDirNameForTest());
HistoryFileManager hfm = new HistoryFileManager();
hfm.conf = conf;
Assert.assertEquals(expected, hfm.tryCreatingHistoryDirs(false));
assertEquals(expected, hfm.tryCreatingHistoryDirs(false));
}

@Test
public void testCreateDirsWithoutFileSystem() throws Exception {
void testCreateDirsWithoutFileSystem() throws Exception {
Configuration conf = new YarnConfiguration();
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs://localhost:1");
testTryCreateHistoryDirs(conf, false);
}

@Test
public void testCreateDirsWithFileSystem() throws Exception {
void testCreateDirsWithFileSystem() throws Exception {
dfsCluster.getFileSystem().setSafeMode(
SafeModeAction.LEAVE);
Assert.assertFalse(dfsCluster.getFileSystem().isInSafeMode());
testTryCreateHistoryDirs(dfsCluster.getConfiguration(0), true);
}

@Test
public void testCreateDirsWithAdditionalFileSystem() throws Exception {
void testCreateDirsWithAdditionalFileSystem() throws Exception {
dfsCluster.getFileSystem().setSafeMode(
SafeModeAction.LEAVE);
dfsCluster2.getFileSystem().setSafeMode(
Expand All @@ -136,7 +138,7 @@ public void testCreateDirsWithAdditionalFileSystem() throws Exception {
// Set default configuration to the first cluster
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
dfsCluster.getURI().toString());
dfsCluster.getURI().toString());
FileOutputStream os = new FileOutputStream(coreSitePath);
conf.writeXml(os);
os.close();
Expand All @@ -145,17 +147,17 @@ public void testCreateDirsWithAdditionalFileSystem() throws Exception {

// Directories should be created only in the default file system (dfsCluster)
Assert.assertTrue(dfsCluster.getFileSystem()
.exists(new Path(getDoneDirNameForTest())));
.exists(new Path(getDoneDirNameForTest())));
Assert.assertTrue(dfsCluster.getFileSystem()
.exists(new Path(getIntermediateDoneDirNameForTest())));
.exists(new Path(getIntermediateDoneDirNameForTest())));
Assert.assertFalse(dfsCluster2.getFileSystem()
.exists(new Path(getDoneDirNameForTest())));
.exists(new Path(getDoneDirNameForTest())));
Assert.assertFalse(dfsCluster2.getFileSystem()
.exists(new Path(getIntermediateDoneDirNameForTest())));
.exists(new Path(getIntermediateDoneDirNameForTest())));
}

@Test
public void testCreateDirsWithFileSystemInSafeMode() throws Exception {
void testCreateDirsWithFileSystemInSafeMode() throws Exception {
dfsCluster.getFileSystem().setSafeMode(
SafeModeAction.ENTER);
Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode());
Expand All @@ -172,7 +174,7 @@ private void testCreateHistoryDirs(Configuration conf, Clock clock)
}

@Test
public void testCreateDirsWithFileSystemBecomingAvailBeforeTimeout()
void testCreateDirsWithFileSystemBecomingAvailBeforeTimeout()
throws Exception {
dfsCluster.getFileSystem().setSafeMode(
SafeModeAction.ENTER);
Expand All @@ -186,16 +188,16 @@ public void run() {
SafeModeAction.LEAVE);
Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode());
} catch (Exception ex) {
Assert.fail(ex.toString());
fail(ex.toString());
}
}
}.start();
testCreateHistoryDirs(dfsCluster.getConfiguration(0),
SystemClock.getInstance());
}

@Test(expected = YarnRuntimeException.class)
public void testCreateDirsWithFileSystemNotBecomingAvailBeforeTimeout()
@Test
void testCreateDirsWithFileSystemNotBecomingAvailBeforeTimeout()
throws Exception {
dfsCluster.getFileSystem().setSafeMode(
SafeModeAction.ENTER);
Expand All @@ -211,13 +213,13 @@ public void run() {
} catch (Exception ex) {
Assert.fail(ex.toString());
}
}
}.start();
testCreateHistoryDirs(dfsCluster.getConfiguration(0), clock);
}.start();
testCreateHistoryDirs(dfsCluster.getConfiguration(0), clock);
});
}

@Test
public void testScanDirectory() throws Exception {
void testScanDirectory() throws Exception {

Path p = new Path("any");
FileContext fc = mock(FileContext.class);
Expand All @@ -228,12 +230,12 @@ public void testScanDirectory() throws Exception {

//primarily, succcess is that an exception was not thrown. Also nice to
//check this
Assert.assertNotNull(lfs);
assertNotNull(lfs);

}

@Test
public void testHistoryFileInfoSummaryFileNotExist() throws Exception {
void testHistoryFileInfoSummaryFileNotExist() throws Exception {
HistoryFileManagerTest hmTest = new HistoryFileManagerTest();
String job = "job_1410889000000_123456";
Path summaryFile = new Path(job + ".summary");
Expand All @@ -248,11 +250,11 @@ public void testHistoryFileInfoSummaryFileNotExist() throws Exception {
HistoryFileInfo info = hmTest.getHistoryFileInfo(null, null,
summaryFile, jobIndexInfo, false);
info.moveToDone();
Assert.assertFalse(info.didMoveFail());
assertFalse(info.didMoveFail());
}

@Test
public void testHistoryFileInfoLoadOversizedJobShouldReturnUnParsedJob()
void testHistoryFileInfoLoadOversizedJobShouldReturnUnParsedJob()
throws Exception {
HistoryFileManagerTest hmTest = new HistoryFileManagerTest();

Expand All @@ -274,12 +276,12 @@ public void testHistoryFileInfoLoadOversizedJobShouldReturnUnParsedJob()
jobIndexInfo, false);

Job job = info.loadJob();
Assert.assertTrue("Should return an instance of UnparsedJob to indicate" +
" the job history file is not parsed", job instanceof UnparsedJob);
assertTrue(job instanceof UnparsedJob, "Should return an instance of UnparsedJob to indicate" +
" the job history file is not parsed");
}

@Test
public void testHistoryFileInfoLoadNormalSizedJobShouldReturnCompletedJob()
void testHistoryFileInfoLoadNormalSizedJobShouldReturnCompletedJob()
throws Exception {
HistoryFileManagerTest hmTest = new HistoryFileManagerTest();

Expand Down Expand Up @@ -307,13 +309,13 @@ public void testHistoryFileInfoLoadNormalSizedJobShouldReturnCompletedJob()
null, jobIndexInfo, false);

Job job = info.loadJob();
Assert.assertTrue("Should return an instance of CompletedJob as " +
"a result of parsing the job history file of the job",
job instanceof CompletedJob);
assertTrue(job instanceof CompletedJob,
"Should return an instance of CompletedJob as " +
"a result of parsing the job history file of the job");
}

@Test
public void testHistoryFileInfoShouldReturnCompletedJobIfMaxNotConfiged()
void testHistoryFileInfoShouldReturnCompletedJobIfMaxNotConfiged()
throws Exception {
HistoryFileManagerTest hmTest = new HistoryFileManagerTest();

Expand All @@ -336,9 +338,9 @@ public void testHistoryFileInfoShouldReturnCompletedJobIfMaxNotConfiged()
null, jobIndexInfo, false);

Job job = info.loadJob();
Assert.assertTrue("Should return an instance of CompletedJob as " +
"a result of parsing the job history file of the job",
job instanceof CompletedJob);
assertTrue(job instanceof CompletedJob,
"Should return an instance of CompletedJob as " +
"a result of parsing the job history file of the job");

}

Expand All @@ -350,7 +352,7 @@ public void testHistoryFileInfoShouldReturnCompletedJobIfMaxNotConfiged()
* FileNotFoundException.
*/
@Test
public void testMoveToDoneAlreadyMovedSucceeds() throws Exception {
void testMoveToDoneAlreadyMovedSucceeds() throws Exception {
HistoryFileManagerTest historyFileManager = new HistoryFileManagerTest();
long jobTimestamp = 1535436603000L;
String job = "job_" + jobTimestamp + "_123456789";
Expand Down Expand Up @@ -386,10 +388,10 @@ public void testMoveToDoneAlreadyMovedSucceeds() throws Exception {
jobIndexInfo, false);
info.moveToDone();

Assert.assertFalse(info.isMovePending());
Assert.assertEquals(doneHistoryFilePath.toString(),
assertFalse(info.isMovePending());
assertEquals(doneHistoryFilePath.toString(),
info.getHistoryFile().toUri().getPath());
Assert.assertEquals(doneConfFilePath.toString(),
assertEquals(doneConfFilePath.toString(),
info.getConfFile().toUri().getPath());
}

Expand Down
Loading
0