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:55 UTC
svn commit: r959553 - in /db/derby/code/branches/10.5: ./
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:54 2010
New Revision: 959553
URL: http://svn.apache.org/viewvc?rev=959553&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.5/ (props changed)
db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 1 08:28:54 2010
@@ -1,2 +1,2 @@
/db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=959553&r1=959552&r2=959553&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Thu Jul 1 08:28:54 2010
@@ -620,7 +620,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,
@@ -645,7 +646,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.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=959553&r1=959552&r2=959553&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Thu Jul 1 08:28:54 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;
}
@@ -2491,14 +2492,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
@@ -2508,12 +2508,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
@@ -2522,15 +2522,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 -- */
@@ -2538,19 +2538,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;
@@ -2568,29 +2568,26 @@ 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();
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();
@@ -2598,19 +2595,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
@@ -2630,6 +2634,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());
+ }
}
}
@@ -2667,7 +2678,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"));
@@ -4053,6 +4064,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