Details
-
Improvement
-
Resolution: Done
-
Minor - P4
-
2.12.2
-
None
Description
When restarting mongodb, the first request after mongodb has restarted fails.
import com.mongodb.DB;
|
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClientOptions;
|
import org.junit.Before;
|
import org.junit.Test;
|
|
|
public class TestMongoReconnection {
|
|
|
public static final int RESTART_DELAY = 20000;
|
private MongoClient mongoClient;
|
|
|
@Before
|
public void setUp() throws Exception {
|
|
|
MongoClientOptions mongoClientOptions = MongoClientOptions.builder()
|
// .heartbeatFrequency(10) //check every 10ms
|
.build();
|
|
|
mongoClient = new MongoClient("127.0.0.1", mongoClientOptions);
|
}
|
|
|
@Test
|
public void first_request_after_mongo_restart_should_success() throws Exception {
|
|
|
DB db = mongoClient.getDB("test");
|
db.getCollectionNames();
|
|
|
System.out.println(String.format("you have %sms to restart your mongodb server before the test resumes", RESTART_DELAY));
|
Thread.sleep(RESTART_DELAY);
|
|
|
db.getCollectionNames();
|
}
|
}
|
The DefaultServer$DefaultServerStateListener class should call connectionProvider.invalidate(); if the state changed from connected to connecting