Poller<Collection<StepExecution>> poller = new DirectPoller<>(pollInterval); Future<Collection<StepExecution>> resultsFuture = poller.poll(callback);
@Test public void testSimpleSingleThreaded() throws Exception { Callable<String> callback = new Callable<String>() { @Override public String call() throws Exception { Set<String> executions = new HashSet<>(repository); if (executions.isEmpty()) { return null; } return executions.iterator().next(); } }; sleepAndCreateStringInBackground(500L); Future<String> task = new DirectPoller<String>(100L).poll(callback); String value = task.get(1000L, TimeUnit.MILLISECONDS); assertEquals("foo", value); }
@Test public void testWithError() throws Exception { Callable<String> callback = new Callable<String>() { @Override public String call() throws Exception { Set<String> executions = new HashSet<>(repository); if (executions.isEmpty()) { return null; } throw new RuntimeException("Expected"); } }; Poller<String> poller = new DirectPoller<>(100L); sleepAndCreateStringInBackground(500L); try { String value = poller.poll(callback).get(1000L, TimeUnit.MILLISECONDS); assertEquals(null, value); fail("Expected ExecutionException"); } catch (ExecutionException e) { assertEquals("Expected", e.getCause().getMessage()); } }
@Test public void testTimeUnit() throws Exception { Callable<String> callback = new Callable<String>() { @Override public String call() throws Exception { Set<String> executions = new HashSet<>(repository); if (executions.isEmpty()) { return null; } return executions.iterator().next(); } }; sleepAndCreateStringInBackground(500L); Future<String> task = new DirectPoller<String>(100L).poll(callback); String value = task.get(1L, TimeUnit.SECONDS); assertEquals("foo", value); }
Poller<Collection<StepExecution>> poller = new DirectPoller<>(this.pollInterval); Future<Collection<StepExecution>> resultsFuture = poller.poll(callback);
Poller<Collection<StepExecution>> poller = new DirectPoller<>(this.pollInterval); Future<Collection<StepExecution>> resultsFuture = poller.poll(callback);