@Test
  public void testBadRegistrationOfDataCenterInfo() throws Exception {
    try {
      // test 400 when configured to return client error
      ConfigurationManager.getConfigInstance()
          .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "true");
      InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
      when(instanceInfo.getDataCenterInfo()).thenReturn(new TestDataCenterInfo());
      Response response = applicationResource.addInstance(instanceInfo, false + "");
      assertThat(response.getStatus(), is(400));

      // test backfill of data for AmazonInfo
      ConfigurationManager.getConfigInstance()
          .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "false");
      instanceInfo = spy(InstanceInfoGenerator.takeOne());
      assertThat(instanceInfo.getDataCenterInfo(), instanceOf(AmazonInfo.class));
      ((AmazonInfo) instanceInfo.getDataCenterInfo())
          .getMetadata()
          .remove(AmazonInfo.MetaDataKey.instanceId.getName()); // clear the Id
      response = applicationResource.addInstance(instanceInfo, false + "");
      assertThat(response.getStatus(), is(204));

    } finally {
      ConfigurationManager.getConfigInstance()
          .clearProperty("eureka.experimental.registration.validation.dataCenterInfoId");
    }
  }
Exemplo n.º 2
0
 @Test
 public void testExecuteWithLB() throws Exception {
   ConfigurationManager.getConfigInstance()
       .setProperty("allservices.ribbon." + CommonClientConfigKey.ReadTimeout, "10000");
   ConfigurationManager.getConfigInstance()
       .setProperty("allservices.ribbon." + CommonClientConfigKey.FollowRedirects, "true");
   RestClient client = (RestClient) ClientFactory.getNamedClient("allservices");
   BaseLoadBalancer lb = new BaseLoadBalancer();
   Server[] servers = new Server[] {new Server("localhost", server.getServerPort())};
   lb.addServers(Arrays.asList(servers));
   client.setLoadBalancer(lb);
   Set<URI> expected = new HashSet<URI>();
   expected.add(new URI(server.getServerPath("/")));
   Set<URI> result = new HashSet<URI>();
   HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
   for (int i = 0; i < 5; i++) {
     HttpResponse response = client.executeWithLoadBalancer(request);
     assertStatusIsOk(response.getStatus());
     assertTrue(response.isSuccess());
     String content = response.getEntity(String.class);
     response.close();
     assertFalse(content.isEmpty());
     result.add(response.getRequestedURI());
   }
   assertEquals(expected, result);
   request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
   HttpResponse response = client.executeWithLoadBalancer(request);
   assertEquals(200, response.getStatus());
 }
Exemplo n.º 3
0
  public void start() {
    this.host =
        ConfigurationManager.getConfigInstance()
            .getString("netty.http.host", "not-found-in-configuration");
    this.port =
        ConfigurationManager.getConfigInstance().getInt("netty.http.port", Integer.MIN_VALUE);

    final PackagesResourceConfig rcf =
        new PackagesResourceConfig(
            ConfigurationManager.getConfigInstance()
                .getString("jersey.resources.package", "not-found-in-configuration"));

    nettyServer =
        NettyServer.builder()
            .host(host)
            .port(port)
            .addHandler(
                "jerseyHandler", ContainerFactory.createContainer(NettyHandlerContainer.class, rcf))
            .numBossThreads(NettyServer.cpus)
            .numWorkerThreads(NettyServer.cpus * 4)
            .build();
    try {
      karyonServer.start();
    } catch (Exception exc) {
      throw new RuntimeException("Cannot start karyon server.", exc);
    }
  }
