Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for java mongodb driver 3.6.4+ #357

Open
albertotn opened this issue Sep 20, 2018 · 12 comments
Open

Support for java mongodb driver 3.6.4+ #357

albertotn opened this issue Sep 20, 2018 · 12 comments

Comments

@albertotn
Copy link

I've tried to use Fongo with java mongodb driver 3.7.1 and receive this exception (with Java 8):

java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor
	at com.github.fakemongo.Fongo.createMongo(Fongo.java:190)
	at com.github.fakemongo.Fongo.<init>(Fongo.java:103)
	at com.github.fakemongo.Fongo.<init>(Fongo.java:90)
	at com.github.fakemongo.Fongo.<init>(Fongo.java:82)
	at it.gpi.flowmanager2.batch.SingleValueHandlerTest.setup(SingleValueHandlerTest.java:39)
	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.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.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ClassNotFoundException: com.mongodb.OperationExecutor
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 20 more

Reading 3.7.x release notes: http://mongodb.github.io/mongo-java-driver/3.7/whats-new/ seems to be a problem related to new Java 9 modular approach.

I've found branch driver37 but I'm not sure If I need to use it or stay with master, please let me know

@ngbalk
Copy link

ngbalk commented Oct 12, 2018

I'm using mongo-java-driver 3.8.2 and getting the exact same exception (also with Java 8).

@markbigler
Copy link

Same issue for me with mongodb-driver 3.8.2 (spring boot 2.1.0).

The class com.mongodb.OperationExecutor as used in MockMongoClient is no longer available.

com.mongodb.OperationExecutor createOperationExecutor() {
  return new FongoOperationExecutor(fongo);
}

@Writtscher
Copy link

@twillouer Hi, can we have a response regarding this issue? What is the priority of this issue as it is currently a show stopper for our project, as we cannot upgrade to latest the spring/mongo version.

I would like to avoid switching to another (embedded) mongo solution...

@tschiman
Copy link

We are also having a similar problem. Using driver 3.8.2 with spring boot 2.1.0. We are getting a null pointer exception in the com.mongodb.Mongo class when attempting to access the:

private final MongoClientDelegate delegate;

This element is not set by the MockMongoClient from Fongo and certain operations fail. The operation we are executing is:

mongoTemplate.indexOps(QueueEntry.class).ensureIndex(new Index(CREATED_DATE_FIELD_NAME, Sort.Direction.DESC));

Here is the stack trace from the failure:

java.lang.NullPointerException
at com.mongodb.Mongo.createOperationExecutor(Mongo.java:790)
at com.mongodb.DB.(DB.java:101)
at com.mongodb.FongoDB.(FongoDB.java:43)
at com.github.fakemongo.Fongo.getDB(Fongo.java:117)
at com.mongodb.FongoMongoCollection.(FongoMongoCollection.java:28)
at com.mongodb.FongoMongoDatabase.getCollection(FongoMongoDatabase.java:47)
at org.springframework.data.mongodb.core.MongoTemplate.getAndPrepareCollection(MongoTemplate.java:2574)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:534)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:521)
at org.springframework.data.mongodb.core.DefaultIndexOperations.execute(DefaultIndexOperations.java:215)
at org.springframework.data.mongodb.core.DefaultIndexOperations.ensureIndex(DefaultIndexOperations.java:121)

@markbigler
Copy link

You should give a try to mongo-java-server.

Except for 2 test cases the switch from fongo to mongo-java-server went without any problems for me. I reported them and they were fixed very quickly. Thanks @bwaldvogel

@jaypatel512
Copy link

Same issue as @tschiman !

@jaypatel512
Copy link

Btw @tschiman ! Seeing that it was created on Sep 20, and nothing has changed in last 4 months, I switched to mongo-java-server, as @markbigler suggested, and it worked like a charm. No code change required in my case. Just a small change in my test-mongo.xml spring configurations, and everything went smoothly.

I would highly recommend doing that to anyone who comes here, until the bug is fixed.

@medialwerk
Copy link

I invested three days before my holidays fixing my specs and didn't get it done. With @markbigler solution, all tests were green again within 10 minutes 💯. Big thanks! :-)

@Writtscher
Copy link

We switched one week later and it everything is working. We will not switch back anymore.

@ndemengel
Copy link

Hi everyone,

