use of com.mongodb.ClusterFixture.TIMEOUT_DURATION 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(builder -> builder.addConnectionPoolListener(connectionPoolListener)).build();
collectionHelper = new CollectionHelper<>(new DocumentCodec(), new MongoNamespace(getDefaultDatabaseName(), COLLECTION_NAME));
client = MongoClients.create(settings);
MongoDatabase database = client.getDatabase(getDefaultDatabaseName());
collection = client.getDatabase(getDefaultDatabaseName()).getCollection(COLLECTION_NAME);
Mono.from(collection.withWriteConcern(WriteConcern.MAJORITY).drop()).block(TIMEOUT_DURATION);
Mono.from(database.withWriteConcern(WriteConcern.MAJORITY).createCollection(COLLECTION_NAME)).block(TIMEOUT_DURATION);
}
use of com.mongodb.ClusterFixture.TIMEOUT_DURATION in project mongo-java-driver by mongodb.
the class BatchCursorFluxTest method ensureExists.
/**
* This method ensures that the server considers the specified {@code collection} existing for the purposes of, e.g.,
* {@link MongoCollection#drop()}, instead of replying with
* {@code "errmsg": "ns not found", "code": 26, "codeName": "NamespaceNotFound"}.
*
* @return {@code operationTime} starting at which the {@code collection} is guaranteed to exist.
*/
private static BsonTimestamp ensureExists(final MongoClient client, final MongoCollection<Document> collection) {
BsonValue insertedId = Mono.from(collection.insertOne(Document.parse("{}"))).map(InsertOneResult::getInsertedId).block(TIMEOUT_DURATION);
BsonArray deleteStatements = new BsonArray();
deleteStatements.add(new BsonDocument().append("q", new BsonDocument().append("_id", insertedId)).append("limit", new BsonInt32(1)));
Publisher<Document> deletePublisher = client.getDatabase(collection.getNamespace().getDatabaseName()).runCommand(new BsonDocument().append("delete", new BsonString(collection.getNamespace().getCollectionName())).append("deletes", deleteStatements));
BsonTimestamp operationTime = Mono.from(deletePublisher).map(doc -> doc.get("operationTime", BsonTimestamp.class)).block(TIMEOUT_DURATION);
assertNotNull(operationTime);
return operationTime;
}
Aggregations