Exemplo n.º 4
0
 @Test
 public void testVipAsURI() throws Exception {
   ConfigurationManager.getConfigInstance()
       .setProperty("test1.ribbon.DeploymentContextBasedVipAddresses", server.getServerPath("/"));
   ConfigurationManager.getConfigInstance()
       .setProperty("test1.ribbon.InitializeNFLoadBalancer", "false");
   RestClient client = (RestClient) ClientFactory.getNamedClient("test1");
   assertNull(client.getLoadBalancer());
   HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
   HttpResponse response = client.executeWithLoadBalancer(request);
   assertStatusIsOk(response.getStatus());
   assertEquals(server.getServerPath("/"), response.getRequestedURI().toString());
 }
  @Test
  public void testZoneAffinityEnabled() throws Exception {
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest1.ribbon.DeploymentContextBasedVipAddresses",
            "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest1.ribbon.NFLoadBalancerClassName",
            DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest1.ribbon.NIWSServerListClassName",
            DiscoveryEnabledNIWSServerList.class.getName());

    ConfigurationManager.getConfigInstance()
        .setProperty("DefaultNIWSServerListFilterTest1.ribbon.EnableZoneAffinity", "true");
    DynamicServerListLoadBalancer lb =
        (DynamicServerListLoadBalancer)
            ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest1");
    assertTrue(lb.getRule() instanceof AvailabilityFilteringRule);
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);
    for (int i = 1; i <= 4; i++) {
      loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);
  }
  private void init() {
    String env = ConfigurationManager.getConfigInstance().getString(EUREKA_ENVIRONMENT, TEST);
    ConfigurationManager.getConfigInstance().setProperty(ARCHAIUS_DEPLOYMENT_ENVIRONMENT, env);

    String eurekaPropsFile = EUREKA_PROPS_FILE.get();
    try {
      // ConfigurationManager
      // .loadPropertiesFromResources(eurekaPropsFile);
      ConfigurationManager.loadCascadedPropertiesFromResources(eurekaPropsFile);
    } catch (IOException e) {
      logger.warn(
          "Cannot find the properties specified : {}. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.",
          eurekaPropsFile);
    }
  }
Exemplo n.º 7
0
  @Test
  public void overrideThreadIsolationTimeout() {
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "hystrix.command.THREAD_ISOLATION_TIMEOUT.execution.isolation.thread.timeoutInMilliseconds",
            "987");
    class ThreadIsolationCommand extends TenacityCommand<String> {
      private ThreadIsolationCommand() {
        super(DependencyKey.THREAD_ISOLATION_TIMEOUT);
      }

      @Override
      protected String run() throws Exception {
        return "value";
      }

      @Override
      protected String getFallback() {
        return "fallback";
      }
    }

    final ThreadIsolationCommand threadIsolationCommand = new ThreadIsolationCommand();

    assertEquals(threadIsolationCommand.execute(), "value");

    final HystrixCommandProperties commandProperties =
        threadIsolationCommand.getCommandProperties();
    assertEquals(
        commandProperties.executionIsolationThreadTimeoutInMilliseconds().get().intValue(), 987);
  }
 private static void initializeHystrixSettings() {
   hystrixConfig = ConfigurationManager.getConfigInstance();
   hystrixConfig.setProperty(CORE_SIZE_CONFIG, "20");
   hystrixConfig.setProperty(MAX_QUEUE_SIZE_CONFIG, "20");
   hystrixConfig.setProperty(QUEUE_REJECTION_THRESHOLD_CONFIG, "10");
   hystrixConfig.setProperty(COLLAPSER_TIMER_DELAY, "50");
 }
Exemplo n.º 9
0
 @Test
 public void testSecureClient() throws Exception {
   ConfigurationManager.getConfigInstance().setProperty("test2.ribbon.IsSecure", "true");
   RestClient client = (RestClient) ClientFactory.getNamedClient("test2");
   HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
   HttpResponse response = client.executeWithLoadBalancer(request);
   assertStatusIsOk(response.getStatus());
 }
 protected void setProp(String serviceId, String suffix, String value) {
   // how to set the namespace properly?
   String key = getKey(serviceId, suffix);
   DynamicStringProperty property = getProperty(key);
   if (property.get().equals(VALUE_NOT_SET)) {
     ConfigurationManager.getConfigInstance().setProperty(key, value);
   }
 }
Exemplo n.º 11
0
 protected void putDefaultTimeUnitProperty(IClientConfigKey propName, TimeUnit defaultValue) {
   TimeUnit value = defaultValue;
   String propValue =
       ConfigurationManager.getConfigInstance().getString(getDefaultPropName(propName));
   if (propValue != null && propValue.length() > 0) {
     value = TimeUnit.valueOf(propValue);
   }
   setPropertyInternal(propName, value);
 }
  @Override
  public void initWithNiwsConfig(IClientConfig clientConfig) {
    clientName = clientConfig.getClientName();
    vipAddresses = clientConfig.resolveDeploymentContextbasedVipAddresses();
    if (vipAddresses == null
        && ConfigurationManager.getConfigInstance()
            .getBoolean("DiscoveryEnabledNIWSServerList.failFastOnNullVip", true)) {
      throw new NullPointerException("VIP address for client " + clientName + " is null");
    }
    isSecure =
        Boolean.parseBoolean(
            "" + clientConfig.getProperty(CommonClientConfigKey.IsSecure, "false"));
    prioritizeVipAddressBasedServers =
        Boolean.parseBoolean(
            ""
                + clientConfig.getProperty(
                    CommonClientConfigKey.PrioritizeVipAddressBasedServers,
                    prioritizeVipAddressBasedServers));
    datacenter = ConfigurationManager.getDeploymentContext().getDeploymentDatacenter();
    targetRegion = (String) clientConfig.getProperty(CommonClientConfigKey.TargetRegion);

    // override client configuration and use client-defined port
    if (clientConfig.getPropertyAsBoolean(
        CommonClientConfigKey.ForceClientPortConfiguration, false)) {

      if (isSecure) {

        if (clientConfig.containsProperty(CommonClientConfigKey.SecurePort)) {

          overridePort =
              clientConfig.getPropertyAsInteger(
                  CommonClientConfigKey.SecurePort, DefaultClientConfigImpl.DEFAULT_PORT);
          shouldUseOverridePort = true;

        } else {
          logger.warn(
              clientName + " set to force client port but no secure port is set, so ignoring");
        }
      } else {

        if (clientConfig.containsProperty(CommonClientConfigKey.Port)) {

          overridePort =
              clientConfig.getPropertyAsInteger(
                  CommonClientConfigKey.Port, DefaultClientConfigImpl.DEFAULT_PORT);
          shouldUseOverridePort = true;

        } else {
          logger.warn(clientName + " set to force client port but no port is set, so ignoring");
        }
      }
    }
  }
Exemplo n.º 13
0
  @Test
  public void testDynamicProperty() throws IOException {
    String spec =
        "{\n" + "    \"type\": \"dynamic\",\n" + "    \"format\": \"property(prop1)\"\n" + "}";

    ConfigurationManager.getConfigInstance().setProperty("prop1", "prop1");

    ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    RemotePrefixFormatter formatter =
        mapper.readValue(spec, new TypeReference<RemotePrefixFormatter>() {});

    assertEquals(formatter.get(), "prop1/");
  }
Exemplo n.º 14
0
  @Test
  public void testSecureClient2() throws Exception {
    ConfigurationManager.getConfigInstance()
        .setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true");
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "test3.ribbon." + CommonClientConfigKey.TrustStore,
            secureServer.getTrustStore().getAbsolutePath());
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);

    RestClient client = (RestClient) ClientFactory.getNamedClient("test3");
    BaseLoadBalancer lb = new BaseLoadBalancer();
    Server[] servers = new Server[] {new Server("localhost", secureServer.getServerPort())};
    lb.addServers(Arrays.asList(servers));
    client.setLoadBalancer(lb);
    HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
    HttpResponse response = client.executeWithLoadBalancer(request);
    assertStatusIsOk(response.getStatus());
    assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString());
  }
 @Override
 public Map<String, Object> invoke() {
   Map<String, Object> map = new LinkedHashMap<String, Object>();
   AbstractConfiguration config = ConfigurationManager.getConfigInstance();
   if (config instanceof ConcurrentCompositeConfiguration) {
     ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) config;
     for (Configuration item : composite.getConfigurations()) {
       append(map, item);
     }
   } else {
     append(map, config);
   }
   return map;
 }
