Search in sources :

Example 16 with Request

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

the class FutureDataTestCase method testFederateSyncAndAsyncData.

/**
 * Federate to one source which returns data immediately and one who return future data
 */
@SuppressWarnings("unchecked")
@Test
public void testFederateSyncAndAsyncData() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> chain = new Chain<>(new DataCounter(), new Federator(new Chain<>(new DataSource()), new Chain<>(futureDataSource)));
    // Execute
    Request request = new Request();
    request.properties().set("appendage", 1);
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    // The sync data list + the (currently empty) future data list) + the data count
    assertEquals(3, response.data().asList().size());
    DataList syncData = (DataList) response.data().get(0);
    DataList asyncData = (DataList) response.data().get(1);
    StringData countData = (StringData) response.data().get(2);
    assertEquals("The sync data is available", 3, syncData.asList().size());
    assertEquals("first.1", syncData.get(0).toString());
    assertEquals("second.1", syncData.get(1).toString());
    assertEquals("third.1", syncData.get(2).toString());
    assertEquals("No async data yet", 0, asyncData.asList().size());
    assertEquals("The data counter has run and accessed the sync data", "Data count: 3", countData.toString());
    // complete async data
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("New data is not visible because we haven't asked for it", 0, asyncData.asList().size());
    asyncData.complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data is available", 2, asyncData.asList().size());
    assertEquals("d1", asyncData.get(0).toString().toString());
    assertEquals("d2", asyncData.get(1).toString().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 17 with Request

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

the class FutureDataTestCase method testAsyncDataProcessing.

/**
 * Register a chain which will be called when some async data is available
 */
@SuppressWarnings("unchecked")
@Test
public void testAsyncDataProcessing() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> asyncChain = new Chain<Processor>(new DataCounter());
    Chain<Processor> chain = new Chain<>(new AsyncDataProcessingInitiator(asyncChain), futureDataSource);
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals("No data yet", 0, response.data().asList().size());
    // complete async data
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    assertEquals("New data is not visible because it is not complete", 0, response.data().asList().size());
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("Not visible because it has not been synced yet", 0, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data as well as the count is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(0).toString().toString());
    assertEquals("d2", response.data().get(1).toString().toString());
    assertEquals("Data count: 2", response.data().get(2).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 18 with Request

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

the class FutureDataTestCase method testFutureDataPassThrough.

/**
 * Run a chain which ends in a processor which returns a response containing future data.
 */
@SuppressWarnings("unchecked")
@Test
public void testFutureDataPassThrough() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> chain = new Chain<>(new DataCounter(), futureDataSource);
    // Execute
    Request request = new Request();
    // Urk ...
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals(1, response.data().asList().size());
    assertEquals("Data count: 0", response.data().get(0).toString());
    // complete delayed data
    assertEquals("Delayed data was requested once", 1, futureDataSource.incomingData.size());
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("New data is not visible because we haven't asked for it", 1, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(1).toString().toString());
    assertEquals("d2", response.data().get(2).toString().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 19 with Request

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

the class RequestTestCase method testProperties.

@Test
public void testProperties() {
    Properties p = new PropertyMap();
    p.set("a", "a1");
    Request r = new Request(p);
    r.properties().set("b", "b1");
    assertEquals(2, r.properties().listProperties().size());
    assertEquals("a1", r.properties().get("a"));
    assertEquals("b1", r.properties().get("b"));
    assertEquals("b1", r.properties().get("b", "default"));
    assertEquals("default", r.properties().get("c", "default"));
    assertNull(r.properties().get("c"));
    assertEquals("b1", r.properties().get(new CompoundName("b")));
    assertEquals("b1", r.properties().get(new CompoundName("b"), "default"));
    assertEquals("default", r.properties().get(new CompoundName("c"), "default"));
    assertNull(r.properties().get(new CompoundName("c")));
    assertEquals("b1", r.properties().getString("b"));
    assertEquals("b1", r.properties().getString("b", "default"));
    assertEquals("default", r.properties().getString("c", "default"));
    assertEquals(null, r.properties().getString("c"));
    assertEquals("b1", r.properties().getString(new CompoundName("b")));
    assertEquals("b1", r.properties().getString(new CompoundName("b"), "default"));
    assertEquals("default", r.properties().getString(new CompoundName("c"), "default"));
    assertEquals(null, r.properties().getString(new CompoundName("c")));
    r.properties().set("i", 7);
    assertEquals(7, (int) r.properties().getInteger("i"));
    assertEquals(7, (int) r.properties().getInteger("i", 3));
    assertEquals(3, (int) r.properties().getInteger("n", 3));
    assertNull(r.properties().getInteger("n"));
    assertEquals(7, (int) r.properties().getInteger(new CompoundName("i")));
    assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"), 3));
    assertEquals(3, (int) r.properties().getInteger(new CompoundName("n"), 3));
    assertNull(r.properties().getInteger("n"));
    r.properties().set(new CompoundName("l"), 7);
    assertEquals(7, (long) r.properties().getLong("l"));
    assertEquals(7, (long) r.properties().getLong("l", 3l));
    assertEquals(3, (long) r.properties().getLong("m", 3l));
    assertNull(r.properties().getInteger("m"));
    assertEquals(7, (long) r.properties().getLong(new CompoundName("l")));
    assertEquals(7, (long) r.properties().getLong(new CompoundName("l"), 3l));
    assertEquals(3, (long) r.properties().getLong(new CompoundName("m"), 3l));
    assertNull(r.properties().getInteger("m"));
    r.properties().set("d", 7.3);
    assertEquals(7.3, r.properties().getDouble("d"));
    assertEquals(7.3, r.properties().getDouble("d", 3.4d));
    assertEquals(3.4, r.properties().getDouble("f", 3.4d));
    assertNull(r.properties().getDouble("f"));
    assertEquals(7.3, r.properties().getDouble(new CompoundName("d")));
    assertEquals(7.3, r.properties().getDouble(new CompoundName("d"), 3.4d));
    assertEquals(3.4, r.properties().getDouble(new CompoundName("f"), 3.4d));
    assertNull(r.properties().getDouble("f"));
    r.properties().set("o", true);
    assertEquals(true, r.properties().getBoolean("o"));
    assertEquals(true, r.properties().getBoolean("o", true));
    assertEquals(true, r.properties().getBoolean("g", true));
    assertEquals(false, r.properties().getBoolean("g"));
    assertEquals(true, r.properties().getBoolean(new CompoundName("o")));
    assertEquals(true, r.properties().getBoolean(new CompoundName("o"), true));
    assertEquals(true, r.properties().getBoolean(new CompoundName("g"), true));
    assertEquals(false, r.properties().getBoolean("g"));
    r.properties().set(new CompoundName("x.y"), "x1.y1");
    r.properties().set("x.z", "x1.z1");
    assertEquals(8, r.properties().listProperties().size());
    assertEquals(0, r.properties().listProperties("a").size());
    assertEquals(0, r.properties().listProperties(new CompoundName("a")).size());
    assertEquals(0, r.properties().listProperties(new CompoundName("none")).size());
    assertEquals(2, r.properties().listProperties(new CompoundName("x")).size());
    assertEquals(2, r.properties().listProperties("x").size());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) PropertyMap(com.yahoo.processing.request.properties.PropertyMap) Request(com.yahoo.processing.Request) Properties(com.yahoo.processing.request.Properties) Test(org.junit.Test)

Example 20 with Request

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

the class RequestTestCase method testErrorMessages.

@Test
public void testErrorMessages() {
    Request r = new Request();
    r.errors().add(new ErrorMessage("foo"));
    r.errors().add(new ErrorMessage("bar"));
    assertEquals(2, r.errors().size());
    assertEquals("foo", r.errors().get(0).getMessage());
    assertEquals("bar", r.errors().get(1).getMessage());
}
Also used : Request(com.yahoo.processing.Request) ErrorMessage(com.yahoo.processing.request.ErrorMessage) 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