Search in sources :

Example 26 with AddressResolverOptions

use of io.vertx.core.dns.AddressResolverOptions in project incubator-servicecomb-java-chassis by apache.

the class TestAddressResolverConfig method testGetResoverFromResource.

@Test
public void testGetResoverFromResource(@Mocked Configuration finalConfig) {
    ArchaiusUtils.resetConfig();
    ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4");
    new Expectations() {

        {
            finalConfig.getStringArray("addressResolver.servers");
            result = new String[] { "6.6.6.6", "6.6.4.4" };
            finalConfig.getStringArray("addressResolver.searchDomains");
            result = new String[] { "default.svc.local.cluster" };
            finalConfig.getInteger("addressResolver.queryTimeout", null);
            result = 2000;
            finalConfig.getInteger("addressResolver.maxQueries", null);
            result = -2;
        }
    };
    AddressResolverOptions aroc = AddressResolverConfig.getAddressResover("test", finalConfig);
    Assert.assertThat(aroc.getServers(), is(Arrays.asList("6.6.6.6", "6.6.4.4")));
    Assert.assertThat(aroc.getSearchDomains(), is(Arrays.asList("default.svc.local.cluster")));
    Assert.assertEquals(aroc.getQueryTimeout(), 2000);
    Assert.assertNotEquals(aroc.getMaxQueries(), -2);
}
Also used : Expectations(mockit.Expectations) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) Test(org.junit.Test)

Example 27 with AddressResolverOptions

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

the class HttpTest method testClientSynchronousConnectFailures.

@Test
public void testClientSynchronousConnectFailures() {
    System.setProperty("vertx.disableDnsResolver", "true");
    Vertx vertx = Vertx.vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setQueryTimeout(100)));
    try {
        int poolSize = 2;
        HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(poolSize));
        AtomicInteger failures = new AtomicInteger();
        vertx.runOnContext(v -> {
            for (int i = 0; i < (poolSize + 1); i++) {
                AtomicBoolean f = new AtomicBoolean();
                client.request(new RequestOptions().setAbsoluteURI("http://invalid-host-name.foo.bar")).onComplete(onFailure(req -> {
                    if (f.compareAndSet(false, true)) {
                        if (failures.incrementAndGet() == poolSize + 1) {
                            testComplete();
                        }
                    }
                }));
            }
        });
        await();
    } finally {
        vertx.close();
        System.setProperty("vertx.disableDnsResolver", "false");
    }
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 28 with AddressResolverOptions

use of io.vertx.core.dns.AddressResolverOptions in project java-chassis by ServiceComb.

the class TestAddressResolverConfig method testGetResolverDefault.

@Test
public void testGetResolverDefault() {
    ArchaiusUtils.resetConfig();
    ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4");
    ArchaiusUtils.setProperty("addressResolver.maxQueries", 3);
    ArchaiusUtils.setProperty("addressResolver.rdFlag", false);
    AddressResolverOptions resolverOptions = AddressResolverConfig.getAddressResover("test");
    Assert.assertThat(resolverOptions.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
    Assert.assertEquals(3, resolverOptions.getMaxQueries());
    Assert.assertEquals(Integer.MAX_VALUE, resolverOptions.getCacheMaxTimeToLive());
    Assert.assertFalse(resolverOptions.isOptResourceEnabled());
    Assert.assertNull(resolverOptions.getSearchDomains());
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) Test(org.junit.Test)

Example 29 with AddressResolverOptions

use of io.vertx.core.dns.AddressResolverOptions in project java-chassis by ServiceComb.

the class TestAddressResolverConfig method testGetResolver.

@Test
public void testGetResolver() {
    ArchaiusUtils.resetConfig();
    ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4");
    ArchaiusUtils.setProperty("addressResolver.optResourceEnabled", true);
    ArchaiusUtils.setProperty("addressResolver.cacheMinTimeToLive", 0);
    ArchaiusUtils.setProperty("addressResolver.cacheMaxTimeToLive", 10000);
    ArchaiusUtils.setProperty("addressResolver.cacheNegativeTimeToLive", 0);
    ArchaiusUtils.setProperty("addressResolver.queryTimeout", 1000);
    ArchaiusUtils.setProperty("addressResolver.maxQueries", 3);
    ArchaiusUtils.setProperty("addressResolver.test.maxQueries", 3);
    ArchaiusUtils.setProperty("addressResolver.rdFlag", true);
    ArchaiusUtils.setProperty("addressResolver.searchDomains", "default.svc.local.cluster,svc.local.cluster,local.cluster");
    ArchaiusUtils.setProperty("addressResolver.test.searchDomains", "test.svc.local.cluster,svc.local.cluster,local.cluster");
    ArchaiusUtils.setProperty("addressResolver.ndots", 3);
    ArchaiusUtils.setProperty("addressResolver.rotateServers", true);
    AddressResolverOptions aroc = AddressResolverConfig.getAddressResover("test");
    Assert.assertThat(aroc.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
    Assert.assertThat(aroc.getSearchDomains(), is(Arrays.asList("test.svc.local.cluster", "svc.local.cluster", "local.cluster")));
    AddressResolverOptions aroc1 = AddressResolverConfig.getAddressResover("test1");
    Assert.assertThat(aroc1.getSearchDomains(), is(Arrays.asList("default.svc.local.cluster", "svc.local.cluster", "local.cluster")));
    Assert.assertTrue(aroc.isOptResourceEnabled());
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) Test(org.junit.Test)

Example 30 with AddressResolverOptions

use of io.vertx.core.dns.AddressResolverOptions in project java-chassis by ServiceComb.

the class HttpClients method getOrCreateVertx.

private static Vertx getOrCreateVertx(HttpClientOptionsSPI option) {
    if (option.useSharedVertx()) {
        return SharedVertxFactory.getSharedVertx();
    }
    AddressResolverOptions resolverOptions = AddressResolverConfig.getAddressResover(option.getConfigTag(), option.getConfigReader());
    VertxOptions vertxOptions = new VertxOptions().setAddressResolverOptions(resolverOptions).setEventLoopPoolSize(option.getEventLoopPoolSize());
    // Maybe we can deploy only one vert.x for the application. However this has did it like this.
    return VertxUtils.getOrCreateVertxByName(option.clientName(), vertxOptions);
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) VertxOptions(io.vertx.core.VertxOptions)

Aggregations

AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)30 Test (org.junit.Test)25 VertxOptions (io.vertx.core.VertxOptions)13 AddressResolver (io.vertx.core.impl.AddressResolver)11 InetAddress (java.net.InetAddress)11 CompletableFuture (java.util.concurrent.CompletableFuture)11 FakeDNSServer (io.vertx.test.fakedns.FakeDNSServer)10 InetSocketAddress (java.net.InetSocketAddress)10 ArrayList (java.util.ArrayList)10 VertxException (io.vertx.core.VertxException)9 Buffer (io.vertx.core.buffer.Buffer)9 VertxInternal (io.vertx.core.impl.VertxInternal)9 JsonObject (io.vertx.core.json.JsonObject)9 NetClient (io.vertx.core.net.NetClient)9 NetServer (io.vertx.core.net.NetServer)9 NetServerOptions (io.vertx.core.net.NetServerOptions)9 HashMap (java.util.HashMap)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 Channel (io.netty.channel.Channel)8