Search in sources :

Example 1 with SocketAddress

use of io.vertx.core.net.SocketAddress in project vert.x by eclipse.

the class Http2ClientTest method testReuseConnection.

@Test
public void testReuseConnection() throws Exception {
    List<SocketAddress> ports = new ArrayList<>();
    server.requestHandler(req -> {
        SocketAddress address = req.remoteAddress();
        assertNotNull(address);
        ports.add(address);
        req.response().end();
    });
    startServer();
    CountDownLatch doReq = new CountDownLatch(1);
    client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
        resp.endHandler(v -> {
            doReq.countDown();
        });
    }).exceptionHandler(err -> {
        fail();
    }).end();
    awaitLatch(doReq);
    client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
        resp.endHandler(v -> {
            assertEquals(2, ports.size());
            assertEquals(ports.get(0), ports.get(1));
            testComplete();
        });
    }).exceptionHandler(err -> {
        fail();
    }).end();
    await();
}
Also used : Arrays(java.util.Arrays) JksOptions(io.vertx.core.net.JksOptions) BiFunction(java.util.function.BiFunction) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) AsciiString(io.netty.util.AsciiString) Cert(io.vertx.test.core.tls.Cert) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) StreamResetException(io.vertx.core.http.StreamResetException) ChannelInitializer(io.netty.channel.ChannelInitializer) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Http2FrameListener(io.netty.handler.codec.http2.Http2FrameListener) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) GZIPOutputStream(java.util.zip.GZIPOutputStream) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) io.vertx.core(io.vertx.core) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) ConnectException(java.net.ConnectException) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) SocketAddress(io.vertx.core.net.SocketAddress) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) SSLHelper(io.vertx.core.net.impl.SSLHelper) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2ServerUpgradeCodec(io.netty.handler.codec.http2.Http2ServerUpgradeCodec) HttpMethod(io.vertx.core.http.HttpMethod) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2CodecUtil(io.netty.handler.codec.http2.Http2CodecUtil) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ArrayList(java.util.ArrayList) SocketAddress(io.vertx.core.net.SocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with SocketAddress

use of io.vertx.core.net.SocketAddress in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetLocalAddr.

@Test
public void testGetLocalAddr() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.localAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.host()).thenReturn("localhost");
        Assert.assertEquals("localhost", instance.getLocalAddr());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 3 with SocketAddress

use of io.vertx.core.net.SocketAddress in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetRemoteHost.

@Test
public void testGetRemoteHost() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.remoteAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.host()).thenReturn("localhost");
        Assert.assertEquals("localhost", instance.getRemoteHost());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 4 with SocketAddress

use of io.vertx.core.net.SocketAddress in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetLocalPort.

@Test
public void testGetLocalPort() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.localAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.port()).thenReturn(8080);
        instance.getLocalPort();
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 5 with SocketAddress

use of io.vertx.core.net.SocketAddress in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetRemotePort.

@Test
public void testGetRemotePort() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.remoteAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.port()).thenReturn(8080);
        Assert.assertEquals(8080, instance.getRemotePort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Aggregations

HttpServerRequest (io.vertx.core.http.HttpServerRequest)5 SocketAddress (io.vertx.core.net.SocketAddress)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)1 AbstractHttp2ConnectionHandlerBuilder (io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1