db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r523621 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/DistinctTest.java functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java junit/JDBC.java
Date Thu, 29 Mar 2007 08:33:50 GMT
Author: kahatlen
Date: Thu Mar 29 01:33:48 2007
New Revision: 523621

URL: http://svn.apache.org/viewvc?view=rev&rev=523621
Log:
DERBY-2493 (partial) Use unsynchronized collections in BackingStoreHashtable

Updated some tests so that they are not sensitive to the order of the
rows in the returned ResultSet.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java?view=diff&rev=523621&r1=523620&r2=523621
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DistinctTest.java
Thu Mar 29 01:33:48 2007
@@ -538,7 +538,9 @@
                                      {"1", "1"},
         		                     {"2", "2"}, 
         		                     {"2", "1"} };
-		JDBC.assertFullResultSet(s.executeQuery("select * from td, (select distinct x from td)
as sub(x)"), expected);	
+		JDBC.assertUnorderedResultSet(s.executeQuery(
+			"select * from td, (select distinct x from td) as sub(x)"),
+			expected);
 		
 		s.execute("drop table td");
 		s.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?view=diff&rev=523621&r1=523620&r2=523621
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Thu Mar 29 01:33:48 2007
@@ -41,6 +41,7 @@
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 
 // TODO:
 // - Add parameters to all PreparedStatements that support it
@@ -709,11 +710,11 @@
         for (int i = 0; i < expected.length; ++i) {
             tst.setString(1,new Integer(i) +"_");
             ResultSet rs = tst.executeQuery();
-            assertResultSet("?="+i+"_", expected[i], rs);
+            JDBC.assertUnorderedResultSet(rs, expected[i], false);
 
             // Re-execute tst with the same parameters
             rs = tst.executeQuery();
-            assertResultSet("R?="+i+"_", expected[i], rs);
+            JDBC.assertUnorderedResultSet(rs, expected[i], false);
 
             if (i < mgrs.length) {
                 del.setObject(1, mgrs[i]);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=523621&r1=523620&r2=523621
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Thu Mar 29 01:33:48
2007
@@ -833,6 +833,87 @@
     }
 
     /**
+     * Assert that the ResultSet contains the same rows as the specified
+     * two-dimensional array. The order of the results is ignored. Convert the
+     * results to trimmed strings before comparing. The ResultSet object will
+     * be closed.
+     *
+     * @param rs the ResultSet to check
+     * @param expectedRows the expected rows
+     */
+    public static void assertUnorderedResultSet(
+            ResultSet rs, String[][] expectedRows) throws SQLException {
+        assertUnorderedResultSet(rs, expectedRows, true);
+    }
+
+    /**
+     * Assert that the ResultSet contains the same rows as the specified
+     * two-dimensional array. The order of the results is ignored. Objects are
+     * read out of the ResultSet with the <code>getObject()</code> method and
+     * compared with <code>equals()</code>. If the
+     * <code>asTrimmedStrings</code> is <code>true</code>, the objects
are read
+     * with <code>getString()</code> and trimmed before they are compared. The
+     * ResultSet object will be closed when this method returns.
+     *
+     * @param rs the ResultSet to check
+     * @param expectedRows the expected rows
+     * @param asTrimmedStrings whether the object should be compared as trimmed
+     * strings
+     */
+    public static void assertUnorderedResultSet(
+            ResultSet rs, Object[][] expectedRows, boolean asTrimmedStrings)
+                throws SQLException {
+
+        if (expectedRows.length == 0) {
+            assertEmpty(rs);
+        }
+
+        ResultSetMetaData rsmd = rs.getMetaData();
+        Assert.assertEquals("Unexpected column count",
+                            expectedRows[0].length, rsmd.getColumnCount());
+
+        ArrayList expected = new ArrayList(expectedRows.length);
+        for (int i = 0; i < expectedRows.length; i++) {
+            Assert.assertEquals("Different column count in expectedRows",
+                                expectedRows[0].length, expectedRows[i].length);
+            if (asTrimmedStrings) {
+                ArrayList row = new ArrayList(expectedRows[i].length);
+                for (int j = 0; j < expectedRows[i].length; j++) {
+                    String val = (String) expectedRows[i][j];
+                    row.add(val == null ? null : val.trim());
+                }
+                expected.add(row);
+            } else {
+                expected.add(Arrays.asList(expectedRows[i]));
+            }
+        }
+
+        ArrayList actual = new ArrayList(expectedRows.length);
+        while (rs.next()) {
+            ArrayList row = new ArrayList(expectedRows[0].length);
+            for (int i = 1; i <= expectedRows[0].length; i++) {
+                if (asTrimmedStrings) {
+                    String s = rs.getString(i);
+                    row.add(s == null ? null : s.trim());
+                } else {
+                    row.add(rs.getObject(i));
+                }
+            }
+            actual.add(row);
+        }
+        rs.close();
+
+        Assert.assertEquals("Unexpected row count",
+                            expectedRows.length, actual.size());
+
+        Assert.assertTrue("Missing rows in ResultSet",
+                          actual.containsAll(expected));
+
+        actual.removeAll(expected);
+        Assert.assertTrue("Extra rows in ResultSet", actual.isEmpty());
+    }
+
+    /**
      * Convert byte array to String.
      * Each byte is converted to a hexadecimal string representation.
      *



Mime
View raw message