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);
}
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");
}
}
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());
}
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());
}
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);
}
Aggregations