Search in sources :

Example 1 with CountOperation

use of io.crate.operation.count.CountOperation in project crate by crate.

the class CountContextTest method testClose.

@Test
public void testClose() throws Exception {
    SettableFuture<Long> future = SettableFuture.create();
    CountOperation countOperation = mock(CountOperation.class);
    when(countOperation.count(anyMap(), any(WhereClause.class))).thenReturn(future);
    CountContext countContext = new CountContext(1, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
    countContext.prepare();
    countContext.start();
    future.set(1L);
    assertTrue(countContext.future.closed());
    // assure that there was no exception
    countContext.completionFuture().get();
    // on error
    future = SettableFuture.create();
    when(countOperation.count(anyMap(), any(WhereClause.class))).thenReturn(future);
    countContext = new CountContext(2, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
    countContext.prepare();
    countContext.start();
    future.setException(new UnknownUpstreamFailure());
    assertTrue(countContext.future.closed());
    expectedException.expectCause(CauseMatcher.cause(UnknownUpstreamFailure.class));
    countContext.completionFuture().get();
}
Also used : UnknownUpstreamFailure(io.crate.exceptions.UnknownUpstreamFailure) WhereClause(io.crate.analyze.WhereClause) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CountOperation(io.crate.operation.count.CountOperation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with CountOperation

use of io.crate.operation.count.CountOperation in project crate by crate.

the class CountContextTest method testKillOperationFuture.

@Test
public void testKillOperationFuture() throws Exception {
    ListenableFuture<Long> future = mock(ListenableFuture.class);
    CountOperation countOperation = new FakeCountOperation(future);
    CountContext countContext = new CountContext(1, countOperation, new TestingBatchConsumer(), null, WhereClause.MATCH_ALL);
    countContext.prepare();
    countContext.start();
    countContext.kill(null);
    verify(future, times(1)).cancel(true);
    assertTrue(countContext.future.closed());
}
Also used : TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) CountOperation(io.crate.operation.count.CountOperation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CountOperation (io.crate.operation.count.CountOperation)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)2 Test (org.junit.Test)2 WhereClause (io.crate.analyze.WhereClause)1 UnknownUpstreamFailure (io.crate.exceptions.UnknownUpstreamFailure)1