}
static ResultSetImpl helpTestBatching(StatementImpl statement, int fetchSize, int batchLength,
int totalLength) throws InterruptedException, ExecutionException,
TeiidProcessingException, SQLException, TimeoutException {
DQP dqp = statement.getDQP();
if (dqp == null) {
dqp = mock(DQP.class);
stub(statement.getDQP()).toReturn(dqp);
}
stub(statement.getFetchSize()).toReturn(fetchSize);
for (int i = batchLength; i < totalLength; i += batchLength) {
//forward requests
ResultsFuture<ResultsMessage> nextBatch = mock(ResultsFuture.class);
stub(nextBatch.get(Matchers.anyLong(), (TimeUnit)Matchers.anyObject())).toReturn(exampleResultsMsg4(i + 1, Math.min(batchLength, totalLength - i), fetchSize, i + batchLength >= totalLength));
stub(dqp.processCursorRequest(REQUEST_ID, i + 1, fetchSize)).toReturn(nextBatch);
if (i + batchLength < totalLength) {
//backward requests
ResultsFuture<ResultsMessage> previousBatch = mock(ResultsFuture.class);
stub(previousBatch.get(Matchers.anyLong(), (TimeUnit)Matchers.anyObject())).toReturn(exampleResultsMsg4(i - batchLength + 1, i, fetchSize, false));
stub(dqp.processCursorRequest(REQUEST_ID, i, fetchSize)).toReturn(previousBatch);
}
}
ResultsMessage msg = exampleResultsMsg4(1, batchLength, fetchSize, batchLength == totalLength);
return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes()))), 0);