Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect timeout test added #587

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading