io.vertx.core.dns.AddressResolverOptions Java Examples

The following examples show how to use io.vertx.core.dns.AddressResolverOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: TestAddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetResover() {
  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")));
}
 
Example #3
Source File: VertxProperties.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Configures the Vert.x options based on this object's property values.
 *
 * @param options The options to configure.
 * @return The (updated) options.
 */
public VertxOptions configureVertx(final VertxOptions options) {

    options.setPreferNativeTransport(this.preferNative);

    if (this.enableMetrics) {
        options.setMetricsOptions(new MetricsOptions().setEnabled(true));
    }

    options.setMaxEventLoopExecuteTime(maxEventLoopExecuteTimeMillis * 1000000L);
    options.setWarningExceptionTime(maxEventLoopExecuteTimeMillis * 1500000L);
    options.setAddressResolverOptions(new AddressResolverOptions()
            .setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
            .setCacheMaxTimeToLive(0) // support DNS based service resolution
            .setQueryTimeout(dnsQueryTimeout));
    return options;
}
 
Example #4
Source File: TestAddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResoverDefault() {
  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 aroc = AddressResolverConfig.getAddressResover("test");
  Assert.assertThat(aroc.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
  Assert.assertEquals(3, aroc.getMaxQueries());
  Assert.assertEquals(Integer.MAX_VALUE, aroc.getCacheMaxTimeToLive());
  Assert.assertTrue(aroc.isOptResourceEnabled());
  Assert.assertNull(aroc.getSearchDomains());
}
 
Example #5
Source File: AbstractClient.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
final Vertx vertx() {
    final VertxOptions options = new VertxOptions()
            .setWarningExceptionTime(1500000000)
            .setAddressResolverOptions(new AddressResolverOptions()
                    .setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
                    .setCacheMaxTimeToLive(0) // support DNS based service resolution
                    .setRotateServers(true)
                    .setQueryTimeout(DEFAULT_ADDRESS_RESOLUTION_TIMEOUT_MILLIS));
    return Vertx.vertx(options);
}
 
Example #6
Source File: VertxConfiguration.java    From enmasse with Apache License 2.0 5 votes vote down vote up
@Bean
public Vertx vertx() {
    final VertxOptions options = new VertxOptions()
            .setWarningExceptionTime(1500000000)
            .setAddressResolverOptions(new AddressResolverOptions()
                    .setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
                    .setCacheMaxTimeToLive(0) // support DNS based service resolution
                    .setQueryTimeout(1000));

    vertxProperties().configureVertx(options);

    return Vertx.vertx(options);
}
 
Example #7
Source File: WebClientTestBase.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
protected VertxOptions getOptions() {
  return super.getOptions().setAddressResolverOptions(new AddressResolverOptions().
    setHostsValue(Buffer.buffer(
      "127.0.0.1 somehost\n" +
        "127.0.0.1 localhost")));
}
 
Example #8
Source File: InterceptorTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
protected VertxOptions getOptions() {
  return super.getOptions().setAddressResolverOptions(new AddressResolverOptions().
    setHostsValue(Buffer.buffer(
      "127.0.0.1 somehost\n" +
      "127.0.0.1 localhost")));
}
 
Example #9
Source File: SVMSubstitutions.java    From aws-lambda-native-vertx with MIT License 4 votes vote down vote up
@Substitute
public static ResolverProvider factory(Vertx vertx, AddressResolverOptions options) {
  return new DefaultResolverProvider();
}
 
Example #10
Source File: VertxProperties.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
public VertxOptions toVertxOptions() {
    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setEventLoopPoolSize(eventLoopPoolSize);
    vertxOptions.setWorkerPoolSize(workerPoolSize);
    vertxOptions.setInternalBlockingPoolSize(internalBlockingPoolSize);
    vertxOptions.setBlockedThreadCheckInterval(blockedThreadCheckInterval);
    vertxOptions.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime);
    vertxOptions.setMaxWorkerExecuteTime(maxWorkerExecuteTime);
    vertxOptions.setHAEnabled(haEnabled);
    vertxOptions.setQuorumSize(quorumSize);
    vertxOptions.setHAGroup(haGroup);
    vertxOptions.setWarningExceptionTime(warningExceptionTime);
    vertxOptions.setPreferNativeTransport(preferNativeTransport);
    vertxOptions.setMaxEventLoopExecuteTimeUnit(maxEventLoopExecuteTimeUnit);
    vertxOptions.setMaxWorkerExecuteTimeUnit(maxWorkerExecuteTimeUnit);
    vertxOptions.setWarningExceptionTimeUnit(warningExceptionTimeUnit);
    vertxOptions.setBlockedThreadCheckIntervalUnit(blockedThreadCheckIntervalUnit);

    MetricsOptions metricsOptions = new MetricsOptions();
    metricsOptions.setEnabled(metricsEnabled);
    vertxOptions.setMetricsOptions(metricsOptions);

    FileSystemOptions fileSystemOptions = new FileSystemOptions();
    fileSystemOptions.setClassPathResolvingEnabled(fileSystem.isClassPathResolvingEnabled());
    fileSystemOptions.setFileCachingEnabled(fileSystem.isFileCachingEnabled());
    vertxOptions.setFileSystemOptions(fileSystemOptions);

    AddressResolverOptions addressResolverOptions = new AddressResolverOptions();
    addressResolverOptions.setHostsPath(addressResolver.getHostsPath());
    addressResolverOptions.setHostsValue(addressResolver.getHostsValue());
    addressResolverOptions.setServers(addressResolver.getServers());
    addressResolverOptions.setOptResourceEnabled(addressResolver.isOptResourceEnabled());
    addressResolverOptions.setCacheMinTimeToLive(addressResolver.getCacheMinTimeToLive());
    addressResolverOptions.setCacheMaxTimeToLive(addressResolver.getCacheMaxTimeToLive());
    addressResolverOptions.setCacheNegativeTimeToLive(addressResolver.getCacheNegativeTimeToLive());
    addressResolverOptions.setQueryTimeout(addressResolver.getQueryTimeout());
    addressResolverOptions.setMaxQueries(addressResolver.getMaxQueries());
    addressResolverOptions.setRdFlag(addressResolver.isRdFlag());
    addressResolverOptions.setSearchDomains(addressResolver.getSearchDomains());
    addressResolverOptions.setNdots(addressResolver.getNdots());
    addressResolverOptions.setRotateServers(addressResolver.isRotateServers());
    vertxOptions.setAddressResolverOptions(addressResolverOptions);

    return vertxOptions;
}
 
