DATAMONGO-2659 - Polishing.

Update Javadoc to reflect find and aggregation nature. Use primitive boolean on Query.allowDiskUse to avoid nullable type usage. Update ReactiveMongoTemplate to consider allowDiskUse.

Original pull request: #891.
This commit is contained in:
Mark Paluch
2020-12-01 09:41:15 +01:00
parent 9d5b72db49
commit 3f5cc897da
5 changed files with 30 additions and 36 deletions

View File

@@ -3329,6 +3329,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
if (meta.getCursorBatchSize() != null) {
findPublisherToUse = findPublisherToUse.batchSize(meta.getCursorBatchSize());
}
if (meta.getAllowDiskUse() != null) {
findPublisherToUse = findPublisherToUse.allowDiskUse(meta.getAllowDiskUse());
}
}
} catch (RuntimeException e) {

View File

@@ -181,7 +181,11 @@ public class Meta {
}
/**
* Set to {@literal true}, to allow aggregation stages to write data to disk.
* Enables writing to temporary files for aggregation stages and queries. When set to {@literal true}, aggregation
* stages can write data to the {@code _tmp} subdirectory in the {@code dbPath} directory.
* <p>
* Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a {@code usedDisk}
* indicator if any aggregation stage wrote data to temporary files due to memory restrictions.
*
* @param allowDiskUse use {@literal null} for server defaults.
* @since 3.0

View File

@@ -374,13 +374,18 @@ public class Query {
}
/**
* Set a allowDiskUse to the query that is propagated to the profile log.
* Enables writing to temporary files for aggregation stages and queries. When set to {@literal true}, aggregation
* stages can write data to the {@code _tmp} subdirectory in the {@code dbPath} directory.
* <p>
* Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a {@code usedDisk}
* indicator if any aggregation stage wrote data to temporary files due to memory restrictions.
*
* @param allowDiskUse must not be {@literal null}.
* @param allowDiskUse
* @return this.
* @see Meta#setAllowDiskUse(Boolean)
* @since 3.2
*/
public Query allowDiskUse(Boolean allowDiskUse) {
public Query allowDiskUse(boolean allowDiskUse) {
meta.setAllowDiskUse(allowDiskUse);
return this;

View File

@@ -96,27 +96,6 @@ class QueryCursorPreparerUnitTests {
verify(cursor).hint(new Document("age", 1));
}
// TODO
// @Test // DATAMONGO-957
// public void doesNotApplyMetaWhenEmpty() {
//
// Query query = query(where("foo").is("bar"));
// query.setMeta(new Meta());
//
// prepare(query);
//
// verify(cursor, never()).modifiers(any(Document.class));
// }
// @Test // DATAMONGO-957
// public void appliesMaxScanCorrectly() {
//
// Query query = query(where("foo").is("bar")).maxScan(100);
// prepare(query);
//
// verify(cursor).maxScan(100);
// }
@Test // DATAMONGO-957
void appliesMaxTimeCorrectly() {
@@ -135,7 +114,7 @@ class QueryCursorPreparerUnitTests {
verify(cursor).comment("spring data");
}
@Test
@Test // DATAMONGO-2659
void appliesAllowDiskUseCorrectly() {
Query query = query(where("foo").is("bar")).allowDiskUse(true);
@@ -144,16 +123,6 @@ class QueryCursorPreparerUnitTests {
verify(cursor).allowDiskUse(true);
}
// TODO
// @Test // DATAMONGO-957
// public void appliesSnapshotCorrectly() {
//
// Query query = query(where("foo").is("bar")).useSnapshot();
// prepare(query);
//
// verify(cursor).snapshot(true);
// }
@Test // DATAMONGO-1480
void appliesNoCursorTimeoutCorrectly() {

View File

@@ -180,6 +180,7 @@ public class ReactiveMongoTemplateUnitTests {
when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
when(findPublisher.collation(any())).thenReturn(findPublisher);
when(findPublisher.first()).thenReturn(findPublisher);
when(findPublisher.allowDiskUse(anyBoolean())).thenReturn(findPublisher);
when(aggregatePublisher.allowDiskUse(anyBoolean())).thenReturn(aggregatePublisher);
when(aggregatePublisher.collation(any())).thenReturn(aggregatePublisher);
when(aggregatePublisher.maxTime(anyLong(), any())).thenReturn(aggregatePublisher);
@@ -231,6 +232,17 @@ public class ReactiveMongoTemplateUnitTests {
verify(findPublisher).batchSize(1234);
}
@Test // DATAMONGO-2659
void executeQueryShouldUseAllowDiskSizeWhenPresent() {
when(findPublisher.batchSize(anyInt())).thenReturn(findPublisher);
Query query = new Query().allowDiskUse(true);
template.find(query, Person.class).subscribe();
verify(findPublisher).allowDiskUse(true);
}
@Test // DATAMONGO-1518
void findShouldUseCollationWhenPresent() {