Return-Path: X-Original-To: apmail-directory-dev-archive@www.apache.org Delivered-To: apmail-directory-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B26C7648 for ; Mon, 1 Aug 2011 22:24:09 +0000 (UTC) Received: (qmail 18267 invoked by uid 500); 1 Aug 2011 22:24:09 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 18212 invoked by uid 500); 1 Aug 2011 22:24:08 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 18205 invoked by uid 99); 1 Aug 2011 22:24:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Aug 2011 22:24:08 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of elecharny@gmail.com designates 74.125.82.44 as permitted sender) Received: from [74.125.82.44] (HELO mail-ww0-f44.google.com) (74.125.82.44) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Aug 2011 22:23:59 +0000 Received: by wwe5 with SMTP id 5so6104667wwe.1 for ; Mon, 01 Aug 2011 15:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=zHxxgRJEhEVOQH4VUyJOoE0M1eUIFtvjAmPcUAHR+Uc=; b=edjj00E+Y1jfYVlYGug6CX/cyo0oSBzSivNgHvVrOMtP9DiE2aHJqA9Ic2Y1XX4PKi qsBnPIsk457PjKljZngDu3bMSTNe2CdHcsWvC+O1rFGYPtDVJIXaA+6l3hprGN7V1GGq gjBQki8Ag8AaJDzgoKVeZg1GPVLfov/2WjhjI= Received: by 10.216.137.142 with SMTP id y14mr1112384wei.0.1312237419510; Mon, 01 Aug 2011 15:23:39 -0700 (PDT) Received: from emmanuel-lecharnys-MacBook-Pro.local (ran75-1-78-192-106-184.fbxo.proxad.net [78.192.106.184]) by mx.google.com with ESMTPS id e56sm689695wed.17.2011.08.01.15.23.38 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Aug 2011 15:23:38 -0700 (PDT) Message-ID: <4E372769.3090903@gmail.com> Date: Tue, 02 Aug 2011 00:23:37 +0200 From: Emmanuel Lecharny Reply-To: elecharny@apache.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Apache Directory Developers List Subject: Re: Test Annotation Feedback References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org On 8/1/11 10:43 PM, Stefan Seelmann wrote: > Hi guys, > > I'd like to share some feedback with some test annotations fun I had today. > > I had to write some integration tests for a custom Tomcat Realm. In > that tests I have to startup three servers: > - Tomcat > - SQL Database (Derby) > - LDAP > > Of course I use ApacheDS for the LDAP part. I started to use > annotations but for multiple reasons that didn't work for me: > > > 1st) > I just added the the following two annotations > > @RunWith(FrameworkRunner.class) > @CreateLdapServer > > When starting the tests I got the following stacktrace at the console: > > org.apache.directory.shared.ldap.model.exception.LdapConfigurationException: > ERR_171 Failed to bind an LDAP service (1,024) to the service > registry. > at org.apache.directory.server.ldap.LdapServer.startNetwork(LdapServer.java:625) > at org.apache.directory.server.ldap.LdapServer.start(LdapServer.java:466) > at org.apache.directory.server.factory.ServerAnnotationProcessor.createLdapServer(ServerAnnotationProcessor.java:217) > at org.apache.directory.server.factory.ServerAnnotationProcessor.createLdapServer(ServerAnnotationProcessor.java:260) > at org.apache.directory.server.core.integ.FrameworkRunner.run(FrameworkRunner.java:222) > ... > Caused by: java.net.BindException: Address already in use > ... > > The reason is that both, LDAP and LDAPS transports try to bind the > same port (1024). As soon as I added the transport annotations it > worked: > > @CreateLdapServer(transports = { > @CreateTransport(protocol = "LDAP"), > @CreateTransport(protocol = "LDAPS") } ) > > I think there should be a better default, right? Absolutely. In fact, we *must* get rid of the AvailablePortFinder, which is not only useless, but also problematic. I have incidentally modified the crrent @nnotation today and removed those 1024 from the code. Funny that you raised the issue at the same time :) > > > 2nd) > My test class needs to extend another class, so I'm not able to extend > AbstrctLdapTestUnit. But the FrameworkRunner forces me to define some > fields and methods: > > public static boolean isRunInSuite; > public static void setService( DirectoryService service ); > public static void setLdapServer( LdapServer server ); > public static void setKdcServer( KdcServer server ); > > Please note that there is a inconsistence: the isRunInSuite must be a > field while for the other properties setters are used. In my case I > only need the LDAP server to be able to get the used port, the other > properties are useless. I wonder if those properties should be > optional? Th eservice is mandatory for the LdapServer, but the KdcServer should definitively be optionnal. > > > 3rd) > For my test class annotations don't fit well because the other server > (Tomcat and Derby DB) need to be setup programatically. I also wanted > to setup ApacheDS programatically because I wanted a more homogenous > setup/teardown. So I added the apacheds-service to the dependencies > and just used > > ApacheDsService apacheds = new ApacheDsService(); > InstanceLayout instanceLayout = new InstanceLayout(dir); > apacheds.start( instanceLayout ); > > and have a running LDAP server. This is quite easy. The drawback is > that the apacheds-service.jar is a shared Jar that contains all the > dependencies (antlr, servlet-api, ehcache, commons-*, activemq, > osgi/felix, log4j, jetty, etc.). In my case that works but in other > cases that may lead to conflicts with other dependencies. OSGi is the way to go, here... This is something we expect to wok on as soon as we get ADS-2.0.0-M2 out, in the next few days. > > > To sum up, I think the annotation approach works well for the ApacheDS > internal tests and also for test where only a LDAP server is required. > For more complex test setups I'd prefer to configure ApacheDS > programmatically. We have to clarify this aspect. I have to work on tests in august and september, so expect this part of the code to be cleaned up. Thanks for the feedback, Stefan ! -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com