JerseyTest Grizzly Web 服务器在 Unix 上的行为
我们创建了一个测试套件,为了运行它,我们使用带有 JerseyTest 框架的嵌入式 Grizzly Web 服务器。
我们正在从 JerseyTest 扩展一个自定义类,并在其构造函数中创建 ApplicationDescriptor,然后调用超类 setupTestEnvironment() ,这实际上会启动嵌入式 grizzly Web 服务器。
我们的测试用例很少扩展这个自定义类来直接启动 grizzly 服务器。然而,我们并没有在代码中的任何地方停止这个嵌入式服务器。
测试用例在 Windows 上运行良好,但在 Unix 上失败,并出现 java.net.BindException 端口 9998 正在被另一个进程使用。
很明显,如果我们不停止代码中的嵌入式 Web 服务器,这些测试在 Windows 上也会失败,并出现类似的错误。它们如何在 Windows 上运行良好而在 Unix 上失败。这与 Unix 如何生成线程或进程有关吗?
PS 我们还使用 netstat -a | 测试了端口 9998 是否被其他进程使用。 grep 9998 但找不到使用该端口的其他进程。
We have created a test suite and in order to run it we are using embedded Grizzly Web Server with JerseyTest framework.
We are extending a custom class from JerseyTest and in its constructor we are creating ApplicationDescriptor and then call superclass setupTestEnvironment() which essentially starts embedded grizzly web server.
Few of our test cases are extending this custom class to start grizzly server directly. However, we are not stopping this embedded server anywhere in the code.
The test cases run fine on windows but on Unix they fail with java.net.BindException port 9998 is in use by another process.
It becomes obvious these tests should fail with similar error on windows too if we are not stopping embedded web server in the code. How they are running fine on windows and failing on unix. Has this something to do with how Unix spawns threads or processes?
P.S. We have also tested whether port 9998 is in use by some other process using netstat -a | grep 9998 but no other process using that port could be found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,并且我确实通过不使用默认端口(如果已使用)来修复它。只需将以下代码添加到您的测试用例中:
i had a similar problem and i did fix it by not using the default port if already used. just add following code to your test case:
当我编写集成测试时,我遇到了同样的问题。我没有在 Windows 机器上进行测试,但在我的 Unix 机器上,我发现问题是默认情况下 JerseyTest 类在其
tearDown
方法上使用@After
来关闭嵌入式服务器。由于我已经重写了此方法来进行清理,因此我必须调用 super.tearDown()执行此操作后,一切都按预期进行。
I had the same problem, when I was writing my integration tests. I didn't get to test on a Windows machine, but on my Unix machine I found the problem was that by default the JerseyTest class utilizes
@After
on it'stearDown
method to close the embedded server. Since I had overridden this method to do clean up on my side, I had to callsuper.tearDown()
After doing this, everything worked as expected.