We (at Malt) encountered the same problems as everyone:

  • first to move to mongo-java-driver 3.7 during a migration to Spring Boot 2.0. It's been eventually solved by using fongo 2.2.0-RC1, as suggested here
  • then to move to mongo-java-driver 3.8 during a migration to Spring Boot 2.1. fongo 2.2.0-RC2 could not help, and though mongo-java-server is a nice piece of work, it fell short on features and many of our tests failed. I started to patch it but there simply was too much work.

So I finally dedicated some hours to fongo itself and here is the result: fongo-mongo-3.8. Please note that only the minimum amount of work required to have all tests pass with the 3.8 driver has been done. I couldn't find a way to contribute it in an "intelligent" way, since it can't just be a pull request for a new version of fongo (it requires Java 8+ and mongo 3.8), so I called it fongo-mongo-3.8 and made it clear that it's not provided by the fongo team (for now). Also we didn't publish it to Maven central, so you will have to build it by yourself if you want to use it.
I hope it can be reintegrated into the fongo project in some way, but meanwhile we at least have a way to move forward.

As a side note, I'd like to share some thoughts if it can be of any help to someone else: we do think in my team that though fongo is a nice tool, we should not rely that much on it. We are improving our testing strategy to mock our repository interfaces (which is easier now that we're more and more applying the hexagonal architecture principles), and we test our repository implementations using a real database via https://www.testcontainers.org/. Also, we're in the process of dropping MongoDB, but that's another story :-)

@rashmidash
Copy link

rashmidash commented Oct 15, 2019

Btw @tschiman ! Seeing that it was created on Sep 20, and nothing has changed in last 4 months, I switched to mongo-java-server, as @markbigler suggested, and it worked like a charm. No code change required in my case. Just a small change in my test-mongo.xml spring configurations, and everything went smoothly.

I would highly recommend doing that to anyone who comes here, until the bug is fixed.

Hi @jaypatel512,

We are trying to fix using same type of xml configuration. Could you please share your test-mongo.xml or inbox me the same. ([email protected])

@markbigler
Copy link

We are trying to fix using same type of xml configuration. Could you please share your test-mongo.xml or inbox me the same. ([email protected])

Solution: bwaldvogel/mongo-java-server#103 (comment)

sundarvenkata-EBI added a commit to sundarvenkata-EBI/variation-commons that referenced this issue May 10, 2020
sundarvenkata-EBI added a commit to sundarvenkata-EBI/eva-ws that referenced this issue May 20, 2020
PR notes
Use pipe delimiter in application properties so that they can be parametrized for both Travis and Gitlab
Replace Fongo with real MongoDB tests because Fongo is not supported in Spring Boot 2.1 - see [here](fakemongo/fongo#357)
Update Travis and Gitlab scripts to include Mongo installations
Update POMs to support "|" delimiters so that EVA mongo host for tests can be parametrized for both Travis and Gitlab
javax.validation API dependency need no longer be explicitly pulled in since Spring Boot 2 contains it
Upgrade jackson-databind version to 2.9.7 to work with Spring Boot 2
JPA repository query methods should be marked with "Query" annotation
sundarvenkata-EBI added a commit to sundarvenkata-EBI/eva-ws that referenced this issue May 20, 2020
PR notes
Use pipe delimiter in application properties so that they can be parametrized for both Travis and Gitlab
Replace Fongo with real MongoDB tests because Fongo is not supported in Spring Boot 2.1 - see [here](fakemongo/fongo#357)
Update Travis and Gitlab scripts to include Mongo installations
Update POMs to support "|" delimiters so that EVA mongo host for tests can be parametrized for both Travis and Gitlab
javax.validation API dependency need no longer be explicitly pulled in since Spring Boot 2 contains it
Upgrade jackson-databind version to 2.9.7 to work with Spring Boot 2
JPA repository query methods should be marked with "Query" annotation
andresfsilva added a commit to EBIvariation/eva-ws that referenced this issue May 29, 2020
EVA-1902 - Spring Boot 2 upgrade

- Replace Fongo with real MongoDB tests because Fongo is not supported in Spring Boot 2.1 - see [here](fakemongo/fongo#357)
  - Update Travis and Gitlab scripts to include Mongo installations
  - Update POMs to support "|" delimiters so that EVA mongo host for tests can be parametrized for both Travis and Gitlab
- javax.validation API dependency need no longer be explicitly pulled in since Spring Boot 2 contains it
- Upgrade jackson-databind version to 2.9.7 to work with Spring Boot 2
- JPA repository query methods should be marked with "Query" annotation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants