ewolff / microservice

Sample of a Microservice setup for my book. Based on Spring Cloud / Netflix / Java / Docker / Docker Compose / Docker Machine / Vagrant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tests are breaking in microservice-demo-catalog

juanwalker opened this issue · comments

Someone did commit

[INFO] Reactor Summary:
[INFO]
[INFO] microservice-demo ................................. SUCCESS [39.818s]
[INFO] microservice-demo-eureka-server ................... SUCCESS [2:22.265s]
[INFO] microservice-demo-turbine-server .................. SUCCESS [7.110s]
[INFO] microservice-demo-customer ........................ SUCCESS [1:17.839s]
[INFO] microservice-demo-catalog ......................... SUCCESS [50.993s]
[INFO] microservice-demo-order ........................... FAILURE [37.500s]
[INFO] microservice-demo-zuul-server ..................... SKIPPED

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 28.675 sec <<< FAILURE! - in com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest
testFindAll(com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest) Time elapsed: 1.721 sec <<< ERROR!
java.lang.NullPointerException: null
at com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest.testFindAll(CatalogConsumerDrivenContractTest.java:35)

I managed to solved it, the problem was that the catalog endpoint wasn't being initializated on start up so what I did was to modify the class OrderApp.java and include a beanFactoryPostProcessor method that I copied from this link http://stackoverflow.com/questions/31322670/how-to-configure-dispatcherservlet-load-on-startup-by-spring-boot , then I ran mvn package and all test passed, great!

Note: Updated the link, the previous one was wrong

Hi ewolff, despite I reverted my changes and ran mvn clean package the problem persists. Is this source code update with your local repository?

screenshot

Is happening because the client calls the end point before its initialization

2016-09-26 10:36:39.225 TRACE 7548 --- [CatalogClient-1] c.e.m.order.clients.CatalogClient : Catalog: URL http://localhost:8080/catalog/

2016-09-26 10:36:40.124 INFO 7548 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'

2016-09-26 10:36:40.124 INFO 7548 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started

Im so sorry on the second post I wrote the wrong link, here is the correct one with the solution that I implemented it http://stackoverflow.com/questions/31322670/how-to-configure-dispatcherservlet-load-on-startup-by-spring-boot

Thanks for the update! I'm sorry but as I said this does not happen for me with a fresh clone of the repo. Can you:

  • Create a fresh clone of the rep
  • Run mvn clean package
  • Send the complete stack trace of the failure with the NullPointerException ?

Thanks!

Hi I followed the suggested steps and the nullpointerexcetion raised again, here is the complete null pointer excetion stack trace:

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 22.654 sec <<< FAILURE! - in com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest
testFindAll(com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest) Time elapsed: 1.542 sec <<< ERROR!
java.lang.NullPointerException: null
at com.ewolff.microservice.order.logic.CatalogConsumerDrivenContractTest.testFindAll(CatalogConsumerDrivenContractTest.java:35)

