Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1252

Should invalidate connection pool when ServerMonitor detects a disconnect

      When restarting mongodb, the first request after mongodb has restarted fails.

      Unable to find source-code formatter for language: title:testmongoreconnection.java. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            dchau David CHAU
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: