Search in sources :

Example 51 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class VertxTest method testCloseHooksCalled.

@Test
public void testCloseHooksCalled() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    Closeable myCloseable1 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    Closeable myCloseable2 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    vertx.addCloseHook(myCloseable1);
    vertx.addCloseHook(myCloseable2);
    // Now undeploy
    vertx.close(ar -> {
        assertTrue(ar.succeeded());
        assertEquals(2, closedCount.get());
        testComplete();
    });
    await();
}
Also used : Closeable(io.vertx.core.Closeable) VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Future(io.vertx.core.Future) VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Closeable(io.vertx.core.Closeable) Test(org.junit.Test)

Example 52 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class VertxTest method testCloseHookFailure2.

@Test
public void testCloseHookFailure2() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    class Hook implements Closeable {

        @Override
        public void close(Handler<AsyncResult<Void>> completionHandler) {
            if (closedCount.incrementAndGet() == 1) {
                completionHandler.handle(Future.succeededFuture());
                throw new RuntimeException();
            } else {
                completionHandler.handle(Future.succeededFuture());
            }
        }
    }
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    vertx.addCloseHook(new Hook());
    vertx.addCloseHook(new Hook());
    // Now undeploy
    vertx.close(ar -> {
        assertTrue(ar.succeeded());
        assertEquals(2, closedCount.get());
        testComplete();
    });
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Closeable(io.vertx.core.Closeable) Handler(io.vertx.core.Handler) Test(org.junit.Test)

Example 53 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class SSLHelperTest method testPreserveEnabledSecureTransportProtocolOrder.

@Test
public void testPreserveEnabledSecureTransportProtocolOrder() throws Exception {
    String[] protocols = { "SSLv2Hello", "TLSv1", "TLSv1.1", "TLSv1.2" };
    HttpServerOptions options = new HttpServerOptions();
    for (String protocol : protocols) {
        options.addEnabledSecureTransportProtocol(protocol);
    }
    assertEquals(new ArrayList<>(options.getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
    assertEquals(new ArrayList<>(new HttpServerOptions(options).getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
    JsonObject json = new JsonObject();
    NetworkOptionsConverter.toJson(options, json);
    TCPSSLOptionsConverter.toJson(options, json);
    NetServerOptionsConverter.toJson(options, json);
    HttpServerOptionsConverter.toJson(options, json);
    assertEquals(new ArrayList<>(new HttpServerOptions(json).getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
    SSLHelper helper = new SSLHelper(options, Cert.SERVER_JKS.get(), null);
    List<String> engineProtocols = Arrays.asList(helper.createSslHandler((VertxInternal) vertx).engine().getEnabledProtocols());
    List<String> expectedProtocols = new ArrayList<>(Arrays.asList(protocols));
    expectedProtocols.retainAll(engineProtocols);
    assertEquals(engineProtocols, expectedProtocols);
}
Also used : SSLHelper(io.vertx.core.net.impl.SSLHelper) VertxInternal(io.vertx.core.impl.VertxInternal) HttpServerOptions(io.vertx.core.http.HttpServerOptions) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 54 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class Http2ClientTest method createH2Server.

private ServerBootstrap createH2Server(BiFunction<Http2ConnectionDecoder, Http2ConnectionEncoder, Http2FrameListener> handler) {
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.channel(NioServerSocketChannel.class);
    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    eventLoopGroups.add(eventLoopGroup);
    bootstrap.group(eventLoopGroup);
    bootstrap.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            SSLHelper sslHelper = new SSLHelper(serverOptions, Cert.SERVER_JKS.get(), null);
            SslHandler sslHandler = sslHelper.setApplicationProtocols(Arrays.asList(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1)).createSslHandler((VertxInternal) vertx, DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT);
            ch.pipeline().addLast(sslHandler);
            ch.pipeline().addLast(new ApplicationProtocolNegotiationHandler("whatever") {

                @Override
                protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
                    if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                        ChannelPipeline p = ctx.pipeline();
                        Http2ConnectionHandler clientHandler = createHttpConnectionHandler(handler);
                        p.addLast("handler", clientHandler);
                        return;
                    }
                    ctx.close();
                    throw new IllegalStateException("unknown protocol: " + protocol);
                }
            });
        }
    });
    return bootstrap;
}
Also used : TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) VertxInternal(io.vertx.core.impl.VertxInternal) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) AsciiString(io.netty.util.AsciiString) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Http2Exception(io.netty.handler.codec.http2.Http2Exception) StreamResetException(io.vertx.core.http.StreamResetException) ConnectException(java.net.ConnectException) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) SSLHelper(io.vertx.core.net.impl.SSLHelper) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 55 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class HostnameResolutionTest method testCaseInsensitiveResolveFromHosts.

@Test
public void testCaseInsensitiveResolveFromHosts() {
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsPath("hosts_config.txt")));
    vertx.resolveAddress("SERVER.NET", onSuccess(addr -> {
        assertEquals("192.168.0.15", addr.getHostAddress());
        assertEquals("server.net", addr.getHostName());
        testComplete();
    }));
    await();
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) VertxException(io.vertx.core.VertxException) Arrays(java.util.Arrays) HttpServer(io.vertx.core.http.HttpServer) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Locale(java.util.Locale) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Collections(java.util.Collections) HttpClient(io.vertx.core.http.HttpClient) VertxInternal(io.vertx.core.impl.VertxInternal) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

VertxInternal (io.vertx.core.impl.VertxInternal)102 Test (org.junit.Test)73 CountDownLatch (java.util.concurrent.CountDownLatch)46 VertxOptions (io.vertx.core.VertxOptions)30 Buffer (io.vertx.core.buffer.Buffer)29 JsonObject (io.vertx.core.json.JsonObject)29 File (java.io.File)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 VertxException (io.vertx.core.VertxException)24 HttpClient (io.vertx.core.http.HttpClient)24 NetClient (io.vertx.core.net.NetClient)24 TimeUnit (java.util.concurrent.TimeUnit)24 NetServerOptions (io.vertx.core.net.NetServerOptions)23 InetAddress (java.net.InetAddress)23 Channel (io.netty.channel.Channel)22 InetSocketAddress (java.net.InetSocketAddress)22 CompletableFuture (java.util.concurrent.CompletableFuture)22 NetServer (io.vertx.core.net.NetServer)21 ChannelFuture (io.netty.channel.ChannelFuture)20 Bootstrap (io.netty.bootstrap.Bootstrap)19