Search in sources :

Example 6 with TestConnectionPoolListener

use of com.mongodb.internal.connection.TestConnectionPoolListener in project mongo-java-driver by mongodb.

the class ConnectionsSurvivePrimaryStepDownProseTest method setUp.

@Before
public void setUp() {
    assumeTrue(isDiscoverableReplicaSet() && serverVersionAtLeast(4, 0));
    connectionPoolListener = new TestConnectionPoolListener();
    MongoClientSettings settings = MongoClientSettings.builder(getMongoClientSettings()).retryWrites(false).applyToConnectionPoolSettings(new Block<ConnectionPoolSettings.Builder>() {

        @Override
        public void apply(final ConnectionPoolSettings.Builder builder) {
            builder.addConnectionPoolListener(connectionPoolListener);
        }
    }).build();
    collectionHelper = new CollectionHelper<Document>(new DocumentCodec(), new MongoNamespace(getDefaultDatabaseName(), COLLECTION_NAME));
    client = MongoClients.create(settings);
    MongoDatabase database = client.getDatabase(getDefaultDatabaseName());
    collection = client.getDatabase(getDefaultDatabaseName()).getCollection(COLLECTION_NAME);
    collection.withWriteConcern(WriteConcern.MAJORITY).drop();
    database.withWriteConcern(WriteConcern.MAJORITY).createCollection(COLLECTION_NAME);
}
Also used : TestConnectionPoolListener(com.mongodb.internal.connection.TestConnectionPoolListener) DocumentCodec(org.bson.codecs.DocumentCodec) Block(com.mongodb.Block) Fixture.getMongoClientSettings(com.mongodb.client.Fixture.getMongoClientSettings) MongoClientSettings(com.mongodb.MongoClientSettings) Document(org.bson.Document) MongoNamespace(com.mongodb.MongoNamespace) ConnectionPoolSettings(com.mongodb.connection.ConnectionPoolSettings) Before(org.junit.Before)

Aggregations

TestConnectionPoolListener (com.mongodb.internal.connection.TestConnectionPoolListener)6 MongoClientSettings (com.mongodb.MongoClientSettings)4 ConnectionPoolClearedEvent (com.mongodb.event.ConnectionPoolClearedEvent)3 TestCommandListener (com.mongodb.internal.connection.TestCommandListener)3 Arrays.asList (java.util.Arrays.asList)3 BsonDocument (org.bson.BsonDocument)3 BsonString (org.bson.BsonString)3 Document (org.bson.Document)3 Assume.assumeTrue (org.junit.Assume.assumeTrue)3 Before (org.junit.Before)3 ClusterFixture.isDiscoverableReplicaSet (com.mongodb.ClusterFixture.isDiscoverableReplicaSet)2 ClusterFixture.isSharded (com.mongodb.ClusterFixture.isSharded)2 ClusterFixture.serverVersionAtLeast (com.mongodb.ClusterFixture.serverVersionAtLeast)2 MongoException (com.mongodb.MongoException)2 MongoNamespace (com.mongodb.MongoNamespace)2 WriteConcern (com.mongodb.WriteConcern)2 Fixture.getMongoClientSettingsBuilder (com.mongodb.client.Fixture.getMongoClientSettingsBuilder)2 ConnectionCheckOutFailedEvent (com.mongodb.event.ConnectionCheckOutFailedEvent)2 ConnectionCheckedOutEvent (com.mongodb.event.ConnectionCheckedOutEvent)2 TimeUnit (java.util.concurrent.TimeUnit)2