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

fongo not compatible with 3.7 driver version #337

Open
zigzago opened this issue May 6, 2018 · 13 comments
Open

fongo not compatible with 3.7 driver version #337

zigzago opened this issue May 6, 2018 · 13 comments

Comments

@zigzago
Copy link

zigzago commented May 6, 2018

MongoOperation, MongoDatabaseImpl, MongoCollectionImpl, etc. have moved to com.mongodb.client.internal package...

twillouer pushed a commit that referenced this issue May 6, 2018
@twillouer
Copy link
Collaborator

can you try with driver37 branch ?

@zigzago
Copy link
Author

zigzago commented May 6, 2018

my tests pass with driver37 branch, thanks! It would be nice to have a first fongo release for 3.7 :)

twillouer pushed a commit that referenced this issue May 9, 2018
twillouer pushed a commit that referenced this issue Jun 5, 2018
@d0x
Copy link

d0x commented Jul 6, 2018

@hoffrocket any plans about merging his PR or supporting 3.7 in general?

@markbigler
Copy link

There are other issues adressing the same topic: #357

@twillouer any news about supporting mongodb driver 3.7+?

@bsautel
Copy link

bsautel commented Oct 31, 2018

I am also facing this issue that prevents me from upgrading to Spring Boot 2.1.0.

I tried to test using the driver37 branch, but I could not build it with Maven. I get the following output:


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Erreur : impossible de trouver ou charger la classe principale org.apache.maven.surefire.booter.ForkedBooter

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

The error message is in french, it tells that it was impossible to find the main class org.apache.maven.surefire.booter.ForkedBooter.

I would have used the manually built jar as a workaround until the new Fongo release is published on the Maven Central repository, but this error prevents me from testing this workaround.

@kiwisincebirth
Copy link

Same issue for me on Spring Boot 2.1.0 mongo db driver 3.8.2 and Java 8. I am on the "fongo-2.2.0-RC2" release.

Caused by: java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor
at com.github.fakemongo.Fongo.createMongo(Fongo.java:190)

@bsautel
Copy link

bsautel commented Nov 8, 2018

I finally could build the driver37 branch thanks to the -DskipTests=true Maven option 🙈.

I tested it with Spring Boot 2.1.0 (driver 3.8.2) and it does not work. I get this error:

java.lang.AbstractMethodError: com.mongodb.client.internal.FongoOperationExecutor.execute(Lcom/mongodb/operation/ReadOperation;Lcom/mongodb/ReadPreference;Lcom/mongodb/ReadConcern;)Ljava/lang/Object;
	at com.mongodb.DBCursor.initializeCursor(DBCursor.java:896)
	at com.mongodb.DBCursor.hasNext(DBCursor.java:148)
	at com.mongodb.DBCursor.one(DBCursor.java:697)
	at com.mongodb.DBCollection.findOne(DBCollection.java:845)
	at com.mongodb.DBCollection.findOne(DBCollection.java:805)
	at com.mongodb.DBCollection.findOne(DBCollection.java:748)
	at com.mongodb.FongoDBCollection.createIndex(FongoDBCollection.java:522)
	at com.mongodb.FongoDBCollection.<init>(FongoDBCollection.java:93)
	at com.mongodb.FongoDB.doGetCollection(FongoDB.java:96)
	at com.mongodb.FongoDB.doGetCollection(FongoDB.java:87)
	at com.mongodb.FongoDB.getCollection(FongoDB.java:82)
	at com.mongodb.client.internal.FongoMongoCollection.<init>(FongoMongoCollection.java:32)
	at com.mongodb.client.internal.FongoMongoDatabase.getCollection(FongoMongoDatabase.java:51)

It sounds like the driver 3.8 is different from the 3.7 one.

@leantrace
Copy link

Same here:
Caused by: java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor
at com.github.fakemongo.Fongo.createMongo(Fongo.java:190)

Java: 11
Spring Boot: 2.1.0.RELEASE
Fongo: 2.2.0-RC2
mongodb-driver: 3.8.2

