Search in sources :

Example 1 with RepeatFailedTest

use of org.junitpioneer.jupiter.RepeatFailedTest in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateIndexTests method indexCreationShouldFail.

// DATAMONGO-1928, DATAMONGO-2264
@RepeatFailedTest(3)
void indexCreationShouldFail() throws InterruptedException {
    // 
    factory.getMongoDatabase().flatMapMany(db -> // 
    db.getCollection("indexfail").createIndex(new Document("field", 1), new IndexOptions().name("foo").unique(true).sparse(true))).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    BlockingQueue<Throwable> queue = new LinkedBlockingQueue<>();
    ReactiveMongoTemplate template = new ReactiveMongoTemplate(factory, this.template.getConverter(), queue::add);
    template.findAll(IndexCreationShouldFail.class).subscribe();
    Throwable failure = queue.poll(10, TimeUnit.SECONDS);
    assertThat(failure).isNotNull().isInstanceOf(DataIntegrityViolationException.class);
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) StepVerifier(reactor.test.StepVerifier) RepeatFailedTest(org.junitpioneer.jupiter.RepeatFailedTest) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index.atIndex(org.assertj.core.data.Index.atIndex) Index(org.springframework.data.mongodb.core.index.Index) MongoClient(com.mongodb.reactivestreams.client.MongoClient) NoOpDbRefResolver(org.springframework.data.mongodb.core.convert.NoOpDbRefResolver) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Duration(java.time.Duration) Direction(org.springframework.data.domain.Sort.Direction) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Assertions(org.springframework.data.mongodb.test.util.Assertions) Indexed(org.springframework.data.mongodb.core.index.Indexed) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) BlockingQueue(java.util.concurrent.BlockingQueue) IndexField(org.springframework.data.mongodb.core.index.IndexField) IndexOptions(com.mongodb.client.model.IndexOptions) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Client(org.springframework.data.mongodb.test.util.Client) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) Data(lombok.Data) Id(org.springframework.data.annotation.Id) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) IndexOptions(com.mongodb.client.model.IndexOptions) Document(org.bson.Document) StepVerifier(reactor.test.StepVerifier) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) RepeatFailedTest(org.junitpioneer.jupiter.RepeatFailedTest)

Example 2 with RepeatFailedTest

use of org.junitpioneer.jupiter.RepeatFailedTest in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateIndexTests method testReadIndexInfoForIndicesCreatedViaMongoShellCommands.

// DATAMONGO-1444, DATAMONGO-2264
@RepeatFailedTest(3)
void testReadIndexInfoForIndicesCreatedViaMongoShellCommands() {
    // 
    template.indexOps(Person.class).dropAllIndexes().as(// 
    StepVerifier::create).verifyComplete();
    // 
    template.indexOps(Person.class).getIndexInfo().as(// 
    StepVerifier::create).verifyComplete();
    // 
    factory.getMongoDatabase().flatMapMany(db -> db.getCollection(template.getCollectionName(Person.class)).createIndex(new Document("age", -1), new IndexOptions().unique(true).sparse(true))).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    template.getCollection(template.getCollectionName(Person.class)).flatMapMany(MongoCollection::listIndexes).collectList().as(// 
    StepVerifier::create).consumeNextWith(indexInfos -> {
        Document indexKey = null;
        boolean unique = false;
        for (Document document : indexInfos) {
            if ("age_-1".equals(document.get("name"))) {
                indexKey = (org.bson.Document) document.get("key");
                unique = (Boolean) document.get("unique");
            }
        }
        assertThat(indexKey).containsEntry("age", -1);
        assertThat(unique).isTrue();
    }).verifyComplete();
    // 
    Flux.from(template.indexOps(Person.class).getIndexInfo().collectList()).as(// 
    StepVerifier::create).consumeNextWith(indexInfos -> {
        IndexInfo info = indexInfos.get(1);
        assertThat(info.isUnique()).isTrue();
        assertThat(info.isSparse()).isTrue();
        assertThat(info.getIndexFields()).contains(IndexField.create("age", Direction.DESC), atIndex(0));
    }).verifyComplete();
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) StepVerifier(reactor.test.StepVerifier) RepeatFailedTest(org.junitpioneer.jupiter.RepeatFailedTest) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index.atIndex(org.assertj.core.data.Index.atIndex) Index(org.springframework.data.mongodb.core.index.Index) MongoClient(com.mongodb.reactivestreams.client.MongoClient) NoOpDbRefResolver(org.springframework.data.mongodb.core.convert.NoOpDbRefResolver) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Duration(java.time.Duration) Direction(org.springframework.data.domain.Sort.Direction) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Assertions(org.springframework.data.mongodb.test.util.Assertions) Indexed(org.springframework.data.mongodb.core.index.Indexed) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) BlockingQueue(java.util.concurrent.BlockingQueue) IndexField(org.springframework.data.mongodb.core.index.IndexField) IndexOptions(com.mongodb.client.model.IndexOptions) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Client(org.springframework.data.mongodb.test.util.Client) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) Data(lombok.Data) Id(org.springframework.data.annotation.Id) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) IndexOptions(com.mongodb.client.model.IndexOptions) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Document(org.bson.Document) StepVerifier(reactor.test.StepVerifier) RepeatFailedTest(org.junitpioneer.jupiter.RepeatFailedTest)

Aggregations

IndexOptions (com.mongodb.client.model.IndexOptions)2 MongoClient (com.mongodb.reactivestreams.client.MongoClient)2 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)2 Duration (java.time.Duration)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 TimeUnit (java.util.concurrent.TimeUnit)2 Data (lombok.Data)2 Index.atIndex (org.assertj.core.data.Index.atIndex)2 Document (org.bson.Document)2 AfterEach (org.junit.jupiter.api.AfterEach)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 RepeatFailedTest (org.junitpioneer.jupiter.RepeatFailedTest)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 Id (org.springframework.data.annotation.Id)2 Direction (org.springframework.data.domain.Sort.Direction)2 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)2 NoOpDbRefResolver (org.springframework.data.mongodb.core.convert.NoOpDbRefResolver)2