db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r494552 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/upgradeTests/ junit/
Date Tue, 09 Jan 2007 20:15:46 GMT
Author: djd
Date: Tue Jan  9 12:15:45 2007
New Revision: 494552

URL: http://svn.apache.org/viewvc?view=rev&rev=494552
Log:
DERBY-2217 (partial) Add more test cases from the old harness upgrade test.
Change setup for the JUnit upgrade test in UpgradeRun so that version specific
upgrade tests are only run if the old version is older than the version the tests
are intended for. E.g. don't run Changes10_1 tests if the old version is
already at 10.1.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_1.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_3.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_1.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_1.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_1.java
Tue Jan  9 12:15:45 2007
@@ -31,6 +31,8 @@
 
 /**
  * Upgrade test cases for changes made in 10.1.
+ * If the old version is 10.1 or later then these tests
+ * will not be run.
  * <BR>
     10.1 Upgrade issues
 
@@ -70,54 +72,22 @@
      */
     public void testProcedureSignature() throws SQLException
     {      
-       boolean signaturesAllowedInOldRelease = oldAtLeast(10, 1);
-        
+       Statement s = createStatement();
         switch (getPhase())
         {
         case PH_CREATE:
+        case PH_POST_SOFT_UPGRADE:
             break;
         case PH_SOFT_UPGRADE:
-        {
-            Statement s = createStatement();
-            try {
-                s.execute(PROC_SIGNATURE);
-                if (!signaturesAllowedInOldRelease)
-                    fail("created procedure with signature");
-
-            } catch (SQLException sqle) {
-                if (signaturesAllowedInOldRelease)
-                    fail("failed to create valid procedure");
-                
-                assertSQLState("XCL47", sqle);
-            }
-            s.close();
-            break;
-        }
-        case PH_POST_SOFT_UPGRADE:
-        {
-            Statement s = createStatement();
-            try {
-                s.execute("CALL GC()");
-                if (!signaturesAllowedInOldRelease)
-                    fail("procedure was created in soft upgrade!");
-                    
-            } catch (SQLException sqle)
-            {
-                if (signaturesAllowedInOldRelease)
-                    fail("procedure was created not in soft upgrade!");
-            }
-            s.close();
+            assertStatementError(SQLSTATE_NEED_UPGRADE, s,
+                    PROC_SIGNATURE);
             break;
-        }
+
         case PH_HARD_UPGRADE:
-        {
-            Statement s = createStatement();
-            if (!signaturesAllowedInOldRelease)
-                s.execute(PROC_SIGNATURE);
+            s.execute(PROC_SIGNATURE);
             s.execute("CALL GC()");
-            s.close();
             break;
         }
-        }
+        s.close();
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
Tue Jan  9 12:15:45 2007
@@ -33,6 +33,9 @@
 
 /**
  * Upgrade test cases for changes made in 10.2.
+ * If the old version is 10.2 or later then these tests
+ * will not be run.
+
  * <BR>
  * 10.2 Upgrade issues
  * <UL>
@@ -40,6 +43,8 @@
  * does not break triggers in soft upgrade mode.
  * <LI> testReusableRecordIdSequenceNumber - Test reuseable record
  * identifiers does not cause issues in soft upgrade
+ * <LI> testGrantRevokeStatements - Check G/R not allowed in soft upgrade.
+ * <LI> testDatabaseOwner - test that on a hard upgrade database owner is set.
  * </UL>
  */
 public class Changes10_2 extends UpgradeChange {
@@ -210,6 +215,126 @@
             break;
         }
         case PH_HARD_UPGRADE:
+            break;
+        }
+    }
+    
+    /**
+     * Simple test of if GRANT/REVOKE statements are handled
+     * correctly in terms of being allowed in soft upgrade.
+     * @throws SQLException 
+     *
+     */
+    public void testGrantRevokeStatements() throws SQLException
+    {
+        Statement s = createStatement();
+        switch(getPhase()) {
+        // 
+        case PH_CREATE:
+        case PH_POST_SOFT_UPGRADE:
+            // was syntax error in 10.0,10.1
+            assertStatementError("42X01", s,
+                "GRANT SELECT ON TABLE1 TO USER1");
+            assertStatementError("42X01", s,
+                "REVOKE SELECT ON TABLE1 FROM USER1");
+
+            break;
+            
+        case PH_SOFT_UPGRADE:
+            // require hard upgrade
+            assertStatementError(SQLSTATE_NEED_UPGRADE, s,
+                "GRANT SELECT ON TABLE1 TO USER1");
+            assertStatementError(SQLSTATE_NEED_UPGRADE, s,
+                "REVOKE SELECT ON TABLE1 FROM USER1");
+
+            break;
+            
+        case PH_HARD_UPGRADE:
+            // not supported because SQL authorization not set
+            assertStatementError("42Z60", s,
+                "GRANT SELECT ON TABLE1 TO USER1");
+            assertStatementError("42Z60", s,
+                "REVOKE SELECT ON TABLE1 FROM USER1");
+            break;
+        }
+        s.close();
+    }
+    
+    /**
+     * This method lists the schema names and authorization ids in 
+     * SYS.SCHEMAS table. This is to test that the owner of system schemas is 
+     * changed from pseudo user "DBA" to the user invoking upgrade. 
+     * 
+     * @throws SQLException
+     */
+    public void testDatabaseOwnerChange() throws SQLException
+    {
+        switch (getPhase())
+        {
+        case PH_CREATE:
+        case PH_SOFT_UPGRADE:
+        case PH_POST_SOFT_UPGRADE:
+            checkSystemSchemasOwner("DBA");
+            break;
+
+        case PH_HARD_UPGRADE:
+            checkSystemSchemasOwner(getTestConfiguration().getUserName());
+            break;
+        }
+    }
+    
+    private void checkSystemSchemasOwner(String name) throws SQLException
+    {
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery(
+                "select AUTHORIZATIONID, SCHEMANAME from SYS.SYSSCHEMAS " +
+                   "WHERE SCHEMANAME LIKE 'SYS%' OR " +
+                   "SCHEMANAME IN ('NULLID', 'SQLJ')");
+        
+        while (rs.next()) {
+            assertEquals("AUTHORIZATIONID not valid for " + rs.getString(2),
+                    name, rs.getString(1));
+        }
+        
+        rs.close();
+        s.close();
+    }
+    
+    /**
+     * This method checks that some system routines are granted public access 
+     * after a full upgrade.
+     * 
+     * @throws SQLException
+     */
+    public void testSystemRoutinePermissions() throws SQLException
+    {
+        switch (getPhase())
+        {
+        case PH_CREATE:
+        case PH_SOFT_UPGRADE:
+        case PH_POST_SOFT_UPGRADE:
+            break;
+
+        case PH_HARD_UPGRADE:
+            Statement s = createStatement();
+            ResultSet rs = s.executeQuery("select A.ALIAS FROM " +
+                    "SYS.SYSROUTINEPERMS R, SYS.SYSALIASES A " +
+                    "WHERE R.ALIASID = A.ALIASID AND " +
+                    "R.GRANTEE = 'PUBLIC' AND " +
+                    "R.GRANTOR = '"
+                        + getTestConfiguration().getUserName() + "'" +
+                    " ORDER BY 1");
+            
+            JDBC.assertFullResultSet(rs, new String[][]
+                    {{"SYSCS_COMPRESS_TABLE"},
+                    {"SYSCS_GET_RUNTIMESTATISTICS"},
+                    {"SYSCS_INPLACE_COMPRESS_TABLE"},
+                    {"SYSCS_SET_RUNTIMESTATISTICS"},
+                    {"SYSCS_SET_STATISTICS_TIMING"}}
+                    );
+
+            rs.close();
+            s.close();
             break;
         }
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_3.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_3.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_3.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_3.java
Tue Jan  9 12:15:45 2007
@@ -20,15 +20,21 @@
 */
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
+import java.sql.Connection;
 import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 /**
  * Upgrade test cases for changes made in 10.3.
+ * If the old version is 10.3 or later then these tests
+ * will not be run.
+
  * <BR>
  * 10.3 Upgrade issues
  */
@@ -78,5 +84,96 @@
         rs.next();
         assertEquals("SYS.SYSVIEWS.COMPILATIONSCHEMAID IS_NULLABLE",
                         "YES", rs.getString("IS_NULLABLE"));
+    }
+    /**
+     * In 10.3: We will write a LogRecord with a different format 
+     * that can also write negative values.
+     * 
+     * Verify here that a 10.2 Database does not malfunction from this and
+     * 10.2 Databases will work with the old LogRecord format.
+     */
+    public void testNegValueSupportedLogRecord()
+        throws SQLException
+    {
+        switch(getPhase()) {
+        case PH_CREATE: {
+            // This case is derived from OnlineCompressTest.test6.
+            Statement s = createStatement();
+            s.execute("create table case606(keycol int, indcol1 int,"+
+                "indcol2 int, data1 char(24), data2 char(24), data3 char(24)," +
+                "data4 char(24), data5 char(24), data6 char(24),"+
+                "data7 char(24), data8 char(24), data9 char(24)," + 
+                "data10 char(24), inddec1 decimal(8), indcol3 int,"+
+                "indcol4 int, data11 varchar(50))");
+            s.close();
+            break;
+        }
+        case PH_SOFT_UPGRADE:
+            // Ensure that the old Log Record format is written
+            // by Newer release without throwing any exceptions.
+            checkDataToCase606(0, 2000);
+            break;
+        case PH_POST_SOFT_UPGRADE:
+            // We are now back to Old release
+            checkDataToCase606(0, 1000);
+            break;
+
+        case PH_HARD_UPGRADE:
+            // Create the Derby606 bug scenario and test that
+            // the error does not occur in Hard Upgrade
+            checkDataToCase606(0, 94000);
+
+            break;
+        }
+    }
+    
+    private void checkDataToCase606(int start_value, int end_value)
+            throws SQLException {
+        Statement s = createStatement();
+        PreparedStatement insert_stmt = prepareStatement("insert into case606 values(?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+        char[] data_dt = new char[24];
+        char[] data_dt2 = new char[50];
+        for (int i = 0; i < data_dt.length; i++)
+            data_dt[i] = 'a';
+        for (int i = 0; i < data_dt2.length; i++)
+            data_dt2[i] = 'z';
+        String data1_str = new String(data_dt);
+        String data2_str = new String(data_dt2);
+
+        for (int i = start_value; i < end_value; i++) {
+            insert_stmt.setInt(1, i); // keycol
+            insert_stmt.setInt(2, i * 10); // indcol1
+            insert_stmt.setInt(3, i * 100); // indcol2
+            insert_stmt.setString(4, data1_str); // data1_data
+            insert_stmt.setString(5, data1_str); // data2_data
+            insert_stmt.setString(6, data1_str); // data3_data
+            insert_stmt.setString(7, data1_str); // data4_data
+            insert_stmt.setString(8, data1_str); // data5_data
+            insert_stmt.setString(9, data1_str); // data6_data
+            insert_stmt.setString(10, data1_str); // data7_data
+            insert_stmt.setString(11, data1_str); // data8_data
+            insert_stmt.setString(12, data1_str); // data9_data
+            insert_stmt.setString(13, data1_str); // data10_data
+            insert_stmt.setInt(14, i * 20); // indcol3
+            insert_stmt.setInt(15, i * 200); // indcol4
+            insert_stmt.setInt(16, i * 50);
+            insert_stmt.setString(17, data2_str); // data11_data
+
+            insert_stmt.execute();
+        }
+        insert_stmt.close();
+        commit();
+
+        s.execute("delete from case606 where case606.keycol > 10000");
+        commit();
+        
+        String schema = getTestConfiguration().getUserName();
+
+        s.execute(
+                "call SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE('"
+                 + schema + "', 'CASE606',1,1,1)");
+        s.close();
+        commit();
+
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
Tue Jan  9 12:15:45 2007
@@ -21,16 +21,15 @@
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
 import java.security.AccessController;
-import java.sql.Connection;
 import java.sql.SQLException;
 
 import javax.sql.DataSource;
 
-import org.apache.derbyTesting.junit.JDBCDataSource;
-
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 
+import org.apache.derbyTesting.junit.JDBCDataSource;
+
 /**
  * Decorator that sets the phase of the upgrade process
  * for a suite of upgrade tests.
@@ -90,7 +89,16 @@
             break;
         }
         
-        ds.getConnection().close();
+        try {
+            ds.getConnection().close();
+        } catch (SQLException e) {
+            // TODO Auto-generated catch block
+            do {
+                e.printStackTrace();
+                e = e.getNextException();
+            } while (e != null);
+            //throw e;
+        }
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeChange.java
Tue Jan  9 12:15:45 2007
@@ -43,6 +43,13 @@
     static ThreadLocal oldVersion = new ThreadLocal();
     
     /**
+     * SWL state thrown when a feature requires upgrade
+     * to a newer version and thus cannot be run in soft
+     * upgrade mode.
+     */
+    static final String SQLSTATE_NEED_UPGRADE = "XCL47";
+    
+    /**
      * Phases in upgrade test
      */
     static final String[] PHASES =

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
Tue Jan  9 12:15:45 2007
@@ -32,7 +32,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.derbyTesting.junit.BaseTestCase;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -107,7 +106,7 @@
             }
             Test phaseTests = baseSuite(
                     "Upgrade Phase: " + UpgradeChange.PHASES[phase],
-                    phase);
+                    phase, version);
             
             suite.addTest(new PhaseChanger(phaseTests, phase, loader, version));
         }
