}
assertEquals(requestLocation.getSequenceId(), token, "token");
// wait for a single page to arrive
Page page = null;
try {
page = pages.poll(10, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// if no page, return NO CONTENT
if (page == null) {
return new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(
PRESTO_PAGE_TOKEN, String.valueOf(token),
PRESTO_PAGE_NEXT_TOKEN, String.valueOf(token)
), new byte[0]);
}
// add pages up to the size limit
List<Page> responsePages = new ArrayList<>();
responsePages.add(page);
long responseSize = page.getSizeInBytes();
while (responseSize < maxSize.toBytes()) {
page = pages.poll();
if (page == null) {
break;
}
responsePages.add(page);
responseSize += page.getSizeInBytes();
}
// update sequence id
long nextToken = token + responsePages.size();
tokenByLocation.put(location, nextToken);