use of com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES in project presto by prestodb.
the class TestExchangeClient method testInitialRequestLimit.
@Test
public void testInitialRequestLimit() {
DataSize bufferCapacity = new DataSize(16, MEGABYTE);
DataSize maxResponseSize = new DataSize(DEFAULT_MAX_PAGE_SIZE_IN_BYTES, BYTE);
CountDownLatch countDownLatch = new CountDownLatch(1);
MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize) {
@Override
public Response handle(Request request) {
if (!awaitUninterruptibly(countDownLatch, 10, SECONDS)) {
throw new UncheckedTimeoutException();
}
return super.handle(request);
}
};
List<URI> locations = new ArrayList<>();
int numLocations = 16;
List<DataSize> expectedMaxSizes = new ArrayList<>();
// add pages
for (int i = 0; i < numLocations; i++) {
URI location = URI.create("http://localhost:" + (8080 + i));
locations.add(location);
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.setComplete(location);
expectedMaxSizes.add(maxResponseSize);
}
try (ExchangeClient exchangeClient = createExchangeClient(processor, bufferCapacity, maxResponseSize)) {
for (int i = 0; i < numLocations; i++) {
exchangeClient.addLocation(locations.get(i), TaskId.valueOf("taskid.0.0." + i));
}
exchangeClient.noMoreLocations();
assertFalse(exchangeClient.isClosed());
long start = System.nanoTime();
countDownLatch.countDown();
// wait for a page to be fetched
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (exchangeClient.getStatus().getBufferedPages() < 16);
// Client should have sent 16 requests for a single page (0) and gotten them back
// The memory limit should be hit immediately and then it doesn't fetch the third page from each
assertEquals(exchangeClient.getStatus().getBufferedPages(), 16);
assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
List<PageBufferClientStatus> pageBufferClientStatuses = exchangeClient.getStatus().getPageBufferClientStatuses();
assertEquals(16, pageBufferClientStatuses.stream().filter(status -> status.getPagesReceived() == 1).mapToInt(PageBufferClientStatus::getPagesReceived).sum());
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
for (int i = 0; i < numLocations * 3; i++) {
assertNotNull(getNextPage(exchangeClient));
}
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (processor.getRequestMaxSizes().size() < 64);
for (int i = 0; i < 48; i++) {
expectedMaxSizes.add(maxResponseSize);
}
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
}
}
Aggregations