Search in sources :

Example 21 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParserIntegrationTests method parsesCustomWriteConcern.

// DATAMONGO-2199
@Test
public void parsesCustomWriteConcern() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("namespace/db-factory-bean-custom-write-concern.xml");
    assertWriteConcern(ctx, new WriteConcern("rack1"));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) WriteConcern(com.mongodb.WriteConcern) Test(org.junit.jupiter.api.Test)

Example 22 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testSecondMongoTemplateFactory.

// DATAMONGO-140
@Test
public void testSecondMongoTemplateFactory() {
    assertThat(ctx.containsBean("anotherMongoTemplate")).isTrue();
    MongoOperations operations = (MongoOperations) ctx.getBean("anotherMongoTemplate");
    MongoDatabaseFactory dbf = (MongoDatabaseFactory) getField(operations, "mongoDbFactory");
    assertThat(getField(dbf, "databaseName")).isEqualTo("database");
    WriteConcern writeConcern = (WriteConcern) getField(operations, "writeConcern");
    assertThat(writeConcern).isEqualTo(WriteConcern.ACKNOWLEDGED);
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) WriteConcern(com.mongodb.WriteConcern) MongoOperations(org.springframework.data.mongodb.core.MongoOperations) Test(org.junit.Test)

Example 23 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class WriteConcernPropertyEditorUnitTests method createsWriteConcernForUnknownConstants.

@Test
public void createsWriteConcernForUnknownConstants() {
    editor.setAsText("-1");
    assertThat(editor.getValue()).isEqualTo(new WriteConcern("-1"));
}
Also used : WriteConcern(com.mongodb.WriteConcern) Test(org.junit.jupiter.api.Test)

Example 24 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class ReactivePerformanceTests method executeWithWriteConcerns.

private void executeWithWriteConcerns(WriteConcernCallback callback) {
    Constants constants = new Constants(WriteConcern.class);
    for (String constantName : constants.getNames(null)) {
        if (IGNORED_WRITE_CONCERNS.contains(constantName)) {
            continue;
        }
        WriteConcern writeConcern = (WriteConcern) constants.asObject(constantName);
        setupCollections();
        callback.doWithWriteConcern(constantName, writeConcern);
    }
}
Also used : WriteConcern(com.mongodb.WriteConcern) Constants(org.springframework.core.Constants)

Example 25 with WriteConcern

use of com.mongodb.WriteConcern in project spring-data-mongodb by spring-projects.

the class ReactivePerformanceTests method writingObjectsUsingPlainDriver.

private long writingObjectsUsingPlainDriver(int numberOfPersons, WriteConcern concern) {
    MongoCollection<Document> collection = mongo.getDatabase(DATABASE_NAME).getCollection("driver").withWriteConcern(concern);
    List<Person> persons = getPersonObjects(numberOfPersons);
    executeWatched(() -> persons.stream().map(it -> Mono.from(collection.insertOne(new Document(it.toDocument()))).block()));
    return watch.getLastTaskTimeMillis();
}
Also used : Document(org.bson.Document) SimpleReactiveMongoDatabaseFactory(org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) ReferenceLoader(org.springframework.data.mongodb.core.convert.ReferenceLoader) PersistenceConstructor(org.springframework.data.annotation.PersistenceConstructor) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) MongoClients(com.mongodb.reactivestreams.client.MongoClients) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) BasicDBList(com.mongodb.BasicDBList) MongoClient(com.mongodb.reactivestreams.client.MongoClient) ReactiveMongoOperations(org.springframework.data.mongodb.core.ReactiveMongoOperations) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) ReferenceLookupDelegate(org.springframework.data.mongodb.core.convert.ReferenceLookupDelegate) DbRefResolverCallback(org.springframework.data.mongodb.core.convert.DbRefResolverCallback) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) MongoDatabase(com.mongodb.reactivestreams.client.MongoDatabase) DbRefProxyHandler(org.springframework.data.mongodb.core.convert.DbRefProxyHandler) MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) Constants(org.springframework.core.Constants) Nullable(org.springframework.lang.Nullable) ReactiveMongoRepository(org.springframework.data.mongodb.repository.ReactiveMongoRepository) DecimalFormat(java.text.DecimalFormat) BasicDBObject(com.mongodb.BasicDBObject) Mono(reactor.core.publisher.Mono) StopWatch(org.springframework.util.StopWatch) ReactiveMongoRepositoryFactory(org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory) Collectors(java.util.stream.Collectors) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DBRef(com.mongodb.DBRef) ObjectId(org.bson.types.ObjectId) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) Pattern(java.util.regex.Pattern) WriteConcern(com.mongodb.WriteConcern) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) Document(org.bson.Document)

Aggregations

WriteConcern (com.mongodb.WriteConcern)53 Document (org.bson.Document)14 MongoException (com.mongodb.MongoException)11 List (java.util.List)11 ArrayList (java.util.ArrayList)9 ReadPreference (com.mongodb.ReadPreference)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 TimeUnit (java.util.concurrent.TimeUnit)7 BsonDocument (org.bson.BsonDocument)7 DeleteResult (com.mongodb.client.result.DeleteResult)6 HashMap (java.util.HashMap)6 ClientSessionOptions (com.mongodb.ClientSessionOptions)5 ReadConcern (com.mongodb.ReadConcern)5 Arrays (java.util.Arrays)5 BsonValue (org.bson.BsonValue)5 FullDocument (com.mongodb.client.model.changestream.FullDocument)4 InsertOneResult (com.mongodb.client.result.InsertOneResult)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)4