db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1575065 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.java
Date Thu, 06 Mar 2014 22:01:06 GMT
Author: myrnavl
Date: Thu Mar  6 22:01:05 2014
New Revision: 1575065

URL: http://svn.apache.org/r1575065
Log:
DERBY-6250; nightly regression test failure: jdbc4.LoginTimeoutTest testBasic client/server
java.sql.SQLTimeoutException: XBDA0, Login timeout Exceeded and junit.framework.AssertionFailedError:
Should not have been able to connect!
  attempt to add more time for failing situations, and add more details to error message on
failure.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/LoginTimeoutTest.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=1575065&r1=1575064&r2=1575065&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
Thu Mar  6 22:01:05 2014
@@ -290,7 +290,14 @@ public class LoginTimeoutTest extends Ba
     private void    vetConnector( Connector connector, boolean shouldSucceed ) throws Exception
     {
         try {
+            // sometimes this succeeds when we expect not, see DERBY-6250,
+            // give more time to the slug sleep
+            if (usingEmbedded())
+                SluggishAuthenticator.secondsToSleep = 4;
             tryTimeout( connector, 1, FAIL && shouldSucceed );
+            // set back.
+            if (usingEmbedded())
+                SluggishAuthenticator.secondsToSleep = 2;
             tryTimeout( connector, LONG_TIMEOUT, SUCCEED && shouldSucceed );
             tryTimeout( connector, 0, SUCCEED && shouldSucceed );
         }
@@ -298,6 +305,8 @@ public class LoginTimeoutTest extends Ba
         {
             // revert to default state
             connector.setLoginTimeout( 0 );
+            // set sluggishauthenticator sleep back
+            SluggishAuthenticator.secondsToSleep = 2;
         }
     }
     private void    tryTimeout( Connector connector, int timeout, boolean shouldSucceed )
throws Exception
@@ -315,7 +324,17 @@ public class LoginTimeoutTest extends Ba
             Connection  conn = connector.getConnection( RUTH, RUTH_PASSWORD );
             println( "    Got a " + conn.getClass().getName() );
             conn.close();
-            if ( !shouldSucceed )   { fail( "Should not have been able to connect!" ); }
+            if ( !shouldSucceed )   
+            {
+                // sometimes the connect succeeds, see DERBY-6250. 
+                // adding more details to fail message.
+                long    duration = System.currentTimeMillis() - startTime;
+                String message ="Should not have been able to connect! \n " +
+                "        connector: " + connector +
+                "        Experiment took " + duration + " milliseconds. \n " +
+                "        seconds sleep time was: " + SluggishAuthenticator.secondsToSleep;
+                fail( message ); 
+            }
         }
         catch (SQLException se)
         {
@@ -365,6 +384,11 @@ public class LoginTimeoutTest extends Ba
             "external name '" + getClass().getName() + ".setLoginTimeout'";
         println( createProc );
         controlConnection.prepareStatement( createProc ).execute();
+        createProc = 
+                "create procedure setAuthenticatorSleep( seconds int ) language java parameter
style java no sql\n" +
+                "external name '" + getClass().getName() + ".setAuthenticatorSleep'";
+        controlConnection.prepareStatement( createProc ).execute();
+        println( createProc );
 
         Connector   connector = new DriverManagerConnector( this );
 
@@ -381,6 +405,14 @@ public class LoginTimeoutTest extends Ba
         throws Exception
     {
         setServerTimeout( controlConnection, serverTimeout );
+        // Sometimes we get an unexpected connection when we expect
+        // the timeout to work, see DERBY-6250.
+        // Setting the sleep Authenticator sleep time longer on the server.
+        // for those cases to make the chance of this occurring smaller.
+        if (!shouldSucceed)
+            setServerAuthenticatorSleep(controlConnection, 4);
+        else 
+            setServerAuthenticatorSleep(controlConnection, 2);
         vetConnector( connector, shouldSucceed );
     }
     private void    setServerTimeout( Connection conn, int seconds ) throws Exception
@@ -391,6 +423,16 @@ public class LoginTimeoutTest extends Ba
         cs.close();
     }
     
+    private void    setServerAuthenticatorSleep( Connection conn, int seconds )
+            throws Exception
+    {
+        CallableStatement   cs = conn.prepareCall( "call setAuthenticatorSleep( ? )" );
+        cs.setInt( 1, seconds );
+        cs.execute();
+        cs.close();
+    }
+    
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // SQL ROUTINES
@@ -403,6 +445,12 @@ public class LoginTimeoutTest extends Ba
         DriverManager.setLoginTimeout( seconds );
     }
     
+    /** Routine to set the SluggishAuthenticator Sleep 
+     *  time on the server */
+    public  static  void    setAuthenticatorSleep( int seconds ) throws Exception
+    {
+        SluggishAuthenticator.secondsToSleep = seconds ;
+    }
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message