Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for result streaming with data-jpa #171

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void queryAnnotatedMethod(AssertableOutput output) {
});
}

@Test
void streamingResult(AssertableOutput output) {
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
assertThat(output).hasSingleLineContaining("streamAuthors(): author = Author{name='Martin Kleppmann'}")
.hasNoLinesContaining("streamAuthors(): author = Author{name='Josh Long'}");
});
}

@Test
void deleteAll(AssertableOutput output) {
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.data.jpa;

import java.util.Optional;
import java.util.stream.Stream;

import com.example.data.jpa.model.Author;

Expand All @@ -14,4 +15,6 @@ public interface AuthorRepository extends ListCrudRepository<Author, Long> {
@Query("SELECT a FROM Author a WHERE a.name = :name")
Optional<Author> queryFindByName(String name);

Stream<Author> findByNameContaining(String name);

}
8 changes: 8 additions & 0 deletions data/data-jpa/src/main/java/com/example/data/jpa/CLR.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import com.example.data.jpa.model.Author;
import com.example.data.jpa.model.Book;
Expand Down Expand Up @@ -32,6 +33,7 @@ public void run(String... args) {
findById(authors);
findByPartialName();
queryFindByName();
streamAuthors();
deleteAll();
entityGraph();
}
Expand Down Expand Up @@ -87,6 +89,12 @@ private void listAllAuthors() {
}
}

private void streamAuthors() {

Stream<Author> authors = this.authorRepository.findByNameContaining("Martin");
authors.forEach(author -> System.out.printf("streamAuthors(): author = %s%n", author));
}

private List<Author> insertAuthors() {
Author author1 = this.authorRepository.save(new Author(null, "Josh Long",
Set.of(new Book(null, "Reactive Spring"), new Book(null, "Cloud Native Java"))));
Expand Down