项目建立在本地但在travis-ci容器中失败

时间:2016-04-14 16:03:50

标签: java travis-ci spark-java

首先,抱歉英语不好......

我创建了项目spark-spring(https://github.com/rascorp/spark-spring),以便提供一种将spring上下文放入spark-java框架的简单方法。

我创建一个测试来检查服务器是否启动并返回一个值。在我的个人计算机上运行,​​所有测试都运行正常,但在travis-ci中连接测试失败。

本地输出:

Running com.github.rascorp.spark.spring.ConsoleAppInitializerTest
abr 14, 2016 12:46:01 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFORMAÇÕES: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@48140564: startup date [Thu Apr 14 12:46:01 BRT 2016]; root of context hierarchy
abr 14, 2016 12:46:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFORMAÇÕES: Loading XML bean definitions from class path resource [application-context-spark-spring-test.xml]
abr 14, 2016 12:46:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFORMAÇÕES: Loading XML bean definitions from class path resource [application-context-spark-spring.xml]
[Thread-1] INFO org.eclipse.jetty.util.log - Logging initialized @663ms
[Thread-1] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
[Thread-1] INFO spark.webserver.JettySparkServer - >> Listening on 0.0.0.0:4568
[Thread-1] INFO org.eclipse.jetty.server.Server - jetty-9.3.2.v20150730
[Thread-1] INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@55d35d9b{HTTP/1.1,[http/1.1]}{0.0.0.0:4568}
[Thread-1] INFO org.eclipse.jetty.server.Server - Started @734ms
[main] INFO spark.webserver.JettySparkServer - >>> Spark shutting down ...
[main] INFO org.eclipse.jetty.server.ServerConnector - Stopped ServerConnector@55d35d9b{HTTP/1.1,[http/1.1]}{0.0.0.0:4568}
[main] INFO spark.webserver.JettySparkServer - done
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.025 sec - in com.github.rascorp.spark.spring.ConsoleAppInitializerTest

Travis-CI输出(您可以在此检查构建:https://travis-ci.org/rascorp/spark-spring/builds/123091116):

Running com.github.rascorp.spark.spring.ConsoleAppInitializerTest
Apr 14, 2016 3:42:15 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6fffcba5: startup date [Thu Apr 14 15:42:15 UTC 2016]; root of context hierarchy
Apr 14, 2016 3:42:15 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [application-context-spark-spring-test.xml]
Apr 14, 2016 3:42:15 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [application-context-spark-spring.xml]
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.876 sec <<< FAILURE!
testContext(com.github.rascorp.spark.spring.ConsoleAppInitializerTest)  Time elapsed: 0.035 sec  <<< FAILURE!
java.lang.AssertionError: Connection refused
    at org.junit.Assert.fail(Assert.java:88)
    at com.github.rascorp.spark.spring.ConsoleAppInitializerTest.testContext(ConsoleAppInitializerTest.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

任何人都可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

我发现了问题!

发生此问题是因为测试运行时服务方法不可用。要修复,我需要在运行测试之前调用以下代码。

/**
 * Waits for the spark server to be initialized.
 * If it's already initialized will return immediately
 */
Spark.awaitInitialization();

答案 1 :(得分:0)

Travis CI输出显示一个测试失败。 Travis CI不一定与本地机器运行的条件相同。看看你可以做些什么来让一个测试在两台机器上传递。毕竟,如果你无法通过特拉维斯,你怎么知道它可以在任何其他计算机上工作,但你自己的?有关调试特定问题的帮助,请参阅Travis CI Common Build Problems