db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1455156 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbc4/LoginTimeoutTest.java junit/BaseTestCase.java
Date Mon, 11 Mar 2013 14:19:15 GMT
Author: rhillegas
Date: Mon Mar 11 14:19:14 2013
New Revision: 1455156

URL: http://svn.apache.org/r1455156
Log:
DERBY-6094: Create the database before running login timeout tests, in order to prevent slow
database creation from killing the LoginTimeoutTest.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.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/jdbc4/LoginTimeoutTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java?rev=1455156&r1=1455155&r2=1455156&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java
Mon Mar 11 14:19:14 2013
@@ -36,6 +36,7 @@ import junit.framework.*;
 
 import org.apache.derby.authentication.UserAuthenticator;
 
+import org.apache.derbyTesting.junit.BaseTestCase;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
@@ -68,6 +69,8 @@ public class LoginTimeoutTest extends Ba
     private static  final   boolean SUCCEED = true;
     private static  final   boolean FAIL = false;
 
+    private static  final   int LONG_TIMEOUT = 10;
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // STATE
@@ -89,6 +92,8 @@ public class LoginTimeoutTest extends Ba
     /** User authenticator which sleeps for a while */
     public  static  final   class   SluggishAuthenticator   implements  UserAuthenticator
     {
+        public  static  boolean debugPrinting = false;
+        
         private static  final   long    MILLIS_PER_SECOND = 1000L;
         
         public  static  long    secondsToSleep = 2;
@@ -107,12 +112,23 @@ public class LoginTimeoutTest extends Ba
         {
             // sleepy...
             try {
+                long    sleepTime = secondsToSleep * MILLIS_PER_SECOND;
+                printText( "SluggishAuthenticator going to sleep for " + sleepTime + " milliseconds."
);
                 Thread.sleep( secondsToSleep * MILLIS_PER_SECOND );
+                printText( "...SluggishAuthenticator waking up after " + sleepTime + " milliseconds."
);
             } catch (Exception e) { throw new SQLException( e.getMessage(), e ); }
 
             // ...and vacuous.
             return returnValue;
         }
+        
+        private static  void    printText( String text )
+        {
+            if ( debugPrinting )
+            {
+                BaseTestCase.println( text );
+            }
+        }
     }
 
     /** Behavior shared by DataSource and DriverManager */
@@ -250,7 +266,11 @@ public class LoginTimeoutTest extends Ba
      */
     public  void    testBasic() throws Exception
     {
-        DataSource  ds = JDBCDataSource.getDataSource();
+        SluggishAuthenticator.debugPrinting = TestConfiguration.getCurrent().isVerbose();
+
+        // make sure the database is created in order to eliminate asymmetries
+        // in running the tests
+        openDefaultConnection( RUTH, RUTH_PASSWORD );
         
         vetConnector( new DriverManagerConnector( this ), true );
         vetConnector( new DataSourceConnector( JDBCDataSource.getDataSource() ), true );
@@ -262,21 +282,25 @@ public class LoginTimeoutTest extends Ba
     }
     private void    vetConnector( Connector connector, boolean shouldSucceed ) throws Exception
     {
-        tryTimeout( connector, 1, FAIL && shouldSucceed );
-        tryTimeout( connector, 10, SUCCEED && shouldSucceed );
-        tryTimeout( connector, 0, SUCCEED && shouldSucceed );
-
-        // revert to default state
-        connector.setLoginTimeout( 0 );
+        try {
+            tryTimeout( connector, 1, FAIL && shouldSucceed );
+            tryTimeout( connector, LONG_TIMEOUT, SUCCEED && shouldSucceed );
+            tryTimeout( connector, 0, SUCCEED && shouldSucceed );
+        }
+        finally
+        {
+            // revert to default state
+            connector.setLoginTimeout( 0 );
+        }
     }
-    private static  void    tryTimeout( Connector connector, int timeout, boolean shouldSucceed
) throws Exception
+    private void    tryTimeout( Connector connector, int timeout, boolean shouldSucceed )
throws Exception
     {
         println( "Setting timeout " + timeout + " on " + connector );
         connector.setLoginTimeout( timeout );
 
         tryTimeout( connector, shouldSucceed );
     }
-    private static  void    tryTimeout( Connector connector, boolean shouldSucceed ) throws
Exception
+    private void    tryTimeout( Connector connector, boolean shouldSucceed ) throws Exception
     {
         long    startTime = System.currentTimeMillis();
         
@@ -287,7 +311,7 @@ public class LoginTimeoutTest extends Ba
         }
         catch (SQLException se)
         {
-            if ( shouldSucceed ) { fail( "Should have been able to connect!" ); }
+            if ( shouldSucceed ) { failWithTrace( se, "Should have been able to connect!"
); }
 
             assertTrue( "Didn't expect to see a " + se.getClass().getName(), (se instanceof
SQLTimeoutException) );
             assertSQLState( LOGIN_TIMEOUT, se );
@@ -299,22 +323,26 @@ public class LoginTimeoutTest extends Ba
     }
     private void    vetExceptionPassthrough() throws Exception
     {
-        println( "Verifying that exceptions are not swallowed by the embedded login timer."
);
-        // set a long timeout which we won't exceed
-        DriverManager.setLoginTimeout( 10 );
+        try {
+            println( "Verifying that exceptions are not swallowed by the embedded login timer."
);
+            // set a long timeout which we won't exceed
+            DriverManager.setLoginTimeout( LONG_TIMEOUT );
 
-        // tell the authenticator to always fail
-        SluggishAuthenticator.returnValue = false;
+            // tell the authenticator to always fail
+            SluggishAuthenticator.returnValue = false;
 
-        try {
-            openDefaultConnection( RUTH, RUTH_PASSWORD );
-            fail( "Didn't expect to get a connection!" );
+            try {
+                openDefaultConnection( RUTH, RUTH_PASSWORD );
+                fail( "Didn't expect to get a connection!" );
+            }
+            catch (SQLException se) { assertSQLState( LOGIN_FAILED, se ); }
+        }
+        finally
+        {
+            // return to default position
+            DriverManager.setLoginTimeout( 0 );
+            SluggishAuthenticator.returnValue = true;
         }
-        catch (SQLException se) { assertSQLState( LOGIN_FAILED, se ); }
-
-        // return to default position
-        DriverManager.setLoginTimeout( 0 );
-        SluggishAuthenticator.returnValue = true;
     }
     private void    vetServerTimeouts() throws Exception
     {
@@ -332,7 +360,7 @@ public class LoginTimeoutTest extends Ba
         Connector   connector = new DriverManagerConnector( this );
 
         vetServerTimeout( controlConnection, connector, 1, FAIL );
-        vetServerTimeout( controlConnection, connector, 10, SUCCEED );
+        vetServerTimeout( controlConnection, connector, LONG_TIMEOUT, SUCCEED );
         vetServerTimeout( controlConnection, connector, 0, SUCCEED );
 
         // reset server timeout to default
@@ -365,4 +393,17 @@ public class LoginTimeoutTest extends Ba
         DriverManager.setLoginTimeout( seconds );
     }
     
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** Fail and print a stack trace */
+    private static void    failWithTrace( Throwable t, String message )
+    {
+        printStackTrace( t );
+        fail( message );
+    }
+
 }

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=1455156&r1=1455155&r2=1455156&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 Mon Mar
11 14:19:14 2013
@@ -200,6 +200,7 @@ public abstract class BaseTestCase
     public static void println(final String text) {
         if (TestConfiguration.getCurrent().isVerbose()) {
             out.println("DEBUG: " + text);
+            out.flush();
         }
     }
 



Mime
View raw message