[teiid-commits] teiid SVN: r3386 - in trunk/client/src: test/java/org/teiid/jdbc and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Aug 16 15:13:32 EDT 2011


Author: shawkins
Date: 2011-08-16 15:13:31 -0400 (Tue, 16 Aug 2011)
New Revision: 3386

Modified:
   trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java
   trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
   trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java
Log:
TEIID-1700 adding improved absolute positioning.  Intermediate batches will no longer be read by the client to determine the final row.

Modified: trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java	2011-08-16 16:03:23 UTC (rev 3385)
+++ trunk/client/src/main/java/org/teiid/jdbc/BatchResults.java	2011-08-16 19:13:31 UTC (rev 3386)
@@ -187,11 +187,11 @@
         }
         
         if (row > 0) {
-        	//row is greater than highest, but the last row is not known
-        	while (row + offset > highestRowNumber && lastRowNumber == -1) {
-        		requestNextBatch();
+        	
+        	if (row + offset > highestRowNumber && lastRowNumber == -1) {
+        		requestBatchAndWait(row + offset);
         	}
-
+        	
         	if (row + offset <= highestRowNumber) {
         		setCurrentRowNumber(row);
         		return true;
@@ -203,9 +203,9 @@
         
         row -= offset;
         
-        while (lastRowNumber == -1) {
-        	requestNextBatch();
-        }
+        if (lastRowNumber == -1) {
+    		requestBatchAndWait(Integer.MAX_VALUE);
+    	}
         
         int positiveRow = lastRowNumber + row + 1;
         

Modified: trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java	2011-08-16 16:03:23 UTC (rev 3385)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java	2011-08-16 19:13:31 UTC (rev 3386)
@@ -34,14 +34,13 @@
 import java.util.Calendar;
 import java.util.List;
 import java.util.TimeZone;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.teiid.client.DQP;
 import org.teiid.client.RequestMessage;
 import org.teiid.client.ResultsMessage;
@@ -709,30 +708,27 @@
         cs.next();
     }
 	
-	static ResultSetImpl helpTestBatching(StatementImpl statement, int fetchSize, int batchLength,
-			int totalLength) throws InterruptedException, ExecutionException,
-			TeiidProcessingException, SQLException, TimeoutException {
+	static ResultSetImpl helpTestBatching(StatementImpl statement, final int fetchSize, final int batchLength,
+			final int totalLength) throws TeiidProcessingException, SQLException {
 		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);
+		stub(dqp.processCursorRequest(Matchers.eq(REQUEST_ID), Matchers.anyInt(), Matchers.eq(fetchSize))).toAnswer(new Answer<ResultsFuture<ResultsMessage>>() {
+			@Override
+			public ResultsFuture<ResultsMessage> answer(
+					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);
+				nextBatch.getResultsReceiver().receiveResults(exampleResultsMsg4(begin, length, begin + length - 1>= totalLength));
+				return nextBatch;
 			}
-		}
+		});
 		
-		ResultsMessage msg = exampleResultsMsg4(1, batchLength, fetchSize, batchLength == totalLength);
+		ResultsMessage msg = exampleResultsMsg4(1, batchLength, batchLength == totalLength);
 		return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes())), null), 0);
 	}
 
@@ -835,7 +831,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, int fetchSize, boolean lastBatch) {
+	private static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
 		RequestMessage request = new RequestMessage();
 		request.setExecutionId(REQUEST_ID);
 		ResultsMessage resultsMsg = new ResultsMessage(request);

Modified: trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java	2011-08-16 16:03:23 UTC (rev 3385)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestBatchResults.java	2011-08-16 19:13:31 UTC (rev 3386)
@@ -41,13 +41,13 @@
 	
 	static class MockBatchFetcher implements BatchFetcher {
 
-		private int totalRows = 50;
+		private int totalRows;
 		private boolean throwException;
 		private boolean useLastRow;
 		List<Integer> batchCalls = new ArrayList<Integer>();
 		
 		public MockBatchFetcher() {
-			
+			this(50);
 		}
 		
 		public MockBatchFetcher(int totalRows) {
@@ -68,7 +68,11 @@
 	        if (beginRow%10==0) {
 	        	endRow = beginRow - 9;
 	        }
-	        if(beginRow > endRow) {
+	        if (beginRow > totalRows) {
+        		beginRow = totalRows + 1;
+        		endRow = totalRows;
+        		isLast = true;
+        	} else if(beginRow > endRow) {
 	            if(endRow < 1) {
 	                endRow = 1;
 	            }
@@ -76,7 +80,7 @@
 	            beginRow = endRow;
 	            endRow = i;
 	        } else if(endRow > totalRows) {
-	            endRow = totalRows;
+        		endRow = totalRows;
 	            isLast = true;
 	        }
 			Batch batch = new Batch(createBatch(beginRow, endRow), beginRow, endRow, isLast);



More information about the teiid-commits mailing list