I thought that unit tests were run sequentially and not threaded. However, we have an intermittent issue where our Mocks seem to not be getting reset between tests. This results in out unit test and build failing. Here's an example of the error output:
13:27:07.599 [jdk-http-server-3] ERROR org.matonto.rest.util.ErrorUtils - 500: null
org.matonto.exception.MatOntoException: null
at org.matonto.catalog.rest.impl.CatalogRestImpl.updateVersionedDistribution(CatalogRestImpl.java:571) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:308) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:291) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1140) [jersey-all-2.18.jar:na]
at org.glassfish.jersey.jdkhttp.JdkHttpHandlerContainer.handle(JdkHttpHandlerContainer.java:161) [jersey-container-jdk-http-2.22.1.jar:na]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) [na:1.8.0_131]
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) [na:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82) [na:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675) [na:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) [na:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
13:27:07.602 [jdk-http-server-3] ERROR org.matonto.rest.util.ErrorUtils - 400: Distribution IDs must match
13:27:07.605 [jdk-http-server-3] ERROR org.matonto.rest.util.ErrorUtils - 400: Invalid JSON-LD
Tests run: 213, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 6.127 sec <<< FAILURE!
removeUnversionedDistributionTest(org.matonto.catalog.rest.impl.CatalogRestImplTest) Time elapsed: 0.008 sec <<< FAILURE!
org.mockito.exceptions.verification.TooManyActualInvocations:
catalogManager.removeUnversionedDistribution(
http://matonto.org/catalogs/local,
http://matonto.org/records/test,
http://matonto.org/distributions/test);
Wanted 1 time:
-> at org.matonto.catalog.rest.impl.CatalogRestImplTest.removeUnversionedDistributionTest(CatalogRestImplTest.java:1098)
But was 2 times. Undesired invocation:
-> at org.matonto.catalog.rest.impl.CatalogRestImpl.deleteUnversionedDistribution(CatalogRestImpl.java:385)
at org.matonto.catalog.rest.impl.CatalogRestImplTest.removeUnversionedDistributionTest(CatalogRestImplTest.java:1098)
Results :
Failed tests:
removeUnversionedDistributionTest(org.matonto.catalog.rest.impl.CatalogRestImplTest)
Tests run: 213, Failures: 1, Errors: 0, Skipped: 0
We're running Jersey 2.22.1 and Mockito 1.10.19.
Just for emphasis; Mockito.reset is being called on all the mock objects in between each test:
@BeforeMethod
public void setupMocks() {
reset(catalogManager, engineManager, transformer, conflict, difference, results);