use of io.crate.testing.TestingBatchConsumer 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();
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class JobExecutionContextTest method testFailureClosesAllSubContexts.
@Test
public void testFailureClosesAllSubContexts() throws Exception {
String localNodeId = "localNodeId";
RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(false);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
JobExecutionContext.Builder builder = new JobExecutionContext.Builder(UUID.randomUUID(), coordinatorNode, Collections.emptyList(), mock(JobsLogs.class));
JobCollectContext jobCollectContext = new JobCollectContext(collectPhase, mock(MapSideDataCollectOperation.class), localNodeId, mock(RamAccountingContext.class), new TestingBatchConsumer(), mock(SharedShardContexts.class));
TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
PageDownstreamContext pageDownstreamContext = spy(new PageDownstreamContext(Loggers.getLogger(PageDownstreamContext.class), "n1", 2, "dummy", batchConsumer, PassThroughPagingIterator.oneShot(), new Streamer[] { IntegerType.INSTANCE.streamer() }, mock(RamAccountingContext.class), 1));
builder.addSubContext(jobCollectContext);
builder.addSubContext(pageDownstreamContext);
JobExecutionContext jobExecutionContext = builder.build();
Exception failure = new Exception("failure!");
jobCollectContext.close(failure);
// other contexts must be killed with same failure
verify(pageDownstreamContext, times(1)).innerKill(failure);
final Field subContexts = JobExecutionContext.class.getDeclaredField("subContexts");
subContexts.setAccessible(true);
int size = ((ConcurrentMap<Integer, ExecutionSubContext>) subContexts.get(jobExecutionContext)).size();
assertThat(size, is(0));
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class PageDownstreamContextTest method testSetBucketOnAKilledCtxReleasesListener.
@Test
public void testSetBucketOnAKilledCtxReleasesListener() throws Exception {
TestingBatchConsumer consumer = new TestingBatchConsumer();
PageDownstreamContext ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
ctx.kill(new InterruptedException("killed"));
CompletableFuture<Void> listenerReleased = new CompletableFuture<>();
ctx.setBucket(0, Bucket.EMPTY, false, needMore -> listenerReleased.complete(null));
// Must not timeout
listenerReleased.get(1, TimeUnit.SECONDS);
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class PageDownstreamContextTest method testCantSetSameBucketTwiceWithoutReceivingFullPage.
@Test
public void testCantSetSameBucketTwiceWithoutReceivingFullPage() throws Throwable {
TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
PageBucketReceiver ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
PageResultListener pageResultListener = mock(PageResultListener.class);
Bucket bucket = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
ctx.setBucket(1, bucket, false, pageResultListener);
ctx.setBucket(1, bucket, false, pageResultListener);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Same bucket of a page set more than once. node=n1 method=setBucket phaseId=1 bucket=1");
batchConsumer.getResult();
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class FileWriterProjectorTest method testWriteRawToFile.
@Test
public void testWriteRawToFile() throws Exception {
Path file = createTempFile("out", "json");
FileWriterProjector fileWriterProjector = new FileWriterProjector(executorService, file.toUri().toString(), null, null, ImmutableSet.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT);
new TestingBatchConsumer().accept(fileWriterProjector.apply(sourceSupplier.get()), null);
assertEquals("input line 00\n" + "input line 01\n" + "input line 02\n" + "input line 03\n" + "input line 04\n", TestingHelpers.readFile(file.toAbsolutePath().toString()));
}
Aggregations