Search in sources :

Example 1 with Request

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

the class AsynchronousSectionedRendererTest method createDataListWithStrangeStrings.

public StringDataList createDataListWithStrangeStrings() {
    Request request = new Request();
    StringDataList dataList = new StringDataList(request);
    dataList.add(new StringDataItem(request, "f\\o\"o"));
    StringDataList secondLevel = new StringDataList(request);
    secondLevel.add(new StringDataItem(request, "b/a\br"));
    secondLevel.add(new StringDataItem(request, "f\f\no\ro\tbar\u0005"));
    dataList.add(secondLevel);
    return dataList;
}
Also used : Request(com.yahoo.processing.Request)

Example 2 with Request

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

the class MockUserDatabaseClientTest method testClientExampleProcessor.

@Test
public void testClientExampleProcessor() {
    Request request = null;
    try {
        Chain<Processor> chain = new Chain<>("default", new MockUserDatabaseClient());
        setupJDisc(Collections.singletonList(chain));
        request = createRequest();
        Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
        MockUserDatabaseClient.User user = (MockUserDatabaseClient.User) response.data().request().properties().get("User");
        assertNotNull(user);
        assertEquals("foo", user.getId());
    } finally {
        release(request);
    }
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.junit.Test)

Example 3 with Request

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

the class StreamingTestCase method testStreamingData.

/**
 * Tests adding a chain which is called every time new data is added to a data list
 */
@SuppressWarnings("unchecked")
@Test
public void testStreamingData() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    StreamProcessor streamProcessor = new StreamProcessor();
    Chain<Processor> streamProcessing = new Chain<Processor>(streamProcessor);
    ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource();
    Chain<Processor> main = new Chain<>(new ProcessorLibrary.DataCounter(), new ProcessorLibrary.StreamProcessingInitiator(streamProcessing), futureDataSource);
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request);
    IncomingData incomingData = futureDataSource.incomingData.get(0);
    // State prior to receiving any additional data
    assertEquals(1, response.data().asList().size());
    assertEquals("Data count: 0", response.data().get(0).toString());
    assertEquals("Add data listener invoked also for DataCounter", 1, streamProcessor.invocationCount);
    assertEquals("Initial data count", 1, response.data().asList().size());
    // add first data - we have no listener so the data is held in the incoming buffer
    incomingData.add(new ProcessorLibrary.StringData(request, "d1"));
    assertEquals("Data add listener not invoked as we are not listening on new data yet", 1, streamProcessor.invocationCount);
    assertEquals("New data is not consumed", 1, response.data().asList().size());
    // start listening on incoming data - this is what a renderer will do
    incomingData.addNewDataListener(new MockNewDataListener(incomingData), MoreExecutors.directExecutor());
    assertEquals("We got a data add event for the data which was already added", 2, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 2, response.data().asList().size());
    incomingData.add(new ProcessorLibrary.StringData(request, "d2"));
    assertEquals("We are now getting data add events each time", 3, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 3, response.data().asList().size());
    incomingData.addLast(new ProcessorLibrary.StringData(request, "d3"));
    assertEquals("We are getting data add events also the last time", 4, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 4, response.data().asList().size());
    // no-op here
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("d1", response.data().get(1).toString().toString());
    assertEquals("d2", response.data().get(2).toString().toString());
    assertEquals("d3", response.data().get(3).toString().toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) ProcessorLibrary(com.yahoo.processing.test.ProcessorLibrary) Response(com.yahoo.processing.Response) IncomingData(com.yahoo.processing.response.IncomingData) Test(org.junit.Test)

Example 4 with Request

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

the class FutureDataTestCase method testAsyncDataProcessingOfFederatedResult.

/**
 * Register a chain which federates over three sources, two of which are future.
 * When the first of the futures are done one additional chain is to be run.
 * When both are done another chain is to be run.
 */
@SuppressWarnings("unchecked")
@Test
public void testAsyncDataProcessingOfFederatedResult() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    // Source 1 (async with completion chain)
    FutureDataSource futureSource1 = new FutureDataSource();
    Chain<Processor> asyncChainSource1 = new Chain<Processor>(new DataCounter("source1"));
    Chain<Processor> chainSource1 = new Chain<>(new AsyncDataProcessingInitiator(asyncChainSource1), futureSource1);
    // Source 2 (async source)
    FutureDataSource futureSource2 = new FutureDataSource();
    Chain<Processor> chainSource2 = new Chain<Processor>(futureSource2);
    // Source 3 (sync source)
    Chain<Processor> chainSource3 = new Chain<Processor>(new DataSource());
    // Main chain federating to the above - not waiting for source 1 and 2 but invoking asyncMain when both are complete
    Chain<Processor> asyncMain = new Chain<Processor>(new DataCounter("main"));
    Chain<Processor> main = new Chain<>(new AsyncDataProcessingInitiator(asyncMain), new Federator(chainSource1, chainSource2, chainSource3));
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals("We have the sync data plus placeholders for the async lists", 3, response.data().asList().size());
    DataList source1Data = ((DataList) response.data().get(0));
    DataList source2Data = ((DataList) response.data().get(1));
    DataList source3Data = ((DataList) response.data().get(2));
    assertEquals("No data yet", 0, source1Data.asList().size());
    assertEquals("No data yet", 0, source2Data.asList().size());
    assertEquals(3, source3Data.asList().size());
    // complete async data in source1
    futureSource1.incomingData.get(0).addLast(new StringData(request, "source1Data"));
    assertEquals("Not visible yet", 0, source1Data.asList().size());
    source1Data.complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals(2, source1Data.asList().size());
    assertEquals("source1Data", source1Data.get(0).toString());
    assertEquals("Completion listener chain on this has run", "[source1] Data count: 1", source1Data.get(1).toString());
    // source2 & main completion
    assertEquals("Main completion listener has not run", 3, response.data().asList().size());
    futureSource2.incomingData.get(0).addLast(new StringData(request, "source2Data"));
    assertEquals("Main completion listener has not run", 3, response.data().asList().size());
    Response.recursiveComplete(response.data()).get();
    assertEquals("Main completion listener has run", 4, response.data().asList().size());
    assertEquals("The main data counter saw all sync data, but not source2 data as it executes after this", "[main] Data count: " + (2 + 0 + 3), response.data().get(3).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 5 with Request

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

the class DocumentationTestCase method test.

@SuppressWarnings("unchecked")
@Test
public final void test() {
    Processor p = new ExampleProcessor();
    Chain<Processor> basic = new Chain<>(p);
    Processor initiator = new AsyncDataProcessingInitiator(basic);
    Chain<Processor> postProcessing = new Chain<>(initiator);
    Execution e = Execution.createRoot(postProcessing, 0, Execution.Environment.createEmpty());
    Response r = e.process(new Request());
    // just adds a listener to the result returned from basic
    assertEquals(0, r.data().asList().size());
    Processor producer = new AsyncDataProducer();
    Chain<Processor> asyncChain = new Chain<>(producer);
    Processor federator = new Federator(basic, asyncChain);
    e = Execution.createRoot(federator, 0, Execution.Environment.createEmpty());
    r = e.process(new Request());
    assertEquals(2, r.data().asList().size());
}
Also used : Response(com.yahoo.processing.Response) AsyncDataProducer(com.yahoo.processing.test.documentation.AsyncDataProducer) Chain(com.yahoo.component.chain.Chain) AsyncDataProcessingInitiator(com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator) Federator(com.yahoo.processing.test.documentation.Federator) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Processor(com.yahoo.processing.Processor) Execution(com.yahoo.processing.execution.Execution) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Request(com.yahoo.processing.Request) 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