我遇到了一个从maven运行单元测试的奇怪问题。我有一套单元测试,如果逐个运行,它们运行得很好。但是,当我从maven(mvn test)运行它时,它会挂起(永久阻塞)。
它始终挂在此测试使用的A类中的相同点(相同的测试类)。我尝试从A.class
删除日志创建,测试开始成功运行。这是一行:
private static final Logger log = LoggerFactory.getLogger(A.class);
这是线程转储:
"main" prio=6 tid=0x00446c00 nid=0x1278 runnable [0x00a2f000]
java.lang.Thread.State: RUNNABLE
at java.lang.ProcessImpl.waitFor(Native Method)
at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine(CommandLineUtils.java:173)
at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine(CommandLineUtils.java:114)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:231)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkOnce(ForkStarter.java:125)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:109)
at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:619)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
我不知道从哪里开始。欢迎任何建议。
答案 0 :(得分:0)
可能是对资源的死锁?鉴于关于正在产生的另一个maven过程的评论,这可能表明要去哪里。您可以尝试将测试中的同步放在某个地方(或所有方法)以查看它是否消失。如果确实如此,则可能是死锁。