Search in sources :

Example 1 with CountingEngine

use of com.linkedin.parseq.CountingEngine in project rest.li by linkedin.

the class TestMultiplexerRunMode method engine.

private CountingEngine engine() {
    ExecutorService taskScheduler = Executors.newFixedThreadPool(1);
    ScheduledExecutorService timerScheduler = Executors.newSingleThreadScheduledExecutor();
    CountingEngine countingEngine = new CountingEngine(taskScheduler, new DelayedExecutorAdapter(timerScheduler), LoggerFactory.getILoggerFactory(), Maps.newHashMap());
    return countingEngine;
}
Also used : DelayedExecutorAdapter(com.linkedin.parseq.DelayedExecutorAdapter) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) CountingEngine(com.linkedin.parseq.CountingEngine)

Example 2 with CountingEngine

use of com.linkedin.parseq.CountingEngine 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

CountingEngine (com.linkedin.parseq.CountingEngine)2 DelayedExecutorAdapter (com.linkedin.parseq.DelayedExecutorAdapter)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)1 RestLiConfig (com.linkedin.restli.server.RestLiConfig)1 RestLiServer (com.linkedin.restli.server.RestLiServer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.testng.annotations.Test)1