Search in sources :

Example 16 with EnableIfMongoServerVersion

use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.

the class SimpleMongoRepositoryTests method countShouldBePossibleInTransaction.

// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void countShouldBePossibleInTransaction() {
    MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
    TransactionTemplate tt = new TransactionTemplate(txmgr);
    tt.afterPropertiesSet();
    long countPreTx = repository.count();
    long count = tt.execute(status -> {
        Person sample = new Person();
        sample.setLastname("Matthews");
        repository.save(sample);
        return repository.count();
    });
    assertThat(count).isEqualTo(countPreTx + 1);
}
Also used : MongoTransactionManager(org.springframework.data.mongodb.MongoTransactionManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Person(org.springframework.data.mongodb.repository.Person) EnableIfReplicaSetAvailable(org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) Test(org.junit.jupiter.api.Test)

Example 17 with EnableIfMongoServerVersion

use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.

the class SimpleMongoRepositoryVersionedEntityTests method deleteWithMatchingVersionInTx.

// DATAMONGO-2195
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
public void deleteWithMatchingVersionInTx() {
    assumeThat(ReplicaSet.required().runsAsReplicaSet()).isTrue();
    long countBefore = repository.count();
    initTxTemplate().execute(status -> {
        VersionedPerson t800 = repository.save(new VersionedPerson("T-800"));
        repository.delete(t800);
        return Void.TYPE;
    });
    assertThat(repository.count()).isEqualTo(countBefore);
}
Also used : VersionedPerson(org.springframework.data.mongodb.repository.VersionedPerson) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)17 EnableIfMongoServerVersion (org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion)17 AggregationUpdate (org.springframework.data.mongodb.core.aggregation.AggregationUpdate)8 EnableIfReplicaSetAvailable (org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable)6 StepVerifier (reactor.test.StepVerifier)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 Disposable (reactor.core.Disposable)4 VersionedPerson (org.springframework.data.mongodb.core.MongoTemplateTests.VersionedPerson)3 Document (org.springframework.data.mongodb.core.mapping.Document)3 MongoTransactionManager (org.springframework.data.mongodb.MongoTransactionManager)2 Person (org.springframework.data.mongodb.repository.Person)2 VersionedPerson (org.springframework.data.mongodb.repository.VersionedPerson)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 ClientSessionOptions (com.mongodb.ClientSessionOptions)1 ClientSession (com.mongodb.reactivestreams.client.ClientSession)1 MongoClient (com.mongodb.reactivestreams.client.MongoClient)1 Instant (java.time.Instant)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Supplier (java.util.function.Supplier)1 Assertions (org.assertj.core.api.Assertions)1