Exemplo n.º 16
0
  @Test
  public void testDynamicCombination() throws IOException {
    String spec =
        "{\n"
            + "    \"type\": \"dynamic\",\n"
            + "    \"format\": \"static(routing_key)/date(YYYYMMDD)/property(prop1)\"\n"
            + "}";

    ConfigurationManager.getConfigInstance().setProperty("prop1", "propvalue1");

    DateTimeFormatter format = DateTimeFormat.forPattern("YYYYMMDD");

    ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    RemotePrefixFormatter formatter =
        mapper.readValue(spec, new TypeReference<RemotePrefixFormatter>() {});

    assertEquals(formatter.get(), "routing_key/" + format.print(new DateTime()) + "/propvalue1/");
  }
Exemplo n.º 17
0
 /**
  * Load properties for a given client. It first loads the default values for all properties, and
  * any properties already defined with Archaius ConfigurationManager.
  */
 @Override
 public void loadProperties(String restClientName) {
   enableDynamicProperties = true;
   setClientName(restClientName);
   loadDefaultValues();
   Configuration props = ConfigurationManager.getConfigInstance().subset(restClientName);
   for (Iterator<String> keys = props.getKeys(); keys.hasNext(); ) {
     String key = keys.next();
     String prop = key;
     try {
       if (prop.startsWith(getNameSpace())) {
         prop = prop.substring(getNameSpace().length() + 1);
       }
       setPropertyInternal(prop, getStringValue(props, key));
     } catch (Exception ex) {
       throw new RuntimeException(String.format("Property %s is invalid", prop));
     }
   }
 }
  @Before
  public void setupOrg() {

    originalShardSize = ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_SIZE);

    originalShardTimeout =
        ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_CACHE_TIMEOUT);

    originalShardDelta =
        ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_MIN_DELTA);

    ConfigurationManager.getConfigInstance().setProperty(GraphFig.SHARD_SIZE, 500);

    final long cacheTimeout = 2000;
    // set our cache timeout to the above value
    ConfigurationManager.getConfigInstance()
        .setProperty(GraphFig.SHARD_CACHE_TIMEOUT, cacheTimeout);

    final long minDelta = (long) (cacheTimeout * 2.5);

    ConfigurationManager.getConfigInstance().setProperty(GraphFig.SHARD_MIN_DELTA, minDelta);

    // get the system property of the UUID to use.  If one is not set, use the defualt
    String uuidString = System.getProperty("org.id", "80a42760-b699-11e3-a5e2-0800200c9a66");

    scope = new ApplicationScopeImpl(IdGenerator.createId(UUID.fromString(uuidString), "test"));

    reporter =
        Slf4jReporter.forRegistry(registry)
            .outputTo(logger)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();

    reporter.start(10, TimeUnit.SECONDS);
  }
Exemplo n.º 19
0
 // Helper methods which first check if a "default" (with rest client name)
 // property exists. If so, that value is used, else the default value
 // passed as argument is used to put into the properties member variable
 protected void putDefaultIntegerProperty(IClientConfigKey propName, Integer defaultValue) {
   Integer value =
       ConfigurationManager.getConfigInstance()
           .getInteger(getDefaultPropName(propName), defaultValue);
   setPropertyInternal(propName, value);
 }
Exemplo n.º 20
0
 protected void putDefaultBooleanProperty(IClientConfigKey propName, Boolean defaultValue) {
   Boolean value =
       ConfigurationManager.getConfigInstance()
           .getBoolean(getDefaultPropName(propName), defaultValue);
   setPropertyInternal(propName, value);
 }
Exemplo n.º 21
0
 protected void putDefaultStringProperty(IClientConfigKey propName, String defaultValue) {
   String value =
       ConfigurationManager.getConfigInstance()
           .getString(getDefaultPropName(propName), defaultValue);
   setPropertyInternal(propName, value);
 }
 public static <T> T getNamedInstance(Class<T> type, String name) {
   ApplicationContext context =
       (ApplicationContext)
           ConfigurationManager.getConfigInstance().getProperty(APPLICATION_CONTEXT);
   return context != null && context.containsBean(name) ? context.getBean(name, type) : null;
 }
