From b099061218af6f8086a9b88758c24454f26439ab Mon Sep 17 00:00:00 2001 From: skarpenko Date: Sat, 15 Apr 2023 00:41:05 +0300 Subject: [PATCH] Connect timeout test added --- .../reactivefeign/ConnectionTimeoutTest.java | 32 +++++++++++-------- .../client5/h1/ConnectionTimeoutTest.java | 10 ++++++ .../client5/h2c/ConnectionTimeoutTest.java | 10 ++++++ .../jetty/ConnectionTimeoutTest.java | 11 +++++++ .../webclient/ConnectionTimeoutTest.java | 9 ++++++ 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/feign-reactor-core/src/test/java/reactivefeign/ConnectionTimeoutTest.java b/feign-reactor-core/src/test/java/reactivefeign/ConnectionTimeoutTest.java index 63353772..091bc006 100644 --- a/feign-reactor-core/src/test/java/reactivefeign/ConnectionTimeoutTest.java +++ b/feign-reactor-core/src/test/java/reactivefeign/ConnectionTimeoutTest.java @@ -13,24 +13,25 @@ */ package reactivefeign; -import org.hamcrest.Matchers; -import org.junit.*; -import org.junit.rules.ExpectedException; +import org.apache.http.conn.HttpHostConnectException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.web.client.ResourceAccessException; +import reactivefeign.client.ReactiveFeignException; import reactivefeign.testcase.IcecreamServiceApi; import java.io.IOException; -import java.net.ConnectException; import java.net.ServerSocket; import java.net.Socket; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + /** * @author Sergii Karpenko */ abstract public class ConnectionTimeoutTest extends BaseReactorTest{ - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private ServerSocket serverSocket; private Socket socket; private int port; @@ -57,19 +58,22 @@ public void after() throws IOException { } } - // TODO investigate why doesn't work on codecov.io but works locally - @Ignore @Test public void shouldFailOnConnectionTimeout() { - expectedException.expectCause( + assertThatThrownBy(() -> { + IcecreamServiceApi client = builder(300) + .target(IcecreamServiceApi.class, "http://localhost:" + port); - Matchers.any(ConnectException.class)); + client.findOrder(1).subscribeOn(testScheduler()).block(); - IcecreamServiceApi client = builder(300) - .target(IcecreamServiceApi.class, "http://localhost:" + port); + }).matches(this::isConnectException); - client.findOrder(1).subscribeOn(testScheduler()).block(); } + protected boolean isConnectException(Throwable throwable){ + return throwable instanceof ReactiveFeignException + && throwable.getCause() instanceof ResourceAccessException + && throwable.getCause().getCause() instanceof HttpHostConnectException; + } } diff --git a/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h1/ConnectionTimeoutTest.java b/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h1/ConnectionTimeoutTest.java index 9e86226c..e4cadfa3 100644 --- a/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h1/ConnectionTimeoutTest.java +++ b/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h1/ConnectionTimeoutTest.java @@ -13,7 +13,10 @@ */ package reactivefeign.webclient.client5.h1; +import org.apache.hc.client5.http.HttpHostConnectException; +import org.springframework.web.reactive.function.client.WebClientRequestException; import reactivefeign.ReactiveFeign; +import reactivefeign.client.ReactiveFeignException; import reactivefeign.testcase.IcecreamServiceApi; import static reactivefeign.webclient.client5.h1.TestUtils.builderHttpWithConnectTimeout; @@ -27,4 +30,11 @@ public class ConnectionTimeoutTest extends reactivefeign.ConnectionTimeoutTest { protected ReactiveFeign.Builder builder(long connectTimeoutInMillis) { return builderHttpWithConnectTimeout(connectTimeoutInMillis); } + + @Override + protected boolean isConnectException(Throwable throwable){ + return throwable instanceof ReactiveFeignException + && throwable.getCause() instanceof WebClientRequestException + && throwable.getCause().getCause() instanceof HttpHostConnectException; + } } diff --git a/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h2c/ConnectionTimeoutTest.java b/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h2c/ConnectionTimeoutTest.java index 70dc927f..8eb3597f 100644 --- a/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h2c/ConnectionTimeoutTest.java +++ b/feign-reactor-webclient-apache-client5/src/test/java/reactivefeign/webclient/client5/h2c/ConnectionTimeoutTest.java @@ -13,7 +13,10 @@ */ package reactivefeign.webclient.client5.h2c; +import org.apache.hc.client5.http.HttpHostConnectException; +import org.springframework.web.reactive.function.client.WebClientRequestException; import reactivefeign.ReactiveFeign; +import reactivefeign.client.ReactiveFeignException; import reactivefeign.testcase.IcecreamServiceApi; import static reactivefeign.webclient.client5.h2c.TestUtils.builderHttp2WithConnectTimeout; @@ -27,4 +30,11 @@ public class ConnectionTimeoutTest extends reactivefeign.ConnectionTimeoutTest { protected ReactiveFeign.Builder builder(long connectTimeoutInMillis) { return builderHttp2WithConnectTimeout(connectTimeoutInMillis); } + + @Override + protected boolean isConnectException(Throwable throwable){ + return throwable instanceof ReactiveFeignException + && throwable.getCause() instanceof WebClientRequestException + && throwable.getCause().getCause() instanceof HttpHostConnectException; + } } diff --git a/feign-reactor-webclient-jetty/src/test/java/reactivefeign/webclient/jetty/ConnectionTimeoutTest.java b/feign-reactor-webclient-jetty/src/test/java/reactivefeign/webclient/jetty/ConnectionTimeoutTest.java index a41d5161..786b2dff 100644 --- a/feign-reactor-webclient-jetty/src/test/java/reactivefeign/webclient/jetty/ConnectionTimeoutTest.java +++ b/feign-reactor-webclient-jetty/src/test/java/reactivefeign/webclient/jetty/ConnectionTimeoutTest.java @@ -13,9 +13,13 @@ */ package reactivefeign.webclient.jetty; +import org.springframework.web.reactive.function.client.WebClientRequestException; import reactivefeign.ReactiveFeign; +import reactivefeign.client.ReactiveFeignException; import reactivefeign.testcase.IcecreamServiceApi; +import java.net.ConnectException; + /** * @author Sergii Karpenko */ @@ -27,4 +31,11 @@ protected ReactiveFeign.Builder builder(long connectTimeoutI new JettyReactiveOptions.Builder().setConnectTimeoutMillis(connectTimeoutInMillis).build() ); } + + @Override + protected boolean isConnectException(Throwable throwable){ + return throwable instanceof ReactiveFeignException + && throwable.getCause() instanceof WebClientRequestException + && throwable.getCause().getCause() instanceof ConnectException; + } } diff --git a/feign-reactor-webclient/src/test/java/reactivefeign/webclient/ConnectionTimeoutTest.java b/feign-reactor-webclient/src/test/java/reactivefeign/webclient/ConnectionTimeoutTest.java index 937d3949..aee67140 100644 --- a/feign-reactor-webclient/src/test/java/reactivefeign/webclient/ConnectionTimeoutTest.java +++ b/feign-reactor-webclient/src/test/java/reactivefeign/webclient/ConnectionTimeoutTest.java @@ -13,9 +13,12 @@ */ package reactivefeign.webclient; +import org.springframework.web.reactive.function.client.WebClientRequestException; import reactivefeign.ReactiveFeign; import reactivefeign.testcase.IcecreamServiceApi; +import java.net.ConnectException; + /** * @author Sergii Karpenko */ @@ -27,4 +30,10 @@ protected ReactiveFeign.Builder builder(long connectTimeoutI new WebReactiveOptions.Builder().setConnectTimeoutMillis(connectTimeoutInMillis).build() ); } + + @Override + protected boolean isConnectException(Throwable throwable){ + return throwable.getCause() instanceof WebClientRequestException + && throwable.getCause().getCause() instanceof ConnectException; + } }