We use embedded glassfish version 3.2-b06 for integration tests.
The problem is that sometimes test that call our web service (RESTful) returns a 404 response and sometimes 200.
For example:
@Test
public void test() throws Exception {
int code = sendPOST(URL);
Assert.assertEquals(200, code);
}
But if I add Thread.sleep (1000) at the beginning of the test - everything is fine always.
@Test
public void test() throws Exception {
Thread.sleep(1000);
int code = sendPOST(URL);
Assert.assertEquals(200, code);
}
We are deploying the application as follows:
@BeforeClass
public void init() {
GlassFishProperties glassFishProperties = new GlassFishProperties();
glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
glassfish.start();
File ear = new File("target/ear.ear");
Deployer deployer = glassfish.getDeployer();
deployer.deploy(ear);
context = new InitialContext();
}
From logs it's clear that ear is deployed.
What could be wrong?
EDIT #1
It turned out that when the code changes the tests pass. But when I run repeated tests, they fail.