我们有一个 Play 1.2.4 应用程序,并且我们为该应用程序安装了 Jenkins(在 Ubuntu 上)。我们遇到了 Cobertura 的问题。
运行测试(成功)后,我们时不时地收到以下错误:
---------------------------------------
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sourceforge.cobertura.util.FileLocker.lock(FileLocker.java:124)
at play.modules.cobertura.CoberturaPlugin$CoberturaPluginShutdownThread.run(Unknown Source)
Caused by: java.nio.channels.OverlappingFileLockException
at sun.nio.ch.FileChannelImpl$SharedFileLockTable.checkList(FileChannelImpl.java:1166)
at sun.nio.ch.FileChannelImpl$SharedFileLockTable.add(FileChannelImpl.java:1068)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:824)
at java.nio.channels.FileChannel.lock(FileChannel.java:860)
... 6 more
---------------------------------------
Unable to get lock on /var/lib/jenkins/jobs/project/workspace/cobertura.ser.lock: null
This is known to happen on Linux kernel 2.6.20.
Make sure cobertura.jar is in the root classpath of the jvm
process running the instrumented code. If the instrumented code
is running in a web server, this means cobertura.jar should be in
the web server's lib directory.
Don't put multiple copies of cobertura.jar in different WEB-INF/lib directories.
Only one classloader should load cobertura. It should be the root classloader.
---------------------------------------
lock file could not be deleted
这似乎并没有“破坏构建”,但在构建过程中,我们得到以下信息(这会导致 cobertura 报告失败)
Publishing Cobertura coverage report...
No coverage results were found using the pattern 'test-result/code-coverage/coverage.xml' relative to '/var/lib/jenkins/jobs/project/workspace'. Did you enter a pattern relative to the correct directory? Did you generate the XML report(s) for Cobertura?
Build step 'Publish Cobertura Coverage Report' changed build result to FAILURE
手动运行后续构建通常会通过。
根据Zero code coverage with cobertura 1.9.2 but tests are working ,我尝试在 Play auto-test -command 后设置 -Dcobertura.use.java.nio=false。
由于这个错误只是偶尔发生,我不确定这是否有帮助。但在那之后,我们遇到了 Play 自动测试挂起的问题:
...
Executing /opt/play-1.2.4/play auto-test "/var/lib/jenkins/jobs/project/workspace" -Dcobertura.use.java.nio=false
[workspace] $ /opt/play-1.2.4/play auto-test "/var/lib/jenkins/jobs/project/workspace" -Dcobertura.use.java.nio=false
<build stuck here for a couple of days>
由于没有什么是完全确定的,所以这里很难说因果关系。 (这似乎发生在 jenkins/server 重启后的一两次构建之后)
目前我正在考虑在我们的项目中禁用 Cobertura,但如果有人有其他想法,那就太好了 =)
最佳答案
很明显,这是由于您的 JVM 实现中的 JVM 锁定问题,或者更确切地说是您部署 cobertura JAR 的方式。
Jenkins 可以生成大量 JVM 线程,如果 cobetura 在您的全局类路径中,则可能会发生一些奇怪的冲突。
我认为,最终,这应该归因于 cobertura 中的一个小错误(除非复杂的 corbertura 文件锁定正在解决一些其他更重要的问题)。
根据 Cobertura 的 FileLock 的源代码 (cobertura/src/main/java/net/sourceforge/cobertura/util/FileLocker.java),多个 JVM 加载 Cobertura jar 存在一些问题。
要解决此问题,请确保只有一个副本和一个应用程序启动和使用 Corbetura。
您的 VM 实现修复它的原因很可能是您减少了加载 cobetrura 方式的可变性。另外,也许您正在以比您的 Jenkins 服务器更高的频率重新启动您的虚拟机。
在我们的 jenkins corbertura 构建中,我们只使用了 maven 插件,这似乎可以正常工作而没有问题(但话又说回来,我们没有使用 java 1.7,也没有使用 Play)。
关于java - Jenkins + 玩 1.2.4 : problems with cobertura lock files/report,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671642/