@Test public void testSorting() { Instant now = Instant.now(); List<JobInfo> jobList = Lists.newArrayList( new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null) ); int min =1; int max =1; SLA sla = new SLA(min,max, null, null); SLAEnforcer slaEnforcer = new SLAEnforcer(sla); Set<JobInfo> sortJobsByIdDesc = slaEnforcer.sortJobsByIdDesc(jobList); String [] expectedOrder = {"cname-1","cname-2","cname-3","cname-4"}; JobInfo [] jobIdArray = sortJobsByIdDesc.toArray(new JobInfo[sortJobsByIdDesc.size()]); for(int i=0; i< jobIdArray.length; i++) { System.out.println("[" + i + "] ->" + jobIdArray[i]); assertEquals(expectedOrder[i],(jobIdArray[i].jobId.getId())); } }
Set<JobInfo> sortJobsByIdDesc(List<JobInfo> list) { SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator); sortedJobSet.addAll(list); return sortedJobSet; }
SLAEnforcer { Set<JobInfo> sortJobsByIdDesc(List<JobInfo> list) { SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator); sortedJobSet.addAll(list); return sortedJobSet; } }
SLAEnforcer { Set<JobInfo> sortJobsByIdDesc(List<JobInfo> list) { SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator); sortedJobSet.addAll(list); return sortedJobSet; } SLAEnforcer(SLA sla); }
SLAEnforcer { Set<JobInfo> sortJobsByIdDesc(List<JobInfo> list) { SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator); sortedJobSet.addAll(list); return sortedJobSet; } SLAEnforcer(SLA sla); int enforceSLAMin(int activeJobsCount, int acceptedJobsCount); List<JobId> enforceSLAMax(List<JobInfo> list); boolean hasSLA(); }
SLAEnforcer { Set<JobInfo> sortJobsByIdDesc(List<JobInfo> list) { SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator); sortedJobSet.addAll(list); return sortedJobSet; } SLAEnforcer(SLA sla); int enforceSLAMin(int activeJobsCount, int acceptedJobsCount); List<JobId> enforceSLAMax(List<JobInfo> list); boolean hasSLA();  }