public Collection<Object> toJson() throws PreloadException { if (t instanceof PreloadException) { throw (PreloadException) t; } throw new PreloadException(t); } }
@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()); }
/** * Injects preloads into the gadget output. * * If preloading fails for any reason, we just output an empty object. */ protected void injectPreloads(Gadget gadget, Node scriptTag) { List<Object> preload = Lists.newArrayList(); for (PreloadedData preloaded : gadget.getPreloads()) { try { preload.addAll(preloaded.toJson()); } catch (PreloadException pe) { // This will be thrown in the event of some unexpected exception. We can move on. if (LOG.isLoggable(Level.WARNING)) { LOG.logp(Level.WARNING, classname, "injectPreloads", MessageKeys.UNEXPECTED_ERROR_PRELOADING); LOG.log(Level.WARNING, pe.getMessage(), pe); } } } Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.io.preloaded_="); text.appendData(JsonSerializer.serialize(preload)); text.appendData(";"); scriptTag.appendChild(text); } }
@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()); }
public Collection<Object> toJson() throws PreloadException { if (t instanceof PreloadException) { throw (PreloadException) t; } throw new PreloadException(t); } }
@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()); }
public Collection<Object> toJson() throws PreloadException { if (t instanceof PreloadException) { throw (PreloadException) t; } throw new PreloadException(t); } }
@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 Collection<Object> toJson() throws PreloadException { throw new PreloadException("test"); } };
@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 Collection<Object> toJson() throws PreloadException { throw new PreloadException("test"); } };
@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 Collection<Object> toJson() throws PreloadException { throw new PreloadException("test"); } };
public PreloadedData call() throws Exception { executedThread = Thread.currentThread(); if (preload == null) { throw new PreloadException("No preload for this test."); } return preload; } }
public PreloadedData call() throws Exception { executedThread = Thread.currentThread(); if (preload == null) { throw new PreloadException("No preload for this test."); } return preload; } }
public PreloadedData call() throws Exception { executedThread = Thread.currentThread(); if (preload == null) { throw new PreloadException("No preload for this test."); } return preload; } }
public PreloadedData get() throws InterruptedException, ExecutionException { if (throwsInterrupted) { throw new InterruptedException("Interrupted!"); } if (throwsExecution) { throw new ExecutionException(new RuntimeException("Fail")); } if (throwsExecutionWrapped) { throw new ExecutionException(new PreloadException("Preload failed.")); } return new PreloadedData() { public Collection<Object> toJson() { return expectedResult(key); } }; }
public PreloadedData get() throws InterruptedException, ExecutionException { if (throwsInterrupted) { throw new InterruptedException("Interrupted!"); } if (throwsExecution) { throw new ExecutionException(new RuntimeException("Fail")); } if (throwsExecutionWrapped) { throw new ExecutionException(new PreloadException("Preload failed.")); } return new PreloadedData() { public Collection<Object> toJson() { return expectedResult(key); } }; }
public PreloadedData get() throws InterruptedException, ExecutionException { if (throwsInterrupted) { throw new InterruptedException("Interrupted!"); } if (throwsExecution) { throw new ExecutionException(new RuntimeException("Fail")); } if (throwsExecutionWrapped) { throw new ExecutionException(new PreloadException("Preload failed.")); } return new PreloadedData() { public Collection<Object> toJson() { return expectedResult(key); } }; }
@Test public void executePreloadException() throws Exception { PipelinedData pipeline = getPipelinedData(CONTENT); final PreloadedData willThrow = control.createMock(PreloadedData.class); Callable<PreloadedData> callable = new Callable<PreloadedData>() { public PreloadedData call() throws Exception { return willThrow; } }; // One batch expect(preloader.createPreloadTasks(same(context), isA(PipelinedData.Batch.class))).andReturn(ImmutableList.of(callable)); // And PreloadedData that throws an exception expect(willThrow.toJson()).andThrow(new PreloadException("Failed")); control.replay(); PipelineExecutor.Results results = executor.execute(context, ImmutableList.of(pipeline)); // The exception is fully handled, and leads to empty results assertEquals(0, results.results.size()); assertTrue(results.keyedResults.isEmpty()); assertTrue(results.remainingPipelines.isEmpty()); control.verify(); }