Search in sources :

Example 1 with ServerVersion

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

the class CommandMonitoringTest method setUp.

@Before
public void setUp() {
    ServerVersion serverVersion = ClusterFixture.getServerVersion();
    if (definition.containsKey("ignore_if_server_version_less_than")) {
        assumeFalse(serverVersion.compareTo(getServerVersion("ignore_if_server_version_less_than")) < 0);
    }
    if (definition.containsKey("ignore_if_server_version_greater_than")) {
        assumeFalse(serverVersion.compareTo(getServerVersion("ignore_if_server_version_greater_than")) > 0);
    }
    if (definition.containsKey("ignore_if_topology_type")) {
        BsonArray topologyTypes = definition.getArray("ignore_if_topology_type");
        for (BsonValue type : topologyTypes) {
            String typeString = type.asString().getValue();
            if (typeString.equals("sharded")) {
                assumeFalse(isSharded());
            } else if (typeString.equals("replica_set")) {
                assumeFalse(isDiscoverableReplicaSet());
            } else if (typeString.equals("standalone")) {
                assumeFalse(isSharded());
            }
        }
    }
    List<BsonDocument> documents = new ArrayList<BsonDocument>();
    for (BsonValue document : data) {
        documents.add(document.asDocument());
    }
    CollectionHelper<Document> collectionHelper = new CollectionHelper<Document>(new DocumentCodec(), new MongoNamespace(databaseName, collectionName));
    collectionHelper.drop();
    collectionHelper.insertDocuments(documents);
    commandListener.reset();
    collection = mongoClient.getDatabase(databaseName).getCollection(collectionName, BsonDocument.class);
    if (definition.getDocument("operation").containsKey("read_preference")) {
        collection = collection.withReadPreference(ReadPreference.valueOf(definition.getDocument("operation").getDocument("read_preference").getString("mode").getValue()));
    }
    helper = new JsonPoweredCrudTestHelper(description, collection);
}
Also used : ServerVersion(com.mongodb.connection.ServerVersion) ArrayList(java.util.ArrayList) DocumentCodec(org.bson.codecs.DocumentCodec) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonString(org.bson.BsonString) MongoNamespace(com.mongodb.MongoNamespace) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) BsonDocument(org.bson.BsonDocument) BsonArray(org.bson.BsonArray) CollectionHelper(com.mongodb.client.test.CollectionHelper) BsonValue(org.bson.BsonValue) Before(org.junit.Before)

Aggregations

MongoNamespace (com.mongodb.MongoNamespace)1 CollectionHelper (com.mongodb.client.test.CollectionHelper)1 ServerVersion (com.mongodb.connection.ServerVersion)1 ArrayList (java.util.ArrayList)1 BsonArray (org.bson.BsonArray)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 BsonValue (org.bson.BsonValue)1 Document (org.bson.Document)1 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)1 DocumentCodec (org.bson.codecs.DocumentCodec)1 Before (org.junit.Before)1