Skip to content

Commit

Permalink
report proxy exception in ChannelInboundHandlerAdapter, add more unit…
Browse files Browse the repository at this point in the history
… tests for error in proxy

Signed-off-by: alexlehm <alexlehm@gmail.com>
  • Loading branch information
alexlehm committed Jul 5, 2016
1 parent 0c63f1e commit 6871e35
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
Expand Up @@ -87,6 +87,12 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
} }
ctx.fireUserEventTriggered(evt); ctx.fireUserEventTriggered(evt);
} }

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception {
channelHandler.handle(Future.failedFuture(cause));
}
}); });
} }
}); });
Expand Down
80 changes: 63 additions & 17 deletions src/test/java/io/vertx/test/core/ProxyErrorTest.java
Expand Up @@ -4,11 +4,6 @@


import org.junit.Test; import org.junit.Test;


import static org.junit.Assert.*;

import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.util.internal.logging.Log4JLoggerFactory;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.logging.Logger; import io.vertx.core.logging.Logger;
Expand All @@ -26,39 +21,39 @@ public class ProxyErrorTest extends VertxTestBase {


private static final Logger log = LoggerFactory.getLogger(ProxyErrorTest.class); private static final Logger log = LoggerFactory.getLogger(ProxyErrorTest.class);


private ConnectHttpProxy proxy; private ConnectHttpProxy proxy = null;


// we don't start a https server, due to the error, it will not be queried // we don't start a https server, due to the error, it will not be queried
@Override
public void setUp() throws Exception { private void startProxy(int error, String username) throws InterruptedException {
// InternalLoggerFactory.setDefaultFactory(Log4JLoggerFactory.INSTANCE);
super.setUp();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
proxy = new ConnectHttpProxy(null); proxy = new ConnectHttpProxy(username);
proxy.setError(403); proxy.setError(error);
proxy.start(vertx, v -> latch.countDown()); proxy.start(vertx, v -> latch.countDown());
latch.await(); latch.await();
log.info("proxy");
} }


@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
proxy.stop(); if (proxy!=null) {
proxy.stop();
}
} }


@Test @Test
public void testProxyError() throws Exception { public void testProxyError() throws Exception {
startProxy(403, null);

CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);


final HttpClientOptions options = new HttpClientOptions() final HttpClientOptions options = new HttpClientOptions()
.setProxyOptions(new ProxyOptions() .setProxyOptions(new ProxyOptions()
.setType(ProxyType.HTTP) .setType(ProxyType.HTTP)
.setHost("localhost") .setHost("localhost")
.setPort(13128)); .setPort(proxy.getPort()));
HttpClient client = vertx.createHttpClient(options); HttpClient client = vertx.createHttpClient(options);


log.info("starting request");
client.getAbs("https://localhost/", resp -> { client.getAbs("https://localhost/", resp -> {
log.info("this request is supposed to fail"); log.info("this request is supposed to fail");
fail(); fail();
Expand All @@ -68,7 +63,58 @@ public void testProxyError() throws Exception {
latch.countDown(); latch.countDown();
}) })
.end(); .end();
log.info("request.end");
latch.await();
}

@Test
public void testProxyAuthFail() throws Exception {
startProxy(0, "user");

CountDownLatch latch = new CountDownLatch(1);

final HttpClientOptions options = new HttpClientOptions()
.setProxyOptions(new ProxyOptions()
.setType(ProxyType.HTTP)
.setHost("localhost")
.setPort(proxy.getPort()));
HttpClient client = vertx.createHttpClient(options);

client.getAbs("https://localhost/", resp -> {
log.info("this request is supposed to fail");
fail();
})
.exceptionHandler(e -> {
log.warn("Exception", e);
latch.countDown();
})
.end();

latch.await();
}

@Test
public void testProxyHostUnknown() throws Exception {
startProxy(0, null);

CountDownLatch latch = new CountDownLatch(1);

final HttpClientOptions options = new HttpClientOptions()
.setProxyOptions(new ProxyOptions()
.setType(ProxyType.HTTP)
.setHost("localhost")
.setPort(proxy.getPort()));
HttpClient client = vertx.createHttpClient(options);

client.getAbs("https://unknown.hostname/", resp -> {
log.info("this request is supposed to fail");
fail();
})
.exceptionHandler(e -> {
log.warn("Exception", e);
latch.countDown();
})
.end();


latch.await(); latch.await();
} }
Expand Down

0 comments on commit 6871e35

Please sign in to comment.