Example #11
Source File: VertxSubstitutions.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Substitute
public static ResolverProvider factory(Vertx vertx, AddressResolverOptions options) {
    return new DefaultResolverProvider();
}
 
Example #12
Source File: AddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
/**
 * get the target endpoints with custom address resolve config
 * @param tag config tag, such as sc.consumer or cc.consumer
 * @param configSource get config from special config source
 * @return AddressResolverOptions
 */
public static AddressResolverOptions getAddressResover(String tag, Configuration configSource) {
  AddressResolverOptions addressResolverOptions = new AddressResolverOptions();
  addressResolverOptions
      .setServers(getStringListProperty(configSource,
          AddressResolverOptions.DEFAULT_SERVERS,
          "addressResolver." + tag + ".servers",
          "addressResolver.servers"));
  addressResolverOptions
      .setOptResourceEnabled(getBooleanProperty(configSource,
          AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED,
          "addressResolver." + tag + ".optResourceEnabled",
          "addressResolver.optResourceEnabled"));
  addressResolverOptions
      .setCacheMinTimeToLive(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE,
          "addressResolver." + tag + ".cacheMinTimeToLive",
          "addressResolver.cacheMinTimeToLive"));
  addressResolverOptions
      .setCacheMaxTimeToLive(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE,
          "addressResolver." + tag + ".cacheMaxTimeToLive",
          "addressResolver.cacheMaxTimeToLive"));
  addressResolverOptions
      .setCacheNegativeTimeToLive(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE,
          "addressResolver." + tag + ".cacheNegativeTimeToLive",
          "addressResolver.cacheNegativeTimeToLive"));
  addressResolverOptions
      .setQueryTimeout(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_QUERY_TIMEOUT,
          "addressResolver." + tag + ".queryTimeout",
          "addressResolver.queryTimeout"));
  addressResolverOptions
      .setMaxQueries(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_MAX_QUERIES,
          "addressResolver." + tag + ".maxQueries",
          "addressResolver.maxQueries"));
  addressResolverOptions
      .setRdFlag(getBooleanProperty(configSource,
          AddressResolverOptions.DEFAULT_RD_FLAG,
          "addressResolver." + tag + ".rdFlag",
          "addressResolver.rdFlag"));
  addressResolverOptions
      .setSearchDomains(getStringListProperty(configSource,
          AddressResolverOptions.DEFAULT_SEACH_DOMAINS,
          "addressResolver." + tag + ".searchDomains",
          "addressResolver.searchDomains"));
  addressResolverOptions
      .setNdots(getPositiveIntProperty(configSource,
          AddressResolverOptions.DEFAULT_NDOTS,
          "addressResolver." + tag + ".ndots",
          "addressResolver.ndots"));
  addressResolverOptions
      .setRotateServers(getBooleanProperty(configSource,
          AddressResolverOptions.DEFAULT_ROTATE_SERVERS,
          "addressResolver." + tag + ".rotateServers",
          "addressResolver.rotateServers"));
  return addressResolverOptions;
}
 
Example #13
Source File: AddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 2 votes vote down vote up
/**
 * get the target endpoints with custom address resolve config
 * @param tag config tag, such as sc.consumer or cc.consumer
 * @return AddressResolverOptions
 */
public static AddressResolverOptions getAddressResover(String tag) {
  return getAddressResover(tag, null);
}