Search in sources :

Example 1 with Chain

use of com.yahoo.component.chain.Chain 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 Chain

use of com.yahoo.component.chain.Chain 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 Chain

use of com.yahoo.component.chain.Chain 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 Chain

use of com.yahoo.component.chain.Chain 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 Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class ProcessingHandlerTestCase method testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser.

@Test
public void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() throws Exception {
    String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID;
    driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList());
    Renderer defaultRenderer = driver.processingHandler().getRenderers().getComponent(defaultId);
    assertThat(defaultRenderer, notNullValue());
}
Also used : Chain(com.yahoo.component.chain.Chain) Renderer(com.yahoo.processing.rendering.Renderer) ProcessingRenderer(com.yahoo.processing.rendering.ProcessingRenderer) Test(org.junit.Test)

Aggregations

Chain (com.yahoo.component.chain.Chain)92 Execution (com.yahoo.search.searchchain.Execution)59 Searcher (com.yahoo.search.Searcher)57 Test (org.junit.Test)56 Result (com.yahoo.search.Result)48 Query (com.yahoo.search.Query)47 FeedContext (com.yahoo.feedapi.FeedContext)21 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)21 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)21 ClusterList (com.yahoo.vespaclient.ClusterList)21 Processor (com.yahoo.processing.Processor)17 Request (com.yahoo.processing.Request)10 Response (com.yahoo.processing.Response)10 ComponentId (com.yahoo.component.ComponentId)8 FederationSearcher (com.yahoo.search.federation.FederationSearcher)8 ArrayList (java.util.ArrayList)8 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 Message (com.yahoo.messagebus.Message)7 Hit (com.yahoo.search.result.Hit)7 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)6