Search in sources :

Example 1 with AggregateOperation

use of com.mongodb.internal.operation.AggregateOperation in project mongo-java-driver by mongodb.

the class AggregatePublisherImplTest method shouldBuildTheExpectedOperationForHintPlusHintString.

@DisplayName("Should build the expected AggregateOperation when both hint and hintString are set")
@Test
void shouldBuildTheExpectedOperationForHintPlusHintString() {
    List<BsonDocument> pipeline = singletonList(BsonDocument.parse("{'$match': 1}"));
    TestOperationExecutor executor = createOperationExecutor(asList(getBatchCursor(), getBatchCursor()));
    AggregatePublisher<Document> publisher = new AggregatePublisherImpl<>(null, createMongoOperationPublisher(executor), pipeline, AggregationLevel.COLLECTION);
    AggregateOperation<Document> expectedOperation = new AggregateOperation<>(NAMESPACE, pipeline, getDefaultCodecRegistry().get(Document.class)).batchSize(Integer.MAX_VALUE).retryReads(true);
    publisher.hint(new Document("x", 1)).hintString("x_1");
    expectedOperation.hint(new BsonDocument("x", new BsonInt32(1)));
    Flux.from(publisher).blockFirst();
    assertOperationIsTheSameAs(expectedOperation, executor.getReadOperation());
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) AggregateOperation(com.mongodb.internal.operation.AggregateOperation) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with AggregateOperation

use of com.mongodb.internal.operation.AggregateOperation in project mongo-java-driver by mongodb.

the class AggregatePublisherImplTest method shouldBuildTheExpectedOperationForHintString.

@DisplayName("Should build the expected AggregateOperation for hint string")
@Test
void shouldBuildTheExpectedOperationForHintString() {
    List<BsonDocument> pipeline = singletonList(BsonDocument.parse("{'$match': 1}"));
    TestOperationExecutor executor = createOperationExecutor(asList(getBatchCursor(), getBatchCursor()));
    AggregatePublisher<Document> publisher = new AggregatePublisherImpl<>(null, createMongoOperationPublisher(executor), pipeline, AggregationLevel.COLLECTION);
    AggregateOperation<Document> expectedOperation = new AggregateOperation<>(NAMESPACE, pipeline, getDefaultCodecRegistry().get(Document.class)).batchSize(Integer.MAX_VALUE).retryReads(true);
    publisher.hintString("x_1");
    expectedOperation.hint(new BsonString("x_1"));
    Flux.from(publisher).blockFirst();
    assertOperationIsTheSameAs(expectedOperation, executor.getReadOperation());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) AggregateOperation(com.mongodb.internal.operation.AggregateOperation) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

AggregateOperation (com.mongodb.internal.operation.AggregateOperation)2 BsonDocument (org.bson.BsonDocument)2 Document (org.bson.Document)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 BsonInt32 (org.bson.BsonInt32)1 BsonString (org.bson.BsonString)1