DATAMONGO-2659 - Allow disk use on query.

Original pull request: #891.
This commit is contained in:
abarkan
2020-11-10 16:53:41 +02:00
committed by Mark Paluch
parent 65401bf4c3
commit 9d5b72db49
3 changed files with 30 additions and 0 deletions

View File

@@ -156,6 +156,7 @@ import com.mongodb.client.result.UpdateResult;
* @author Michael J. Simons
* @author Roman Puchkovskiy
* @author Yadhukrishna S Pai
* @author Anton Barkan
*/
public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
@@ -3289,6 +3290,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
cursorToUse = cursorToUse.batchSize(meta.getCursorBatchSize());
}
if (meta.getAllowDiskUse() != null) {
cursorToUse = cursorToUse.allowDiskUse(meta.getAllowDiskUse());
}
for (Meta.CursorOption option : meta.getFlags()) {
switch (option) {

View File

@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
* @author Anton Barkan
*/
public class Query {
@@ -372,6 +373,19 @@ public class Query {
return this;
}
/**
* Set a allowDiskUse to the query that is propagated to the profile log.
*
* @param allowDiskUse must not be {@literal null}.
* @return this.
* @see Meta#setAllowDiskUse(Boolean)
*/
public Query allowDiskUse(Boolean allowDiskUse) {
meta.setAllowDiskUse(allowDiskUse);
return this;
}
/**
* Set the number of documents to return in each response batch. <br />
* Use {@literal 0 (zero)} for no limit. A <strong>negative limit</strong> closes the cursor after returning a single

View File

@@ -45,6 +45,7 @@ import com.mongodb.client.FindIterable;
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @author Anton Barkan
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -61,6 +62,7 @@ class QueryCursorPreparerUnitTests {
when(factory.getCodecRegistry()).thenReturn(MongoClientSettings.getDefaultCodecRegistry());
when(cursor.batchSize(anyInt())).thenReturn(cursor);
when(cursor.comment(anyString())).thenReturn(cursor);
when(cursor.allowDiskUse(anyBoolean())).thenReturn(cursor);
when(cursor.maxTime(anyLong(), any())).thenReturn(cursor);
when(cursor.hint(any())).thenReturn(cursor);
when(cursor.noCursorTimeout(anyBoolean())).thenReturn(cursor);
@@ -133,6 +135,15 @@ class QueryCursorPreparerUnitTests {
verify(cursor).comment("spring data");
}
@Test
void appliesAllowDiskUseCorrectly() {
Query query = query(where("foo").is("bar")).allowDiskUse(true);
prepare(query);
verify(cursor).allowDiskUse(true);
}
// TODO
// @Test // DATAMONGO-957
// public void appliesSnapshotCorrectly() {