use of io.crate.executor.transport.ShardUpsertRequest in project crate by crate.
the class UpsertByIdContextTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
ShardUpsertRequest request = mock(ShardUpsertRequest.class);
UpsertById.Item item = mock(UpsertById.Item.class);
context = new UpsertByIdContext(1, request, item, delegate);
}
use of io.crate.executor.transport.ShardUpsertRequest in project crate by crate.
the class BulkRetryCoordinatorTest method testScheduleRetryAfterRejectedExecution.
@Test
public void testScheduleRetryAfterRejectedExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onFailure(new EsRejectedExecutionException("Dummy execution rejected"));
};
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
}
@Override
public void onFailure(Throwable e) {
}
});
verify(threadPool).schedule(eq(TimeValue.timeValueMillis(0)), eq(ThreadPool.Names.SAME), any(Runnable.class));
}
use of io.crate.executor.transport.ShardUpsertRequest in project crate by crate.
the class BulkRetryCoordinatorTest method testNoPendingOperationsOnFailedExecution.
@Test
public void testNoPendingOperationsOnFailedExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onFailure(new InterruptedException("Dummy execution failed"));
};
final SettableFuture<ShardResponse> future = SettableFuture.create();
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
}
@Override
public void onFailure(Throwable e) {
future.set(null);
}
});
ShardResponse response = future.get();
assertNull(response);
assertEquals(0, coordinator.numPendingOperations());
}
use of io.crate.executor.transport.ShardUpsertRequest in project crate by crate.
the class BulkRetryCoordinatorTest method testParallelSuccessfulExecution.
@Test
public void testParallelSuccessfulExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
final BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
final BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onResponse(new ShardResponse());
};
final CountDownLatch latch = new CountDownLatch(1000);
ExecutorService executorService = Executors.newFixedThreadPool(10, daemonThreadFactory("DummyThreadPool"));
for (int i = 0; i < 1000; i++) {
executorService.submit(new Runnable() {
@Override
public void run() {
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
latch.countDown();
}
@Override
public void onFailure(Throwable e) {
}
});
}
});
}
latch.await();
assertEquals(0, coordinator.numPendingOperations());
executorService.awaitTermination(5, TimeUnit.SECONDS);
executorService.shutdown();
}
Aggregations