Search in sources :

Example 6 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTest method testHAProxyProtocolAccepted.

private void testHAProxyProtocolAccepted(Buffer header, SocketAddress remote, SocketAddress local) throws Exception {
    /*
     * In case remote / local is null then we will use the connected remote / local address from the proxy. This is needed
     * in order to test unknown protocol since we will use the actual connected addresses and ports.
     * This is only valid when testAddress is an InetSocketAddress. If testAddress is a DomainSocketAddress then
     * remoteAddress and localAddress are null
     *
     * Have in mind that proxies connectionRemoteAddress is the server request local address and proxies connectionLocalAddress is the
     * server request remote address.
     * */
    waitFor(2);
    HAProxy proxy = new HAProxy(testAddress, header);
    proxy.start(vertx);
    server.close();
    server = vertx.createHttpServer(createBaseServerOptions().setUseProxyProtocol(true)).requestHandler(req -> {
        assertAddresses(remote == null && testAddress.isInetSocket() ? proxy.getConnectionLocalAddress() : remote, req.remoteAddress());
        assertAddresses(local == null && testAddress.isInetSocket() ? proxy.getConnectionRemoteAddress() : local, req.localAddress());
        req.response().end();
        complete();
    });
    startServer(testAddress);
    client.request(new RequestOptions().setHost(proxy.getHost()).setPort(proxy.getPort()).setURI(DEFAULT_TEST_URI)).onComplete(onSuccess(req -> {
        req.send(onSuccess(event -> complete()));
    }));
    try {
        await();
    } finally {
        proxy.stop();
    }
}
Also used : HAProxyMessageCompletionHandler(io.vertx.core.net.impl.HAProxyMessageCompletionHandler) IntStream(java.util.stream.IntStream) java.util(java.util) DecompressionException(io.netty.handler.codec.compression.DecompressionException) io.vertx.core(io.vertx.core) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Utils(io.vertx.core.impl.Utils) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ReadStream(io.vertx.core.streams.ReadStream) HAProxy(io.vertx.test.proxy.HAProxy) Pump(io.vertx.core.streams.Pump) Assume(org.junit.Assume) DetectFileDescriptorLeaks(io.vertx.test.core.DetectFileDescriptorLeaks) DateFormat(java.text.DateFormat) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) java.util.concurrent(java.util.concurrent) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Future(io.vertx.core.Future) io.vertx.core.net(io.vertx.core.net) Nullable(io.vertx.codegen.annotations.Nullable) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) AtomicLong(java.util.concurrent.atomic.AtomicLong) Repeat(io.vertx.test.core.Repeat) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) java.io(java.io) PUT(io.vertx.core.http.HttpMethod.PUT) java.util.function(java.util.function) FakeStream(io.vertx.test.fakestream.FakeStream) TemporaryFolder(org.junit.rules.TemporaryFolder) ServerCookie(io.vertx.core.http.impl.ServerCookie) HAProxy(io.vertx.test.proxy.HAProxy)

Example 7 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTest method testHAProxyProtocolIdleTimeout.

@Test
public void testHAProxyProtocolIdleTimeout() throws Exception {
    HAProxy proxy = new HAProxy(testAddress, Buffer.buffer());
    proxy.start(vertx);
    server.close();
    server = vertx.createHttpServer(createBaseServerOptions().setProxyProtocolTimeout(2).setUseProxyProtocol(true));
    server.requestHandler(req -> fail("Should not be called"));
    startServer(testAddress);
    vertx.createNetClient().connect(proxy.getPort(), proxy.getHost(), res -> {
        res.result().closeHandler(event -> testComplete());
    });
    try {
        await();
    } finally {
        proxy.stop();
    }
}
Also used : HAProxy(io.vertx.test.proxy.HAProxy) Test(org.junit.Test)

Aggregations

HAProxy (io.vertx.test.proxy.HAProxy)7 Test (org.junit.Test)7 Buffer (io.vertx.core.buffer.Buffer)6 Future (io.vertx.core.Future)5 ReadStream (io.vertx.core.streams.ReadStream)5 TestUtils (io.vertx.test.core.TestUtils)5 java.util (java.util)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)4 DecompressionException (io.netty.handler.codec.compression.DecompressionException)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 Http2Exception (io.netty.handler.codec.http2.Http2Exception)4 Nullable (io.vertx.codegen.annotations.Nullable)4 io.vertx.core (io.vertx.core)4 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)4 PUT (io.vertx.core.http.HttpMethod.PUT)4 HttpServerRequestInternal (io.vertx.core.http.impl.HttpServerRequestInternal)4 ServerCookie (io.vertx.core.http.impl.ServerCookie)4