Tasks { public static IScheduledTask getLatestActiveTask(Iterable<IScheduledTask> tasks) { Preconditions.checkArgument(Iterables.size(tasks) != 0); return Ordering.explicit(ORDERED_TASK_STATUSES) .onResultOf(IScheduledTask::getStatus) .compound(LATEST_ACTIVITY) .max(tasks); } private  Tasks(); static ITaskConfig getConfig(IScheduledTask scheduledTask); static int getInstanceId(IScheduledTask scheduledTask); static IJobKey getJob(IAssignedTask assignedTask); static IJobKey getJob(IScheduledTask scheduledTask); static String scheduledToSlaveHost(IScheduledTask scheduledTask); static Multimap<IJobKey, IScheduledTask> byJobKey(Iterable<IScheduledTask> tasks); static boolean isActive(ScheduleStatus status); static boolean isTerminated(ScheduleStatus status); static String id(IScheduledTask task); static Set<String> ids(Iterable<IScheduledTask> tasks); static Set<String> ids(IScheduledTask... tasks); static IScheduledTask getLatestActiveTask(Iterable<IScheduledTask> tasks); static ITaskEvent getLatestEvent(IScheduledTask task); static final EnumSet<ScheduleStatus> ACTIVE_STATES; static final Set<ScheduleStatus> TERMINAL_STATES; static final Set<ScheduleStatus> SLAVE_ASSIGNED_STATES; static final Ordering<IScheduledTask> LATEST_ACTIVITY; }
@Test public void testLatestTransitionedTasks() { IScheduledTask f1 = makeTask(FINISHED, 100); IScheduledTask f2 = makeTask(FINISHED, 200); IScheduledTask f3 = makeTask(FINISHED, 300); IScheduledTask r1 = makeTask(RUNNING, 400); IScheduledTask r2 = makeTask(RUNNING, 500); IScheduledTask r3 = makeTask(RUNNING, 600); try { getLatestActiveTask(ImmutableList.of()); fail("Should have thrown IllegalArgumentException."); } catch (IllegalArgumentException e) { } assertLatestTask(r1, r1); assertLatestTask(r2, r1, r2); assertLatestTask(r2, r2, r1); assertLatestTask(r3, r2, r1, r3); assertLatestTask(r3, r3, r2, r1); assertLatestTask(f1, f1); assertLatestTask(f2, f1, f2); assertLatestTask(f2, f2, f1); assertLatestTask(f3, f2, f1, f3); assertLatestTask(f3, f3, f2, f1); assertLatestTask(r1, f2, f1, r1); assertLatestTask(r2, f2, f1, r1, r2); assertLatestTask(r3, f2, f1, f3, r1, r2, r3); assertLatestTask(r3, r1, r3, r2, f3, f1, f2); }