我们使用嵌入式glassfish版本3.2-b06进行集成测试 .
问题是有时候调用我们的Web服务(RESTful)的测试会返回404响应,有时会返回200 .
例如:
@Test
public void test() throws Exception {
int code = sendPOST(URL);
Assert.assertEquals(200, code);
}
但是如果我在测试开始时添加Thread.sleep(1000) - 一切都很好 .
@Test
public void test() throws Exception {
Thread.sleep(1000);
int code = sendPOST(URL);
Assert.assertEquals(200, code);
}
我们正在部署应用程序如下:
@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();
}
从日志中可以看出,耳朵已经部署完毕 .
可能有什么不对?
EDIT #1
事实证明,当代码更改时,测试通过 . 但是,当我重复测试时,他们会失败 .