@@ -123,8 +122,32 @@
         return SecurityManagerSetup.noSecurityManager(setup);
     }
     
-    private static Test baseSuite(String name, int phase) {
+    /**
+     * Add the tests from the various Changes classes (sub-classes
+     * of UpgradeChange) to the base suite which corresponds to
+     * a single phase of a run against an old database version.
+     * <BR>
+     * Changes are only added if the old version is older than
+     * then version the changes represent. Thus Changes10_2
+     * is not added if the old database (upgrade from) is already
+     * at 10.2, since Changes10_2 is intended to test upgrade
+     * from an older version to 10.2.
+     * <BR>
+     * This is for two reasons:
+     * <OL>
+     * <LI> Prevents an endless increase in number of test
+     * cases that do no real testing. 
+     * <LI> Simplifies test fixtures by allowing them to
+     * focus on cases where testing is required, and not
+     * handling all future situations.
+     * </OL>
+     * 
+     */
+    private static Test baseSuite(String name, int phase, int[] version) {
         TestSuite suite = new TestSuite(name);
+        
+        int oldMajor = version[0];
+        int oldMinor = version[1];
           
         // No connection is expected in the post hard upgrade
         // phase, so don't bother adding test fixtures.
@@ -132,9 +155,14 @@
         {
             suite.addTest(BasicSetup.suite());
             
-            suite.addTest(Changes10_1.suite());
-            suite.addTest(Changes10_2.suite());
-            suite.addTest(Changes10_3.suite());
+            if (oldMajor == 10) {
+                if (oldMinor < 1)
+                    suite.addTest(Changes10_1.suite());
+                if (oldMinor < 2)
+                   suite.addTest(Changes10_2.suite());
+                if (oldMinor < 3)
+                   suite.addTest(Changes10_3.suite());
+            }
         }
                 
         return TestConfiguration.connectionDSDecorator(suite);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=494552&r1=494551&r2=494552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Tue
Jan  9 12:15:45 2007
@@ -141,7 +141,7 @@
             }
             return ds;
         } catch (Exception e) {
-            Assert.fail(e.getMessage());
+            Assert.fail(e.toString());
             return null;
         }
     }



Mime
View raw message