Search in sources :

Example 6 with VertxOptions

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

the class HostnameResolutionTest method testResolveFromBuffer.

@Test
public void testResolveFromBuffer() {
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsValue(Buffer.buffer("192.168.0.15 server.net"))));
    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)

Example 7 with VertxOptions

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

the class HostnameResolutionTest method testResolveFromClasspath.

@Test
public void testResolveFromClasspath() {
    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)

Example 8 with VertxOptions

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

the class VertxOptionsTest method testJsonOptions.

@Test
public void testJsonOptions() {
    VertxOptions options = new VertxOptions(new JsonObject());
    assertEquals(0, options.getClusterPort());
    assertEquals(-1, options.getClusterPublicPort());
    assertEquals(20000, options.getClusterPingInterval());
    assertEquals(20000, options.getClusterPingReplyInterval());
    assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
    assertEquals(20, options.getInternalBlockingPoolSize());
    assertEquals(20, options.getWorkerPoolSize());
    assertEquals(1000, options.getBlockedThreadCheckInterval());
    assertEquals("localhost", options.getClusterHost());
    assertNull(options.getClusterPublicHost());
    assertEquals(null, options.getClusterManager());
    assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
    assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
    assertFalse(options.isHAEnabled());
    assertEquals(1, options.getQuorumSize());
    assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
    assertNotNull(options.getMetricsOptions());
    assertEquals(5000000000l, options.getWarningExceptionTime());
    int clusterPort = TestUtils.randomPortInt();
    int clusterPublicPort = TestUtils.randomPortInt();
    int eventLoopPoolSize = TestUtils.randomPositiveInt();
    int internalBlockingPoolSize = TestUtils.randomPositiveInt();
    int workerPoolSize = TestUtils.randomPositiveInt();
    int blockedThreadCheckInterval = TestUtils.randomPositiveInt();
    String clusterHost = TestUtils.randomAlphaString(100);
    String clusterPublicHost = TestUtils.randomAlphaString(100);
    long clusterPingInterval = TestUtils.randomPositiveLong();
    long clusterPingReplyInterval = TestUtils.randomPositiveLong();
    int maxEventLoopExecuteTime = TestUtils.randomPositiveInt();
    int maxWorkerExecuteTime = TestUtils.randomPositiveInt();
    int proxyOperationTimeout = TestUtils.randomPositiveInt();
    long warningExceptionTime = TestUtils.randomPositiveLong();
    Random rand = new Random();
    boolean haEnabled = rand.nextBoolean();
    int quorumSize = TestUtils.randomShort() + 1;
    String haGroup = TestUtils.randomAlphaString(100);
    boolean metricsEnabled = rand.nextBoolean();
    boolean jmxEnabled = rand.nextBoolean();
    String jmxDomain = TestUtils.randomAlphaString(100);
    options = new VertxOptions(new JsonObject().put("clusterPort", clusterPort).put("clusterPublicPort", clusterPublicPort).put("eventLoopPoolSize", eventLoopPoolSize).put("internalBlockingPoolSize", internalBlockingPoolSize).put("workerPoolSize", workerPoolSize).put("blockedThreadCheckInterval", blockedThreadCheckInterval).put("clusterHost", clusterHost).put("clusterPublicHost", clusterPublicHost).put("clusterPingInterval", clusterPingInterval).put("clusterPingReplyInterval", clusterPingReplyInterval).put("maxEventLoopExecuteTime", maxEventLoopExecuteTime).put("maxWorkerExecuteTime", maxWorkerExecuteTime).put("proxyOperationTimeout", proxyOperationTimeout).put("haEnabled", haEnabled).put("quorumSize", quorumSize).put("haGroup", haGroup).put("warningExceptionTime", warningExceptionTime).put("metricsOptions", new JsonObject().put("enabled", metricsEnabled).put("jmxEnabled", jmxEnabled).put("jmxDomain", jmxDomain)));
    assertEquals(clusterPort, options.getClusterPort());
    assertEquals(clusterPublicPort, options.getClusterPublicPort());
    assertEquals(clusterPublicHost, options.getClusterPublicHost());
    assertEquals(clusterPingInterval, options.getClusterPingInterval());
    assertEquals(clusterPingReplyInterval, options.getClusterPingReplyInterval());
    assertEquals(eventLoopPoolSize, options.getEventLoopPoolSize());
    assertEquals(internalBlockingPoolSize, options.getInternalBlockingPoolSize());
    assertEquals(workerPoolSize, options.getWorkerPoolSize());
    assertEquals(blockedThreadCheckInterval, options.getBlockedThreadCheckInterval());
    assertEquals(clusterHost, options.getClusterHost());
    assertEquals(null, options.getClusterManager());
    assertEquals(maxEventLoopExecuteTime, options.getMaxEventLoopExecuteTime());
    assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
    assertEquals(haEnabled, options.isHAEnabled());
    assertEquals(quorumSize, options.getQuorumSize());
    assertEquals(haGroup, options.getHAGroup());
    MetricsOptions metricsOptions = options.getMetricsOptions();
    assertEquals(metricsEnabled, metricsOptions.isEnabled());
    assertEquals(warningExceptionTime, options.getWarningExceptionTime());
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) Random(java.util.Random) JsonObject(io.vertx.core.json.JsonObject) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 9 with VertxOptions

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

