Search in sources :

Example 11 with Processor

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

the class ProcessingTestCase method testChainedProcessing1.

/**
 * Execute three simple processors doing some phony processing
 */
@Test
public void testChainedProcessing1() {
    // Create a chain
    Chain<Processor> chain = new Chain<>(new CombineData(), 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 - 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());
}
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 12 with Processor

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

the class ProcessingTestCase method testChainedProcessing2.

/**
 * Execute the same processors in a different order
 */
@Test
public void testChainedProcessing2() {
    // Create a chain
    Chain<Processor> chain = new Chain<>(new Get6DataItems(), new CombineData(), new DataSource());
    // Execute it
    Request request = new Request();
    request.properties().set("appendage", 1);
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Check the result
    assertEquals(6, response.data().asList().size());
    assertEquals("first.2, third.2", response.data().get(0).toString());
    assertEquals("second.2", response.data().get(1).toString());
    assertEquals("first.4, third.4", response.data().get(2).toString());
    assertEquals("second.4", response.data().get(3).toString());
    assertEquals("first.6, third.6", response.data().get(4).toString());
    assertEquals("second.6", response.data().get(5).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 13 with Processor

use of com.yahoo.processing.Processor 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());
}
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 14 with Processor

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

the class ProcessingHandlerTestCase method testResponseDataStatusOverridesErrors.

/**
 * Tests that the ResponseStatus takes precedence over errors
 */
@Test
public void testResponseDataStatusOverridesErrors() throws InterruptedException {
    ProcessingTestDriver.MockResponseHandler responseHandler = null;
    try {
        List<Chain<Processor>> chains = new ArrayList<>();
        chains.add(new Chain<Processor>("default", new ResponseStatusSetter(200), new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
        driver = new ProcessingTestDriver(chains);
        responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
        Response response = responseHandler.getResponse();
        assertEquals(200, response.getStatus());
    } finally {
        if (responseHandler != null)
            responseHandler.readAll();
    }
}
Also used : Response(com.yahoo.jdisc.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 15 with Processor

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

the class ProcessingHandlerTestCase method testResponseDataStatus.

@Test
public void testResponseDataStatus() throws InterruptedException {
    ProcessingTestDriver.MockResponseHandler responseHandler = null;
    try {
        List<Chain<Processor>> chains = new ArrayList<>();
        chains.add(new Chain<Processor>("default", new ResponseStatusSetter(429)));
        driver = new ProcessingTestDriver(chains);
        responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
        Response response = responseHandler.getResponse();
        assertEquals(429, response.getStatus());
        assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read());
    } finally {
        if (responseHandler != null)
            responseHandler.readAll();
    }
}
Also used : Response(com.yahoo.jdisc.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) 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