Skip to content

Commit

Permalink
Connect timeout test added
Browse files Browse the repository at this point in the history
  • Loading branch information
skarpenko committed Apr 15, 2023
1 parent 836da31 commit b099061
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,4 +30,11 @@ public class ConnectionTimeoutTest extends reactivefeign.ConnectionTimeoutTest {
protected ReactiveFeign.Builder<IcecreamServiceApi> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,4 +30,11 @@ public class ConnectionTimeoutTest extends reactivefeign.ConnectionTimeoutTest {
protected ReactiveFeign.Builder<IcecreamServiceApi> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -27,4 +31,11 @@ protected ReactiveFeign.Builder<IcecreamServiceApi> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -27,4 +30,10 @@ protected ReactiveFeign.Builder<IcecreamServiceApi> 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;
}
}

0 comments on commit b099061

Please sign in to comment.