Last active
May 8, 2020 14:44
-
-
Save yannbriancon/7cf45cab19c050d7688171f72e329dfc to your computer and use it in GitHub Desktop.
Test triggering N+1 query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(MockitoJUnitRunner.class) | |
@SpringBootTest | |
@Transactional | |
class NPlusOneQueriesLoggingTest { | |
@Autowired | |
private MessageRepository messageRepository; | |
@Test | |
void nPlusOneQueriesDetection_isLoggingWhenDetectingNPlusOneQueries() { | |
// Fetch the messages without the authors | |
List<Message> messages = messageRepository.findAll(); | |
// Trigger N+1 queries | |
List<String> names = messages.stream() | |
.map(message -> message.getAuthor().getName()) | |
.collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment