--- jsr166/src/test/tck/ExecutorCompletionService9Test.java 2016/08/24 22:22:39 1.5 +++ jsr166/src/test/tck/ExecutorCompletionService9Test.java 2016/11/06 22:42:10 1.7 @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.HashSet; @@ -50,7 +51,7 @@ public class ExecutorCompletionService9T List> futures = new ArrayList<>(n); Integer result = null; try { - solvers.forEach((solver) -> futures.add(cs.submit(solver))); + solvers.forEach(solver -> futures.add(cs.submit(solver))); for (int i = n; i > 0; i--) { try { Integer r = cs.take().get(); @@ -61,17 +62,17 @@ public class ExecutorCompletionService9T } catch (ExecutionException ignore) {} } } finally { - futures.forEach((future) -> future.cancel(true)); + futures.forEach(future -> future.cancel(true)); } if (result != null) use(result); } - HashSet results; + ArrayList results; void use(Integer x) { - if (results == null) results = new HashSet(); + if (results == null) results = new ArrayList(); results.add(x); } @@ -80,6 +81,7 @@ public class ExecutorCompletionService9T */ public void testSolveAll() throws InterruptedException, ExecutionException { + results = null; Set> solvers = Set.of( () -> null, () -> 1, @@ -87,7 +89,8 @@ public class ExecutorCompletionService9T () -> 3, () -> null); solveAll(cachedThreadPool, solvers); - assertEquals(Set.of(1, 2, 3), results); + results.sort(Comparator.naturalOrder()); + assertEquals(List.of(1, 2, 3), results); } /** @@ -95,6 +98,7 @@ public class ExecutorCompletionService9T */ public void testSolveAny() throws InterruptedException { + results = null; Set> solvers = Set.of( () -> { throw new ArithmeticException(); }, () -> null, @@ -102,7 +106,7 @@ public class ExecutorCompletionService9T () -> 2); solveAny(cachedThreadPool, solvers); assertEquals(1, results.size()); - Integer elt = results.iterator().next(); + Integer elt = results.get(0); assertTrue(elt.equals(1) || elt.equals(2)); }