我有一些junit测试用例,我为每个测试用例创建DatagramChannelFactory
。当我正常运行这些测试用例时,我在实例化NioDatagramChannelFactory
时没有任何问题。
DatagramChannelFactory channelFactory = new NioDatagramChannelFactory(Executors.newFixedThreadPool(10));
但是当我为同一段代码启用jacoco
时,实例化失败了。我的jacoco
与ant集成在一起,build.xml的部分内容如下所示:
由于jacoco需要fork="yes"
属性,我才会添加相同的内容。
<jacoco:coverage>
<junit printsummary="yes" haltonfailure="no" showoutput="yes" fork="yes" >
blah.. blah..
<batchtest fork="true" todir="${reportsUTrawdir}">
blah.. blah..
</batchtest>
</junit>
</jacoco:coverage>
我的junit目标如下所示:
<junit printsummary="yes" haltonfailure="no" showoutput="yes">
<formatter type="xml" />
<batchtest fork="yes" todir="${reportsUTrawdir}">
blah.. blah..
</batchtest>
</junit>
我得到的堆栈跟踪是:
Failed to create a selector.
org.jboss.netty.channel.ChannelException: Failed to create a selector.
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(AbstractNioSelector.java:343)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.<init>(AbstractNioSelector.java:100)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.<init>(AbstractNioSelector.java:95)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.<init>(AbstractNioWorker.java:48)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.<init>(NioDatagramWorker.java:54)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.createWorker(NioDatagramWorkerPool.java:35)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.createWorker(NioDatagramWorkerPool.java:26)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.newWorker(AbstractNioWorkerPool.java:143)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.init(AbstractNioWorkerPool.java:81)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.<init>(AbstractNioWorkerPool.java:69)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.<init>(AbstractNioWorkerPool.java:55)
at org.jboss.netty.channel.socket.nio.NioDatagramWorkerPool.<init>(NioDatagramWorkerPool.java:29)
at org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory.<init>(NioDatagramChannelFactory.java:140)
at org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory.<init>(NioDatagramChannelFactory.java:124)
当我拆除我的测试用例时,我有什么遗失的东西。请帮帮我。
编辑:添加了我从junit报告中得到的原因:
Caused by: java.io.IOException: Unable to establish loopback connection
at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:106)
at java.security.AccessController.doPrivileged(Native Method)
at sun.nio.ch.PipeImpl.<init>(PipeImpl.java:122)
at sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:27)
at java.nio.channels.Pipe.open(Pipe.java:133)
at sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:105)
at sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:26)
at java.nio.channels.Selector.open(Selector.java:209)
at org.jboss.netty.channel.socket.nio.SelectorUtil.open(SelectorUtil.java:63)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(AbstractNioSelector.java:341)
Caused by: java.net.SocketException: Permission denied: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:507)
at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:78)