Search in sources :

Example 1 with Processor

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

the class ProcessingHandlerTestCase method testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData.

@Test
public void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() throws Exception {
    List<Chain<Processor>> chains = new ArrayList<>();
    chains.add(simpleChain);
    chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message"))));
    chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message"))));
    chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message"))));
    chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message"))));
    chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
    chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message"))));
    chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message"))));
    chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message"))));
    chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message"))));
    chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message"))));
    chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message"))));
    chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message"))));
    chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message"))));
    chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message"))));
    chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message"))));
    chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message"))));
    chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message"))));
    chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message"))));
    chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message"))));
    driver = new ProcessingTestDriver(chains);
    assertEqualStatus(200, "http://localhost/?chain=simple");
    assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
    assertEqualStatus(401, "http://localhost/?chain=unauthorized");
    assertEqualStatus(401, "http://localhost/?chain=unauthorized_mapped");
    assertEqualStatus(403, "http://localhost/?chain=forbidden");
    assertEqualStatus(403, "http://localhost/?chain=forbidden_mapped");
    assertEqualStatus(404, "http://localhost/?chain=not_found");
    assertEqualStatus(404, "http://localhost/?chain=not_found_mapped");
    assertEqualStatus(429, "http://localhost/?chain=too_many_requests");
    assertEqualStatus(400, "http://localhost/?chain=bad_request");
    assertEqualStatus(400, "http://localhost/?chain=bad_request_mapped");
    assertEqualStatus(500, "http://localhost/?chain=internal_server_error");
    assertEqualStatus(500, "http://localhost/?chain=internal_server_error_mapped");
    assertEqualStatus(503, "http://localhost/?chain=service_unavailable");
    // as this didn't fail and this isn't a web service mapped code
    assertEqualStatus(200, "http://localhost/?chain=service_unavailable_mapped");
    assertEqualStatus(504, "http://localhost/?chain=gateway_timeout");
    // as this didn't fail and this isn't a web service mapped code
    assertEqualStatus(200, "http://localhost/?chain=gateway_timeout_mapped");
    assertEqualStatus(502, "http://localhost/?chain=bad_gateway");
    // as this didn't fail and this isn't a web service mapped code
    assertEqualStatus(200, "http://localhost/?chain=bad_gateway_mapped");
    // as this didn't fail and this isn't a web service mapped code
    assertEqualStatus(200, "http://localhost/?chain=unknown_code");
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 2 with Processor

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

the class ProcessingHandlerTestCase method testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData.

@Test
public void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() throws Exception {
    List<Chain<Processor>> chains = new ArrayList<>();
    chains.add(simpleChain);
    chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message"))));
    chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message"))));
    chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message"))));
    chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message"))));
    chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
    chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message"))));
    chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message"))));
    chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message"))));
    chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message"))));
    chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message"))));
    chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message"))));
    chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message"))));
    chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message"))));
    chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message"))));
    chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message"))));
    chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message"))));
    chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message"))));
    chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message"))));
    chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message"))));
    driver = new ProcessingTestDriver(chains);
    assertEqualStatus(200, "http://localhost/?chain=simple");
    assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
    assertEqualStatus(401, "http://localhost/?chain=unauthorized");
    assertEqualStatus(401, "http://localhost/?chain=unauthorized_mapped");
    assertEqualStatus(403, "http://localhost/?chain=forbidden");
    assertEqualStatus(403, "http://localhost/?chain=forbidden_mapped");
    assertEqualStatus(404, "http://localhost/?chain=not_found");
    assertEqualStatus(404, "http://localhost/?chain=not_found_mapped");
    assertEqualStatus(429, "http://localhost/?chain=too_many_requests");
    assertEqualStatus(400, "http://localhost/?chain=bad_request");
    assertEqualStatus(400, "http://localhost/?chain=bad_request_mapped");
    assertEqualStatus(500, "http://localhost/?chain=internal_server_error");
    assertEqualStatus(500, "http://localhost/?chain=internal_server_error_mapped");
    assertEqualStatus(503, "http://localhost/?chain=service_unavailable");
    assertEqualStatus(503, "http://localhost/?chain=service_unavailable_mapped");
    assertEqualStatus(504, "http://localhost/?chain=gateway_timeout");
    assertEqualStatus(504, "http://localhost/?chain=gateway_timeout_mapped");
    assertEqualStatus(502, "http://localhost/?chain=bad_gateway");
    assertEqualStatus(503, "http://localhost/?chain=bad_gateway_mapped");
    assertEqualStatus(500, "http://localhost/?chain=unknown_code");
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 3 with Processor

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

the class ProcessingHandlerTestCase method testStreamedRendering.

@SuppressWarnings("unchecked")
@Test
public void testStreamedRendering() throws Exception {
    // Set up
    Chain<Processor> streamChain = new Chain<Processor>(new StreamProcessor());
    ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource();
    Chain<Processor> mainChain = new Chain<Processor>("main", new ProcessorLibrary.StreamProcessingInitiator(streamChain), futureDataSource);
    driver = new ProcessingTestDriver(mainChain);
    ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
    // Add one data element
    futureDataSource.incomingData.get().add(new MapData(null));
    assertEquals("{\"datalist\":[" + "{\"data\":\"map data: {streamProcessed=true}\"}", responseHandler.read());
    // add another
    futureDataSource.incomingData.get().add(new MapData(null));
    assertEquals(",{\"data\":\"map data: {streamProcessed=true}\"}", responseHandler.read());
    // add last
    futureDataSource.incomingData.get().addLast(new MapData(null));
    assertEquals(",{\"data\":\"map data: {streamProcessed=true}\"}]}", responseHandler.read());
    assertTrue("Transmission completed", null == responseHandler.read());
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) MapData(com.yahoo.processing.test.ProcessorLibrary.MapData) ProcessorLibrary(com.yahoo.processing.test.ProcessorLibrary) Test(org.junit.Test)

Example 4 with Processor

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

the class ProcessingHandlerTestCase method testProcessorSetsResponseHeaders.

@Test
public void testProcessorSetsResponseHeaders() throws InterruptedException {
    ProcessingTestDriver.MockResponseHandler responseHandler = null;
    try {
        Map<String, List<String>> responseHeaders = new HashMap<>();
        responseHeaders.put("foo", Collections.singletonList("fooValue"));
        responseHeaders.put("bar", Arrays.asList(new String[] { "barValue", "bazValue" }));
        Map<String, List<String>> otherResponseHeaders = new HashMap<>();
        otherResponseHeaders.put("foo", Collections.singletonList("fooValue2"));
        otherResponseHeaders.put("bax", Collections.singletonList("baxValue"));
        List<Chain<Processor>> chains = new ArrayList<>();
        chains.add(new Chain<Processor>("default", new ResponseHeaderSetter(responseHeaders), new ResponseHeaderSetter(otherResponseHeaders)));
        driver = new ProcessingTestDriver(chains);
        responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
        Response response = responseHandler.getResponse();
        assertEquals("[fooValue2, fooValue]", response.headers().get("foo").toString());
        assertEquals("[barValue, bazValue]", response.headers().get("bar").toString());
        assertEquals("[baxValue]", response.headers().get("bax").toString());
        assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read());
    } finally {
        if (responseHandler != null)
            responseHandler.readAll();
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Response(com.yahoo.jdisc.Response) Test(org.junit.Test)

Example 5 with Processor

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

the class MockUserDatabaseClientTest method setupJDisc.

private void setupJDisc(Collection<Chain<Processor>> chains) {
    driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ChainRegistry<Processor> registry = new ChainRegistry<>();
    for (Chain<Processor> chain : chains) registry.register(chain.getId(), chain);
    builder.clientBindings().bind("pio://endpoint/*", new MockUserDatabaseRequestHandler());
    driver.activateContainer(builder);
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Processor(com.yahoo.processing.Processor) ChainRegistry(com.yahoo.processing.execution.chain.ChainRegistry)

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