Search in sources :

Example 6 with Request

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

the class RequestTestCase method testCloning.

@Test
public void testCloning() {
    Request request = new Request();
    request.properties().set("a", "a1");
    request.properties().set("b", "b1");
    request.errors().add(new ErrorMessage("foo"));
    request.errors().add(new ErrorMessage("bar"));
    Request rcloned = request.clone();
    rcloned.properties().set("c", "c1");
    rcloned.errors().add(new ErrorMessage("baz"));
    request.properties().set("d", "d1");
    request.errors().add(new ErrorMessage("boz"));
    assertEquals("a1", request.properties().get("a"));
    assertEquals("a1", rcloned.properties().get("a"));
    assertEquals("b1", request.properties().get("b"));
    assertEquals("b1", rcloned.properties().get("b"));
    assertEquals(null, request.properties().get("c"));
    assertEquals("c1", rcloned.properties().get("c"));
    assertEquals("d1", request.properties().get("d"));
    assertEquals(null, rcloned.properties().get("d"));
    assertEquals(3, request.errors().size());
    assertEquals(1, rcloned.errors().size());
    assertEquals("foo", request.errors().get(0).getMessage());
    assertEquals("bar", request.errors().get(1).getMessage());
    assertEquals("boz", request.errors().get(2).getMessage());
    assertEquals("baz", rcloned.errors().get(0).getMessage());
}
Also used : Request(com.yahoo.processing.Request) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 7 with Request

use of com.yahoo.processing.Request 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 8 with Request

use of com.yahoo.processing.Request 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 9 with Request

use of com.yahoo.processing.Request 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 10 with Request

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

the class JDiscContainerProcessingTest method processing_and_rendering_works.

@Test
public void processing_and_rendering_works() throws Exception {
    try (JDisc container = getContainerWithRot13()) {
        Processing processing = container.processing();
        Request req = new Request();
        req.properties().set("title", "Good day!");
        byte[] rendered = processing.processAndRender(ComponentSpecification.fromString("foo"), ComponentSpecification.fromString("default"), req);
        String renderedAsString = new String(rendered, "utf-8");
        assertThat(renderedAsString, containsString("Tbbq qnl!"));
    }
}
Also used : Request(com.yahoo.processing.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Request (com.yahoo.processing.Request)20 Test (org.junit.Test)16 Response (com.yahoo.processing.Response)12 Chain (com.yahoo.component.chain.Chain)10 Processor (com.yahoo.processing.Processor)10 DataList (com.yahoo.processing.response.DataList)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)2 Execution (com.yahoo.processing.execution.Execution)2 ErrorMessage (com.yahoo.processing.request.ErrorMessage)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 CompoundName (com.yahoo.processing.request.CompoundName)1 Properties (com.yahoo.processing.request.Properties)1 PropertyMap (com.yahoo.processing.request.properties.PropertyMap)1 ArrayDataList (com.yahoo.processing.response.ArrayDataList)1 IncomingData (com.yahoo.processing.response.IncomingData)1 ProcessorLibrary (com.yahoo.processing.test.ProcessorLibrary)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