wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Embedded Jetty Servers running in separate threads not accessible from unit test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply locked New topic
Author

Embedded Jetty Servers running in separate threads not accessible from unit test

Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Hi,

I have the following integration test case that starts up 3 embedded jetty servers, and runs unit tests against them. My problem is that while the JUnit class is running, it gets stuck in the waitForStartup method, while the servers return "Connection to https://localhost:8440 refused" ("Connect to localhost:8440 timed out. Connection will be retried using another IP address") it is stuck in a loop waiting for the servers to be ready to run the tests against.

Once I terminate the JUnit test, with the servers still running, then I can access the servers via a browser or Poster (i.e. 200 return code). It is as if the unit test is holding onto the server threads I think. I want the servers to run in separate threads (see where I start the serves).
(While the test is still running the tests httpClient, a browser and Poster all timeout. But once the test is terminated, a browser and Poster can do a GET returning a 200.)

I think it's something to do with the processes are not released from the unit test thread.

Please can you have a look at my code and if you know why the servers seem stuck, please can you advise?

Thanks

Edit: Removed disputed code
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hi Blikkies,

I'm not expert in jetty. However, I have few questions:

1) Does this source code belong to you? I'm asking because the part
<problematic code here>
does not look good to me. If you've copied the code from workplace (or basically if you do not own the code), please do not post it on any forum(also, please let us know if this is the case - so that the code can be removed). Publishing code owned by somebody else(especially a corporation) might be (very)troublesome for you.

If you own this code, then it'll be better if you change the name of your package.

2) What is exact output on console? That is, what does the get method returns? Please print and share the exact output. Also, you can simply return from the waitForStartup method instead of breaking the loop.

3) Is it that when your test is running, you can't access the server, but if test is not running, you can access the server? Sounds pretty weird to me (again, since I'm not familiar with jetty).


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Hi Anayonkar Shivalkar,

Please can you delete this post, I will add a new edited one.

Thanks for the advise
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hi Blikkies,

You are welcome.

As of now, I'm locking this topic.

In case if you have any more question, feel free to create a new topic.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Embedded Jetty Servers running in separate threads not accessible from unit test
 
Similar Threads
Problem in posting json data from android
HTTP request 'GET' example
apache HttpClient make connection for url1 ,if url1 failed connect url2
Trying to Redirect. 302 Error. HTTP CLIENT
How to create our own payment gateway?