use of io.crate.Streamer in project crate by crate.
the class CountAggregationTest method testStreaming.
@Test
public void testStreaming() throws Exception {
CountAggregation.LongState l1 = new CountAggregation.LongState(12345L);
BytesStreamOutput out = new BytesStreamOutput();
Streamer streamer = CountAggregation.LongStateType.INSTANCE.streamer();
streamer.writeValueTo(out, l1);
StreamInput in = StreamInput.wrap(out.bytes());
CountAggregation.LongState l2 = (CountAggregation.LongState) streamer.readValueFrom(in);
assertEquals(l1.value, l2.value);
}
use of io.crate.Streamer in project crate by crate.
the class DistributingConsumerTest method testDistributingConsumerForwardsFailure.
@Test
public void testDistributingConsumerForwardsFailure() throws Exception {
Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
TestingRowConsumer collectingConsumer = new TestingRowConsumer();
DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
distributingConsumer.accept(null, new CompletionException(new IllegalArgumentException("foobar")));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("foobar");
collectingConsumer.getResult();
}
use of io.crate.Streamer in project crate by crate.
the class DistributingConsumerTest method test_exception_on_loadNextBatch_is_forwarded.
@Test
public void test_exception_on_loadNextBatch_is_forwarded() throws Exception {
Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
TestingRowConsumer collectingConsumer = new TestingRowConsumer();
DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService) {
@Override
public CompletionStage<?> loadNextBatch() {
throw new CircuitBreakingException("data too large");
}
};
distributingConsumer.accept(batchSimulatingIterator, null);
expectedException.expect(CircuitBreakingException.class);
collectingConsumer.getResult();
}
use of io.crate.Streamer in project crate by crate.
the class TDigestStateTest method testStreaming.
@Test
public void testStreaming() throws Exception {
TDigestState digestState1 = new TDigestState(250, new double[] { 0.5, 0.8 });
BytesStreamOutput out = new BytesStreamOutput();
TDigestStateType digestStateType = TDigestStateType.INSTANCE;
Streamer streamer = digestStateType.streamer();
streamer.writeValueTo(out, digestState1);
StreamInput in = out.bytes().streamInput();
TDigestState digestState2 = (TDigestState) streamer.readValueFrom(in);
assertEquals(digestState1.compression(), digestState2.compression(), 0.001d);
assertEquals(digestState1.fractions()[0], digestState2.fractions()[0], 0.001d);
assertEquals(digestState1.fractions()[1], digestState2.fractions()[1], 0.001d);
}
use of io.crate.Streamer in project crate by crate.
the class ReservoirSampler method getSamples.
public Samples getSamples(RelationName relationName, List<Reference> columns, int maxSamples) {
TableInfo table;
try {
table = schemas.getTableInfo(relationName);
} catch (RelationUnknown e) {
return Samples.EMPTY;
}
if (!(table instanceof DocTableInfo)) {
return Samples.EMPTY;
}
DocTableInfo docTable = (DocTableInfo) table;
Random random = Randomness.get();
Metadata metadata = clusterService.state().metadata();
CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
List<Engine.Searcher> searchersToRelease = new ArrayList<>();
CircuitBreaker breaker = circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY);
RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "Reservoir-sampling"), MAX_BLOCK_SIZE_IN_BYTES);
try {
return getSamples(columns, maxSamples, docTable, random, metadata, coordinatorTxnCtx, streamers, searchersToRelease, ramAccounting);
} finally {
ramAccounting.close();
for (Engine.Searcher searcher : searchersToRelease) {
searcher.close();
}
}
}
Aggregations