[teiid-commits] teiid SVN: r3760 - in branches/7.6.x: client/src/main/java/org/teiid/net/socket and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Sat Dec 24 20:40:11 EST 2011


Author: shawkins
Date: 2011-12-24 20:40:08 -0500 (Sat, 24 Dec 2011)
New Revision: 3760

Modified:
   branches/7.6.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
   branches/7.6.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
   branches/7.6.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java
   branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
   branches/7.6.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
Log:
TEIID-1883 fix for not using the appropriate timeout

Modified: branches/7.6.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.6.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java	2011-12-23 02:17:51 UTC (rev 3759)
+++ branches/7.6.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java	2011-12-25 01:40:08 UTC (rev 3760)
@@ -40,6 +40,8 @@
 import java.util.Properties;
 import java.util.TimeZone;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
@@ -543,16 +545,21 @@
 		});
     	if (synch) {
     		try {
-				pendingResult.get();
+				pendingResult.get(queryTimeoutMS==0?Integer.MAX_VALUE:queryTimeoutMS, TimeUnit.MILLISECONDS);
     			result.get(); //throw an exception if needed
     			return result;
     		} catch (ExecutionException e) {
     			if (e.getCause() instanceof SQLException) {
     				throw (SQLException)e.getCause();
     			}
+    			if (e.getCause() != null) {
+        			throw TeiidSQLException.create(e.getCause());
+    			}
     			throw TeiidSQLException.create(e);
     		} catch (InterruptedException e) {
     			timeoutOccurred();
+			} catch (TimeoutException e) {
+    			timeoutOccurred();
 			}
     		throw new TeiidSQLException(JDBCPlugin.Util.getString("MMStatement.Timeout_before_complete")); //$NON-NLS-1$
     	}
@@ -577,7 +584,7 @@
         reqMsg.setExecutionId(this.currentRequestID);
         
         ResultsFuture.CompletionListener<ResultsMessage> compeletionListener = null;
-		if (queryTimeoutMS > 0) {
+		if (queryTimeoutMS > 0 && !synch) {
 			final Task c = cancellationTimer.add(cancelTask, queryTimeoutMS);
 			compeletionListener = new ResultsFuture.CompletionListener<ResultsMessage>() {
 				@Override

Modified: branches/7.6.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
===================================================================
--- branches/7.6.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java	2011-12-23 02:17:51 UTC (rev 3759)
+++ branches/7.6.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java	2011-12-25 01:40:08 UTC (rev 3760)
@@ -70,7 +70,7 @@
         }
     }
     
-    private static SocketProfile SOCKET_PROFILE = new SocketProfile();
+    private ConnectionProfile socketProfile = new SocketProfile();
     private ConnectionProfile embeddedProfile = new EmbeddedProfile();
 
     public static TeiidDriver getInstance() {
@@ -104,7 +104,7 @@
         	if (conn == ConnectionType.Embedded) {
         		myConnection = embeddedProfile.connect(url, info);
         	} else { 
-        		myConnection = SOCKET_PROFILE.connect(url, info);
+        		myConnection = socketProfile.connect(url, info);
         	}
         } catch (TeiidSQLException e) {
             logger.log(Level.SEVERE, "Could not create connection", e); //$NON-NLS-1$
@@ -122,6 +122,10 @@
 		this.embeddedProfile = embeddedProfile;
 	}
     
+    public void setSocketProfile(ConnectionProfile socketProfile) {
+		this.socketProfile = socketProfile;
+	}
+    
     /**
      * Returns true if the driver thinks that it can open a connection to the given URL.
      * Expected URL format for server mode is

Modified: branches/7.6.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java
===================================================================
--- branches/7.6.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java	2011-12-23 02:17:51 UTC (rev 3759)
+++ branches/7.6.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java	2011-12-25 01:40:08 UTC (rev 3760)
@@ -269,7 +269,7 @@
 				timeoutMillis -= now - start;
 				start = now;
 				if (timeoutMillis <= 0) {
-					throw new TimeoutException();
+					throw new TimeoutException("Read timeout after " + timeout + " milliseconds."); //$NON-NLS-1$ //$NON-NLS-2$
 				}
 			}
 		}
@@ -332,7 +332,7 @@
 					@Override
 					public Object get() throws InterruptedException, ExecutionException {
 						try {
-							return this.get(SocketServerConnectionFactory.getInstance().getSynchronousTtl(), TimeUnit.MILLISECONDS);
+							return this.get(instance.getSynchTimeout(), TimeUnit.MILLISECONDS);
 						} catch (TimeoutException e) {
 							throw new ExecutionException(e);
 						} 

Modified: branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java	2011-12-23 02:17:51 UTC (rev 3759)
+++ branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java	2011-12-25 01:40:08 UTC (rev 3760)
@@ -28,7 +28,6 @@
 import java.util.Properties;
 
 import org.jboss.deployers.spi.DeploymentException;
-import org.mockito.Mockito;
 import org.teiid.adminapi.AdminException;
 import org.teiid.adminapi.VDB;
 import org.teiid.adminapi.impl.ModelMetaData;
@@ -142,13 +141,24 @@
         this.dqp.setCacheFactory(new DefaultCacheFactory());
         this.dqp.setTransactionService(new FakeTransactionService());
         
-        cmr = Mockito.mock(ConnectorManagerRepository.class);
-        Mockito.stub(cmr.getConnectorManager("source")).toReturn(new ConnectorManager("x", "x") {
+        cmr = new ConnectorManagerRepository() {
         	@Override
-        	public SourceCapabilities getCapabilities() {
-        		return new BasicSourceCapabilities();
+        	public ConnectorManager getConnectorManager(String connectorName) {
+        		ConnectorManager cm = super.getConnectorManager(connectorName);
+        		if (cm != null) {
+        			return cm;
+        		}
+        		if (connectorName.equalsIgnoreCase("source")) {
+        			return new ConnectorManager("x", "x") {
+        	        	@Override
+        	        	public SourceCapabilities getCapabilities() {
+        	        		return new BasicSourceCapabilities();
+        	        	}
+        			};
+        		}
+        		return null;
         	}
-        });
+        };
         
         config.setResultsetCacheConfig(new CacheConfiguration(Policy.LRU, 60, 250, "resultsetcache")); //$NON-NLS-1$
         this.dqp.setCacheFactory(new DefaultCacheFactory() {
@@ -168,6 +178,10 @@
 		return dqp;
 	}
 	
+	public ConnectorManagerRepository getConnectorManagerRepository() {
+		return cmr;
+	}
+	
 	public void setConnectorManagerRepository(ConnectorManagerRepository cmr) {
 		this.cmr = cmr;
 	}

Modified: branches/7.6.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
===================================================================
--- branches/7.6.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java	2011-12-23 02:17:51 UTC (rev 3759)
+++ branches/7.6.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java	2011-12-25 01:40:08 UTC (rev 3760)
@@ -37,16 +37,26 @@
 import org.junit.Test;
 import org.teiid.common.buffer.BufferManagerFactory;
 import org.teiid.core.util.UnitTestUtil;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
 import org.teiid.dqp.internal.process.DQPConfiguration;
+import org.teiid.dqp.service.AutoGenDataService;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.jdbc.ConnectionProfile;
 import org.teiid.jdbc.FakeServer;
 import org.teiid.jdbc.TeiidDriver;
+import org.teiid.jdbc.TeiidSQLException;
 import org.teiid.jdbc.TestMMDatabaseMetaData;
+import org.teiid.net.CommunicationException;
+import org.teiid.net.ConnectionException;
+import org.teiid.net.socket.SocketServerConnectionFactory;
+import org.teiid.translator.TranslatorException;
 
 @SuppressWarnings("nls")
 public class TestJDBCSocketTransport {
 
 	static InetSocketAddress addr;
 	static SocketListener jdbcTransport;
+	static FakeServer server;
 	
 	@BeforeClass public static void oneTimeSetup() throws Exception {
 		SocketConfiguration config = new SocketConfiguration();
@@ -57,7 +67,7 @@
 		
 		DQPConfiguration dqpConfig = new DQPConfiguration();
 		dqpConfig.setMaxActivePlans(2);
-		FakeServer server = new FakeServer(dqpConfig);
+		server = new FakeServer(dqpConfig);
 		server.setUseCallingThread(false);
 		server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
 		
@@ -68,6 +78,7 @@
 		if (jdbcTransport != null) {
 			jdbcTransport.stop();
 		}
+		server.stop();
 	}
 	
 	Connection conn;
@@ -127,4 +138,46 @@
 		}
 	}
 	
+	@Test public void testSyncTimeout() throws Exception {
+		TeiidDriver td = new TeiidDriver();
+		td.setSocketProfile(new ConnectionProfile() {
+			
+			@Override
+			public ConnectionImpl connect(String url, Properties info)
+					throws TeiidSQLException {
+				SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
+				sscf.initialize(info);
+				try {
+					return new ConnectionImpl(sscf.getConnection(info), info, url);
+				} catch (CommunicationException e) {
+					throw TeiidSQLException.create(e);
+				} catch (ConnectionException e) {
+					throw TeiidSQLException.create(e);
+				}
+			}
+		});
+		Properties p = new Properties();
+		p.setProperty("user", "testuser");
+		p.setProperty("password", "testpassword");
+		p.setProperty("org.teiid.sockets.soTimeout", "50");
+		p.setProperty("org.teiid.sockets.SynchronousTtl", "50");
+		ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
+		AutoGenDataService agds = new AutoGenDataService() {
+			@Override
+			protected Object getConnectionFactory()
+					throws TranslatorException {
+				return null;
+			}
+		};
+		agds.setSleep(100);
+		cmr.addConnectorManager("source", agds);
+		try {
+			conn = td.connect("jdbc:teiid:parts at mm://"+addr.getHostName()+":" +jdbcTransport.getPort(), p);
+			Statement s = conn.createStatement();
+			assertTrue(s.execute("select * from parts"));
+		} finally {
+			server.setConnectorManagerRepository(cmr);
+		}
+	}
+	
 }



More information about the teiid-commits mailing list