Skip to content

Commit

Permalink
JAMES-2456 Add a test to make sure CachingTextExtractor work well aft…
Browse files Browse the repository at this point in the history
…er first failure call
  • Loading branch information
quantranhong1999 authored and Arsnael committed Oct 10, 2024
1 parent 5e60733 commit 16cec18
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,6 +97,27 @@ void extractContentShouldAvoidCallingUnderlyingTextExtractorWhenPossible() throw
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");
Expand Down

0 comments on commit 16cec18

Please sign in to comment.