Skip to content

Commit

Permalink
MAPREDUCE-7418. Fix CheckStyle & Junit Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
fanshilun committed Feb 5, 2025
1 parent 4d18776 commit 405920d
Show file tree
Hide file tree
Showing 39 changed files with 1,369 additions and 1,310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@
import org.apache.hadoop.yarn.event.Event;
import org.apache.hadoop.yarn.event.EventHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class TestLocalContainerLauncher {
private static final Logger LOG =
LoggerFactory.getLogger(TestLocalContainerLauncher.class);
Expand Down Expand Up @@ -104,11 +106,15 @@ public void testKillJob() throws Exception {
AppContext context = mock(AppContext.class);
// a simple event handler solely to detect the container cleaned event
final CountDownLatch isDone = new CountDownLatch(1);
EventHandler<Event> handler = event -> {
LOG.info("handling event {} with type {}.", event.getClass(), event.getType());
if (event instanceof TaskAttemptEvent) {
if (event.getType() == TaskAttemptEventType.TA_CONTAINER_CLEANED) {
isDone.countDown();
EventHandler<Event> handler = new EventHandler<Event>() {
@Override
public void handle(Event event) {
LOG.info("handling event " + event.getClass() +
" with type " + event.getType());
if (event instanceof TaskAttemptEvent) {
if (event.getType() == TaskAttemptEventType.TA_CONTAINER_CLEANED) {
isDone.countDown();
}
}
}
};
Expand All @@ -129,7 +135,7 @@ public void testKillJob() throws Exception {
Job job = mock(Job.class);
when(job.getTotalMaps()).thenReturn(1);
when(job.getTotalReduces()).thenReturn(0);
Map<JobId,Job> jobs = new HashMap<>();
Map<JobId,Job> jobs = new HashMap<JobId,Job>();
jobs.put(jobId, job);
// app context returns the one and only job
when(context.getAllJobs()).thenReturn(jobs);
Expand All @@ -146,11 +152,14 @@ public void testKillJob() throws Exception {
TaskAttemptID taskID = TypeConverter.fromYarn(taId);
when(mapTask.getTaskID()).thenReturn(taskID);
when(mapTask.getJobID()).thenReturn(taskID.getJobID());
doAnswer((Answer<Void>) invocation -> {
// sleep for a long time
LOG.info("sleeping for 5 minutes...");
Thread.sleep(5 * 60 * 1000);
return null;
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
// sleep for a long time
LOG.info("sleeping for 5 minutes...");
Thread.sleep(5*60*1000);
return null;
}
}).when(mapTask).run(isA(JobConf.class), isA(TaskUmbilicalProtocol.class));

// pump in a task attempt launch event
Expand All @@ -162,7 +171,7 @@ public void testKillJob() throws Exception {
// now pump in a container clean-up event
ContainerLauncherEvent cleanupEvent =
new ContainerLauncherEvent(taId, null, null, null,
ContainerLauncher.EventType.CONTAINER_REMOTE_CLEANUP);
ContainerLauncher.EventType.CONTAINER_REMOTE_CLEANUP);
launcher.handle(cleanupEvent);

// wait for the event to fire: this should be received promptly
Expand All @@ -188,11 +197,11 @@ public void testRenameMapOutputForReduce() throws Exception {

// make sure both dirs are distinct
//
conf.set(MRConfig.LOCAL_DIR, localDirs[0]);
conf.set(MRConfig.LOCAL_DIR, localDirs[0].toString());
final Path mapOut = mrOutputFiles.getOutputFileForWrite(1);
conf.set(MRConfig.LOCAL_DIR, localDirs[1]);
conf.set(MRConfig.LOCAL_DIR, localDirs[1].toString());
final Path mapOutIdx = mrOutputFiles.getOutputIndexFileForWrite(1);
Assertions.assertNotEquals(
assertNotEquals(
mapOut.getParent(), mapOutIdx.getParent(), "Paths must be different!");

// make both dirs part of LOCAL_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class TestTaskAttemptFinishingMonitor {

@Test
public void testFinishingAttemptTimeout()
public void testFinshingAttemptTimeout()
throws IOException, InterruptedException {
SystemClock clock = SystemClock.getInstance();
Configuration conf = new Configuration();
Expand Down Expand Up @@ -103,6 +103,6 @@ public void handle(Event event) {
}
}
}
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -187,7 +188,7 @@ public void testGetTask() throws IOException {
startListener(false);

// Verify ask before registration.
//The JVM ID has not been registered yet, so we should kill it.
//The JVM ID has not been registered yet so we should kill it.
JvmContext context = new JvmContext();

context.jvmId = id;
Expand Down Expand Up @@ -221,7 +222,7 @@ public void testGetTask() throws IOException {

listener.unregister(attemptId, wid);

// Verify after un-registration.
// Verify after unregistration.
result = listener.getTask(context);
assertNotNull(result);
assertTrue(result.shouldDie);
Expand All @@ -245,7 +246,7 @@ public void testJVMId() {

JVMId jvmid = new JVMId("test", 1, true, 2);
JVMId jvmid1 = JVMId.forName("jvm_test_0001_m_000002");
// test compare method should be the same
// test compare methot should be the same
assertEquals(0, jvmid.compareTo(jvmid1));
}

Expand Down Expand Up @@ -377,7 +378,7 @@ protected void registerHeartbeatHandler(Configuration conf) {

TaskAttemptID tid = new TaskAttemptID("12345", 1, TaskType.REDUCE, 1, 0);

List<Path> partialOut = new ArrayList<>();
List<Path> partialOut = new ArrayList<Path>();
partialOut.add(new Path("/prev1"));
partialOut.add(new Path("/prev2"));

Expand Down Expand Up @@ -555,13 +556,16 @@ protected void stopRpcServer() {
long unregisterTimeout = conf.getLong(MRJobConfig.TASK_EXIT_TIMEOUT,
MRJobConfig.TASK_EXIT_TIMEOUT_DEFAULT);
clock.setTime(unregisterTimeout + 1);
GenericTestUtils.waitFor(() -> {
try {
AMFeedback response =
tal.statusUpdate(attemptID, firstReduceStatus);
return !response.getTaskFound();
} catch (Exception e) {
throw new RuntimeException("status update failed", e);
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
try {
AMFeedback response =
tal.statusUpdate(attemptID, firstReduceStatus);
return !response.getTaskFound();
} catch (Exception e) {
throw new RuntimeException("status update failed", e);
}
}
}, 10, 10000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Tests the behavior of YarnChild.
Expand Down
Loading

0 comments on commit 405920d

Please sign in to comment.