@SuppressWarnings("unchecked") // java 1.5 screwed up invokeAll's definition public void testInvokeAnyWithRetry() throws Exception { Collection<Callable<String>> callables = new ArrayList<Callable<String>>( Arrays.asList( new TestRtryCallable<String>("A", 4, 5), new TestRtryCallable<String>("B", 6, 5), new TestRtryCallable<String>("C", 3, 5))); String res = schedPooled.invokeAny(callables); assertEquals("Got " + res + ", expected C", "C", res); }
@SuppressWarnings("unchecked") // java 1.5 screwed up invokeAll's definition public void testInvokeAnyWithRetryTimeout() throws Exception { Collection<Callable<String>> callables = new ArrayList<Callable<String>>( Arrays.asList( new TestRtryCallable<String>("A", 4, 3), new TestRtryCallable<String>("B", 1, 3), new TestRtryCallable<String>("C", 3, 5))); String res = schedPooled.invokeAny(callables, 10, TimeUnit.SECONDS); assertEquals("B", res); }
public void testInvokeAnyTimeout() throws Exception { // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection<Callable<String>> callables = new ArrayList<Callable<String>>( Arrays.asList( new TestCallable<String>("A"), new TestCallable<String>("B", 30), new TestCallable<String>("C", 30))); String res = schedPooled.invokeAny(callables, 10, TimeUnit.MILLISECONDS); assertEquals("A", res); }
public void testInvokeAnyException() throws Exception { // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection<Callable<String>> callables = new ArrayList<Callable<String>>( Arrays.asList( new TestRtryCallable<String>("A", 4, 3), new TestRtryCallable<String>("B", 4, 3), new TestRtryCallable<String>("C", 4, 3))); try { String res = schedPooled.invokeAny(callables); fail("Expected exception, got " + res); } catch (ExecutionException e) { // OK } }
public void testInvokeAnyWithRetryTimeoutTimedOut() throws Exception { // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection<Callable<String>> callables = new ArrayList<Callable<String>>( Arrays.asList( new TestRtryCallable<String>("A", 5, 9, 1000), new TestRtryCallable<String>("B", 5, 9, 1000), new TestRtryCallable<String>("C", 5, 9, 1000))); try { String res = schedPooled.invokeAny(callables, 10, TimeUnit.MILLISECONDS); fail("Expected timeout, got " + res); } catch (TimeoutException e) { // OK } }
public void testInvokeAny() throws Exception { // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection c = Arrays.asList( new TestCallable<String>("A"), new TestCallable<String>("B"), new TestCallable<String>("C")); // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection<Callable<String>> callables = c; Set<String> expected = new HashSet<String>(); expected.addAll(Arrays.asList("A", "B", "C")); String res = schedInline.invokeAny(callables); assertTrue(expected.contains(res)); }
public void testInvokeAnyExceptionTimeout() throws Exception { // java 1.5 screwed up invokeAny's definition @SuppressWarnings("unchecked") Collection<Callable<String>> callables = new ArrayList<Callable<String>>(); for (int i = 0; i < 3; i++) { callables.add( new Callable<String>() { public String call() throws Exception { throw new Exception("Nope"); } }); } try { String res = schedPooled.invokeAny(callables, 10, TimeUnit.MILLISECONDS); fail("Expected exception, got " + res); } catch (ExecutionException e) { // OK } }