Reputation: 84
First, sorry for bad english...
I created the project spark-spring (https://github.com/rascorp/spark-spring) to provide an easy way to put spring context into spark-java framework.
I create a test to check if the server starts and returns a value. Running in my personal computer, all tests run ok, but in travis-ci the connection test fails.
local output:
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 output (you can check the build here: 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)
Anyone can help me to solve this issue?
Upvotes: 2
Views: 1010
Reputation: 84
I found the problem!
The problem occurs because the service methods are not available when the test runs. To fix, I need to call the following code before run the test.
/**
* Waits for the spark server to be initialized.
* If it's already initialized will return immediately
*/
Spark.awaitInitialization();
Upvotes: 2
Reputation: 623
The Travis CI output is saying that one test is failing. Travis CI doesn't necessarily run in the same conditions as your local machine. See what you can do to get that one test to pass on both machines. After all, if you can't get it to pass with Travis, how can you know it will work on any other computer but your own? For help debugging the specific issue, see the Travis CI Common Build Problems.
Upvotes: 0