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);
}
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();
}
Aggregations