AsynchronousSectionedRenderer extends AsynchronousRenderer<RESPONSE> { @Override public final ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response, Execution execution, Request request) { if (beforeHandoverMode) { beforeHandoverMode = false; if ( ! dataListListenerStack.isEmpty() && dataListListenerStack.getFirst().list.incoming().isComplete()) { getExecutor().execute(dataListListenerStack.getFirst()); } return success; } else { return startRender(stream, response, execution, request); } } AsynchronousSectionedRenderer();  AsynchronousSectionedRenderer(Executor executor); abstract void beginResponse(OutputStream stream); abstract void beginList(DataList<?> list); abstract void data(Data data); abstract void endList(DataList<?> list); abstract void endResponse(); @Override final ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response,
                                                  Execution execution, Request request); @Override void deconstruct(); final ListenableFuture<Boolean> renderBeforeHandover(OutputStream stream, RESPONSE response,
                                                                Execution execution, Request request); Execution getExecution(); Response getResponse(); int getRecursionLevel(); @Override final void setNetworkWiring(ContentChannel channel, CompletionHandler completionHandler); @Override void init();  }
@Test public void testEmptyProcessingRendering() throws IOException, InterruptedException { Request request = new Request(); DataList dataList = ArrayDataList.create(request); assertThat(render(dataList), equalTo("{\"datalist\":[" + "]}")); }
@Test public void testProcessingRendering() throws IOException, InterruptedException { StringDataList dataList = createDataListWithStrangeStrings(); assertThat(render(dataList), equalTo("{\"datalist\":[" + "{\"data\":\"f\\\\o\\\"o\"}," + "{\"datalist\":[" + "{\"data\":\"b/a\\br\"}," + "{\"data\":\"f\\f\\no\\ro\\tbar\\u0005\"}" + "]}" + "]}")); }
@Test public void testProcessingRenderingWithErrors() throws IOException, InterruptedException { StringDataList dataList = createDataList(); dataList.request().errors().add(new ErrorMessage("m1","d1")); dataList.request().errors().add(new ErrorMessage("m2","d2")); assertThat(render(dataList), equalTo("{\"errors\":[" + "\"m1: d1\"," + "\"m2: d2\"" + "]," + "\"datalist\":[" + "{\"data\":\"l1\"}," + "{\"datalist\":[" + "{\"data\":\"l11\"}," + "{\"data\":\"l12\"}" + "]}" + "]}")); }
@Test public void testProcessingRenderingWithStackTraces() throws IOException, InterruptedException { Exception exception=null; try { throw new RuntimeException("Thrown"); } catch (RuntimeException e) { exception=e; } StringDataList dataList = createDataList(); dataList.request().errors().add(new ErrorMessage("m1","d1",exception)); dataList.request().errors().add(new ErrorMessage("m2","d2")); assertEquals( "{\"errors\":[" + "{" + "\"error\":\"m1: d1: Thrown\"," + "\"stacktrace\":\"java.lang.RuntimeException: Thrown\\n\\tat com.yahoo.processing.rendering.AsynchronousSectionedRendererTest.", render(dataList).substring(0,157)); }
@Test public void testProcessingRenderingWithClonedErrorRequest() throws IOException, InterruptedException { StringDataList dataList = createDataList(); dataList.request().errors().add(new ErrorMessage("m1","d1")); dataList.request().errors().add(new ErrorMessage("m2","d2")); dataList.add(new StringDataList(dataList.request().clone())); assertThat(render(dataList), equalTo("{\"errors\":[" + "\"m1: d1\"," + "\"m2: d2\"" + "]," + "\"datalist\":[" + "{\"data\":\"l1\"}," + "{\"datalist\":[" + "{\"data\":\"l11\"}," + "{\"data\":\"l12\"}" + "]}," + "{\"datalist\":[]}" + "]}")); }
@Test public void testProcessingRenderingWithClonedErrorRequestContainingNewErrors() throws IOException, InterruptedException { StringDataList dataList = createDataList(); dataList.request().errors().add(new ErrorMessage("m1","d1")); dataList.request().errors().add(new ErrorMessage("m2","d2")); dataList.add(new StringDataList(dataList.request().clone())); dataList.asList().get(2).request().errors().add(new ErrorMessage("m3","d3")); assertThat(render(dataList), equalTo("{\"errors\":[" + "\"m1: d1\"," + "\"m2: d2\"" + "]," + "\"datalist\":[" + "{\"data\":\"l1\"}," + "{\"datalist\":[" + "{\"data\":\"l11\"}," + "{\"data\":\"l12\"}" + "]}," + "{\"errors\":[" + "\"m3: d3\"" + "]," + "\"datalist\":[]}" + "]}")); }