diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/poller/DirectPoller.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/poller/DirectPoller.java index 67dbb181a..33bd077a6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/poller/DirectPoller.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/poller/DirectPoller.java @@ -92,11 +92,12 @@ public class DirectPoller implements Poller { Long nextExecutionTime = startTime + interval; long currentTimeMillis = System.currentTimeMillis(); + long timeoutMillis = TimeUnit.MILLISECONDS.convert(timeout, unit); while (result == null && !cancelled) { long delta = nextExecutionTime - startTime; - if (delta >= timeout && timeout > 0) { + if (delta >= timeoutMillis && timeoutMillis > 0) { throw new TimeoutException("Timed out waiting for task to return non-null result"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java index 62ae9216c..2d9de3b6c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java @@ -59,6 +59,30 @@ public class DirectPollerTests { } + @Test + public void testTimeUnit() throws Exception { + + Callable callback = new Callable() { + + public String call() throws Exception { + Set executions = new HashSet(repository); + if (executions.isEmpty()) { + return null; + } + return executions.iterator().next(); + } + + }; + + sleepAndCreateStringInBackground(500L); + + Future task = new DirectPoller(100L).poll(callback); + + String value = task.get(1L, TimeUnit.SECONDS); + assertEquals("foo", value); + + } + @Test public void testWithError() throws Exception {