DATAMONGO-1687 - Initialize collation in CollectionOptions eagerly.
CollectionOptions.collation is initialized with Optional.empty() to guard collection creation against null dereference. Original Pull Request: #462
This commit is contained in:
committed by
Christoph Strobl
parent
5885d084be
commit
a5a4c6d8c4
@@ -53,7 +53,9 @@ public class CollectionOptions {
|
||||
this.collation = collation;
|
||||
}
|
||||
|
||||
private CollectionOptions() {}
|
||||
private CollectionOptions() {
|
||||
this.collation = Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link CollectionOptions} by just providing the {@link Collation} to use.
|
||||
|
||||
@@ -114,8 +114,6 @@ public class MongoTemplateTests {
|
||||
|
||||
private static final org.springframework.data.util.Version TWO_DOT_FOUR = org.springframework.data.util.Version
|
||||
.parse("2.4");
|
||||
private static final org.springframework.data.util.Version TWO_DOT_EIGHT = org.springframework.data.util.Version
|
||||
.parse("2.8");
|
||||
private static final org.springframework.data.util.Version THREE_DOT_FOUR = org.springframework.data.util.Version
|
||||
.parse("3.4");
|
||||
|
||||
@@ -333,6 +331,26 @@ public class MongoTemplateTests {
|
||||
template.insertAll(records);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1687
|
||||
public void createCappedCollection() {
|
||||
|
||||
template.createCollection(Person.class, CollectionOptions.empty().capped(1000).maxDocuments(1000));
|
||||
|
||||
org.bson.Document collectionOptions = getCollectionInfo(template.getCollectionName(Person.class)).get("options",
|
||||
org.bson.Document.class);
|
||||
assertThat(collectionOptions.get("capped"), is(true));
|
||||
}
|
||||
|
||||
private org.bson.Document getCollectionInfo(String collectionName) {
|
||||
|
||||
return template.execute(db -> {
|
||||
|
||||
org.bson.Document result = db.runCommand(new org.bson.Document().append("listCollections", 1).append("filter",
|
||||
new org.bson.Document("name", collectionName)));
|
||||
return (org.bson.Document) result.get("cursor", org.bson.Document.class).get("firstBatch", List.class).get(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testEnsureIndex() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user