Skip to content

Commit

Permalink
Merge pull request #1548 from zalando/failsafe_log_tests
Browse files Browse the repository at this point in the history
Added additional tests for failsafe logging
  • Loading branch information
fatroom authored Dec 5, 2023
2 parents 1903712 + 85024e6 commit 455a93d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions riptide-failsafe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>logcaptor</artifactId>
<version>2.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import dev.failsafe.Timeout;
import dev.failsafe.TimeoutExceededException;
import lombok.extern.slf4j.Slf4j;
import nl.altindag.log.LogCaptor;
import okhttp3.mockwebserver.MockWebServer;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.logging.LoggerFactory;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.slf4j.event.LoggingEvent;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.zalando.riptide.Http;
import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -137,4 +138,18 @@ void shouldTimeout() {
assertEquals(1, countingExecutor.counter.get());
}

@Test
void shouldLogWarningOnSingleThreadedExecutor() {
LogCaptor logCaptor = LogCaptor.forClass(FailsafePlugin.class);
new FailsafePlugin().withExecutor(Executors.newFixedThreadPool(1));
assertEquals(1, logCaptor.getWarnLogs().size());
}

@Test
void shouldNotLogWarningOnMultiThreadedExecutor() {
LogCaptor logCaptor = LogCaptor.forClass(FailsafePlugin.class);
new FailsafePlugin().withExecutor(ForkJoinPool.commonPool());
assertEquals(0, logCaptor.getWarnLogs().size());
}

}

0 comments on commit 455a93d

Please sign in to comment.