Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 62CDF467A for ; Fri, 1 Jul 2011 18:08:49 +0000 (UTC) Received: (qmail 82836 invoked by uid 500); 1 Jul 2011 18:08:49 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 82766 invoked by uid 500); 1 Jul 2011 18:08:48 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 82759 invoked by uid 99); 1 Jul 2011 18:08:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 18:08:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 18:08:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0602B238890D; Fri, 1 Jul 2011 18:08:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1142013 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests: Changes10_8_2.java UpgradeChange.java UpgradeRun.java Date: Fri, 01 Jul 2011 18:08:22 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110701180823.0602B238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhillegas Date: Fri Jul 1 18:08:22 2011 New Revision: 1142013 URL: http://svn.apache.org/viewvc?rev=1142013&view=rev Log: DERBY-4437: Add more upgrade tests for the changes to the behavior of sequences/identities. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java (with props) Modified: 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 Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java?rev=1142013&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java Fri Jul 1 18:08:22 2011 @@ -0,0 +1,240 @@ +/* + +Derby - Class org.apache.derbyTesting.functionTests.tests.upgradeTests.Changes10_8_2 + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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.upgradeTests; + +import org.apache.derbyTesting.junit.SupportFilesSetup; + +import java.sql.Statement; +import java.sql.ResultSet; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.derbyTesting.junit.JDBC; + + +/** + * Upgrade test cases for 10.8.2. + * If the old version is 10.8.2 or later then these tests + * will not be run. + *
+ 10.8.2 Upgrade issues + +
    +
  • Performance/concurrency changes to identity columns and sequences (see DERBY-4437).
  • +
+ + */ +public class Changes10_8_2 extends UpgradeChange +{ + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTANTS + // + /////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////// + // + // STATE + // + /////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTOR + // + /////////////////////////////////////////////////////////////////////////////////// + + public Changes10_8_2(String name) + { + super(name); + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // JUnit BEHAVIOR + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + * Return the suite of tests to test the changes made in 10.8. + * @param phase an integer that indicates the current phase in + * the upgrade test. + * @return the test suite created. + */ + public static Test suite(int phase) { + TestSuite suite = new TestSuite("Upgrade test for 10.8.2"); + + suite.addTestSuite(Changes10_8_2.class); + return new SupportFilesSetup((Test) suite); + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // TESTS + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + * Make sure that generator-based identity columns don't break upgrade/downgrade. + * See DERBY-4437. + */ + 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( 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( 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( s, "t_identity2_4437", 1, 21 ); + + if ( supportsSequences ) + { + vetSequenceValue( s, "seq1_4437", -2147483647, -2147483627 ); + + 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( s, "t_identity1_4437", 3, 4 ); + + s.execute( "insert into t_identity2_4437( a ) values ( 200 )" ); + vetIdentityValues( s, "t_identity2_4437", 2, 3 ); + + if ( supportsSequences ) + { + vetSequenceValue( s, "seq1_4437", -2147483646, -2147483641 ); + 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( s, "t_identity1_4437", 4, 24 ); + + s.execute( "insert into t_identity2_4437( a ) values ( 300 )" ); + vetIdentityValues( s, "t_identity2_4437", 3, 23 ); + + if ( supportsSequences ) + { + vetSequenceValue( s, "seq1_4437", -2147483641, -2147483621 ); + vetSequenceValue( s, "seq2_4437", -2147483642, -2147483622 ); + } + + break; + } + + s.close(); + } + private void vetIdentityValues( 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 + ); + } + +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_8_2.java ------------------------------------------------------------------------------ svn:eol-style = native 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?rev=1142013&r1=1142012&r2=1142013&view=diff ============================================================================== --- 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 Fri Jul 1 18:08:22 2011 @@ -178,5 +178,21 @@ abstract class UpgradeChange extends Bas { return (getOldMajor() == requiredMajor) && (getOldMinor() == requiredMinor); - } + } + + /** + * Pretty-print the phase. + */ + String getPhaseString() + { + return PHASES[ getPhase() ]; + } + + /** + * Pretty-print the original version number. + */ + String getOldVersionString() + { + return "( " + getOldMajor() + ", " + getOldMinor() + ", " + getOldFixPack() + ", " + getOldPoint() + " )"; + } } 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=1142013&r1=1142012&r2=1142013&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 Fri Jul 1 18:08:22 2011 @@ -195,6 +195,8 @@ 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)); } @@ -239,6 +241,21 @@ class UpgradeRun extends UpgradeClassLoa return TestConfiguration.connectionDSDecorator(suite); } + /** + * Return true if and only if the left version is less than the + * right version. + */ + private static boolean lessThan( int[] left, int[] right ) + { + for (int i = 0; i < left.length; i++) + { + if ( left[ i ] < right[ i ] ) return true; + if ( left[ i ] > right[ i ] ) return false; + } + + // Versions match exactly. That is, not less than. + return false; + } /** * When running against certains old releases in Java SE 6