Search in sources :

Example 1 with CountOperation

use of io.crate.execution.engine.collect.count.CountOperation in project crate by crate.

the class CountTaskTest method testKillOperationFuture.

@Test
public void testKillOperationFuture() throws Exception {
    CompletableFuture<Long> future = mock(CompletableFuture.class);
    CountOperation countOperation = new FakeCountOperation(future);
    CountTask countTask = new CountTask(countPhaseWithId(1), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    countTask.kill(JobKilledException.of("dummy"));
    verify(future, times(1)).cancel(true);
    assertTrue(countTask.isClosed());
}
Also used : CountOperation(io.crate.execution.engine.collect.count.CountOperation) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 2 with CountOperation

use of io.crate.execution.engine.collect.count.CountOperation in project crate by crate.

the class CountTaskTest method testClose.

@Test
public void testClose() throws Exception {
    CompletableFuture<Long> future = new CompletableFuture<>();
    CountOperation countOperation = mock(CountOperation.class);
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    CountTask countTask = new CountTask(countPhaseWithId(1), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.complete(1L);
    assertTrue(countTask.isClosed());
    // assure that there was no exception
    countTask.completionFuture().get();
    // on error
    future = new CompletableFuture<>();
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    countTask = new CountTask(countPhaseWithId(2), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.completeExceptionally(new UnhandledServerException("dummy"));
    assertTrue(countTask.isClosed());
    expectedException.expectCause(CauseMatcher.cause(UnhandledServerException.class));
    countTask.completionFuture().get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Symbol(io.crate.expression.symbol.Symbol) UnhandledServerException(io.crate.exceptions.UnhandledServerException) CountOperation(io.crate.execution.engine.collect.count.CountOperation) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Aggregations

CountOperation (io.crate.execution.engine.collect.count.CountOperation)2 TestingRowConsumer (io.crate.testing.TestingRowConsumer)2 Test (org.junit.Test)2 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 Symbol (io.crate.expression.symbol.Symbol)1 CompletableFuture (java.util.concurrent.CompletableFuture)1