Skip to content
Closed
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 @@ -85,7 +85,10 @@ public void execute(final IOSession session) {

}))) {
if (status.compareAndSet(Status.READY, Status.RUNNING)) {
ioReactorRef.get().start();
if(this instanceof AsyncServer){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaohu-zhang This is terrible. Even for test classes we should not be doing things like that.

//start DefaultListeningIOReactor
ioReactorRef.get().start(0);
}
}
} else {
throw new IllegalStateException("I/O reactor has already been started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.testing.classic.LoggingHttp1StreamListener;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class Http1AuthenticationTest {
Expand Down Expand Up @@ -202,11 +202,10 @@ protected void after() {

@Test
public void testGetRequestAuthentication() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort());

Expand Down Expand Up @@ -236,11 +235,10 @@ public void testGetRequestAuthentication() throws Exception {

@Test
public void testPostRequestAuthentication() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort());
final Random rnd = new Random();
Expand Down Expand Up @@ -274,11 +272,10 @@ public void testPostRequestAuthentication() throws Exception {

@Test
public void testPostRequestAuthenticationNoExpectContinue() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort());
final Random rnd = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class Http1ServerAndRequesterTest {
Expand Down Expand Up @@ -244,11 +244,10 @@ protected void after() {

@Test
public void testSequentialRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down Expand Up @@ -287,11 +286,10 @@ public void testSequentialRequests() throws Exception {

@Test
public void testSequentialRequestsNonPersistentConnection() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down Expand Up @@ -330,11 +328,10 @@ public void testSequentialRequestsNonPersistentConnection() throws Exception {

@Test
public void testSequentialRequestsSameEndpoint() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, Timeout.ofSeconds(5));
Expand Down Expand Up @@ -381,11 +378,10 @@ public void testSequentialRequestsSameEndpoint() throws Exception {

@Test
public void testPipelinedRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, Timeout.ofSeconds(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.testing.TestingSupport;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -71,6 +69,8 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Http2ALPNTest {

Expand Down Expand Up @@ -191,11 +191,10 @@ public void testALPNLax() throws Exception {
.setStreamListener(LoggingHttp2StreamListener.INSTANCE)
.create();

server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), URIScheme.HTTPS.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down Expand Up @@ -228,11 +227,10 @@ public void testALPNStrict() throws Exception {
.setStreamListener(LoggingHttp2StreamListener.INSTANCE)
.create();

server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), URIScheme.HTTPS.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.testing.classic.LoggingHttp1StreamListener;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -73,6 +71,8 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Http2ProtocolNegotiationTest {

Expand Down Expand Up @@ -206,11 +206,10 @@ public void checkVersion() {

@Test
public void testForceHttp1() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_1, null);
Expand All @@ -229,11 +228,10 @@ public void testForceHttp1() throws Exception {

@Test
public void testForceHttp2() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_2, null);
Expand All @@ -252,11 +250,10 @@ public void testForceHttp2() throws Exception {

@Test
public void testNegotiateProtocol() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.NEGOTIATE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
import org.apache.hc.core5.testing.TestingSupport;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -80,6 +78,8 @@
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class Http2ServerAndMultiplexingRequesterTest {
Expand Down Expand Up @@ -215,11 +215,10 @@ public void checkVersion() {

@Test
public void testSequentialRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down Expand Up @@ -258,11 +257,10 @@ public void testSequentialRequests() throws Exception {

@Test
public void testMultiplexedRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Queue<Future<Message<HttpResponse, String>>> queue = new LinkedList<>();
Expand Down Expand Up @@ -293,11 +291,10 @@ public void testMultiplexedRequests() throws Exception {

@Test
public void testValidityCheck() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();
requester.setValidateAfterInactivity(TimeValue.ofMillis(10));

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
Expand Down Expand Up @@ -341,11 +338,10 @@ public void testValidityCheck() throws Exception {

@Test
public void testMultiplexedRequestCancellation() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final int reqNo = 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
import org.apache.hc.core5.testing.TestingSupport;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -77,6 +75,8 @@
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class Http2ServerAndRequesterTest {
Expand Down Expand Up @@ -217,11 +217,10 @@ public void checkVersion() {

@Test
public void testSequentialRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
Expand Down Expand Up @@ -260,11 +259,10 @@ public void testSequentialRequests() throws Exception {

@Test
public void testSequentialRequestsSameEndpoint() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, Timeout.ofSeconds(5));
Expand Down Expand Up @@ -311,11 +309,10 @@ public void testSequentialRequestsSameEndpoint() throws Exception {

@Test
public void testPipelinedRequests() throws Exception {
server.start();
server.serverStart();
final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
requester.start();

final HttpHost target = new HttpHost("localhost", address.getPort(), scheme.id);
final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, Timeout.ofSeconds(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void cleanup() throws Exception {

@Test
public void testEndpointUpAndDown() throws Exception {
ioreactor.start();
ioreactor.start(0);

Set<ListenerEndpoint> endpoints = ioreactor.getEndpoints();
Assert.assertNotNull(endpoints);
Expand Down Expand Up @@ -138,7 +138,7 @@ public void testEndpointUpAndDown() throws Exception {

@Test
public void testEndpointAlreadyBound() throws Exception {
ioreactor.start();
ioreactor.start(0);

final Future<ListenerEndpoint> future1 = ioreactor.listen(new InetSocketAddress(0));
final ListenerEndpoint endpoint1 = future1.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public Future<IOSession> requestSession(
}

@Override
public void start() {
ioReactor.start();
public void start(final int i) {
ioReactor.start(i);
}

@Override
Expand Down
Loading