@Test public void getDataWithRuntimeException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecution()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a PreloadException around // a RuntimeException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertSame(pe.getCause().getClass(), RuntimeException.class); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test public void getDataWithPreloadException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecutionWrapped()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a straight PreloadException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertNull(pe.getCause()); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test(expected = RuntimeException.class) public void getDataThrowsInterruped() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsInterrupted()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // InterruptedException should immediately terminate iterator.next(); }
@Test public void getDataWithRuntimeException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecution()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a PreloadException around // a RuntimeException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertSame(pe.getCause().getClass(), RuntimeException.class); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test public void getDataWithRuntimeException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecution()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a PreloadException around // a RuntimeException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertSame(pe.getCause().getClass(), RuntimeException.class); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test public void getDataWithPreloadException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecutionWrapped()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a straight PreloadException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertNull(pe.getCause()); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test public void getDataWithPreloadException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecutionWrapped()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); // First item should throw an exception, a straight PreloadException PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertNull(pe.getCause()); } // And iteration should continue assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
public static TestFuture returnsNormal(String key) { return new TestFuture(key); }
public static TestFuture returnsNormal(String key) { return new TestFuture(key); }
public static TestFuture returnsNormal(String key) { return new TestFuture(key); }
public Collection<Object> toJson() { return expectedResult(key); } };
public Collection<Object> toJson() { return expectedResult(key); } };
public Collection<Object> toJson() { return expectedResult(key); } };
public PreloadedData get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { return get(); }
public PreloadedData get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { return get(); }
public static TestFuture throwsExecution() { TestFuture future = new TestFuture(null); future.throwsExecution = true; return future; }
public static TestFuture throwsExecutionWrapped() { TestFuture future = new TestFuture(null); future.throwsExecutionWrapped = true; return future; }
public static TestFuture throwsExecution() { TestFuture future = new TestFuture(null); future.throwsExecution = true; return future; }
public PreloadedData get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { return get(); }
public static TestFuture throwsInterrupted() { TestFuture future = new TestFuture(null); future.throwsInterrupted = true; return future; }