use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class FileWriterProjectorTest method testDirectoryAsFile.
@Test
public void testDirectoryAsFile() throws Exception {
expectedException.expect(UnhandledServerException.class);
expectedException.expectMessage("Failed to open output: 'Output path is a directory: ");
Path directory = createTempDir();
FileWriterProjector fileWriterProjector = new FileWriterProjector(executorService, directory.toUri().toString(), null, null, Set.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT, Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()), Settings.EMPTY);
new TestingRowConsumer().accept(fileWriterProjector.apply(sourceSupplier.get()), null);
}
use of io.crate.testing.TestingRowConsumer 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, Set.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT, Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()), Settings.EMPTY);
new TestingRowConsumer().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", TestingHelpers.readFile(file.toAbsolutePath().toString()));
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class DocValuesGroupByOptimizedIteratorTest method test_group_by_doc_values_optimized_iterator_for_many_keys.
@Test
public void test_group_by_doc_values_optimized_iterator_for_many_keys() throws Exception {
SumAggregation<?> sumAggregation = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.LONG), DataTypes.LONG);
var sumDocValuesAggregator = sumAggregation.getDocValueAggregator(List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "z"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null)), mock(DocTableInfo.class), List.of());
var keyExpressions = List.of(new BytesRefColumnReference("x"), new LongColumnReference("y"));
var keyRefs = List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "x"), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 1, null), new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 2, null));
var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forManyKeys(List.of(sumDocValuesAggregator), indexSearcher, keyRefs, keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
var rowConsumer = new TestingRowConsumer();
rowConsumer.accept(it, null);
assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { "0", 0L, 6L }, new Object[] { "1", 1L, 4L }));
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class CollectTaskTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
localNodeId = "dummyLocalNodeId";
collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(true);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
collectOperation = mock(MapSideDataCollectOperation.class);
Mockito.doAnswer(new Answer<>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}
}).when(collectOperation).launch(Mockito.any(), Mockito.anyString());
consumer = new TestingRowConsumer();
collectTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), collectOperation, RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), consumer, mock(SharedShardContexts.class), Version.CURRENT, 4096);
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class HashInnerJoinBatchIteratorBehaviouralTest method test_SwitchToRightWhenLeftExhausted.
@Test
public void test_SwitchToRightWhenLeftExhausted() throws Exception {
BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(1, 2, 3, 4)), 2, 1, null);
BatchSimulatingIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(2, 0, 4, 5)), 2, 1, null);
BatchIterator<Row> batchIterator = new HashInnerJoinBatchIterator(leftIterator, rightIterator, mock(RowAccounting.class), new CombinedRow(1, 1), row -> Objects.equals(row.get(0), row.get(1)), row -> Objects.hash(row.get(0)), row -> Objects.hash(row.get(0)), () -> 500000);
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(batchIterator, null);
List<Object[]> result = consumer.getResult();
assertThat(result, contains(new Object[] { 2, 2 }, new Object[] { 4, 4 }));
}
Aggregations