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));
}
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));
}
Aggregations