use of org.springframework.data.mongodb.core.messaging.ChangeStreamRequest.ChangeStreamRequestOptions in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method readsOnlyDiffForUpdateWhenOptionsDeclareDefaultExplicitly.
// DATAMONGO-1803
@Test
public void readsOnlyDiffForUpdateWhenOptionsDeclareDefaultExplicitly() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, User> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<User> request = new ChangeStreamRequest<>(messageListener, new ChangeStreamRequestOptions("user", ChangeStreamOptions.builder().fullDocumentLookup(FullDocument.DEFAULT).build()));
Subscription subscription = container.register(request, User.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.update(User.class).matching(query(where("id").is(jellyBelly.id))).apply(Update.update("age", 8)).first();
awaitMessages(messageListener, 2);
assertThat(messageListener.getFirstMessage().getBody()).isEqualTo(jellyBelly);
assertThat(messageListener.getLastMessage().getBody()).isNull();
}
use of org.springframework.data.mongodb.core.messaging.ChangeStreamRequest.ChangeStreamRequestOptions in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method readsFullDocumentForUpdateWhenNotMappedToDomainTypeButLookupSpecified.
// DATAMONGO-1803
@Test
public void readsFullDocumentForUpdateWhenNotMappedToDomainTypeButLookupSpecified() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, Document> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<Document> request = new ChangeStreamRequest<>(messageListener, new ChangeStreamRequestOptions("user", ChangeStreamOptions.builder().returnFullDocumentOnUpdate().build()));
Subscription subscription = container.register(request, Document.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.update(User.class).matching(query(where("id").is(jellyBelly.id))).apply(Update.update("age", 8)).first();
awaitMessages(messageListener, 2);
assertThat(messageListener.getFirstMessage().getBody()).isEqualTo(new Document("_id", "id-1").append("user_name", "jellyBelly").append("age", 7).append("_class", User.class.getName()));
assertThat(messageListener.getLastMessage().getBody()).isEqualTo(new Document("_id", "id-1").append("user_name", "jellyBelly").append("age", 8).append("_class", User.class.getName()));
}
use of org.springframework.data.mongodb.core.messaging.ChangeStreamRequest.ChangeStreamRequestOptions in project spring-data-mongodb by spring-projects.
the class TaskFactoryUnitTests method createsChangeStreamRequestCorrectly.
// DATAMONGO-1803
@Test
void createsChangeStreamRequestCorrectly() {
when(template.getConverter()).thenReturn(converter);
ChangeStreamRequestOptions options = Mockito.mock(ChangeStreamRequestOptions.class);
Task task = factory.forRequest(new ChangeStreamRequest(messageListener, options), Object.class, errorHandler);
assertThat(task).isInstanceOf(ChangeStreamTask.class);
}
use of org.springframework.data.mongodb.core.messaging.ChangeStreamRequest.ChangeStreamRequestOptions in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method readsOnlyDiffForUpdateWhenNotMappedToDomainType.
// DATAMONGO-1803
@Test
void readsOnlyDiffForUpdateWhenNotMappedToDomainType() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, Document> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<Document> request = new ChangeStreamRequest<>(messageListener, new ChangeStreamRequestOptions(null, "user", Duration.ofMillis(10), ChangeStreamOptions.builder().build()));
Subscription subscription = container.register(request, Document.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.update(User.class).matching(query(where("id").is(jellyBelly.id))).apply(Update.update("age", 8)).first();
awaitMessages(messageListener, 2);
assertThat(messageListener.getFirstMessage().getBody()).isEqualTo(new Document("_id", "id-1").append("user_name", "jellyBelly").append("age", 7).append("_class", User.class.getName()));
assertThat(messageListener.getLastMessage().getBody()).isNull();
}
use of org.springframework.data.mongodb.core.messaging.ChangeStreamRequest.ChangeStreamRequestOptions in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method readsAndConvertsUpdateMessageBodyCorrectly.
// DATAMONGO-1803
@Test
void readsAndConvertsUpdateMessageBodyCorrectly() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, User> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<User> request = new ChangeStreamRequest<>(messageListener, new ChangeStreamRequestOptions(null, "user", Duration.ofMillis(10), ChangeStreamOptions.builder().build()));
Subscription subscription = container.register(request, User.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.update(User.class).matching(query(where("id").is(jellyBelly.id))).apply(Update.update("age", 8)).first();
awaitMessages(messageListener, 2);
assertThat(messageListener.getFirstMessage().getBody()).isEqualTo(jellyBelly);
assertThat(messageListener.getLastMessage().getBody()).isNotNull().hasFieldOrPropertyWithValue("age", 8);
}
Aggregations