Browse Source

DATAMONGO-1928 - Polishing.

Use native driver operations to avoid potential unwanted template index interaction.

Original Pull Request: #550
pull/551/merge
Christoph Strobl 8 years ago
parent
commit
31630c0dcc
  1. 19
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateIndexTests.java

19
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateIndexTests.java

@ -45,6 +45,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.mongodb.reactivestreams.client.ListIndexesPublisher; import com.mongodb.reactivestreams.client.ListIndexesPublisher;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.Success;
/** /**
* Integration test for index creation via {@link ReactiveMongoTemplate}. * Integration test for index creation via {@link ReactiveMongoTemplate}.
@ -60,15 +62,14 @@ public class ReactiveMongoTemplateIndexTests {
@Autowired SimpleReactiveMongoDatabaseFactory factory; @Autowired SimpleReactiveMongoDatabaseFactory factory;
@Autowired ReactiveMongoTemplate template; @Autowired ReactiveMongoTemplate template;
@Autowired MongoClient client;
@Before @Before
public void setUp() { public void setUp() {
template.dropCollection(Person.class) // StepVerifier.create(template.getCollection("person").drop()).expectNext(Success.SUCCESS).verifyComplete();
.as(StepVerifier::create).verifyComplete(); StepVerifier.create(template.getCollection("indexfail").drop()).expectNext(Success.SUCCESS).verifyComplete();
StepVerifier.create(template.getCollection("indexedSample").drop()).expectNext(Success.SUCCESS).verifyComplete();
template.dropCollection("indexfail") //
.as(StepVerifier::create).verifyComplete();
} }
@After @After
@ -144,6 +145,7 @@ public class ReactiveMongoTemplateIndexTests {
String command = "db." + template.getCollectionName(Person.class) String command = "db." + template.getCollectionName(Person.class)
+ ".createIndex({'age':-1}, {'unique':true, 'sparse':true}), 1"; + ".createIndex({'age':-1}, {'unique':true, 'sparse':true}), 1";
template.indexOps(Person.class).dropAllIndexes() // template.indexOps(Person.class).dropAllIndexes() //
.as(StepVerifier::create) // .as(StepVerifier::create) //
.verifyComplete(); .verifyComplete();
@ -194,13 +196,14 @@ public class ReactiveMongoTemplateIndexTests {
@Test // DATAMONGO-1928 @Test // DATAMONGO-1928
public void shouldCreateIndexOnAccess() { public void shouldCreateIndexOnAccess() {
StepVerifier.create(template.getCollection("indexedSample").listIndexes(Document.class)).expectNextCount(0)
.verifyComplete();
template.findAll(IndexedSample.class) // template.findAll(IndexedSample.class) //
.as(StepVerifier::create) // .as(StepVerifier::create) //
.verifyComplete(); .verifyComplete();
template.indexOps(IndexedSample.class).getIndexInfo() // StepVerifier.create(template.getCollection("indexedSample").listIndexes(Document.class)).expectNextCount(2)
.as(StepVerifier::create) //
.expectNextCount(2) //
.verifyComplete(); .verifyComplete();
} }

Loading…
Cancel
Save