@Test public void greedyPartitionDifferentTimes() { Timestamp now = Timestamp.from(Clock.systemUTC().instant()); TestTime test1 = new TestTime("test1", 10, false, "host1", now); TestTime test2 = new TestTime("test2", 5, false, "host1", now); TestTime test3 = new TestTime("test3", 1, false, "host1", now); TestTime test4 = new TestTime("test4", 2, false, "host1", now); Collection<TestTime> testTimes = Lists.newArrayList(test1, test2, test3, test4); Set<TestContainer> testContainers = createTestContainers(2); PartitionUtil.greedyPartition(testTimes, testContainers); Iterator<TestContainer> iterator = testContainers.iterator(); TestContainer first = iterator.next(); TestContainer second = iterator.next(); assertEquals(18, first.getTime() + second.getTime()); assertEquals(4, first.getTestTimes().size() + second.getTestTimes().size()); long longerTime = Math.max(first.getTime(), second.getTime()); long shorterTime = Math.min(first.getTime(), second.getTime()); assertEquals(10, longerTime); assertEquals(8, shorterTime); }
public static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { if(testContainers.isEmpty()) { throw new IllegalArgumentException("Queue must be populated with a partition for each host"); } List<TestTime> sortedList = testTimes.stream() .sorted(Comparator.comparingLong(TestTime::getTime).reversed()) .collect(Collectors.toList()); PriorityQueue<TestContainer> queues = new PriorityQueue<>(testContainers); greedyPartition(sortedList, queues); }
PartitionUtil { public static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { if(testContainers.isEmpty()) { throw new IllegalArgumentException("Queue must be populated with a partition for each host"); } List<TestTime> sortedList = testTimes.stream() .sorted(Comparator.comparingLong(TestTime::getTime).reversed()) .collect(Collectors.toList()); PriorityQueue<TestContainer> queues = new PriorityQueue<>(testContainers); greedyPartition(sortedList, queues); } }
PartitionUtil { public static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { if(testContainers.isEmpty()) { throw new IllegalArgumentException("Queue must be populated with a partition for each host"); } List<TestTime> sortedList = testTimes.stream() .sorted(Comparator.comparingLong(TestTime::getTime).reversed()) .collect(Collectors.toList()); PriorityQueue<TestContainer> queues = new PriorityQueue<>(testContainers); greedyPartition(sortedList, queues); }  }
PartitionUtil { public static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { if(testContainers.isEmpty()) { throw new IllegalArgumentException("Queue must be populated with a partition for each host"); } List<TestTime> sortedList = testTimes.stream() .sorted(Comparator.comparingLong(TestTime::getTime).reversed()) .collect(Collectors.toList()); PriorityQueue<TestContainer> queues = new PriorityQueue<>(testContainers); greedyPartition(sortedList, queues); }  static void greedyPartitionFailuresOnSameHost(Collection<TestTime> testTimes, Set<TestContainer> testContainers); static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers); }
PartitionUtil { public static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { if(testContainers.isEmpty()) { throw new IllegalArgumentException("Queue must be populated with a partition for each host"); } List<TestTime> sortedList = testTimes.stream() .sorted(Comparator.comparingLong(TestTime::getTime).reversed()) .collect(Collectors.toList()); PriorityQueue<TestContainer> queues = new PriorityQueue<>(testContainers); greedyPartition(sortedList, queues); }  static void greedyPartitionFailuresOnSameHost(Collection<TestTime> testTimes, Set<TestContainer> testContainers); static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers);  }