Search in sources :

Example 11 with AggregationOptions

use of org.springframework.data.mongodb.core.aggregation.AggregationOptions in project spring-data-mongodb by spring-projects.

the class StringBasedAggregationUnitTests method returnSingleObject.

// DATAMONGO-2153, DATAMONGO-2449
@Test
void returnSingleObject() {
    PersonAggregate expected = new PersonAggregate();
    when(aggregationResults.getUniqueMappedResult()).thenReturn(Collections.singletonList(expected));
    AggregationInvocation invocation = executeAggregation("returnSingleEntity");
    assertThat(invocation.result).isEqualTo(expected);
    AggregationOptions options = invocation.aggregation.getOptions();
    assertThat(options.getComment()).isEmpty();
    assertThat(options.getCursorBatchSize()).isNull();
    assertThat(options.isAllowDiskUse()).isFalse();
    assertThat(options.getMaxTime()).isEqualTo(Duration.ZERO);
}
Also used : AggregationOptions(org.springframework.data.mongodb.core.aggregation.AggregationOptions) Test(org.junit.jupiter.api.Test)

Example 12 with AggregationOptions

use of org.springframework.data.mongodb.core.aggregation.AggregationOptions in project spring-data-mongodb by spring-projects.

the class StringBasedAggregationUnitTests method plainStringAggregationConsidersMeta.

// DATAMONGO-2153, DATAMONGO-2449
@Test
void plainStringAggregationConsidersMeta() {
    AggregationInvocation invocation = executeAggregation("plainStringAggregation");
    AggregationOptions options = invocation.aggregation.getOptions();
    assertThat(options.getComment()).contains("expensive-aggregation");
    assertThat(options.getCursorBatchSize()).isEqualTo(42);
    assertThat(options.isAllowDiskUse()).isTrue();
    assertThat(options.getMaxTime()).isEqualTo(Duration.ofMillis(100));
}
Also used : AggregationOptions(org.springframework.data.mongodb.core.aggregation.AggregationOptions) Test(org.junit.jupiter.api.Test)

Aggregations

AggregationOptions (org.springframework.data.mongodb.core.aggregation.AggregationOptions)12 Document (org.bson.Document)7 Test (org.junit.jupiter.api.Test)6 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)4 AggregationResults (org.springframework.data.mongodb.core.aggregation.AggregationResults)3 AutogenerateableId (org.springframework.data.mongodb.core.MongoTemplateUnitTests.AutogenerateableId)2 ClientSessionOptions (com.mongodb.ClientSessionOptions)1 MongoException (com.mongodb.MongoException)1 ReadPreference (com.mongodb.ReadPreference)1 WriteConcern (com.mongodb.WriteConcern)1 AggregateIterable (com.mongodb.client.AggregateIterable)1 ClientSession (com.mongodb.client.ClientSession)1 DistinctIterable (com.mongodb.client.DistinctIterable)1 FindIterable (com.mongodb.client.FindIterable)1 MapReduceIterable (com.mongodb.client.MapReduceIterable)1 MongoClient (com.mongodb.client.MongoClient)1 MongoCollection (com.mongodb.client.MongoCollection)1 MongoCursor (com.mongodb.client.MongoCursor)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 MongoIterable (com.mongodb.client.MongoIterable)1