db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1195476 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests: Changes10_8_2.java Changes10_9.java UpgradeRun.java
Date Mon, 31 Oct 2011 14:31:23 GMT
Author: rhillegas
Date: Mon Oct 31 14:31:23 2011
New Revision: 1195476

URL: http://svn.apache.org/viewvc?rev=1195476&view=rev
Log:
DERBY-5486: Remove special upgrade exception for 10.8.2 now that DERBY-4437 has been backed
out of the 10.8 branch.

Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java?rev=1195476&r1=1195475&r2=1195476&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_9.java
Mon Oct 31 14:31:23 2011
@@ -156,5 +156,149 @@ public class Changes10_9 extends Upgrade
         assertEquals( expectedRowCount, actualRowCount );
     }
 
+    /**
+     * Make sure that generator-based identity columns don't break upgrade/downgrade.
+     * See DERBY-4437. Originally, this behavior was backported to 10.8.2. However, the behavior
+     * was backed out of 10.8.2.
+     */
+    public void testIdentity10_8_2() throws Exception
+    {
+        Statement s = createStatement();
+
+        boolean supportsSequences = oldAtLeast( 10, 6 );
+
+        switch ( getPhase() )
+        {
+        case PH_CREATE: // create with old version
+            s.execute( "create table t_identity1_4437( a int, b int generated always as identity
)" );
+            s.execute( "insert into t_identity1_4437( a ) values ( 100 )" );
+            vetIdentityValues_4437( s, "t_identity1_4437", 1, 2 );
+
+            if ( supportsSequences )
+            {
+                s.execute( "create sequence seq1_4437" );
+                vetSequenceValue( s, "seq1_4437", -2147483648, -2147483643 );
+            }
+            
+            break;
+            
+        case PH_SOFT_UPGRADE: // boot with new version and soft-upgrade
+            s.execute( "insert into t_identity1_4437( a ) values ( 200 )" );
+            vetIdentityValues_4437( s, "t_identity1_4437", 2, 22 );
+
+            s.execute( "create table t_identity2_4437( a int, b int generated always as identity
)" );
+            s.execute( "insert into t_identity2_4437( a ) values ( 100 )" );
+            vetIdentityValues_4437( s, "t_identity2_4437", 1, 21 );
+
+            if ( supportsSequences )
+            {
+                vetSequenceValue( s, "seq1_4437", -2147483643, -2147483623 );
+            
+                s.execute( "create sequence seq2_4437" );
+                vetSequenceValue( s, "seq2_4437", -2147483648, -2147483628 );
+            }
+
+            break;
+            
+        case PH_POST_SOFT_UPGRADE: // soft-downgrade: boot with old version after soft-upgrade
+            s.execute( "insert into t_identity1_4437( a ) values ( 300 )" );
+            vetIdentityValues_4437( s, "t_identity1_4437", 3, 4 );
+
+            s.execute( "insert into t_identity2_4437( a ) values ( 200 )" );
+            vetIdentityValues_4437( s, "t_identity2_4437", 2, 3 );
+
+            if ( supportsSequences )
+            {
+                vetSequenceValue( s, "seq1_4437", -2147483642, -2147483637 );
+                vetSequenceValue( s, "seq2_4437", -2147483647, -2147483642 );
+            }
+            
+            break;
+
+        case PH_HARD_UPGRADE: // boot with new version and hard-upgrade
+            s.execute( "insert into t_identity1_4437( a ) values ( 400 )" );
+            vetIdentityValues_4437( s, "t_identity1_4437", 4, 24 );
+
+            s.execute( "insert into t_identity2_4437( a ) values ( 300 )" );
+            vetIdentityValues_4437( s, "t_identity2_4437", 3, 23 );
+
+            if ( supportsSequences )
+            {
+                vetSequenceValue( s, "seq1_4437", -2147483637, -2147483617 );
+                vetSequenceValue( s, "seq2_4437", -2147483642, -2147483622 );
+            }
+            
+            break;
+        }
+        
+        s.close();
+    }
+    private void    vetIdentityValues_4437( Statement s, String tableName, int expectedRowCount,
int expectedSyscolumnsValue ) throws Exception
+    {
+        vetTable( s, tableName, expectedRowCount );
+
+        ResultSet rs = s.executeQuery
+            (
+             "select c.autoincrementvalue\n" +
+             "from sys.syscolumns c, sys.systables t\n" +
+             "where t.tablename = '" + tableName.toUpperCase() + "'\n" +
+             "and t.tableid = c.referenceid\n" +
+             "and c.columnname = 'B'"
+             );
+        rs.next();
+        int    actualSyscolumnsValue = rs.getInt( 1 );
+        vetValues( expectedSyscolumnsValue, actualSyscolumnsValue );
+        rs.close();
+    }
+    private void    vetSequenceValue( Statement s, String sequenceName, int expectedSequenceValue,
int expectedSyssequencesValue ) throws Exception
+    {
+        ResultSet   rs = s.executeQuery( "values ( next value for " + sequenceName + " )"
);
+        rs.next();
+        int actualSequenceValue = rs.getInt( 1 );
+        vetValues( expectedSequenceValue, actualSequenceValue );
+        rs.close();
+
+        rs = s.executeQuery
+            (
+             "select currentvalue\n" +
+             "from sys.syssequences\n" +
+             "where sequencename = '" + sequenceName.toUpperCase() + "'\n"
+             );
+        rs.next();
+        int    actualSyssequencesValue = rs.getInt( 1 );
+        vetValues( expectedSyssequencesValue, actualSyssequencesValue );
+        rs.close();
+    }
+    private void    vetTable( Statement s, String tableName, int expectedRowCount ) throws
Exception
+    {
+        int     actualRowCount = 0;
+        int     lastValue = 0;
+
+        ResultSet   rs = s.executeQuery( "select * from " + tableName + " order by a" );
+
+        while( rs.next() )
+        {
+            actualRowCount++;
+            
+            int currentValue = rs.getInt( 2 );
+            if ( actualRowCount > 1 )
+            {
+                assertTrue( currentValue > lastValue );
+            }
+            lastValue = currentValue;
+        }
+        rs.close();
+
+        vetValues( expectedRowCount, actualRowCount );
+    }
+    private void    vetValues( int expected, int actual )   throws Exception
+    {
+        assertEquals
+            (
+             getOldVersionString(),
+             expected,
+             actual
+             );
+    }
 
 }

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?rev=1195476&r1=1195475&r2=1195476&view=diff
==============================================================================
--- 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
Mon Oct 31 14:31:23 2011
@@ -195,8 +195,6 @@ class UpgradeRun extends UpgradeClassLoa
                 	suite.addTest(Changes10_6.suite(phase));
                 if (oldMinor < 7)
                 	suite.addTest(Changes10_7.suite(phase));
-                if ( lessThan( version, new int[] { 10, 8, 1, 6 } ) )
-                { suite.addTest(Changes10_8_2.suite(phase)); }
                 if (oldMinor < 9)
                 	suite.addTest(Changes10_9.suite(phase));
             }



Mime
View raw message