@SuppressWarnings("unchecked") // java 1.5 screwed up invokeAll's definition public void testInvokeAllTimeout() throws Exception { Collection callables = Arrays.asList( new TestCallable<String>("A"), new TestCallable<String>("B"), new TestCallable<String>("C")); Set<String> expected = new HashSet<String>(); expected.addAll(Arrays.asList("A", "B", "C")); Set<String> got = new HashSet<String>(); List<Future<String>> res = schedInline.invokeAll(callables, 10, TimeUnit.MILLISECONDS); for (Future<String> f : res) { got.add(f.get()); } assertEquals(expected, got); }
@SuppressWarnings("unchecked") // java 1.5 screwed up invokeAll's definition public void testInvokeAllWithRetry() throws Exception { Collection callables = Arrays.asList( new TestRtryCallable<String>("A", 2, 3), new TestRtryCallable<String>("B", 2, 3), new TestRtryCallable<String>("C", 2, 3)); List<String> expected = new ArrayList<String>(); expected.addAll(Arrays.asList("A", "B", "C")); List<String> got = new ArrayList<String>(); List<Future<String>> res = schedPooled.invokeAll(callables); for (Future<String> f : res) { got.add(f.get()); } assertEquals(expected, got); }
@SuppressWarnings("unchecked") // java 1.5 screwed up invokeAll's definition public void testInvokeAllWithRetryTimeout() throws Exception { Collection callables = Arrays.asList( new TestRtryCallable<String>("A", 1, 9, 10), new TestRtryCallable<String>("B", 5, 9, 100), new TestRtryCallable<String>("C", 7, 9, 1000)); // Only one of these should finish. List<String> expected = new ArrayList<String>(); expected.addAll(Arrays.asList("A")); List<String> got = new ArrayList<String>(); List<Future<String>> res = schedPooled.invokeAll(callables, 20, TimeUnit.MILLISECONDS); for (Future<String> f : res) { if (f.isDone()) { got.add(f.get()); } } assertEquals(expected, got); }