JUnit 测试因网络连接错误而结束

发布于 2024-08-16 00:45:49 字数 1256 浏览 2 评论 0原文

我正在 eclipse 中为我的 Java 项目运行一些 JUnit 4 测试,我知道这些测试两天前已经正常运行了。

但今天,我遇到了错误:

Could not connect to:  : 40212          
java.net.SocketException: Network is unreachable
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at java.net.Socket.connect(Socket.java:475)
    at java.net.Socket.<init>(Socket.java:372)
    at java.net.Socket.<init>(Socket.java:186)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:570)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:381)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

测试和代码都没有对网络执行任何操作。

此外,用于安装新软件的 eclipse 对话框无法连接到更新站点,SVN 插件也无法连接到存储库。 SVN 存储库是可访问的,我已经使用 cli-svn 程序进行了检查。 Eclipse 中的代理被禁用。

所以我的问题是,为什么 JUnit 首先要连接到互联网(离线工作如何成为可能......),我可以做些什么来找到问题的根源吗? (我的B计划是删除eclipse并重新安装)

I'm running some JUnit 4 tests in eclipse for my Java project which I know have functioned two days ago without problems.

Today, though, I get errors:

Could not connect to:  : 40212          
java.net.SocketException: Network is unreachable
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at java.net.Socket.connect(Socket.java:475)
    at java.net.Socket.<init>(Socket.java:372)
    at java.net.Socket.<init>(Socket.java:186)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:570)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:381)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Neither the test nor the code do something with networks.

Also the eclipse dialog for installing new software can't connect to the update sites and neither can the SVN plug-in connect to the repository. The SVN repository is reachable, I've checked with the cli-svn program. Proxies in eclipse are disabled.

So my question is, why does JUnit want to connect to the internet in the first place (how should offline working even be possible..) and can I do something to find the source of the problems? (My plan B is to remove eclipse and re-install it again)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤星 2024-08-23 00:45:49

我怀疑 Junit 在同一台机器上作为单独的进程启动(请注意上面对 RemoteTestRunner 的引用),然后 Eclipse 将通过套接字与其通信。

那么您的机器上是否存在与 TCP 堆栈相关的问题。您的网络资源不够了吗?有什么东西霸占了这些吗?

netstat 可能在这里有用。或者也许只是简单的重新启动?

I suspect Junit is launched as a separate process on the same machine (note the references to RemoteTestRunner above), and then Eclipse will talk to it via a socket.

So is there some issue related to your TCP stack on your machine. Are you out of networking resources ? Is something hogging these ?

netstat may be of use here. Or maybe a simple reboot ?

青巷忧颜 2024-08-23 00:45:49

“为什么 Eclipse 想要连接到互联网”这个问题的答案是 Eclipse 根本不连接到互联网,但是 Eclipse 有一个特殊的 JUnit 测试监听器,它与正在运行的 JVM 进行通信JUnit 测试。这个测试侦听器在 localhost 上打开一个套接字(我不能 100% 确定服务器套接字在哪一侧,但这可能并不重要)。

我认为您的网络出现了一些问题,导致 Eclipse 进程无法在本地主机上打开套接字。在启动/关闭 VPN 以及从暂停/恢复周期恢复后,我也遇到过类似的问题。

我会先尝试重新启动。如果这不起作用,我会尝试从不同的工作区运行(运行 .../eclipse.exe -data path/to/new/workspace)。请记住,卸载 Eclipse 是没有意义的。只需在某处解压一个新的 Eclipse 并尝试从那里运行即可。

The answer to the question "why would Eclipse want to connect to the internet" is that Eclipse doesn't connect to the internet at all, however Eclipse has a special JUnit test listener which communicates with the JVM running the JUnit tests. This test listener opens up a socket on localhost (I'm not 100% sure on which side the server-socket is, but that probably doesn't matter).

I think that you have some networking trouble on your end preventing the Eclipse process from opening a socket on localhost. I've experienced similar trouble after bringing up/down a VPN and after coming back from a suspend/resume cycle.

I'd try a reboot first. If that doesn't work, I'd try running from a different workspace (run .../eclipse.exe -data path/to/new/workspace). Remember that there is no point in uninstalling Eclipse. Just unpack a new Eclipse somewhere and try running from there instead.

非要怀念 2024-08-23 00:45:49

您是否尝试过查看您要执行的测试的“运行配置”? (即右键单击测试并选择“运行方式>运行配置”)也许有些设置有点混乱。也许“测试”选项卡中的“测试运行程序”设置配置有误?

Have you tried looking at the "Run Configurations" for the test that you're trying to execute? (i.e. right click the test and choose "Run As > Run Configurations") Perhaps there are some settings that have gone a little haywire. Perhaps there is something mis-configured with the "Test runner" setting in the "Test" tab?

柒夜笙歌凉 2024-08-23 00:45:49

在我的 Windows 7 x64 机器上,出于某种奇怪的原因,我使用了一个单独的防火墙来阻止 javaw.exe,在解除阻止后,它再次起作用。没想到防火墙也会阻止机器内部套接字通信

on my windows 7 x64 machine i used a separate firewall blocking javaw.exe for some weird reason, after unblocking it, it worked again. didn't think the firewall would block machine internal socket communications too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文