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 my...@apache.org on 2012/06/04 23:56:10 UTC
svn commit: r1346174 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit:
ConnectionPoolDataSourceConnector.java Connector.java
DataSourceConnector.java DriverManagerConnector.java TestConfiguration.java
XADataSourceConnector.java
Author: myrnavl
Date: Mon Jun 4 21:56:09 2012
New Revision: 1346174
URL: http://svn.apache.org/viewvc?rev=1346174&view=rev
Log:
DERBY-5686; multiple intermittent errors in nightly tests during DriverMgrAuthenticationTest test. reason: An SQL data change is not permitted for a read-only connection, user or database.
implementing a change that waits for completely shutting down of the database.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectionPoolDataSourceConnector.java Mon Jun 4 21:56:09 2012
@@ -153,7 +153,8 @@ public class ConnectionPoolDataSourceCon
public void shutDatabase() throws SQLException {
singleUseDS( DataSourceConnector.makeShutdownDBAttributes( config ) ).
- getPooledConnection().getConnection();
+ getPooledConnection().getConnection();
+ config.waitForShutdownComplete(getDatabaseName());
}
public void shutEngine() throws SQLException {
@@ -163,6 +164,17 @@ public class ConnectionPoolDataSourceCon
tmpDs.getPooledConnection();
}
+ public String getDatabaseName() {
+ String databaseName=null;
+ try {
+ // get the physical database name
+ databaseName = (String) JDBCDataSource.getBeanProperty(ds, "databaseName");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return databaseName;
+ }
+
/**
* Get a connection from a single use ConnectionPoolDataSource configured
* from the configuration but with the passed in property set.
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Connector.java Mon Jun 4 21:56:09 2012
@@ -87,6 +87,12 @@ interface Connector {
throws SQLException;
/**
+ * get the physical databasename in use at this time
+ * @return Name of database
+ */
+ abstract String getDatabaseName();
+
+ /**
* Shutdown the running default database using user and password
* defined by the configuration passed to setConfiguration.
* Return nothing, exception is expected to be thrown with SQLState 08006
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DataSourceConnector.java Mon Jun 4 21:56:09 2012
@@ -19,6 +19,7 @@
*/
package org.apache.derbyTesting.junit;
+import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
@@ -132,9 +133,11 @@ public class DataSourceConnector impleme
return tmpDs.getConnection(user, password);
}
}
+
public void shutDatabase() throws SQLException {
- singleUseDS( makeShutdownDBAttributes( config ) ).getConnection();
+ singleUseDS( makeShutdownDBAttributes( config ) ).getConnection();
+ config.waitForShutdownComplete(getDatabaseName());
}
public void shutEngine() throws SQLException {
@@ -168,5 +171,16 @@ public class DataSourceConnector impleme
return hm;
}
+
+ public String getDatabaseName() {
+ String databaseName=null;
+ try {
+ // get the physical database name
+ databaseName = (String) JDBCDataSource.getBeanProperty(ds, "databaseName");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return databaseName;
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DriverManagerConnector.java Mon Jun 4 21:56:09 2012
@@ -126,6 +126,7 @@ public class DriverManagerConnector impl
public void shutDatabase() throws SQLException {
getConnectionByAttributes(config.getJDBCUrl(),
"shutdown", "true");
+ config.waitForShutdownComplete(getDatabaseName());
}
/**
@@ -162,6 +163,14 @@ public class DriverManagerConnector impl
return DriverManager.getConnection(url, attributes);
}
+
+ public String getDatabaseName(){
+ // always use the default database name
+ // if this connector is used with other databases, we
+ // might need another method that takes the databasename
+ String databaseName = config.getDefaultDatabaseName();
+ return databaseName;
+ }
/**
* Load the JDBC driver defined by the JDBCClient for
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Mon Jun 4 21:56:09 2012
@@ -73,6 +73,8 @@ public final class TestConfiguration {
private final static String DEFAULT_FRAMEWORK = "embedded";
private final static String DEFAULT_HOSTNAME = "localhost";
+ private static final int LOCKFILETIMEOUT = 300000; // 5 mins
+
/**
* Maximum number of ports used by Suites.All
* If this changes, this constant and the Wiki
@@ -1746,6 +1748,37 @@ public final class TestConfiguration {
}
}
+ public void waitForShutdownComplete(String physicalDatabaseName) {
+ String path = getDatabasePath(physicalDatabaseName);
+ boolean lockfilepresent = true;
+ int timeout = LOCKFILETIMEOUT; // 5 mins
+ int totalsleep = 0;
+ File lockfile = new File (path + File.separatorChar + "db.lck");
+ File exlockfile = new File (path + File.separatorChar + "dbex.lck");
+ while (lockfilepresent) {
+ if (totalsleep >= timeout)
+ {
+ System.out.println("TestConfigruation.waitForShutdownComplete: " +
+ "been looping waiting for lock files to be deleted for at least 5 minutes, giving up");
+ break;
+ }
+ if (lockfile.exists() || exlockfile.exists())
+ {
+ // TODO: is it interesting to know whether db.lck or dbex.lck or both is still present?
+ try {
+ System.out.println("TestConfiguration.waitForShutdownComplete: " +
+ "db*.lck files not deleted after " + totalsleep + " ms.");
+ Thread.sleep(1000);
+ totalsleep=totalsleep+1000;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ else
+ lockfilepresent=false;
+ }
+ }
+
/**
* stops the Network server for this configuration.
*
@@ -2048,4 +2081,16 @@ public final class TestConfiguration {
{
return getPassword(user, passwordToken);
}
+
+ public final String getDatabasePath(String physicalDatabaseName)
+ {
+ String dbName = physicalDatabaseName.replace('/', File.separatorChar);
+ String dsh = BaseTestCase.getSystemProperty("derby.system.home");
+ if (dsh == null) {
+ Assert.fail("not implemented");
+ } else {
+ dbName = dsh + File.separator + dbName;
+ }
+ return dbName;
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java?rev=1346174&r1=1346173&r2=1346174&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XADataSourceConnector.java Mon Jun 4 21:56:09 2012
@@ -137,13 +137,25 @@ public class XADataSourceConnector imple
public void shutDatabase() throws SQLException {
singleUseDS( DataSourceConnector.makeShutdownDBAttributes( config ) )
- .getXAConnection().getConnection();
+ .getXAConnection().getConnection();
+ config.waitForShutdownComplete(getDatabaseName());
}
public void shutEngine() throws SQLException {
Assert.fail("shutdown engine not implemened");
}
+ public String getDatabaseName() {
+ String databaseName=null;
+ try {
+ // get the physical database name
+ databaseName = (String) JDBCDataSource.getBeanProperty(ds, "databaseName");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return databaseName;
+ }
+
/**
* Get a connection from a single use XADataSource configured
* from the configuration but with the passed in property set.