You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2010/07/01 10:28:05 UTC
svn commit: r959552 - in /db/derby/code/branches/10.6: ./
java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Author: kristwaa
Date: Thu Jul 1 08:28:05 2010
New Revision: 959552
URL: http://svn.apache.org/viewvc?rev=959552&view=rev
Log:
DERBY-4717: Driver trace file isn't closed/released on physical connection close when specified with the traceFile attribute/setter
Merged fix from trunk (revision 959550).
Modified:
db/derby/code/branches/10.6/ (props changed)
db/derby/code/branches/10.6/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 1 08:28:05 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618,959550
/db/derby/docs/trunk:954344
Modified: db/derby/code/branches/10.6/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=959552&r1=959551&r2=959552&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/branches/10.6/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Thu Jul 1 08:28:05 2010
@@ -621,7 +621,8 @@ public abstract class ClientBaseDataSour
}
LogWriter dncLogWriter = new NetLogWriter(printWriter, traceLevel);
- if (printWriter != logWriter && traceDirectory != null)
+ if (printWriter != logWriter &&
+ (traceDirectory != null || traceFile != null))
// When printWriter is an internal trace file and
// traceDirectory is not null, each connection has
// its own trace file and the trace file is not cached,
@@ -646,7 +647,8 @@ public abstract class ClientBaseDataSour
}
LogWriter dncLogWriter = connection.agent_.newLogWriter_(printWriter, traceLevel);
- if (printWriter != logWriter && traceDirectory != null)
+ if (printWriter != logWriter &&
+ (traceDirectory != null || traceFile != null))
// When printWriter is an internal trace file and
// traceDirectory is not null, each connection has
// its own trace file and the trace file is not cached,
Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=959552&r1=959551&r2=959552&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Thu Jul 1 08:28:05 2010
@@ -170,8 +170,9 @@ public class J2EEDataSourceTest extends
suite.addTest(new J2EEDataSourceTest("testClientDSConnectionAttributes"));
suite.addTest(new J2EEDataSourceTest(
"testClientTraceFileDSConnectionAttribute"));
- suite.addTest(new J2EEDataSourceTest(
- "testClientMessageTextConnectionAttribute"));
+ //DISABLED until DERBY-4067 is fixed.
+ //suite.addTest(new J2EEDataSourceTest(
+ // "testClientMessageTextConnectionAttribute"));
return suite;
}
@@ -2524,14 +2525,13 @@ public class J2EEDataSourceTest extends
* the tracefile.
*
* Note also that this test cannot run against a remote server.
+ * <p>
+ * This is also a regression test for DERBY-4717.
*
* @throws SQLException
*/
public void testClientTraceFileDSConnectionAttribute() throws SQLException
{
- if (usingEmbedded())
- return;
-
String traceFile;
// with ConnectionPoolDataSource
@@ -2541,12 +2541,12 @@ public class J2EEDataSourceTest extends
JDBCDataSource.setBeanProperty(cpds, "connectionAttributes",
"traceFile="+traceFile);
// DERBY-2468 - trace3.out does not get created
- ((ClientConnectionPoolDataSource) cpds).getConnection();
+ ((PooledConnection)getPhysicalConnection(cpds)).close();
JDBCDataSource.clearStringBeanProperty(cpds, "connectionAttributes");
traceFile = "trace4.out";
JDBCDataSource.setBeanProperty(cpds, "traceFile", traceFile);
- ((ClientConnectionPoolDataSource) cpds).getConnection();
+ ((PooledConnection)getPhysicalConnection(cpds)).close();
cpds = null;
// now with XADataSource
@@ -2555,15 +2555,15 @@ public class J2EEDataSourceTest extends
traceFile = "trace5.out";
JDBCDataSource.setBeanProperty(xads, "connectionAttributes",
"traceFile="+traceFile);
- ((ClientXADataSource) xads).getConnection();
+ ((XAConnection)getPhysicalConnection(xads)).close();
// DERBY-2468 - trace5.out does not get created
JDBCDataSource.clearStringBeanProperty(xads, "connectionAttributes");
traceFile = "trace6.out";
JDBCDataSource.setBeanProperty(xads, "traceFile", traceFile);
- ((ClientXADataSource) xads).getConnection();
+ ((XAConnection)getPhysicalConnection(xads)).close();
- assertTraceFilesExist();
+ assertTraceFilesExistAndCanBeDeleted();
}
/* -- Helper Methods for testClientTraceFileDSConnectionAttribute -- */
@@ -2571,19 +2571,19 @@ public class J2EEDataSourceTest extends
/**
* Check that trace file exists in <framework> directory
*/
- private static void assertTraceFilesExist()
+ private static void assertTraceFilesExistAndCanBeDeleted()
{
AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
- for (int i=3 ; i < 6 ; i++)
- {
- String traceFileName = "trace" + (i+1) + ".out";
- File traceFile = new File(traceFileName);
- if (i == 4)
+ for (int i=3 ; i <= 6 ; i++) {
+ File traceFile = new File("trace" + i + ".out");
+ // Skip trace 3 and 5 until DERBY-2468/DERBY-4067 is fixed.
+ if (i == 3 || i == 5)
continue;
else
{
- assertTrue(traceFile.exists());
+ assertTrue("Doesn't exist", traceFile.exists());
+ assertTrue("Delete failed", traceFile.delete());
}
}
return null;
@@ -2601,14 +2601,11 @@ public class J2EEDataSourceTest extends
* There is a corresponding fixture for clientDataSource in DataSourceTest
*
* @throws SQLException
+ * NOTE: DISABLED until DERBY-4067 is fixed.
*/
public void testClientMessageTextConnectionAttribute() throws SQLException
{
- if (usingEmbedded())
- return;
-
String retrieveMessageTextProperty = "retrieveMessageText";
- Connection conn;
// with ConnectionPoolDataSource
// ConnectionPoolDataSource - retrieveMessageTextProperty
ClientConnectionPoolDataSource cpds = new ClientConnectionPoolDataSource();
@@ -2617,15 +2614,15 @@ public class J2EEDataSourceTest extends
cpds.setDatabaseName(dbName);
cpds.setConnectionAttributes(
retrieveMessageTextProperty + "=false");
- conn = cpds.getConnection();
- assertMessageText(conn,"false");
- conn.close();
+ PooledConnection cpConn = cpds.getPooledConnection();
+ assertMessageText(cpConn.getConnection(), "false");
+ cpConn.close();
cpds.setConnectionAttributes(
retrieveMessageTextProperty + "=true");
- conn = cpds.getConnection();
- assertMessageText(conn,"true");
+ cpConn = cpds.getPooledConnection();
+ assertMessageText(cpConn.getConnection(), "true");
cpds.setConnectionAttributes(null);
- conn.close();
+ cpConn.close();
// now with XADataSource
ClientXADataSource xads = new ClientXADataSource();
@@ -2634,19 +2631,26 @@ public class J2EEDataSourceTest extends
xads.setDatabaseName(dbName);
xads.setConnectionAttributes(
retrieveMessageTextProperty + "=false");
- conn = xads.getConnection();
- assertMessageText(conn,"false");
- conn.close();
+ XAConnection xaConn = xads.getXAConnection();
+ assertMessageText(xaConn.getConnection(), "false");
+ xaConn.close();
xads.setConnectionAttributes(
retrieveMessageTextProperty + "=true");
- conn = xads.getConnection();
- assertMessageText(conn,"true");
- conn.close();
+ xaConn = xads.getXAConnection();
+ assertMessageText(xaConn.getConnection(), "true");
+ xaConn.close();
xads.setConnectionAttributes(null);
}
/* -- Helper Method for testClientMessageTextDSConnectionAttribute -- */
+ /**
+ * Checks if <tt>retrieveMessageText</tt> takes effect.
+ *
+ * @param conn the connection to use, will be closed
+ * @param retrieveMessageTextValue the current value
+ * @throws SQLException if something goes wrong
+ */
private static void assertMessageText(
Connection conn, String retrieveMessageTextValue)
throws SQLException
@@ -2667,6 +2671,13 @@ public class J2EEDataSourceTest extends
// retrieveMessageTextValue is false
assertTrue(e.getMessage().indexOf("does not exist") == -1);
}
+ } finally {
+ try {
+ conn.close();
+ } catch (SQLException ignore) {
+ // Ignore error on close
+ println("Ignored error on close: " + ignore.getMessage());
+ }
}
}
@@ -2704,7 +2715,7 @@ public class J2EEDataSourceTest extends
"Everything you ever wanted to know about this datasource";
JDBCDataSource.setBeanProperty(ds, "description", setDescription);
- ds.getConnection();
+ getPhysicalConnection(ds);
assertEquals(setDescription, JDBCDataSource.getBeanProperty(ds, "description"));
JDBCDataSource.clearStringBeanProperty(ds, "description");
assertNull(JDBCDataSource.getBeanProperty(ds, "description"));
@@ -4090,6 +4101,34 @@ public class J2EEDataSourceTest extends
new J2EEDataSourceTest("J2EEDataSourceTest").assertConnectionOK(
expectedValues, dsName, conn);
}
+
+ /**
+ * Creates a physical connection from the given data source.
+ * <p>
+ * For a XADataSource, <tt>getXAConnection</tt> is invoked, for a
+ * ConnectionPoolDataSource <tt>getPooledConnection</tt> is invoked, and
+ * for a DataSource <tt>getConnection</tt> is invoked.
+ *
+ * @param ds the data source to get the physical connection from
+ * @return A pysical connection, which can be an instance of
+ * <tt>XAConnection</tt>, <tt>PooledConnection</tt>, or
+ * <tt>Connection</tt>
+ * @throws SQLException if getting a connection fails
+ * @throws IllegalArgumentException if the object isn't a data source
+ */
+ public static Object getPhysicalConnection(Object ds)
+ throws SQLException {
+ if (ds instanceof XADataSource) {
+ return ((XADataSource)ds).getXAConnection();
+ } else if (ds instanceof ConnectionPoolDataSource) {
+ return ((ConnectionPoolDataSource)ds).getPooledConnection();
+ } else if (ds instanceof DataSource) {
+ return ((DataSource)ds).getConnection();
+ } else {
+ throw new IllegalArgumentException(
+ "Not a data source: " + ds.getClass());
+ }
+ }
}
class cdsXid implements Xid, Serializable