Search in sources :

Example 6 with ShardUpsertRequest

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);
}
Also used : ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) UpsertById(io.crate.planner.node.dml.UpsertById) Before(org.junit.Before)

Example 7 with ShardUpsertRequest

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));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardResponse(io.crate.executor.transport.ShardResponse) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with ShardUpsertRequest

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());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardResponse(io.crate.executor.transport.ShardResponse) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with ShardUpsertRequest

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();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch) ShardResponse(io.crate.executor.transport.ShardResponse) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)9 UUID (java.util.UUID)7 ShardId (org.elasticsearch.index.shard.ShardId)7 ShardResponse (io.crate.executor.transport.ShardResponse)6 Reference (io.crate.metadata.Reference)6 ReferenceIdent (io.crate.metadata.ReferenceIdent)6 RowGranularity (io.crate.metadata.RowGranularity)6 TableIdent (io.crate.metadata.TableIdent)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 DataTypes (io.crate.types.DataTypes)6 ActionListener (org.elasticsearch.action.ActionListener)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)6 ThreadPool (org.elasticsearch.threadpool.ThreadPool)6 Test (org.junit.Test)6 Matchers.any (org.mockito.Matchers.any)6 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)4 ClusterService (org.elasticsearch.cluster.ClusterService)4 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)4 Before (org.junit.Before)4