You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jim Talbut <jt...@spudsoft.co.uk> on 2011/03/04 21:12:23 UTC

How to completely eradicate a server?

Hi,

I'm writing some unit tests (for a load distributing ConduitSelector) 
and I'm hitting some kind of race condition somewhere.

Each of my tests has an @Before that creates four server ports:
         for( int i = 0; i < serverCount; ++i ) {
             AddNumbersImpl implementor = new AddNumbersImpl();
             // Build a URL on a unique port
             String address = getAddress( basePort + curPortOffset );
             Endpoint endpoint = Endpoint.create( implementor );
             endpoint.publish( address );
             endpoints.add( endpoint );
	}

And then I have an @After to clean up:
         for( Endpoint endpoint : endpoints ) {
             endpoint.stop();
         }
         endpoints.clear();

My problem is that if I reuse port numbers between tests I'm getting 
spurious 404 errors when I actually call some of the servers, but if 
every port number is unique across all tests everything passes cleanly.
The ports are all allocated using TestUtil.getPortNumber, so they should 
be free - and I'm getting 404s, not failures to connect, so jetty is 
listening.

Also, for added fun, it never fails under the debugger (sure sign of a 
race condition).

So it looks like something somewhere is either not being cleaned up 
correctly, or has some kind of asynchronouse cleanup that hasn't 
finished quickly enough.

Please can someone point me in the right direction?

Thanks

Jim