BATCH-1597: calculate timeout from input
This commit is contained in:
@@ -92,11 +92,12 @@ public class DirectPoller<S> implements Poller<S> {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,30 @@ public class DirectPollerTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeUnit() throws Exception {
|
||||
|
||||
Callable<String> callback = new Callable<String>() {
|
||||
|
||||
public String call() throws Exception {
|
||||
Set<String> executions = new HashSet<String>(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);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithError() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user