directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1590296 - in /directory/shared/trunk/ldap/client/api/src: main/java/org/apache/directory/ldap/client/api/ test/java/org/ test/java/org/apache/ test/java/org/apache/directory/ test/java/org/apache/directory/ldap/ test/java/org/apache/direct...
Date Sat, 26 Apr 2014 20:44:31 GMT
Author: seelmann
Date: Sat Apr 26 20:44:31 2014
New Revision: 1590296

URL: http://svn.apache.org/r1590296
Log:
Fix timeout for search operations (DIRAPI-190, DIRSTUDIO-967)

Added:
    directory/shared/trunk/ldap/client/api/src/test/java/org/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1590296&r1=1590295&r2=1590296&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Sat Apr 26 20:44:31 2014
@@ -308,25 +308,23 @@ public class LdapNetworkConnection exten
 
 
     /**
-     * Get the smallest timeout from the client timeout and the connection
+     * Get the largest timeout from the search time limit and the connection
      * timeout.
      */
-    private long getTimeout( long clientTimeout )
+    static long getTimeout( long connectionTimoutInMS, int searchTimeLimitInSeconds )
     {
-        if ( clientTimeout <= 0 )
+        if ( searchTimeLimitInSeconds < 0 )
         {
-            return ( timeout <= 0 ) ? Long.MAX_VALUE : timeout;
+            return connectionTimoutInMS;
         }
-
-        long timeoutMs = clientTimeout * 1000L;
-
-        if ( timeout <= 0 )
+        else if ( searchTimeLimitInSeconds == 0 )
         {
-            return timeoutMs;
+            return Long.MAX_VALUE;
         }
         else
         {
-            return timeout < timeoutMs ? timeout : timeoutMs;
+            long searchTimeLimitInMS = searchTimeLimitInSeconds * 1000L;
+            return Math.max( searchTimeLimitInMS, connectionTimoutInMS );
         }
     }
 
@@ -1709,7 +1707,7 @@ public class LdapNetworkConnection exten
 
         SearchFuture searchFuture = searchAsync( searchRequest );
 
-        long timeout = getTimeout( searchRequest.getTimeLimit() );
+        long timeout = getTimeout( this.timeout, searchRequest.getTimeLimit() );
 
         return new SearchCursorImpl( searchFuture, timeout, TimeUnit.MILLISECONDS );
     }

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java?rev=1590296&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
Sat Apr 26 20:44:31 2014
@@ -0,0 +1,67 @@
+package org.apache.directory.ldap.client.api;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+
+@RunWith(Parameterized.class)
+public class LdapNetworkConnectionTest
+{
+
+    private long connectionTimeoutInMS;
+    private int searchTimeLimitInSeconds;
+    private long expectedTimeoutInMS;
+
+
+    @Parameters(name = "{index}: {0},{1}->{2}")
+    public static Collection<Object[]> data()
+    {
+        return Arrays.asList( new Object[][]
+            {
+                    // index 0: connection timout in ms
+                    // index 1: search time limit in seconds
+                    // index 2: expected timeout in ms
+                    { 2000, -1, 2000, "Invalid search time limit, use connection timeout"
},
+                    { 2000, 0, Long.MAX_VALUE, "Search time limit is 0, use max value" },
+                    { 2000, 1, 2000, "search time limit < connection timeout, use connection
timeout" },
+                    { 2000, 5, 5000, "search time limit > connection timeout, use search
time limit" },
+                    { 2000, Integer.MAX_VALUE, 2147483647000L, "Integer overflow" },
+                    { 30000, -1, 30000, "Invalid search time limit, use connection timeout"
},
+                    { 30000, 0, Long.MAX_VALUE, "Search time limit is 0, use max value" },
+                    { 30000, 1, 30000, "search time limit < connection timeout, use connection
timeout" },
+                    { 30000, 29, 30000, "search time limit < connection timeout, use connection
timeout" },
+                    { 30000, 31, 31000, "search time limit > connection timeout, use search
time limit" },
+                    { 30000, 60, 60000, "search time limit > connection timeout, use search
time limit" },
+                    { Long.MAX_VALUE, -1, Long.MAX_VALUE, "Invalid search time limit, use
connection timeout" },
+                    { Long.MAX_VALUE, 0, Long.MAX_VALUE, "Search time limit is 0, use max
value" },
+                    { Long.MAX_VALUE, 1, Long.MAX_VALUE,
+                        "search time limit < connection timeout, use connection timeout"
},
+            } );
+    }
+
+
+    public LdapNetworkConnectionTest( long connectionTimeoutInMS, int searchTimeLimitInSeconds,
+        long expectedTimeoutInMS, String testDescription )
+    {
+        this.connectionTimeoutInMS = connectionTimeoutInMS;
+        this.searchTimeLimitInSeconds = searchTimeLimitInSeconds;
+        this.expectedTimeoutInMS = expectedTimeoutInMS;
+    }
+
+
+    @Test
+    public void testGetClientTimeout()
+    {
+        long timeout = LdapNetworkConnection.getTimeout( connectionTimeoutInMS, searchTimeLimitInSeconds
);
+        assertEquals( expectedTimeoutInMS, timeout );
+    }
+
+}



Mime
View raw message