@bsautel
Copy link

bsautel commented Nov 14, 2018

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

I tried it recently, I encountered two blocking issues (features not yet implemented), I reported them and they were fixed very quickly. All my tests are now running with Spring Boot 2.1.0. 😀

@leantrace
Copy link

leantrace commented Nov 14, 2018

Thx @bsautel - works like a charm! 👍

A short How-To for those, running into same Problem
Java Runtime: 11
Syntax: Kotlin (its easy to translate to Java with IntelliJ)
Spring Boot: 2.1.0.RELEASE
mongo-java-server: 1.9.7
mongodb-driver: 3.8.2

Replace "fongo" with "mongo-java-server" in your pom.xml, gradle whatever

<dependency>
	<groupId>de.bwaldvogel</groupId>
	<artifactId>mongo-java-server</artifactId>
	<version>1.9.7</version>
	<scope>test</scope>
</dependency>

Add Spring Boot Configuration

@EnableAutoConfiguration(exclude = [EmbeddedMongoAutoConfiguration::class, MongoAutoConfiguration::class, MongoDataAutoConfiguration::class, SecurityAutoConfiguration::class])
@EnableMongoRepositories(basePackages = ["my.project.repositories"])
@Configuration
@ComponentScan(basePackages = ["my.project"],
        excludeFilters = [ComponentScan.Filter(classes = [SpringBootApplication::class])])
class InMemoryMongoDbConfiguration : AbstractMongoConfiguration(){
    
    lateinit var client: MongoClient
    lateinit var server: MongoServer

    @Bean
    fun userCascadingMongoEventListener(): CascadeSaveMongoEventListener {
        return CascadeSaveMongoEventListener()
    }

    @Throws(Exception::class)
    override fun mongoClient(): MongoClient {
        server = MongoServer(MemoryBackend())
        // bind on a random local port
        val serverAddress = server.bind()
        client = MongoClient(ServerAddress(serverAddress))
        return client
    }

    override fun getDatabaseName(): String {
        return "test"
    }
    
    @PreDestroy
    fun shutdown(){
        client.close()
        server.shutdown()
    }

}

Make a Test

@RunWith(SpringRunner::class)
@SpringBootTest(
  classes = [InMemoryMongoDbConfiguration::class],
  webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApplicationsTest {

	@Autowired
	lateinit var testRestTemplate: TestRestTemplate

    @Test
    fun whenCalled_thenShouldReturnApplications() {
        val _prj_base = Utils.createBasicProjectFull(UUID.randomUUID().toString())
        val p = testRestTemplate.withBasicAuth("admin", "admin").postForEntity("/api/v1/projects", _prj_base, Project::class.java).body
        val req = testRestTemplate.withBasicAuth("admin", "admin").getForEntity("/api/v1/projects/${p._id}", Project::class.java)
        assertNotNull(req)
        assertEquals(HttpStatus.OK, req?.statusCode)
        Utils.assertIgnoreIdAndCreatedOn(p, req.body!!, true)
        assertEquals(setOf<Application>(), req.body!!.applications.toSet())
    }
}

Keep smiling! :)

@bsautel
Copy link

bsautel commented Nov 14, 2018

Nice @leantrace , thanks for sharing the replacement example!

I just noticed noticed that you don't close the server in your InMemoryMongoDbConfiguration (server.shutdown() as explained in the project documentation) when the application context is destroyed. This may lead to resource leaks in your tests execution. It's not a big deal if the tests run in a dedicated JVM that stops at the ends of tests execution but it is better to free it anyway.

@bwaldvogel
Copy link

@leantrace @bsautel: I’m happy to hear that mongo-java-server works for you.

The Spring Boot configuration example could be something to include in the README.
Do you want to submit a pull request?

@ndemengel
Copy link

Hi,

Not sure if I should double-post it or not, but you might be interested in that other comment of mine for a solution to have fongo working with mongo 3.8 : #357 (comment)

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