MongoSocketException when testing a new Saga

Hi,

I have been building some software with Axon for a couple of months now, but I have got stuck on a particular issue.

My project is in Maven, with a Core module holding commands, events,etc… The query layer comes next in a separate module, with Spring Data injecting into a postgreSQL database. The domain layer is the third Maven module, holding the aggregates, and sagas, which are stored in Mongo. The fourth module holds some services, and the fifth module holds Web stuff.

I currently have one saga, which manages several subtasks for a parent task, and it works fine. I am trying to add a second saga which handles a different set of subtasks for the same parent. However, I am getting some very strange behaviour, and I cannot track down the root cause.

Specifically, I am seeing the following stack trace:

java.lang.NoClassDefFoundError: com/mongodb/MongoSocketException

at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:58)

at org.springframework.data.mongodb.core.MongoFactoryBean.translateExceptionIfPossible(MongoFactoryBean.java:144)

at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)

at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)

at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

at com.sun.proxy.$Proxy54.findByParentItemUuidAndNoteTypeAndActive(Unknown Source)

at TRUNCATED.end2end.NotesEndToEndIT.endToEndTest(NotesEndToEndIT.java:77)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)

at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)

at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoSocketException

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

… 42 more

The specific line TRUNCATED.end2end.NotesEndToEndIT.endToEndTest (NotesEndToEndIT.java:77) reads as follows:

Set notesFound = noteRecordRepository.findByParentItemUuidAndNoteTypeAndActive(userUuid, NoteType.USER_NOTE, ACTIVE);

This command will retrieve notes from the JPA Repository in the Query layer.

During the @Before step of this test, I am setting up one of the Parent items, which triggers my new Saga. The new Saga will trigger another Command which is placed on the CommandGateway. If I disable the additional command, then my test works fine.

My initial Saga also submits additional commands to the CommandGateway, and does not suffer from this problem, so I confident that my approach should be sound, but I cannot understand why I am getting a MongoSocketException when trying to access a JPA Repository.

Any help is appreciated !

Thanks,

Mark Allen

Hi Mark,

sorry for the late reply. It has been busy around here the last couple of days.

This error is very likely a classpath issue, not so much a programming one. Do you have multiple versions of Spring Data and/or Mongo on the classpath? Are the versions of Spring Core, Spring Data and the Mongo client compatible?

Cheers,

Allard

Hi Allard,

Thank you very much for getting back to me. I have been looking into the versioning as suggested, but I cannot see a problem.

I am using Maven to manage the dependencies, which has not identified an issue. I have compared the output from “mvn dependency:tree” between my project, and the Axon-trader project, and I have ensured that the dependencies are matched.

Specifically, I am using:
spring-core 4.0.6.RELEASE
spring-data-mongodb 1.5.2.RELEASE
spring-data-jpa 1.6.2.RELEASE
spring-data-commons 1.8.2.RELEASE
mongo-java-driver 2.11.3

These versions are the same as used with Axon-trader. (Although the axon-trader uses axon 2.3 and I am using axon 2.3.2, I have tried moving the axon version back to 2.3, but the behaviour is still the same.)

What is most peculiar is that if I have a single Saga based on a PARENT object, it all works fine. When I add a second saga on the PARENT item, I start getting the MongoSocketException whist accessing a JPA repository.
Actually, scratch that, I just tried only wiring in the second saga, and I still have the same issue.

Very odd !

Regards,
Mark

Hi Allard,
I think I may have made progress…

I have overridden the mongo version brought in by Axon from 2.11.x to 2.12.x, and my error message has become much more meaningful, and I can see a problem in my code.

You are right, that somehow the MongoSocketException from version 2.12.x is being thrown, and cannot be caught using mongo 2.11.x

There is clearly an issue with my dependencies as you correctly guessed first time.

Many Thanks for your help !
Mark