Search in sources :

Example 16 with Processor

use of com.yahoo.processing.Processor in project vespa by vespa-engine.

the class ProcessingTestDriver method createProcessingHandler.

private static ProcessingHandler createProcessingHandler(Collection<Chain<Processor>> chains, ComponentRegistry<Renderer> renderers, AccessLog accessLog) {
    Executor executor = Executors.newSingleThreadExecutor();
    ChainRegistry<Processor> registry = new ChainRegistry<>();
    for (Chain<Processor> chain : chains) registry.register(chain.getId(), chain);
    return new ProcessingHandler(registry, renderers, executor, accessLog);
}
Also used : Executor(java.util.concurrent.Executor) Processor(com.yahoo.processing.Processor) ChainRegistry(com.yahoo.processing.execution.chain.ChainRegistry)

Example 17 with Processor

use of com.yahoo.processing.Processor in project vespa by vespa-engine.

the class ApplicationStatusHandlerTest method chains_are_rendered.

@Test
public void chains_are_rendered() throws Exception {
    ChainRegistry<Processor> chains = new ChainRegistry<>();
    Chain<Processor> chain = new Chain<Processor>("myChain", new VoidProcessor(new ComponentId("voidProcessor")));
    chains.register(new ComponentId("myChain"), chain);
    String json = ApplicationStatusHandler.StatusResponse.renderChains(chains).toString();
    assertThat(json, containsString("myChain"));
    assertThat(json, containsString("voidProcessor"));
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ChainRegistry(com.yahoo.processing.execution.chain.ChainRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 18 with Processor

use of com.yahoo.processing.Processor in project vespa by vespa-engine.

the class FutureDataTestCase method testFederateSyncAndAsyncData.

/**
 * Federate to one source which returns data immediately and one who return future data
 */
@SuppressWarnings("unchecked")
@Test
public void testFederateSyncAndAsyncData() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> chain = new Chain<>(new DataCounter(), new Federator(new Chain<>(new DataSource()), new Chain<>(futureDataSource)));
    // Execute
    Request request = new Request();
    request.properties().set("appendage", 1);
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    // The sync data list + the (currently empty) future data list) + the data count
    assertEquals(3, response.data().asList().size());
    DataList syncData = (DataList) response.data().get(0);
    DataList asyncData = (DataList) response.data().get(1);
    StringData countData = (StringData) response.data().get(2);
    assertEquals("The sync data is available", 3, syncData.asList().size());
    assertEquals("first.1", syncData.get(0).toString());
    assertEquals("second.1", syncData.get(1).toString());
    assertEquals("third.1", syncData.get(2).toString());
    assertEquals("No async data yet", 0, asyncData.asList().size());
    assertEquals("The data counter has run and accessed the sync data", "Data count: 3", countData.toString());
    // complete async data
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("New data is not visible because we haven't asked for it", 0, asyncData.asList().size());
    asyncData.complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data is available", 2, asyncData.asList().size());
    assertEquals("d1", asyncData.get(0).toString().toString());
    assertEquals("d2", asyncData.get(1).toString().toString());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) DataList(com.yahoo.processing.response.DataList) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Example 19 with Processor

use of com.yahoo.processing.Processor in project vespa by vespa-engine.

the class FutureDataTestCase method testAsyncDataProcessing.

/**
 * Register a chain which will be called when some async data is available
 */
@SuppressWarnings("unchecked")
@Test
public void testAsyncDataProcessing() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> asyncChain = new Chain<Processor>(new DataCounter());
    Chain<Processor> chain = new Chain<>(new AsyncDataProcessingInitiator(asyncChain), futureDataSource);
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals("No data yet", 0, response.data().asList().size());
    // complete async data
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    assertEquals("New data is not visible because it is not complete", 0, response.data().asList().size());
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("Not visible because it has not been synced yet", 0, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data as well as the count is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(0).toString().toString());
    assertEquals("d2", response.data().get(1).toString().toString());
    assertEquals("Data count: 2", response.data().get(2).toString());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Example 20 with Processor

use of com.yahoo.processing.Processor in project vespa by vespa-engine.

the class FutureDataTestCase method testFutureDataPassThrough.

/**
 * Run a chain which ends in a processor which returns a response containing future data.
 */
@SuppressWarnings("unchecked")
@Test
public void testFutureDataPassThrough() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> chain = new Chain<>(new DataCounter(), futureDataSource);
    // Execute
    Request request = new Request();
    // Urk ...
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals(1, response.data().asList().size());
    assertEquals("Data count: 0", response.data().get(0).toString());
    // complete delayed data
    assertEquals("Delayed data was requested once", 1, futureDataSource.incomingData.size());
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("New data is not visible because we haven't asked for it", 1, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(1).toString().toString());
    assertEquals("d2", response.data().get(2).toString().toString());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Aggregations

Processor (com.yahoo.processing.Processor)20 Chain (com.yahoo.component.chain.Chain)17 Test (org.junit.Test)17 Response (com.yahoo.processing.Response)11 Request (com.yahoo.processing.Request)10 Response (com.yahoo.jdisc.Response)3 ChainRegistry (com.yahoo.processing.execution.chain.ChainRegistry)3 ErrorMessage (com.yahoo.processing.request.ErrorMessage)3 DataList (com.yahoo.processing.response.DataList)2 ProcessorLibrary (com.yahoo.processing.test.ProcessorLibrary)2 ComponentId (com.yahoo.component.ComponentId)1 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 Execution (com.yahoo.processing.execution.Execution)1 IncomingData (com.yahoo.processing.response.IncomingData)1 MapData (com.yahoo.processing.test.ProcessorLibrary.MapData)1 AsyncDataProcessingInitiator (com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator)1 AsyncDataProducer (com.yahoo.processing.test.documentation.AsyncDataProducer)1 ExampleProcessor (com.yahoo.processing.test.documentation.ExampleProcessor)1 Federator (com.yahoo.processing.test.documentation.Federator)1