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