Announcement Announcement Module
Collapse
No announcement yet.
Occasional error binding to ldap port when using TestContextSourceFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Occasional error binding to ldap port when using TestContextSourceFactoryBean

    Hi,

    I've added some ldap test using the TestContextSourceFactoryBean class.
    My configuration is:
    <bean primary="true" id="contextSource" class="org.springframework.ldap.test.TestContextSo urceFactoryBean ">
    <property name="ldifFile" value="classpath:test-schema.ldif"/>
    <property name="defaultPartitionSuffix" value="dc=test"/>
    <property name="defaultPartitionName" value="com"/>
    <property name="principal" value="" />
    <property name="password" value="" />
    <property name="port" value="${ldap.port}" />
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
    <constructor-arg ref="contextSource" />
    </bean>

    and my test properties file says:
    ldap.port=11389

    When I run the tests, once in a while I get an error binding to the port and (as a result?) error creating the LdapTemplate:

    2011-05-16 04:16:49 gobuilds.Compile : 04:16:49,138 ERROR org.apache.directory.server.jndi.ServerContextFact ory -- Failed to bind an LDAP service (11389) to the service registry.
    2011-05-16 04:16:49 gobuilds.Compile : java.net.BindException: Address already in use
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.Net.bind(Native Method)
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSock etChannelImpl.java:119)
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAd aptor.java:59)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r.registerNew(SocketAcceptor.java:429)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r.access$900(SocketAcceptor.java:52)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r$Worker.run(SocketAcceptor.java:258)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.util.NamePreservingRunnable.run(Na mePreservingRunnable.java:43)
    2011-05-16 04:16:49 gobuilds.Compile : at java.lang.Thread.run(Thread.java:662)
    2011-05-16 04:16:49 gobuilds.Compile : 04:16:49,147 ERROR org.springframework.test.context.TestContextManage r -- Caught exception while allowing TestExecutionListener

    ...

    2011-05-16 04:16:49 gobuilds.Compile : Caused by: javax.naming.CommunicationException: localhost:11389 [Root exception is java.net.ConnectException: Connection refused]
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.Connection.<init>(Connection.jav a:210)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.jav a:118)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClientFactory.createPooledCo nnection(LdapClientFactory.java:46)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.pool.Connections.<init>(Connecti ons.java:97)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.pool.Pool.getPooledConnection(Po ol.java:114)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapPoolManager.getLdapClient(Ld apPoolManager.java:310)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClient.getInstance(LdapClien t.java:1572)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:265 2)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapC txFactory.java:175)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Ldap CtxFactory.java:193)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstanc e(LdapCtxFactory.java:136)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext (LdapCtxFactory.java:66)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:667)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:288)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.InitialContext.init(InitialContext.ja va:223)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.ldap.InitialLdapContext.<init>(Initia lLdapContext.java:134)
    2011-05-16 04:16:49 gobuilds.Compile : at org.springframework.ldap.core.support.LdapContextS ource.getDirContextInstance(LdapContextSource.java :43)
    2011-05-16 04:16:49 gobuilds.Compile : at org.springframework.ldap.core.support.AbstractCont extSource.createContext(AbstractContextSource.java :254)
    2011-05-16 04:16:49 gobuilds.Compile : ... 116 more

    ====

    I've tried rewriting the TestContextSourceFactoryBean and adding some delays before and after creation and destruction of the ldap server ( LdapTestUtils.startApacheDirectoryServer(..) and LdapTestUtils.destroyApacheDirectoryServer(..) ) - which was a lame solution anyway and did not help. Also, I have added a mechanism that calls startApacheDirectoryServer() only once during JVM lifetime and to destroyApacheDirectoryServer() once during its shutdown using a shutdown hook, that did not help either.
    I am about to give up on these tests, as these occasional breakages are wasting the time of everybody in the team here, but that would cause a lot of other problems as we are using LDAP for security and the tests are needed, if not crucial.

    Would anyone have an idea what might be going on?

    Thanks in advance for any idea,

  • #2
    Ldap test in embedded environment issue

    I am facing the same issue while running on CI build, does anyone know how to resolve

    Originally posted by zvizvi View Post
    Hi,

    I've added some ldap test using the TestContextSourceFactoryBean class.
    My configuration is:
    <bean primary="true" id="contextSource" class="org.springframework.ldap.test.TestContextSo urceFactoryBean ">
    <property name="ldifFile" value="classpath:test-schema.ldif"/>
    <property name="defaultPartitionSuffix" value="dc=test"/>
    <property name="defaultPartitionName" value="com"/>
    <property name="principal" value="" />
    <property name="password" value="" />
    <property name="port" value="${ldap.port}" />
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
    <constructor-arg ref="contextSource" />
    </bean>

    and my test properties file says:
    ldap.port=11389

    When I run the tests, once in a while I get an error binding to the port and (as a result?) error creating the LdapTemplate:

    2011-05-16 04:16:49 gobuilds.Compile : 04:16:49,138 ERROR org.apache.directory.server.jndi.ServerContextFact ory -- Failed to bind an LDAP service (11389) to the service registry.
    2011-05-16 04:16:49 gobuilds.Compile : java.net.BindException: Address already in use
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.Net.bind(Native Method)
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSock etChannelImpl.java:119)
    2011-05-16 04:16:49 gobuilds.Compile : at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAd aptor.java:59)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r.registerNew(SocketAcceptor.java:429)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r.access$900(SocketAcceptor.java:52)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.transport.socket.nio.SocketAccepto r$Worker.run(SocketAcceptor.java:258)
    2011-05-16 04:16:49 gobuilds.Compile : at org.apache.mina.util.NamePreservingRunnable.run(Na mePreservingRunnable.java:43)
    2011-05-16 04:16:49 gobuilds.Compile : at java.lang.Thread.run(Thread.java:662)
    2011-05-16 04:16:49 gobuilds.Compile : 04:16:49,147 ERROR org.springframework.test.context.TestContextManage r -- Caught exception while allowing TestExecutionListener

    ...

    2011-05-16 04:16:49 gobuilds.Compile : Caused by: javax.naming.CommunicationException: localhost:11389 [Root exception is java.net.ConnectException: Connection refused]
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.Connection.<init>(Connection.jav a:210)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.jav a:118)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClientFactory.createPooledCo nnection(LdapClientFactory.java:46)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.pool.Connections.<init>(Connecti ons.java:97)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.pool.Pool.getPooledConnection(Po ol.java:114)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapPoolManager.getLdapClient(Ld apPoolManager.java:310)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapClient.getInstance(LdapClien t.java:1572)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:265 2)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapC txFactory.java:175)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Ldap CtxFactory.java:193)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstanc e(LdapCtxFactory.java:136)
    2011-05-16 04:16:49 gobuilds.Compile : at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext (LdapCtxFactory.java:66)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:667)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:288)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.InitialContext.init(InitialContext.ja va:223)
    2011-05-16 04:16:49 gobuilds.Compile : at javax.naming.ldap.InitialLdapContext.<init>(Initia lLdapContext.java:134)
    2011-05-16 04:16:49 gobuilds.Compile : at org.springframework.ldap.core.support.LdapContextS ource.getDirContextInstance(LdapContextSource.java :43)
    2011-05-16 04:16:49 gobuilds.Compile : at org.springframework.ldap.core.support.AbstractCont extSource.createContext(AbstractContextSource.java :254)
    2011-05-16 04:16:49 gobuilds.Compile : ... 116 more

    ====

    I've tried rewriting the TestContextSourceFactoryBean and adding some delays before and after creation and destruction of the ldap server ( LdapTestUtils.startApacheDirectoryServer(..) and LdapTestUtils.destroyApacheDirectoryServer(..) ) - which was a lame solution anyway and did not help. Also, I have added a mechanism that calls startApacheDirectoryServer() only once during JVM lifetime and to destroyApacheDirectoryServer() once during its shutdown using a shutdown hook, that did not help either.
    I am about to give up on these tests, as these occasional breakages are wasting the time of everybody in the team here, but that would cause a lot of other problems as we are using LDAP for security and the tests are needed, if not crucial.

    Would anyone have an idea what might be going on?

    Thanks in advance for any idea,

    Comment


    • #3
      In the upcoming 1.3.2 release the version of the embedded Apache Directory Server has been upgraded, which seems to solve these kinds of problems.

      https://jira.springsource.org/browse/LDAP-232

      Comment

      Working...
      X