use of io.trino.spi.Page in project trino by trinodb.
the class TestHttpPageBufferClient method testMemoryExceededInAddPages.
@Test
public void testMemoryExceededInAddPages() throws Exception {
URI location = URI.create("http://localhost:8080");
Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 1L, 100));
MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(DataSize.of(10, MEGABYTE));
CyclicBarrier requestComplete = new CyclicBarrier(2);
TrinoException expectedException = new TrinoException(EXCEEDED_LOCAL_MEMORY_LIMIT, "Memory limit exceeded");
AtomicBoolean addPagesCalled = new AtomicBoolean(false);
TestingClientCallback callback = new TestingClientCallback(requestComplete) {
@Override
public boolean addPages(HttpPageBufferClient client, List<Slice> pages) {
addPagesCalled.set(true);
throw expectedException;
}
};
HttpPageBufferClient client = new HttpPageBufferClient("localhost", new TestingHttpClient(processor, scheduler), DataIntegrityVerification.ABORT, DataSize.of(10, MEGABYTE), new Duration(30, TimeUnit.SECONDS), true, TASK_ID, location, callback, scheduler, pageBufferClientCallbackExecutor);
// attempt to fetch a page
processor.addPage(location, page);
callback.resetStats();
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
// addPages was called
assertTrue(addPagesCalled.get());
// Memory exceeded failure is reported
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertEquals(callback.getFailure(), expectedException);
}
use of io.trino.spi.Page in project trino by trinodb.
the class TestHttpPageBufferClient method testHappyPath.
@Test
public void testHappyPath() throws Exception {
Page expectedPage = new Page(100);
DataSize expectedMaxSize = DataSize.of(11, Unit.MEGABYTE);
MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(expectedMaxSize);
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
HttpPageBufferClient client = new HttpPageBufferClient("localhost", new TestingHttpClient(processor, scheduler), DataIntegrityVerification.ABORT, expectedMaxSize, new Duration(1, TimeUnit.MINUTES), true, TASK_ID, location, callback, scheduler, pageBufferClientCallbackExecutor);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
// fetch a page and verify
processor.addPage(location, expectedPage);
callback.resetStats();
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 1);
assertPageEquals(expectedPage, callback.getPages().get(0));
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertStatus(client, location, "queued", 1, 1, 1, 0, "not scheduled");
// fetch no data and verify
callback.resetStats();
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertStatus(client, location, "queued", 1, 2, 2, 0, "not scheduled");
// fetch two more pages and verify
processor.addPage(location, expectedPage);
processor.addPage(location, expectedPage);
callback.resetStats();
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 2);
assertPageEquals(expectedPage, callback.getPages().get(0));
assertPageEquals(expectedPage, callback.getPages().get(1));
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 0);
callback.resetStats();
assertStatus(client, location, "queued", 3, 3, 3, 0, "not scheduled");
// finish and verify
callback.resetStats();
processor.setComplete(location);
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
// get the buffer complete signal
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
// schedule the delete call to the buffer
callback.resetStats();
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getFinishedBuffers(), 1);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 0);
assertEquals(callback.getFailedBuffers(), 0);
assertStatus(client, location, "closed", 3, 5, 5, 0, "not scheduled");
}
use of io.trino.spi.Page in project trino by trinodb.
the class TestLimitOperator method testLimitWithBlockView.
@Test
public void testLimitWithBlockView() {
List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(2, 6).build();
OperatorFactory operatorFactory = new LimitOperatorFactory(0, new PlanNodeId("test"), 6);
List<Page> expected = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(1, 6).build();
OperatorAssertion.assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
use of io.trino.spi.Page in project trino by trinodb.
the class TestLimitOperator method testLimitWithPageAlignment.
@Test
public void testLimitWithPageAlignment() {
List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(2, 6).build();
OperatorFactory operatorFactory = new LimitOperatorFactory(0, new PlanNodeId("test"), 5);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).page(createSequencePage(ImmutableList.of(BIGINT), 3, 1)).page(createSequencePage(ImmutableList.of(BIGINT), 2, 4)).build();
OperatorAssertion.assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.spi.Page in project trino by trinodb.
the class TestMarkDistinctOperator method testMemoryReservationYield.
@Test(dataProvider = "dataType")
public void testMemoryReservationYield(Type type) {
List<Page> input = createPagesWithDistinctHashKeys(type, 6_000, 600);
OperatorFactory operatorFactory = new MarkDistinctOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(type), ImmutableList.of(0), Optional.of(1), joinCompiler, blockTypeOperators);
// get result with yield; pick a relatively small buffer for partitionRowCount's memory usage
GroupByHashYieldAssertion.GroupByHashYieldResult result = finishOperatorWithYieldingGroupByHash(input, type, operatorFactory, operator -> ((MarkDistinctOperator) operator).getCapacity(), 1_400_000);
assertGreaterThan(result.getYieldCount(), 5);
assertGreaterThan(result.getMaxReservedBytes(), 20L << 20);
int count = 0;
for (Page page : result.getOutput()) {
assertEquals(page.getChannelCount(), 3);
for (int i = 0; i < page.getPositionCount(); i++) {
assertEquals(page.getBlock(2).getByte(i, 0), 1);
count++;
}
}
assertEquals(count, 6_000 * 600);
}
Aggregations