db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1347888 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/ functionTests/tests/memorydb/ junit/
Date Fri, 08 Jun 2012 06:13:44 GMT
Author: kristwaa
Date: Fri Jun  8 06:13:44 2012
New Revision: 1347888

URL: http://svn.apache.org/viewvc?rev=1347888&view=rev
Log:
DERBY-5797: AssertionFailedError in functionTests.tests.lang.UpdateStatisticsTest.testDisposableStatsEagerness

Make the test sleep for at least one tick of the system timer to ensure the
comparison of statistics creation timestamps are valid in the normal case
(i.e. when there is no bug).
Added two utility methods to BaseTestCase:
 o sleep(long ms)
 o sleepAtLeastOneTick()
Removed two existing sleep-methods in test classes (note that the one taking
numbers of seconds as argument was unused).

Patch file: derby-5797-1a-sleep_a_tick.diff

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/DropWhileConnectingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java?rev=1347888&r1=1347887&r2=1347888&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
Fri Jun  8 06:13:44 2012
@@ -332,15 +332,6 @@ public class SecurityPolicyReloadingTest
     }
 
     /**
-     * A handy method for debugging.
-     */
-    public static void sleep( long numberOfSeconds )
-        throws Exception
-    {
-        Thread.currentThread().sleep( numberOfSeconds * (1000L) );
-    }
-
-    /**
      * Try to change the policy file.
      */
     private void changePolicyFile( Connection conn, String newPolicyFileName, boolean shouldSucceed,
String expectedSQLState )

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java?rev=1347888&r1=1347887&r2=1347888&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
Fri Jun  8 06:13:44 2012
@@ -559,14 +559,10 @@ public class UpdateStatisticsTest extend
         stats.assertNoStatsTable(tbl_fk);
         stats.assertTableStats(tbl, 4);
         IndexStatsUtil.IdxStats[] tbl_stats_0 = stats.getStatsTable(tbl);
-        // Avoid timestamp comparison problems on super-fast machines...
-        try {
-            Thread.sleep(10);
-        } catch (InterruptedException ie) {
-            Thread.currentThread().interrupt();
-        }
 
         // Run the update statistics procedure.
+        // Sleep at least one tick to ensure the timestamps differ.
+        sleepAtLeastOneTick();
         ps = prepareStatement(
                 "call syscs_util.syscs_update_statistics('APP', ?, ?)");
         ps.setNull(2, Types.VARCHAR);
@@ -586,6 +582,7 @@ public class UpdateStatisticsTest extend
         }
 
         // Now make sure updating one index doesn't modify the others' stats.
+        sleepAtLeastOneTick();
         ps.setString(1, tbl);
         ps.setString(2, nuIdx);
         ps.execute();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/DropWhileConnectingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/DropWhileConnectingTest.java?rev=1347888&r1=1347887&r2=1347888&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/DropWhileConnectingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/DropWhileConnectingTest.java
Fri Jun  8 06:13:44 2012
@@ -103,21 +103,6 @@ public class DropWhileConnectingTest
         println(report.toString());
     }
 
-    /**
-     * Puts the current thread to sleep, but <em>does not</em> guarantee
-     * that the thread sleeps for the specified amount of time (interrupts are
-     * not handled).
-     *
-     * @param millis number of milliseconds to sleep
-     */
-    private static void sleep(long millis) {
-        try {
-            Thread.sleep(millis);
-        } catch (InterruptedException ie) {
-            alarm("sleep call interrupted");
-        }
-    }
-
     public static Test suite() {
        return new TestSuite(DropWhileConnectingTest.class);
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1347888&r1=1347887&r2=1347888&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Fri Jun
 8 06:13:44 2012
@@ -949,6 +949,24 @@ public abstract class BaseTestCase
         assertExecJavaCmdAsExpected(new String[] { "OK (1 test)" }, cmd, 0);
     }
 
+    /** Returns once the system timer has advanced at least one tick. */
+    public static void sleepAtLeastOneTick() {
+        long currentTime = System.currentTimeMillis(); 
+        while (System.currentTimeMillis() == currentTime) {
+            sleep(1);
+        }
+    }
+
+    /** Makes the current thread sleep up to {@code ms} milliseconds. */
+    public static void sleep(long ms) {
+        try {
+            Thread.sleep(ms);
+        } catch (InterruptedException ie) {
+            // For now we just print a warning if we are interrupted.
+            alarm("sleep interrupted");
+        }
+    }
+
     private static String traceClientType() {
        if (TestConfiguration.getCurrent().getJDBCClient().isEmbedded()) {
             return "(emb)";



Mime
View raw message