use of com.yahoo.processing.Response in project vespa by vespa-engine.
the class AsyncExecutionTestCase method testAsyncExecution.
/**
* Execute a processing chain which forks off into multiple threads
*/
@Test
public void testAsyncExecution() {
// Create a chain
Chain<Processor> chain = new Chain<>(new CombineData(), new BlockingSplitter(2), new Get6DataItems(), new DataSource());
// Execute it
Request request = new Request();
request.properties().set("appendage", 1);
Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
// Verify the result
assertEquals(6 * 2 - 1, response.data().asList().size());
assertEquals("first.2, third.2", response.data().get(0).toString());
assertEquals("second.2", response.data().get(1).toString());
assertEquals("first.3", response.data().get(2).toString());
assertEquals("second.3", response.data().get(3).toString());
assertEquals("third.3", response.data().get(4).toString());
// from the parallel execution
assertEquals("first.2", response.data().get(5).toString());
assertEquals("second.2", response.data().get(6).toString());
assertEquals("third.2", response.data().get(7).toString());
assertEquals("first.3", response.data().get(8).toString());
assertEquals("second.3", response.data().get(9).toString());
assertEquals("third.3", response.data().get(10).toString());
}
use of com.yahoo.processing.Response in project vespa by vespa-engine.
the class JDiscContainerProcessingTest method requireThatBasicProcessingWorks.
@Test
public void requireThatBasicProcessingWorks() {
try (JDisc container = getContainerWithRot13()) {
Processing processing = container.processing();
Request req = new Request();
req.properties().set("title", "Good day!");
Response response = processing.process(ComponentSpecification.fromString("foo"), req);
assertThat(response.data().get(0).toString(), equalTo("Tbbq qnl!"));
}
}
use of com.yahoo.processing.Response 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.Response 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);
}
use of com.yahoo.processing.Response in project vespa by vespa-engine.
the class AsyncExecution method waitForAll.
/*
* Waits for all futures until the given timeout. If a FutureResult isn't
* done when the timeout expires, it will be cancelled, and it will return a
* response. All unfinished Futures will be cancelled.
*
* @return the list of responses in the same order as returned from the task collection
*/
// Note that this may also be achieved using guava Futures. Not sure if this should be deprecated because of it.
public static List<Response> waitForAll(final Collection<FutureResponse> tasks, final long timeout) {
// Copy the list in case it is modified while we are waiting
final List<FutureResponse> workingTasks = new ArrayList<>(tasks);
@SuppressWarnings({ "rawtypes", "unchecked" }) final Future task = getFuture(new Callable() {
@Override
public List<Future> call() {
for (final FutureResponse task : workingTasks) {
task.get();
}
return null;
}
});
try {
task.get(timeout, TimeUnit.MILLISECONDS);
} catch (final TimeoutException | InterruptedException | ExecutionException e) {
// Handle timeouts below
}
final List<Response> responses = new ArrayList<>(tasks.size());
for (final FutureResponse future : workingTasks) responses.add(getTaskResponse(future));
return responses;
}
Aggregations