BATCH-1597: calculate timeout from input

This commit is contained in:
dsyer
2010-08-13 10:22:43 +00:00
parent 01d1000f99
commit e4344f303f
2 changed files with 26 additions and 1 deletions

View File

@@ -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");
}

View File

@@ -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 {