Running com.ewolff.microservice.order.logic.CustomerConsumerDrivenContractTest
2016-09-26 21:20:09.705 INFO 5756 --- [ main] o.s.t.c.support.AbstractContextLoader : Could not detect default resource locations for test class [com.ewolff.microservice.order.logic.CustomerConsumerDrivenContractTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2016-09-26 21:20:09.709 INFO 5756 --- [ main] o.s.t.c.web.WebTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.boot.test.IntegrationTestPropertiesListener@2792c28, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6fa7ce4, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@351e86b2, org.springframework.test.context.support.DirtiesContextTestExecutionListener@5a8b42a3, org.springframework.test.context.transaction.TransactionalTestExecutionListener@11582db6, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@44106e25]
2016-09-26 21:20:09.718 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:09.890 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:09.968 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:10.015 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:10.046 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:10.077 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec - in com.ewolff.microservice.order.logic.CustomerConsumerDrivenContractTest
Running com.ewolff.microservice.order.logic.OrderWebIntegrationTest
2016-09-26 21:20:10.093 INFO 5756 --- [ main] o.s.t.c.support.AbstractContextLoader : Could not detect default resource locations for test class [com.ewolff.microservice.order.logic.OrderWebIntegrationTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2016-09-26 21:20:10.108 INFO 5756 --- [ main] o.s.t.c.web.WebTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.boot.test.IntegrationTestPropertiesListener@5ca4c88a, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1791e231, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@55397d15, org.springframework.test.context.support.DirtiesContextTestExecutionListener@5e360c3b, org.springframework.test.context.transaction.TransactionalTestExecutionListener@24ac6fef, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@3cb49121]
2016-09-26 21:20:10.155 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:10.218 TRACE 5756 --- [nio-8080-exec-5] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:12.170 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:12.643 TRACE 5756 --- [nio-8080-exec-1] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:12.846 TRACE 5756 --- [nio-8080-exec-6] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:12.949 TRACE 5756 --- [nio-8080-exec-6] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:12.966 TRACE 5756 --- [nio-8080-exec-6] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:13.013 TRACE 5756 --- [CatalogClient-4] c.e.m.order.clients.CatalogClient : Catalog: URL http://localhost:8080/catalog/
2016-09-26 21:20:13.091 INFO 5756 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@c6bf8d9 testClass = OrderWebIntegrationTest, testInstance = com.ewolff.microservice.order.logic.OrderWebIntegrationTest@44392e64, testMethod = IsSubmittedOrderSaved@OrderWebIntegrationTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@227b9277 testClass = OrderWebIntegrationTest, locations = '{}', classes = '{class com.ewolff.microservice.order.OrderApp}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.IntegrationTest=true}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@e18d2a2]; rollback [true]
2016-09-26 21:20:13.091 TRACE 5756 --- [ main] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:13.172 TRACE 5756 --- [nio-8080-exec-4] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:13.221 TRACE 5756 --- [nio-8080-exec-4] c.e.m.order.clients.CustomerClient : Customer: URL http://localhost:8080/customer/
2016-09-26 21:20:13.268 INFO 5756 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test context [DefaultTestContext@c6bf8d9 testClass = OrderWebIntegrationTest, testInstance = com.ewolff.microservice.order.logic.OrderWebIntegrationTest@44392e64, testMethod = IsSubmittedOrderSaved@OrderWebIntegrationTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@227b9277 testClass = OrderWebIntegrationTest, locations = '{}', classes = '{class com.ewolff.microservice.order.OrderApp}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.IntegrationTest=true}', resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]].
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.594 sec - in com.ewolff.microservice.order.logic.OrderWebIntegrationTest
2016-09-26 21:20:13.283 INFO 5756 --- [ Thread-4] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6955cb39: startup date [Mon Sep 26 21:19:49 COT 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@48974e45
2016-09-26 21:20:13.283 INFO 5756 --- [ Thread-4] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647
2016-09-26 21:20:13.315 INFO 5756 --- [ Thread-4] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-09-26 21:20:13.315 INFO 5756 --- [ Thread-4] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2016-09-26 21:20:13.330 INFO 5756 --- [ Thread-4] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete

Results :

Tests in error:
CatalogConsumerDrivenContractTest.testFindAll:35 NullPointer

Tests run: 8, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] microservice-demo ................................. SUCCESS [1.318s]
[INFO] microservice-demo-eureka-server ................... SUCCESS [21.049s]
[INFO] microservice-demo-turbine-server .................. SUCCESS [1.138s]
[INFO] microservice-demo-customer ........................ SUCCESS [25.129s]
[INFO] microservice-demo-catalog ......................... SUCCESS [35.768s]
[INFO] microservice-demo-order ........................... FAILURE [29.150s]
[INFO] microservice-demo-zuul-server ..................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:54.529s
[INFO] Finished at: Mon Sep 26 21:20:13 COT 2016
[INFO] Final Memory: 52M/432M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project microservice-demo-order: There are test failures.
[ERROR]
[ERROR] Please refer to D:\microservicios\microservice\microservice-demo\microservice-demo-order\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project microservice-demo-order: There are test failures.

Please refer to D:\microservicios\microservice\microservice-demo\microservice-demo-order\target\surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
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:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
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:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to D:\microservicios\microservice\microservice-demo\microservice-demo-order\target\surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:82)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:254)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:854)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:722)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :microservice-demo-order

Thanks. I am still surprised about the problem because the test in question uses @IntegrationTestand @WebAppConfiguration. If this is a race condition about a request that cannot be handled because the DispatcherServlet is not yet started, it should also happen in other Spring Applications. There is an update to Spring Boot to enable this configuration more easily, see spring-projects/spring-boot@699d083 . I will take another look.

I have updated the demo to Spring Cloud Amden and Spring Boot 1.4.0. Can you check whether that solves the problem? Thanks!

Close b/c no update for several months and could not reproduce.