the class VertxOptionsTest method testOptions.

@Test
public void testOptions() {
    VertxOptions options = new VertxOptions();
    assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
    int rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setEventLoopPoolSize(rand));
    assertEquals(rand, options.getEventLoopPoolSize());
    try {
        options.setEventLoopPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(20, options.getWorkerPoolSize());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setWorkerPoolSize(rand));
    assertEquals(rand, options.getWorkerPoolSize());
    try {
        options.setWorkerPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(20, options.getInternalBlockingPoolSize());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setInternalBlockingPoolSize(rand));
    assertEquals(rand, options.getInternalBlockingPoolSize());
    try {
        options.setInternalBlockingPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertFalse(options.isClustered());
    assertEquals(options, options.setClustered(true));
    assertTrue(options.isClustered());
    assertEquals(0, options.getClusterPort());
    assertEquals(options, options.setClusterPort(1234));
    assertEquals(1234, options.getClusterPort());
    try {
        options.setClusterPort(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setClusterPort(65536);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(-1, options.getClusterPublicPort());
    assertEquals(options, options.setClusterPublicPort(1234));
    assertEquals(1234, options.getClusterPublicPort());
    try {
        options.setClusterPublicPort(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setClusterPublicPort(65536);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals("localhost", options.getClusterHost());
    String randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setClusterHost(randString));
    assertEquals(randString, options.getClusterHost());
    assertEquals(null, options.getClusterPublicHost());
    randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setClusterPublicHost(randString));
    assertEquals(randString, options.getClusterPublicHost());
    assertEquals(20000, options.getClusterPingInterval());
    long randomLong = TestUtils.randomPositiveLong();
    assertEquals(options, options.setClusterPingInterval(randomLong));
    assertEquals(randomLong, options.getClusterPingInterval());
    try {
        options.setClusterPingInterval(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
        assertEquals(randomLong, options.getClusterPingInterval());
    }
    assertEquals(20000, options.getClusterPingReplyInterval());
    randomLong = TestUtils.randomPositiveLong();
    assertEquals(options, options.setClusterPingReplyInterval(randomLong));
    assertEquals(randomLong, options.getClusterPingReplyInterval());
    try {
        options.setClusterPingReplyInterval(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
        assertEquals(randomLong, options.getClusterPingReplyInterval());
    }
    assertEquals(1000, options.getBlockedThreadCheckInterval());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setBlockedThreadCheckInterval(rand));
    assertEquals(rand, options.getBlockedThreadCheckInterval());
    try {
        options.setBlockedThreadCheckInterval(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    // 2 seconds in nano seconds
    assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setMaxEventLoopExecuteTime(rand));
    assertEquals(rand, options.getMaxEventLoopExecuteTime());
    try {
        options.setMaxEventLoopExecuteTime(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    // 1 minute in nano seconds
    assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setMaxWorkerExecuteTime(rand));
    assertEquals(rand, options.getMaxWorkerExecuteTime());
    try {
        options.setMaxWorkerExecuteTime(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    ClusterManager mgr = new FakeClusterManager();
    assertNull(options.getClusterManager());
    assertEquals(options, options.setClusterManager(mgr));
    assertSame(mgr, options.getClusterManager());
    assertFalse(options.isHAEnabled());
    assertEquals(options, options.setHAEnabled(true));
    assertTrue(options.isHAEnabled());
    rand = TestUtils.randomPositiveInt();
    assertEquals(1, options.getQuorumSize());
    assertEquals(options, options.setQuorumSize(rand));
    assertEquals(rand, options.getQuorumSize());
    try {
        options.setQuorumSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setQuorumSize(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
    randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setHAGroup(randString));
    assertEquals(randString, options.getHAGroup());
    try {
        options.setHAGroup(null);
        fail("Should throw exception");
    } catch (NullPointerException e) {
    // OK
    }
    assertNotNull(options.getMetricsOptions());
    try {
        options.setWarningExceptionTime(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(options, options.setWarningExceptionTime(1000000000l));
    assertEquals(1000000000l, options.getWarningExceptionTime());
}
Also used : VertxOptions(io.vertx.core.VertxOptions) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) Test(org.junit.Test)

Example 10 with VertxOptions

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

the class HttpMetricsTest method getOptions.

@Override
protected VertxOptions getOptions() {
    VertxOptions options = super.getOptions();
    options.setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(new FakeMetricsFactory()));
    return options;
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions)

Aggregations

VertxOptions (io.vertx.core.VertxOptions)38 Test (org.junit.Test)30 VertxInternal (io.vertx.core.impl.VertxInternal)12 JsonObject (io.vertx.core.json.JsonObject)12 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Vertx (io.vertx.core.Vertx)9 VertxException (io.vertx.core.VertxException)9 NetClient (io.vertx.core.net.NetClient)9 NetServer (io.vertx.core.net.NetServer)9 NetServerOptions (io.vertx.core.net.NetServerOptions)9 InetAddress (java.net.InetAddress)9 HashMap (java.util.HashMap)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 Channel (io.netty.channel.Channel)8 ChannelFuture (io.netty.channel.ChannelFuture)8 ChannelInitializer (io.netty.channel.ChannelInitializer)8