use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.
the class Processing method doProcessAndRender.
@Override
protected ListenableFuture<Boolean> doProcessAndRender(ComponentSpecification chainSpec, Request request, Renderer<Response> renderer, ByteArrayOutputStream stream) throws IOException {
Execution execution = handler.createExecution(getChain(chainSpec), request);
Response response = execution.process(request);
return renderer.render(stream, response, execution, request);
}
use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.
the class ExecutionContextTestCase method testtrace.
/**
* Tests combined use of trace messages, context values and access log entries
*/
public void testtrace() {
Execution execution1 = Execution.createRoot(chain, 2, Execution.Environment.createEmpty());
execution1.trace().setProperty("a", "a1");
execution1.trace().logValue("a", "a1");
execution1.trace().trace("root 1", 2);
execution1.trace().setProperty("a", "a2");
execution1.trace().setProperty("b", "b1");
execution1.trace().logValue("a", "a2");
execution1.trace().logValue("b", "b1");
Execution execution2 = new Execution(chain, execution1);
execution2.trace().setProperty("b", "b2");
execution2.trace().logValue("b", "b2");
execution2.trace().trace(" child-1 1", 2);
execution2.trace().setProperty("b", "b3");
execution2.trace().logValue("b", "b3");
execution1.trace().setProperty("b", "b4");
execution1.trace().logValue("b", "b4");
Execution execution3 = new Execution(chain, execution1);
execution3.trace().setProperty("b", "b5");
execution3.trace().setProperty("c", "c1");
execution3.trace().logValue("b", "b5");
execution3.trace().logValue("c", "c1");
execution3.trace().trace(" child-2 1", 2);
execution2.trace().setProperty("c", "c2");
execution2.trace().logValue("c", "c2");
execution1.trace().trace("root 2", 2);
execution3.trace().setProperty("d", "d1");
execution1.trace().logValue("d", "d1");
execution2.trace().trace(" child-1 2", 2);
execution2.trace().setProperty("c", "c3");
execution2.trace().logValue("c", "c3");
execution1.trace().setProperty("c", "c4");
execution1.trace().logValue("c", "c4");
Iterator<String> traceIterator = execution1.trace().traceNode().root().descendants(String.class).iterator();
assertEquals("root 1", traceIterator.next());
assertEquals(" child-1 1", traceIterator.next());
assertEquals(" child-1 2", traceIterator.next());
assertEquals(" child-2 1", traceIterator.next());
assertEquals("root 2", traceIterator.next());
assertFalse(traceIterator.hasNext());
// Verify context variables
assertEquals("a2", execution1.trace().getProperty("a"));
assertEquals("b5", execution1.trace().getProperty("b"));
assertEquals("c4", execution1.trace().getProperty("c"));
assertEquals("d1", execution1.trace().getProperty("d"));
assertNull(execution1.trace().getProperty("e"));
// Verify access log
Set<String> logValues = new HashSet<>();
for (Iterator<Execution.Trace.LogValue> logValueIterator = execution1.trace().logValueIterator(); logValueIterator.hasNext(); ) logValues.add(logValueIterator.next().toString());
assertEquals(12, logValues.size());
assertTrue(logValues.contains("a=a1"));
assertTrue(logValues.contains("a=a2"));
assertTrue(logValues.contains("b=b1"));
assertTrue(logValues.contains("b=b2"));
assertTrue(logValues.contains("b=b3"));
assertTrue(logValues.contains("b=b4"));
assertTrue(logValues.contains("b=b5"));
assertTrue(logValues.contains("c=c1"));
assertTrue(logValues.contains("c=c2"));
assertTrue(logValues.contains("d=d1"));
assertTrue(logValues.contains("c=c3"));
assertTrue(logValues.contains("c=c4"));
}
use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.
the class DocumentationTestCase method test.
@SuppressWarnings("unchecked")
@Test
public final void test() {
Processor p = new ExampleProcessor();
Chain<Processor> basic = new Chain<>(p);
Processor initiator = new AsyncDataProcessingInitiator(basic);
Chain<Processor> postProcessing = new Chain<>(initiator);
Execution e = Execution.createRoot(postProcessing, 0, Execution.Environment.createEmpty());
Response r = e.process(new Request());
// just adds a listener to the result returned from basic
assertEquals(0, r.data().asList().size());
Processor producer = new AsyncDataProducer();
Chain<Processor> asyncChain = new Chain<>(producer);
Processor federator = new Federator(basic, asyncChain);
e = Execution.createRoot(federator, 0, Execution.Environment.createEmpty());
r = e.process(new Request());
assertEquals(2, r.data().asList().size());
}
use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.
the class AsynchronousSectionedRendererTest method render.
@SuppressWarnings("unchecked")
public String render(Renderer renderer, DataList data) throws InterruptedException, IOException {
TestContentChannel contentChannel = new TestContentChannel();
Execution execution = Execution.createRoot(new NoopProcessor(), 0, null);
final ContentChannelOutputStream stream = new ContentChannelOutputStream(contentChannel);
ListenableFuture result = renderer.render(stream, new Response(data), execution, null);
int waitCounter = 1000;
while (!result.isDone()) {
Thread.sleep(60);
--waitCounter;
if (waitCounter < 0) {
throw new IllegalStateException();
}
}
stream.close();
contentChannel.close(null);
String str = "";
for (ByteBuffer buf : contentChannel.getBuffers()) {
str += Utf8.toString(buf);
}
return str;
}
use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.
the class AbstractProcessingHandler method handle.
@Override
@SuppressWarnings("unchecked")
public HttpResponse handle(HttpRequest request, ContentChannel channel) {
com.yahoo.processing.Request processingRequest = new com.yahoo.processing.Request();
populate("", request.propertyMap(), processingRequest.properties());
populate("context", request.getJDiscRequest().context(), processingRequest.properties());
processingRequest.properties().set(Request.JDISC_REQUEST, request);
FreezeListener freezeListener = new FreezeListener(processingRequest, renderers, defaultRenderer, channel, renderingExecutor);
processingRequest.properties().set(freezeListenerKey, freezeListener);
Chain<COMPONENT> chain = chainRegistry.getComponent(resolveChainId(processingRequest.properties()));
if (chain == null)
throw new IllegalArgumentException("Chain '" + processingRequest.properties().get("chain") + "' not found");
Execution execution = createExecution(chain, processingRequest);
freezeListener.setExecution(execution);
Response processingResponse = execution.process(processingRequest);
return freezeListener.getHttpResponse(processingResponse);
}
Aggregations