SpringBoot Data Mongodb with Testcontainers lead to "Prematurely reached end of stream"

271 Views Asked by At

It started after I upgraded my SB application to 3.2.0. I initially thought there was something wrong with my spring context. So after a couple of days banging my head against the wall, I finally decided to try something new (and kind of obvious): start with a fresh SB application. So I went to https://start.spring.io/ and created a new SB 3.2.0 with only web, mongodb and testcontainers, which gave me this clean gradle build config:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '21'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.boot:spring-boot-testcontainers'
    testImplementation 'org.testcontainers:junit-jupiter'
    testImplementation 'org.testcontainers:mongodb'
}

tasks.named('test') {
    useJUnitPlatform()
}

Everything looks fine so far, so I went to the demo test file that spring provided and changed it into this:

@Testcontainers
@SpringBootTest
class DemoApplicationTests {

    @Container
    @ServiceConnection
    static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:latest");

    @Test
    void contextLoads() {
    }
}

If I run the test now, although the test itself passes, it throws the following exception:

com.mongodb.MongoSocketReadException: Prematurely reached end of stream
    at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:177) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:200) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:739) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.receiveMessageWithAdditionalTimeout(InternalStreamConnection.java:603) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:451) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.receive(InternalStreamConnection.java:404) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:224) ~[mongodb-driver-core-4.11.1.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:156) ~[mongodb-driver-core-4.11.1.jar:na]
    at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]

I'm on an Apple M1 Max - but I also get the same result when running on Github Actions runner with Linux (Ubuntu).

Any ideas whether this is a bug or whether I got something wrong?

0

There are 0 best solutions below