This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 16cec185053d04e6ee1f957ca895cff7a41f9aee Author: Quan Tran <hqt...@linagora.com> AuthorDate: Tue Oct 8 15:24:24 2024 +0700 JAMES-2456 Add a test to make sure CachingTextExtractor work well after first failure call --- .../mailbox/tika/CachingTextExtractorTest.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java index be77065ac7..ab7b6515c5 100644 --- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java +++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java @@ -19,6 +19,7 @@ package org.apache.james.mailbox.tika; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -96,6 +97,27 @@ class CachingTextExtractorTest { verifyNoMoreInteractions(wrappedTextExtractor); } + @Test + void cacheShouldBeRecomputedWhenSuccessSecondCallWithActualContent() { + // The first call fails + when(wrappedTextExtractor.extractContentReactive(any(), any())) + .thenReturn(Mono.error(() -> new IOException("test"))); + assertThatThrownBy(() -> textExtractor.extractContent(INPUT_STREAM.get(), CONTENT_TYPE)) + .hasRootCauseInstanceOf(IOException.class); + verify(wrappedTextExtractor, times(1)).extractContentReactive(any(), any()); + + // The second call succeeds and CachingTextExtractor should recompute the cache + when(wrappedTextExtractor.extractContentReactive(any(), any())) + .thenReturn(Mono.just(RESULT)); + assertThat(textExtractor.extractContent(INPUT_STREAM.get(), CONTENT_TYPE)) + .isEqualTo(RESULT); + verify(wrappedTextExtractor, times(2)).extractContentReactive(any(), any()); + + // The third call would get actual value from the cache + textExtractor.extractContent(INPUT_STREAM.get(), CONTENT_TYPE); + verifyNoMoreInteractions(wrappedTextExtractor); + } + @Test void extractContentShouldPropagateCheckedException() { IOException ioException = new IOException("Any"); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org