Author: jolee
Date: 2012-01-04 10:08:03 -0500 (Wed, 04 Jan 2012)
New Revision: 3767
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
branches/7.4.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
Log:
SOA-3685 / TEIID-1883 Query timeout is superceded by synch ttl
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2012-01-03
22:02:42 UTC (rev 3766)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2012-01-04
15:08:03 UTC (rev 3767)
@@ -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;
@@ -536,16 +538,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$
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java 2012-01-03
22:02:42 UTC (rev 3766)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidDriver.java 2012-01-04
15:08:03 UTC (rev 3767)
@@ -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.4.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java
===================================================================
---
branches/7.4.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java 2012-01-03
22:02:42 UTC (rev 3766)
+++
branches/7.4.x/client/src/main/java/org/teiid/net/socket/SocketServerInstanceImpl.java 2012-01-04
15:08:03 UTC (rev 3767)
@@ -267,7 +267,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$
}
}
}
@@ -330,7 +330,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.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
---
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-01-03
22:02:42 UTC (rev 3766)
+++
branches/7.4.x/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-01-04
15:08:03 UTC (rev 3767)
@@ -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;
@@ -92,13 +91,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() {
@@ -114,6 +124,14 @@
registerClientService(DQP.class, dqp, null);
}
+ public DQPCore getDqp() {
+ return dqp;
+ }
+
+ public ConnectorManagerRepository getConnectorManagerRepository() {
+ return cmr;
+ }
+
public void setConnectorManagerRepository(ConnectorManagerRepository cmr) {
this.cmr = cmr;
}
Modified:
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java
===================================================================
---
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java 2012-01-03
22:02:42 UTC (rev 3766)
+++
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestJDBCSocketTransport.java 2012-01-04
15:08:03 UTC (rev 3767)
@@ -36,16 +36,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();
@@ -56,7 +66,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");
@@ -67,6 +77,7 @@
if (jdbcTransport != null) {
jdbcTransport.stop();
}
+ server.stop();
}
Connection conn;
@@ -103,4 +114,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@mm://"+addr.getHostName()+":"
+jdbcTransport.getPort(), p);
+ Statement s = conn.createStatement();
+ assertTrue(s.execute("select * from parts"));
+ } finally {
+ server.setConnectorManagerRepository(cmr);
+ }
+ }
+
}