Search in sources :

Example 1 with OperationProcessor

use of com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor in project vespa by vespa-engine.

the class EndpointResultQueueTest method testTimeout.

@Test
public void testTimeout() throws InterruptedException {
    Endpoint endpoint = Endpoint.create("a");
    OperationProcessor mockAggregator = mock(OperationProcessor.class);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocationOnMock -> {
        latch.countDown();
        return null;
    }).when(mockAggregator).resultReceived(anyObject(), eq(0));
    EndpointResultQueue q = new EndpointResultQueue(mockAggregator, endpoint, 0, new ScheduledThreadPoolExecutor(1), 100L);
    q.operationSent("1234");
    assert (latch.await(120, TimeUnit.SECONDS));
}
Also used : Endpoint(com.yahoo.vespa.http.client.config.Endpoint) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) OperationProcessor(com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor) Test(org.junit.Test)

Example 2 with OperationProcessor

use of com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor in project vespa by vespa-engine.

the class EndpointResultQueueTest method testBasics.

@Test
public void testBasics() {
    Endpoint endpoint = Endpoint.create("a");
    OperationProcessor mockAggregator = mock(OperationProcessor.class);
    final AtomicInteger resultCount = new AtomicInteger(0);
    doAnswer(invocationOnMock -> {
        resultCount.getAndIncrement();
        return null;
    }).when(mockAggregator).resultReceived(anyObject(), eq(0));
    EndpointResultQueue q = new EndpointResultQueue(mockAggregator, endpoint, 0, new ScheduledThreadPoolExecutor(1), 100L * 1000L);
    q.operationSent("op1");
    assertThat(q.getPendingSize(), is(1));
    q.operationSent("op2");
    assertThat(q.getPendingSize(), is(2));
    q.operationSent("op3");
    assertThat(q.getPendingSize(), is(3));
    q.resultReceived(new EndpointResult("op1", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(2));
    q.resultReceived(new EndpointResult("op2", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(1));
    q.resultReceived(new EndpointResult("op3", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    q.resultReceived(new EndpointResult("op1", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    q.resultReceived(new EndpointResult("abc", new Result.Detail(endpoint)), 0);
    assertThat(q.getPendingSize(), is(0));
    assertThat(resultCount.get(), is(5));
    q.operationSent("op4");
    assertThat(q.getPendingSize(), is(1));
    q.operationSent("op5");
    assertThat(q.getPendingSize(), is(2));
    q.failPending(new RuntimeException());
    assertThat(resultCount.get(), is(7));
}
Also used : Endpoint(com.yahoo.vespa.http.client.config.Endpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) OperationProcessor(com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor) Test(org.junit.Test)

Aggregations

Endpoint (com.yahoo.vespa.http.client.config.Endpoint)2 OperationProcessor (com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 Test (org.junit.Test)2 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1