Search in sources :

Example 1 with UnknownUpstreamFailure

use of io.crate.exceptions.UnknownUpstreamFailure 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)

Aggregations

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