Exemplo n.º 23
0
 public void loadDefaultValues() {
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxHttpConnectionsPerHost, getDefaultMaxHttpConnectionsPerHost());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxTotalHttpConnections, getDefaultMaxTotalHttpConnections());
   putDefaultBooleanProperty(
       CommonClientConfigKey.EnableConnectionPool, getDefaultEnableConnectionPool());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxConnectionsPerHost, getDefaultMaxConnectionsPerHost());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxTotalConnections, getDefaultMaxTotalConnections());
   putDefaultIntegerProperty(CommonClientConfigKey.ConnectTimeout, getDefaultConnectTimeout());
   putDefaultIntegerProperty(
       CommonClientConfigKey.ConnectionManagerTimeout, getDefaultConnectionManagerTimeout());
   putDefaultIntegerProperty(CommonClientConfigKey.ReadTimeout, getDefaultReadTimeout());
   putDefaultIntegerProperty(CommonClientConfigKey.MaxAutoRetries, getDefaultMaxAutoRetries());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxAutoRetriesNextServer, getDefaultMaxAutoRetriesNextServer());
   putDefaultBooleanProperty(
       CommonClientConfigKey.OkToRetryOnAllOperations, getDefaultOkToRetryOnAllOperations());
   putDefaultBooleanProperty(CommonClientConfigKey.FollowRedirects, getDefaultFollowRedirects());
   putDefaultBooleanProperty(
       CommonClientConfigKey.ConnectionPoolCleanerTaskEnabled,
       getDefaultConnectionPoolCleanerTaskEnabled());
   putDefaultIntegerProperty(
       CommonClientConfigKey.ConnIdleEvictTimeMilliSeconds, getDefaultConnectionidleTimeInMsecs());
   putDefaultIntegerProperty(
       CommonClientConfigKey.ConnectionCleanerRepeatInterval,
       getDefaultConnectionIdleTimertaskRepeatInMsecs());
   putDefaultBooleanProperty(
       CommonClientConfigKey.EnableGZIPContentEncodingFilter,
       getDefaultEnableGzipContentEncodingFilter());
   String proxyHost =
       ConfigurationManager.getConfigInstance()
           .getString(getDefaultPropName(CommonClientConfigKey.ProxyHost.key()));
   if (proxyHost != null && proxyHost.length() > 0) {
     setProperty(CommonClientConfigKey.ProxyHost, proxyHost);
   }
   Integer proxyPort =
       ConfigurationManager.getConfigInstance()
           .getInteger(
               getDefaultPropName(CommonClientConfigKey.ProxyPort),
               (Integer.MIN_VALUE + 1)); // + 1 just to avoid potential clash with user setting
   if (proxyPort != (Integer.MIN_VALUE + 1)) {
     setProperty(CommonClientConfigKey.ProxyPort, proxyPort);
   }
   putDefaultIntegerProperty(CommonClientConfigKey.Port, getDefaultPort());
   putDefaultBooleanProperty(
       CommonClientConfigKey.EnablePrimeConnections, getDefaultEnablePrimeConnections());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxRetriesPerServerPrimeConnection,
       getDefaultMaxRetriesPerServerPrimeConnection());
   putDefaultIntegerProperty(
       CommonClientConfigKey.MaxTotalTimeToPrimeConnections,
       getDefaultMaxTotalTimeToPrimeConnections());
   putDefaultStringProperty(
       CommonClientConfigKey.PrimeConnectionsURI, getDefaultPrimeConnectionsUri());
   putDefaultIntegerProperty(CommonClientConfigKey.PoolMinThreads, getDefaultPoolMinThreads());
   putDefaultIntegerProperty(CommonClientConfigKey.PoolMaxThreads, getDefaultPoolMaxThreads());
   putDefaultLongProperty(CommonClientConfigKey.PoolKeepAliveTime, getDefaultPoolKeepAliveTime());
   putDefaultTimeUnitProperty(
       CommonClientConfigKey.PoolKeepAliveTimeUnits, getDefaultPoolKeepAliveTimeUnits());
   putDefaultBooleanProperty(
       CommonClientConfigKey.EnableZoneAffinity, getDefaultEnableZoneAffinity());
   putDefaultBooleanProperty(
       CommonClientConfigKey.EnableZoneExclusivity, getDefaultEnableZoneExclusivity());
   putDefaultStringProperty(CommonClientConfigKey.ClientClassName, getDefaultClientClassname());
   putDefaultStringProperty(
       CommonClientConfigKey.NFLoadBalancerClassName, getDefaultNfloadbalancerClassname());
   putDefaultStringProperty(
       CommonClientConfigKey.NFLoadBalancerRuleClassName, getDefaultNfloadbalancerRuleClassname());
   putDefaultStringProperty(
       CommonClientConfigKey.NFLoadBalancerPingClassName, getDefaultNfloadbalancerPingClassname());
   putDefaultBooleanProperty(
       CommonClientConfigKey.PrioritizeVipAddressBasedServers,
       getDefaultPrioritizeVipAddressBasedServers());
   putDefaultFloatProperty(
       CommonClientConfigKey.MinPrimeConnectionsRatio, getDefaultMinPrimeConnectionsRatio());
   putDefaultStringProperty(
       CommonClientConfigKey.PrimeConnectionsClassName, getDefaultPrimeConnectionsClass());
   putDefaultStringProperty(
       CommonClientConfigKey.NIWSServerListClassName, getDefaultSeverListClass());
   putDefaultStringProperty(
       CommonClientConfigKey.VipAddressResolverClassName, getDefaultVipaddressResolverClassname());
   putDefaultBooleanProperty(
       CommonClientConfigKey.IsClientAuthRequired, getDefaultIsClientAuthRequired());
   // putDefaultStringProperty(CommonClientConfigKey.RequestIdHeaderName,
   // getDefaultRequestIdHeaderName());
   putDefaultBooleanProperty(
       CommonClientConfigKey.UseIPAddrForServer, getDefaultUseIpAddressForServer());
   putDefaultStringProperty(CommonClientConfigKey.ListOfServers, "");
 }
  @Test
  public void testZoneAffinityOverride() throws Exception {
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest3.ribbon.DeploymentContextBasedVipAddresses",
            "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest3.ribbon.NFLoadBalancerClassName",
            DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance()
        .setProperty("DefaultNIWSServerListFilterTest3.ribbon.EnableZoneAffinity", "true");
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest3.ribbon.NIWSServerListClassName",
            DiscoveryEnabledNIWSServerList.class.getName());
    ConfigurationManager.getConfigInstance()
        .setProperty(
            "DefaultNIWSServerListFilterTest3.ribbon.zoneAffinity.minAvailableServers", "3");
    DynamicServerListLoadBalancer lb =
        (DynamicServerListLoadBalancer)
            ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest3");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    /*
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c")); */
    // less than 3 servers in zone c, will not honor zone affinity
    assertEquals(servers, filtered);
    lb.setServersList(filtered);
    servers.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    // now we have enough servers in C
    assertEquals(expected, filtered);

    // make one server black out
    for (int i = 1; i <= 3; i++) {
      loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);
    // new server added in zone c, zone c should now have enough servers
    servers.add(createServer(4, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(4, "c"));
    assertEquals(expected, filtered);
  }
 public static void addApplicationContext(ConfigurableApplicationContext context) {
   AbstractConfiguration config = ConfigurationManager.getConfigInstance();
   config.clearProperty(APPLICATION_CONTEXT);
   config.setProperty(APPLICATION_CONTEXT, context);
 }
Exemplo n.º 26
0
 protected void putDefaultFloatProperty(IClientConfigKey propName, Float defaultValue) {
   Float value =
       ConfigurationManager.getConfigInstance()
           .getFloat(getDefaultPropName(propName), defaultValue);
   setPropertyInternal(propName, value);
 }