directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1779296 - /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Date Wed, 18 Jan 2017 07:33:49 GMT
Author: elecharny
Date: Wed Jan 18 07:33:49 2017
New Revision: 1779296

URL: http://svn.apache.org/viewvc?rev=1779296&view=rev
Log:
o Removed useless import
o Used a try-with-resource for a connection

Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=1779296&r1=1779295&r2=1779296&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Wed Jan 18 07:33:49 2017
@@ -38,7 +38,6 @@ import java.util.UUID;
 
 import javax.naming.Context;
 import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
 import javax.naming.PartialResultException;
 import javax.naming.ReferralException;
 import javax.naming.directory.Attributes;
@@ -52,8 +51,6 @@ import javax.naming.directory.SearchResu
 import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.LdapName;
 
-import netscape.ldap.LDAPException;
-
 import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.csn.Csn;
@@ -1158,37 +1155,41 @@ public class AddIT extends AbstractLdapT
     {
         // Limit the PDU size to 1024
         getLdapServer().getDirectoryService().setMaxPDUSize( 1024 );
-        LdapConnection connection = new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME,
getLdapServer().getPort() );
-        connection.bind( "uid=admin,ou=system", "secret" );
-
-        // Inject a 1024 bytes long description
-        StringBuilder sb = new StringBuilder();
-
-        for ( int i = 0; i < 128; i++ )
-        {
-            sb.append( "0123456789ABCDEF" );
-        }
-
-        Attribute description = new DefaultAttribute( "description", sb.toString() );
-
-        try
-        {
-            Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
description );
-            connection.modify( "cn=the person, ou=system", modification );
-            fail();
-        }
-        catch ( Exception e )
+        
+        try ( LdapConnection connection = new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME,
getLdapServer().getPort() ) )
         {
-            // We are expecting the session to be close here.
-            if ( connection.isConnected() )
+            connection.bind( "uid=admin,ou=system", "secret" );
+    
+            // Inject a 1024 bytes long description
+            StringBuilder sb = new StringBuilder();
+    
+            for ( int i = 0; i < 128; i++ )
             {
-                // Race condition:
-                // Upon NoticeOfDisconnection the API sends an abandon request but does not
immediately close the connection.
-                // So at this point it is not guaranteed that the connnection is already
closed.
-                // TODO: This is just a workaround, better check the connection for any outstanding
abandon requests
-                Thread.sleep( 1000 );
+                sb.append( "0123456789ABCDEF" );
+            }
+    
+            Attribute description = new DefaultAttribute( "description", sb.toString() );
+    
+            try
+            {
+                Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
description );
+                connection.modify( "cn=the person, ou=system", modification );
+                fail();
+            }
+            catch ( Exception e )
+            {
+                // We are expecting the session to be close here.
+                if ( connection.isConnected() )
+                {
+                    // Race condition:
+                    // Upon NoticeOfDisconnection the API sends an abandon request but does
not immediately close the connection.
+                    // So at this point it is not guaranteed that the connnection is already
closed.
+                    // TODO: This is just a workaround, better check the connection for any
outstanding abandon requests
+                    Thread.sleep( 1000 );
+                }
+                
+                assertFalse( connection.isConnected() );
             }
-            assertFalse( connection.isConnected() );
         }
     }
 



Mime
View raw message