Search in sources :

Example 21 with IndividualRequest

use of com.linkedin.restli.common.multiplexer.IndividualRequest in project rest.li by linkedin.

the class TestMultiplexerRunMode method testMultiplexedAsyncGetRequest.

@Test(dataProvider = "multiplexerConfigurations")
public void testMultiplexedAsyncGetRequest(MultiplexerRunMode multiplexerRunMode) throws URISyntaxException, IOException, InterruptedException {
    RestLiConfig config = new RestLiConfig();
    config.addResourcePackageNames("com.linkedin.restli.server.multiplexer.resources");
    config.setMultiplexerRunMode(multiplexerRunMode);
    CountingEngine engine = engine();
    RestLiServer server = new RestLiServer(config, resourceFactory(), engine);
    IndividualRequest r0 = individualRequest("/users/0", null, Collections.<String, IndividualRequest>emptyMap());
    IndividualRequest r1 = individualRequest("/users/1", null, Collections.<String, IndividualRequest>emptyMap());
    IndividualRequest r2 = individualRequest("/users/2", null, ImmutableMap.of("0", r0, "1", r1));
    // request is seq(par(r0, r1), r2)
    RestRequest request = muxRestRequest(ImmutableMap.of("2", r2));
    CountDownLatch latch = new CountDownLatch(1);
    server.handleRequest(request, new RequestContext(), callback(latch));
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    if (multiplexerRunMode == MultiplexerRunMode.SINGLE_PLAN) {
        assertEquals(engine.plansStarted(), 1);
    } else {
        // in MULTIPLE_PLANS mode: 1 task for multiplexed request itself + 3 individual tasks r0, r1, r2
        assertEquals(engine.plansStarted(), 1 + 3);
    }
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiServer(com.linkedin.restli.server.RestLiServer) RequestContext(com.linkedin.r2.message.RequestContext) CountingEngine(com.linkedin.parseq.CountingEngine) CountDownLatch(java.util.concurrent.CountDownLatch) RestLiConfig(com.linkedin.restli.server.RestLiConfig) Test(org.testng.annotations.Test)

Aggregations

IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)21 IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)12 Test (org.testng.annotations.Test)12 RequestContext (com.linkedin.r2.message.RequestContext)9 RestRequest (com.linkedin.r2.message.rest.RestRequest)9 FutureCallback (com.linkedin.common.callback.FutureCallback)7 StringMap (com.linkedin.data.template.StringMap)7 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 ByteString (com.linkedin.data.ByteString)5 RestException (com.linkedin.r2.message.rest.RestException)4 MultiplexedResponseContent (com.linkedin.restli.common.multiplexer.MultiplexedResponseContent)4 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 HashMap (java.util.HashMap)4 ExecutionException (java.util.concurrent.ExecutionException)4 IndividualResponse (com.linkedin.restli.common.multiplexer.IndividualResponse)3 IndividualResponseMap (com.linkedin.restli.common.multiplexer.IndividualResponseMap)3 MultiplexedRequestContent (com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)3 HttpCookie (java.net.HttpCookie)3