Skip to content

Commit

Permalink
MAPREDUCE-7354. Use empty array constant present in TaskCompletionEve…
Browse files Browse the repository at this point in the history
…nt to avoid creating redundant objects
  • Loading branch information
virajjasani committed Jun 19, 2021
1 parent 51991c4 commit 4be88c9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public class JobImpl implements org.apache.hadoop.mapreduce.v2.app.job.Job,
EMPTY_TASK_ATTEMPT_COMPLETION_EVENTS = new TaskAttemptCompletionEvent[0];

private static final TaskCompletionEvent[]
EMPTY_TASK_COMPLETION_EVENTS = new TaskCompletionEvent[0];
EMPTY_TASK_COMPLETION_EVENTS = TaskCompletionEvent.EMPTY_ARRAY;

private static final Logger LOG = LoggerFactory.getLogger(JobImpl.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testJobToString() throws IOException, InterruptedException {
when(client.getTaskReports(jobid, TaskType.REDUCE)).thenReturn(
new TaskReport[0]);
when(client.getTaskCompletionEvents(jobid, 0, 10)).thenReturn(
new TaskCompletionEvent[0]);
TaskCompletionEvent.EMPTY_ARRAY);
Job job = Job.getInstance(cluster, status, new JobConf());
Assert.assertNotNull(job.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,9 @@ public void testJobMonitorAndPrint() throws Exception {
1f, 1f, State.SUCCEEDED, JobPriority.HIGH, "tmp-user", "tmp-jobname",
"tmp-queue", "tmp-jobfile", "tmp-url", true);

doAnswer(
new Answer<TaskCompletionEvent[]>() {
@Override
public TaskCompletionEvent[] answer(InvocationOnMock invocation)
throws Throwable {
return new TaskCompletionEvent[0];
}
}
).when(job).getTaskCompletionEvents(anyInt(), anyInt());
doAnswer((Answer<TaskCompletionEvent[]>) invocation ->
TaskCompletionEvent.EMPTY_ARRAY).when(job)
.getTaskCompletionEvents(anyInt(), anyInt());

doReturn(new TaskReport[5]).when(job).getTaskReports(isA(TaskType.class));
when(clientProtocol.getJobStatus(any(JobID.class))).thenReturn(jobStatus_1, jobStatus_2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public TaskAttemptCompletionEvent[] getTaskAttemptCompletionEvents(
@Override
public TaskCompletionEvent[] getMapAttemptCompletionEvents(
int startIndex, int maxEvents) {
return new TaskCompletionEvent[0];
return TaskCompletionEvent.EMPTY_ARRAY;
}

@Override
Expand Down

0 comments on commit 4be88c9

Please sign in to comment.