teiid SVN: r4576 - in branches/7.7.x: client/src/test/java/org/teiid/jdbc and 1 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2013-06-10 09:11:33 -0400 (Mon, 10 Jun 2013)
New Revision: 4576
Modified:
branches/7.7.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestResultSet.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
Log:
BZ947471 + TEIID-2525: Prefetch exception with small fetch size
Modified: branches/7.7.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- branches/7.7.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2013-06-07 12:22:47 UTC (rev 4575)
+++ branches/7.7.x/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2013-06-10 13:11:33 UTC (rev 4576)
@@ -366,10 +366,8 @@
ResultsMessage result = getResults(prefetch);
prefetch = null;
Batch nextBatch = processBatch(result);
- if (result.getFirstRow() == beginRow) {
- return nextBatch;
- }
- }
+ return nextBatch;
+ }
ResultsFuture<ResultsMessage> results = submitRequestBatch(beginRow);
ResultsMessage currentResultMsg = getResults(results);
return processBatch(currentResultMsg);
Modified: branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2013-06-07 12:22:47 UTC (rev 4575)
+++ branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2013-06-10 13:11:33 UTC (rev 4576)
@@ -53,7 +53,7 @@
public class TestAllResultsImpl {
- private static final long REQUEST_ID = 0;
+ static final long REQUEST_ID = 0;
private static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
private static final int TYPE_SCROLL_SENSITIVE = ResultSet.TYPE_SCROLL_SENSITIVE;
@@ -710,6 +710,11 @@
static ResultSetImpl helpTestBatching(StatementImpl statement, final int fetchSize, final int batchLength,
final int totalLength) throws TeiidProcessingException, SQLException {
+ return helpTestBatching(statement, fetchSize, batchLength, totalLength, false);
+ }
+
+ static ResultSetImpl helpTestBatching(StatementImpl statement, final int fetchSize, final int batchLength,
+ final int totalLength, final boolean partial) throws TeiidProcessingException, SQLException {
DQP dqp = statement.getDQP();
if (dqp == null) {
dqp = mock(DQP.class);
@@ -722,13 +727,17 @@
InvocationOnMock invocation) throws Throwable {
ResultsFuture<ResultsMessage> nextBatch = new ResultsFuture<ResultsMessage>();
int begin = Math.min(totalLength, (Integer)invocation.getArguments()[1]);
- int length = Math.min(totalLength - begin + 1, batchLength);
+ if (partial && begin == fetchSize + 1) {
+ begin = begin -5;
+ }
+ int length = Math.min(fetchSize, Math.min(totalLength - begin + 1, batchLength));
nextBatch.getResultsReceiver().receiveResults(exampleResultsMsg4(begin, length, begin + length - 1>= totalLength));
return nextBatch;
}
});
- ResultsMessage msg = exampleResultsMsg4(1, batchLength, batchLength == totalLength);
+ int initial = Math.min(fetchSize, batchLength);
+ ResultsMessage msg = exampleResultsMsg4(1, initial, initial == totalLength);
return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes())), null), 0);
}
@@ -831,7 +840,7 @@
return exampleMessage(new List[0], new String[] { "IntNum", "StringNum" }, new String[] { JDBCSQLTypeInfo.INTEGER, JDBCSQLTypeInfo.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
}
- private static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
+ static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
ResultsMessage resultsMsg = new ResultsMessage();
Modified: branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestResultSet.java
===================================================================
--- branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestResultSet.java 2013-06-07 12:22:47 UTC (rev 4575)
+++ branches/7.7.x/client/src/test/java/org/teiid/jdbc/TestResultSet.java 2013-06-10 13:11:33 UTC (rev 4576)
@@ -692,6 +692,19 @@
cs.close();
}
+ @Test public void testForwardOnlyPrefetchSmallFetchSize() throws Exception {
+ StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
+ ResultSetImpl cs = TestAllResultsImpl.helpTestBatching(statement, 10, 128, 256, true);
+ for (int i = 0; i < 256; i++) {
+ cs.next();
+ cs.getObject(1);
+ }
+ Mockito.verify(statement.getDQP(), Mockito.times(1)).processCursorRequest(TestAllResultsImpl.REQUEST_ID, 11, 10);
+ assertFalse(cs.next());
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
@Test public void testOutputParameter() throws Exception {
StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultsMessage resultsMsg = new ResultsMessage();
Modified: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2013-06-07 12:22:47 UTC (rev 4575)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2013-06-10 13:11:33 UTC (rev 4576)
@@ -658,7 +658,7 @@
fromBuffer = true;
}
if (batch.getRowCount() > count) {
- int beginRow = Math.min(this.begin, batch.getEndRow() - count + 1);
+ int beginRow = isForwardOnly()?begin:Math.min(this.begin, batch.getEndRow() - count + 1);
int endRow = Math.min(beginRow + count - 1, batch.getEndRow());
boolean last = false;
if (endRow == batch.getEndRow()) {