use of io.trino.operator.WorkProcessor.ProcessState in project trino by trinodb.
the class MergeSortedPages method pageWithPositions.
private static WorkProcessor<PageWithPosition> pageWithPositions(WorkProcessor<Page> pages, AggregatedMemoryContext aggregatedMemoryContext) {
return pages.flatMap(page -> {
LocalMemoryContext memoryContext = aggregatedMemoryContext.newLocalMemoryContext(MergeSortedPages.class.getSimpleName());
memoryContext.setBytes(page.getRetainedSizeInBytes());
return WorkProcessor.create(new WorkProcessor.Process<PageWithPosition>() {
int position;
@Override
public ProcessState<PageWithPosition> process() {
if (position >= page.getPositionCount()) {
memoryContext.close();
return ProcessState.finished();
}
return ProcessState.ofResult(new PageWithPosition(page, position++));
}
});
});
}
use of io.trino.operator.WorkProcessor.ProcessState in project trino by trinodb.
the class TestWorkProcessor method testYield.
@Test(timeOut = 10_000)
public void testYield() {
SettableFuture<Void> future = SettableFuture.create();
List<ProcessState<Integer>> baseScenario = ImmutableList.of(ProcessState.ofResult(1), ProcessState.ofResult(2), ProcessState.blocked(future), ProcessState.ofResult(3), ProcessState.ofResult(4), ProcessState.finished());
AtomicBoolean yieldSignal = new AtomicBoolean();
WorkProcessor<Integer> processor = processorFrom(baseScenario).yielding(yieldSignal::get);
// no yield, process normally
assertResult(processor, 1);
yieldSignal.set(true);
assertYields(processor);
// processor should progress since it yielded last time
assertResult(processor, 2);
// yield signal is still set
assertYields(processor);
// base scenario future blocks
assertBlocks(processor);
assertUnblocks(processor, future);
// continue to process normally
yieldSignal.set(false);
assertResult(processor, 3);
assertResult(processor, 4);
assertFinishes(processor);
}
use of io.trino.operator.WorkProcessor.ProcessState in project trino by trinodb.
the class TestWorkProcessor method testFinished.
@Test(timeOut = 10_000)
public void testFinished() {
AtomicBoolean finished = new AtomicBoolean();
SettableFuture<Void> future = SettableFuture.create();
List<ProcessState<Integer>> scenario = ImmutableList.of(ProcessState.ofResult(1), ProcessState.yielded(), ProcessState.blocked(future), ProcessState.ofResult(2));
WorkProcessor<Integer> processor = processorFrom(scenario).finishWhen(finished::get);
assertResult(processor, 1);
assertYields(processor);
assertBlocks(processor);
finished.set(true);
assertBlocks(processor);
assertUnblocks(processor, future);
assertFinishes(processor);
}
Aggregations