db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andre...@apache.org
Subject svn commit: r425388 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/ engine/org/apache/derby/impl/services/monitor/ testing/org/apache/derbyTesting/functionTests/harness/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org...
Date Tue, 25 Jul 2006 12:58:19 GMT
Author: andreask
Date: Tue Jul 25 05:58:18 2006
New Revision: 425388

URL: http://svn.apache.org/viewvc?rev=425388&view=rev
Log:
DERBY-1296 Setting property derby.system.bootAll causes NullPointerException in BaseMonitor.bootProviderServices.
Fix and test contributed by Fernanda Pizzorno

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirStorageFactory4.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirStorageFactory4.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirStorageFactory4.java?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirStorageFactory4.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirStorageFactory4.java Tue Jul
25 05:58:18 2006
@@ -52,9 +52,14 @@
      */
     StorageFile newPersistentFile( String path)
     {
+        String dir = dataDirectory;
+        if (canonicalName != null && path != null && home != null &&

+                !path.startsWith(home)) {
+            dir = canonicalName;
+        }
         if( path == null)
-            return new DirFile4( dataDirectory, rwsOK);
-        return new DirFile4(dataDirectory, path, rwsOK);
+            return new DirFile4(dir, rwsOK);
+        return new DirFile4(dir, path, rwsOK);
     }
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
Tue Jul 25 05:58:18 2006
@@ -1436,8 +1436,8 @@
 		to boot all the services that that provider knows about.
 	*/
 	protected void bootPersistentServices() {
-		for (Enumeration e = new ProviderEnumeration( applicationProperties); ; ) {
-
+		Enumeration e = new ProviderEnumeration( applicationProperties);
+		while (e.hasMoreElements()) {
 			PersistentService provider = (PersistentService) e.nextElement();
 			bootProviderServices(provider);
 		}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
Tue Jul 25 05:58:18 2006
@@ -164,6 +164,7 @@
 
         //Filter to suppress absould paths in error message for roll forward recovery tests

         searchStrings.addElement("Directory.*.wombat.already.exists");
+        searchStrings.addElement("Directory.*.extinout/crwombatlog/log.*.exists");
 
         // Filter for "DB2ConnectionCorrelator" text that can be printed as
         // part of some JCC error messages.
@@ -233,6 +234,7 @@
             subStrings.addElement("-----"); 
         }
         subStrings.addElement("Directory DBLOCATION/wombat already exists");
+        subStrings.addElement("Directory 'extinout<sp>crwombatlog<sp>log' exists");
         // ignore the 'DB2ConnectionCorrelator' thing altogether.
         subStrings.addElement("");
 		// Filter for SAX exception name diffs between jvms.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
Tue Jul 25 05:58:18 2006
@@ -35,3 +35,4 @@
 store/onlineBackupTest4.sql
 store/BackupPathTests.java
 store/LogDeviceTest.java
+store/BootAllTest.junit

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java?rev=425388&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java
Tue Jul 25 05:58:18 2006
@@ -0,0 +1,144 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.store.BootAllTest
+
+   Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import org.apache.derbyTesting.functionTests.util.BaseTestCase;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
+
+import junit.framework.*;
+import java.sql.*;
+import java.util.Properties;
+import java.util.Arrays;
+
+/**
+ * Tests for the system property "derby.system.bootAll"
+ *
+ * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
+ * 
+ */
+public class BootAllTest  extends BaseTestCase {
+
+    /** JDBC Connection */
+    private Connection con;
+    private Driver driver;
+    private String databases[] = new String[] {"wombat1", "wombat2", "wombat3"};
+    
+    final static String DATABASE_SHUT_DOWN = "08006";
+    final static String ALL_DATABASES_SHUT_DOWN = "XJ015";
+
+    /**
+     * Creates a new instance of BootAllTest
+     */
+    public BootAllTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Create the databases
+     */
+    public void setUp() throws Exception {
+        for (int i = 0; i < databases.length; i++) {
+            con = CONFIG.getConnection(databases[i]);
+            con.close();
+            try {
+                con = CONFIG.
+                        getConnection(databases[i] + ";shutdown=true");
+            } catch (SQLException se) {
+                assertEquals("Expected exception on setUp " + se.getSQLState(), 
+                        DATABASE_SHUT_DOWN, se.getSQLState());
+            }
+        }
+        String url = CONFIG.getJDBCUrl("");
+        driver = DriverManager.getDriver(url);
+        DriverManager.deregisterDriver(driver);
+        try {
+            driver.connect(url + ";shutdown=true", null);
+        } catch (SQLException se) {
+            assertEquals("Expected exception on tearDown " + se.getSQLState(), 
+                    ALL_DATABASES_SHUT_DOWN, se.getSQLState());
+        }
+        System.runFinalization();
+        System.gc();
+    }
+
+    /**
+     * Shutdown all databases
+     */
+    public void tearDown() throws Exception {
+        String driverName = CONFIG.getJDBCClient().getJDBCDriverName();
+        Class.forName(driverName);
+        println("Teardown of: " + getName());
+        try {
+            con = CONFIG.
+                    getConnection(";shutdown=true");
+        } catch (SQLException se) {
+            assertEquals("Expected exception on tearDown " + se.getSQLState(), 
+                    ALL_DATABASES_SHUT_DOWN, se.getSQLState());
+        }
+    }
+
+    /**
+     * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
+     *
+     * Check that setting the system property "derby.system.bootAll" will not 
+     * cause an exception when used in combination with the system property
+     * "derby.system.home".
+     *
+     * The property "derby.system.home" is set by default for all tests and does
+     * not need to be explicitly set in this test.
+     */
+    public void testSettingBootAllPropertyWithHomePropertySet() 
+            throws Exception 
+    {
+        String returnedDatabases[] = null;
+
+        setSystemProperty("derby.system.bootAll", "true");
+
+        String driverName = CONFIG.getJDBCClient().getJDBCDriverName();
+        String url = CONFIG.getJDBCUrl("");
+
+        Class.forName(driverName).newInstance();
+        DriverManager.registerDriver(driver);
+
+        Driver driver = DriverManager.getDriver(url);
+
+        DriverPropertyInfo[] attributes = driver.getPropertyInfo(url, null);
+        for (int i = 0; i < attributes.length; i++) {
+            if (attributes[i].name.equalsIgnoreCase("databaseName")) {
+                returnedDatabases = attributes[i].choices;
+            }
+        }
+
+        Arrays.sort(returnedDatabases);
+
+        assertEquals("The number of databases should be", 
+                databases.length, 
+                returnedDatabases.length);
+
+        for (int i = 0; i < databases.length; i++) {
+            assertEquals("Database names should be", 
+                    databases[i], 
+                    returnedDatabases[i]);
+        }
+
+    }
+    
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/BootAllTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/build.xml
Tue Jul 25 05:58:18 2006
@@ -65,6 +65,7 @@
       <classpath>
         <!--pathelement location="${oro}"/-->
         <pathelement path="${compile.classpath}"/>
+        <pathelement path="${junit}"/>
       </classpath>
       <include name="${this.dir}/*.java"/>
       <exclude name="${this.dir}/bootLock.java"/>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=425388&r1=425387&r2=425388&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
Tue Jul 25 05:58:18 2006
@@ -127,7 +127,7 @@
      */
     private String createJDBCUrlWithDatabaseName(String name) {
         if (jdbcClient == JDBCClient.EMBEDDED) {
-            return jdbcClient.getUrlBase() + dbName;
+            return jdbcClient.getUrlBase() + name;
         } else {
             return jdbcClient.getUrlBase() + hostName + ":" + port + "/" + name;
         }
@@ -216,23 +216,40 @@
      */
     public Connection getDefaultConnection()
         throws SQLException {
+        return getConnection(getDatabaseName());
+    }
+    
+    /**
+     * Get connection to a database.
+     * If the database does not exist, it will be created.
+     * A default username and password will be used for the connection.
+     *
+     * @param databaseName database to connect to
+     *
+     * @return connection to default database.
+     */
+    public Connection getConnection (String databaseName) throws SQLException {
         Connection con = null;
         JDBCClient client =getJDBCClient();
         if (HAVE_DRIVER) {            
             loadJDBCDriver(client.getJDBCDriverName());
             if (!isSingleLegXA()) {
                 con = DriverManager.getConnection(
-                        getJDBCUrl() + ";create=true",
+                        getJDBCUrl(databaseName) + ";create=true",
                         getUserName(),
                         getUserPassword());
             }
             else {
-                con = TestDataSourceFactory.getXADataSource().getXAConnection (getUserName(),
-                            getUserPassword()).getConnection();                
+                Properties attrs = 
+                        getDataSourcePropertiesForDatabase(databaseName);
+                con = TestDataSourceFactory.getXADataSource(attrs).
+                        getXAConnection (getUserName(), 
+                        getUserPassword()).getConnection();
             }
         } else {
             //Use DataSource for JSR169
-            con = TestDataSourceFactory.getDataSource().getConnection();
+            Properties attrs = getDataSourcePropertiesForDatabase(databaseName);
+            con = TestDataSourceFactory.getDataSource(attrs).getConnection();
         }
         return con;
     }
@@ -390,16 +407,34 @@
      * connect to the default database
      */
     public static Properties getDefaultDataSourceProperties() {
+        return getDataSourcePropertiesForDatabase(
+                DERBY_TEST_CONFIG.getDatabaseName());
+    }
+    
+    /**
+     * Generate properties which can be set on a
+     * <code>DataSource</code> in order to connect to a given
+     * database.
+     *
+     * @param databaseName database to connect to
+     *
+     * @return a <code>Properties</code> object containing server
+     * name, port number, database name and other attributes needed to
+     * connect to the database
+     */
+    public static Properties getDataSourcePropertiesForDatabase
+            (String databaseName) 
+    {
         Properties attrs = new Properties();
         if (!(DERBY_TEST_CONFIG.getJDBCClient() == JDBCClient.EMBEDDED)) {
             attrs.setProperty("serverName", DERBY_TEST_CONFIG.getHostName());
             attrs.setProperty("portNumber", Integer.toString(DERBY_TEST_CONFIG.getPort()));
         }
-        attrs.setProperty("databaseName", DERBY_TEST_CONFIG.getDatabaseName());
+        attrs.setProperty("databaseName", databaseName);
         attrs.setProperty("connectionAttributes", "create=true");
         return attrs;
     }
-    
+
     /**
      * Load the specified JDBC driver
      *



Mime
View raw message