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 ka...@apache.org on 2014/07/14 11:58:54 UTC

svn commit: r1610373 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java

Author: kahatlen
Date: Mon Jul 14 09:58:53 2014
New Revision: 1610373

URL: http://svn.apache.org/r1610373
Log:
DERBY-6342: failure in ConglomerateSharingTest.testConstraintDrops

Accept different errors from statements that violate multiple
constraints, since it's not deterministic which constraint is checked
first.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java?rev=1610373&r1=1610372&r2=1610373&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConglomerateSharingTest.java Mon Jul 14 09:58:53 2014
@@ -25,6 +25,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Arrays;
 import junit.framework.Test;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
@@ -266,12 +267,24 @@ public final class ConglomerateSharingTe
 
         // Make sure non-dropped constraints are still enforced.
 
+        // This statement attempts to insert a duplicate in the C column.
+        // This violates both the unique index DROPC_UIX2 and the unique
+        // constraint DROPC_UC1. Additionally, the backing index of the
+        // foreign key DROPC_FK2 is a unique index. It is not deterministic
+        // which index will be checked first, so accept any of the three.
         checkStatementError("23505", st,
-            "insert into dropc_t2 values (1, 2, 4)", "DROPC_UIX2");
+            "insert into dropc_t2 values (1, 2, 4)",
+            "DROPC_UIX2", "DROPC_UC1", "DROPC_FK2");
 
+        // This statement violates the foreign key DROPC_FK1. It also
+        // violates the same unique constraints/indexes as the previous
+        // statement (duplicate value in column C). Foreign key violations
+        // are checked before unique index violations, so expect the error
+        // to be reported as a violation of DROPC_FK1.
         checkStatementError("23503", st,
             "insert into dropc_t2 values (2, 2, 4)", "DROPC_FK1");
 
+        // This statement violates the foreign key DROPC_FK2.
         checkStatementError("23503", st,
             "insert into dropc_t2 values (1, 2, 3)", "DROPC_FK2");
 
@@ -302,12 +315,22 @@ public final class ConglomerateSharingTe
 
         // Make sure non-dropped constraints are still enforced.
 
+        // This statement attempts to insert a duplicate into the unique
+        // index DROPC_UIX2 and the unique backing index of the foreign
+        // key constraint DROPC_FK2. It is not deterministic which of the
+        // two indexes will be inserted into first, so accept both in the
+        // error message.
         checkStatementError("23505", st,
-            "insert into dropc_t2 values (1, 2, 4)", "DROPC_UIX2");
+            "insert into dropc_t2 values (1, 2, 4)", "DROPC_UIX2", "DROPC_FK2");
 
+        // This statement both violates the foreign key DROPC_FK1 and
+        // attempts to insert a duplicate value into the column C. Expect
+        // foreign key constraint violations to be checked before unique
+        // index violations.
         checkStatementError("23503", st,
             "insert into dropc_t2 values (2, 2, 4)", "DROPC_FK1");
 
+        // This statement violates the foreign key DROPC_FK2.
         checkStatementError("23503", st,
             "insert into dropc_t2 values (1, 2, 3)", "DROPC_FK2");
 
@@ -740,9 +763,16 @@ public final class ConglomerateSharingTe
      *     constraint name in its message.  This is intended to
      *     be used for uniqueness and foreign key violations,
      *     esp. SQLSTATE 23503 and 23505.
+     *
+     * @param sqlState the expected SQLState of the error
+     * @param st the statement to use for execution
+     * @param query the SQL text to execute
+     * @param violatedConstraints the constraints or indexes that are
+     *   violated by this statement; expect the error message to mention
+     *   at least one of them
      */
     private void checkStatementError(String sqlState,
-        Statement st, String query, String ixOrConstraint)
+        Statement st, String query, String... violatedConstraints)
         throws SQLException
     {
         try {
@@ -754,12 +784,22 @@ public final class ConglomerateSharingTe
         } catch (SQLException se) {
 
             assertSQLState(sqlState, se);
-            if (se.getMessage().indexOf(ixOrConstraint) == -1)
+
+            boolean foundConstraint = false;
+            for (String c : violatedConstraints) {
+                if (se.getMessage().contains(c)) {
+                    foundConstraint = true;
+                    break;
+                }
+            }
+
+            if (!foundConstraint)
             {
                 fail("Error " + sqlState + " should have been caused " +
-                    "by index/constraint '" + ixOrConstraint + "' but " +
-                    "'" + ixOrConstraint + "' did not appear in the " +
-                    "following error message: \"" + se.getMessage() + "\"");
+                    "by one of the following indexes/constraints " +
+                    Arrays.toString(violatedConstraints) +
+                    ", but none of them appeared in the error message.",
+                    se);
             }
 
         }