Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 87396 invoked from network); 6 May 2009 22:06:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 May 2009 22:06:50 -0000 Received: (qmail 98258 invoked by uid 500); 6 May 2009 22:06:49 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 98196 invoked by uid 500); 6 May 2009 22:06:49 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 98187 invoked by uid 99); 6 May 2009 22:06:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 May 2009 22:06:49 +0000 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 May 2009 22:06:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 16B572388B9A; Wed, 6 May 2009 22:06:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r772447 - /directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java Date: Wed, 06 May 2009 22:06:27 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090506220628.16B572388B9A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Wed May 6 22:06:27 2009 New Revision: 772447 URL: http://svn.apache.org/viewvc?rev=772447&view=rev Log: Added a test for an asynchronous search Modified: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java Modified: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java?rev=772447&r1=772446&r2=772447&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java (original) +++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java Wed May 6 22:06:27 2009 @@ -20,6 +20,8 @@ package org.apache.directory.shared.client.api; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.apache.directory.server.core.integ.Level; import org.apache.directory.server.core.integ.annotations.CleanupLevel; @@ -27,8 +29,15 @@ import org.apache.directory.server.ldap.LdapService; import org.apache.directory.shared.ldap.client.api.LdapConnection; import org.apache.directory.shared.ldap.client.api.exception.LdapException; +import org.apache.directory.shared.ldap.client.api.listeners.SearchListener; +import org.apache.directory.shared.ldap.client.api.messages.Response; +import org.apache.directory.shared.ldap.client.api.messages.SearchRequest; +import org.apache.directory.shared.ldap.client.api.messages.SearchRequestImpl; import org.apache.directory.shared.ldap.client.api.messages.SearchResponse; +import org.apache.directory.shared.ldap.client.api.messages.SearchResultDone; import org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry; +import org.apache.directory.shared.ldap.client.api.messages.SearchResultReference; +import org.apache.directory.shared.ldap.client.api.messages.future.SearchFuture; import org.apache.directory.shared.ldap.cursor.Cursor; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.filter.SearchScope; @@ -53,7 +62,12 @@ { /** The server instance */ public static LdapService ldapService; + + /** A list containing asynchronous results */ + private List entries; + /** A flag set to true when the searchResultDone has been received for an async search operation */ + private boolean done = false; //------------------------------------------------------------------------ // Synchronous Search @@ -170,4 +184,98 @@ } } } + + + /** + * Test a simple async search request + */ + @Test + public void testAsyncSearchRequest() + { + LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() ); + + try + { + connection.bind( "uid=admin,ou=system", "secret" ); + + SearchRequest searchRequest = new SearchRequestImpl(); + searchRequest.setBaseDn( "uid=admin,ou=system" ); + searchRequest.setFilter( "(objectClass=*)" ); + searchRequest.setScope( SearchScope.SUBTREE ); + searchRequest.addAttributes( "*" ); + + entries = new ArrayList(); + + SearchFuture searchFuture = connection.search( searchRequest, new SearchListener() + { + public void entryFound( LdapConnection connection, SearchResultEntry searchResultEntry ) throws LdapException + { + assertFalse( done ); + assertNotNull( searchResultEntry ); + assertEquals( 2, searchResultEntry.getMessageId() ); + entries.add( searchResultEntry ); + + System.out.println( "Received : " + searchResultEntry ); + } + + public void referralFound( LdapConnection connection, SearchResultReference searchResultReference ) throws LdapException + { + assertFalse( done ); + assertNotNull( searchResultReference ); + assertEquals( 2, searchResultReference.getMessageId() ); + entries.add( searchResultReference ); + } + + public void searchDone( LdapConnection connection, SearchResultDone searchResultDone ) throws LdapException + { + assertFalse( done ); + assertNotNull( searchResultDone ); + assertEquals( 2, searchResultDone.getMessageId() ); + done = true; + } + } ); + + int count = 0; + + // Wait for the search to be done + while ( ! searchFuture.isDone() ) + { + Response response = searchFuture.get(); + + if ( response instanceof SearchResultDone ) + { + break; + } + + count ++; + } + + assertEquals( 1, count ); + assertEquals( count, entries.size() ); + + connection.unBind(); + } + catch ( LdapException le ) + { + fail(); + } + catch ( Exception e ) + { + fail(); + } + finally + { + entries = null; + done = false; + + try + { + connection.close(); + } + catch( IOException ioe ) + { + fail(); + } + } + } }