Java Code Examples for com.netflix.client.config.DefaultClientConfigImpl#loadProperties()
The following examples show how to use
com.netflix.client.config.DefaultClientConfigImpl#loadProperties() .
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: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testDefaultHonorsVipPortDefinition() throws Exception{ ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.DeploymentContextBasedVipAddresses", "dummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.IsSecure", "false"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.Port", "6999"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance(); clientConfig.loadProperties("DiscoveryEnabled.testDefaultHonorsVipPortDefinition"); deList.initWithNiwsConfig(clientConfig); List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers(); Assert.assertEquals(1, serverList.size()); Assert.assertEquals(8001, serverList.get(0).getPort()); // vip indicated Assert.assertEquals(8001, serverList.get(0).getInstanceInfo().getPort()); // vip indicated Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort()); // 7002 is the secure default }
Example 2
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testDefaultHonorsVipSecurePortDefinition() throws Exception{ ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.DeploymentContextBasedVipAddresses", "secureDummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.IsSecure", "true"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.SecurePort", "6002"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance(); clientConfig.loadProperties("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition"); deList.initWithNiwsConfig(clientConfig); List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers(); Assert.assertEquals(1, serverList.size()); Assert.assertEquals(8002, serverList.get(0).getPort()); // vip indicated Assert.assertEquals(8002, serverList.get(0).getInstanceInfo().getPort()); // vip indicated Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort()); // 7002 is the secure default }
Example 3
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testVipPortCanBeOverriden() throws Exception{ ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.DeploymentContextBasedVipAddresses", "dummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.IsSecure", "false"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.Port", "6001"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration", "true"); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance(); clientConfig.loadProperties("DiscoveryEnabled.testVipPortCanBeOverriden"); deList.initWithNiwsConfig(clientConfig); List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers(); Assert.assertEquals(1, serverList.size()); Assert.assertEquals(6001, serverList.get(0).getPort()); // client property indicated Assert.assertEquals(6001, serverList.get(0).getInstanceInfo().getPort()); // client property indicated Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort()); // 7002 is the secure default }
Example 4
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testSecureVipPortCanBeOverriden() throws Exception{ ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.DeploymentContextBasedVipAddresses", "secureDummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.IsSecure", "true"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.SecurePort", "6002"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration", "true"); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance(); clientConfig.loadProperties("DiscoveryEnabled.testSecureVipPortCanBeOverriden"); deList.initWithNiwsConfig(clientConfig); List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers(); Assert.assertEquals(1, serverList.size()); Assert.assertEquals(8002, serverList.get(0).getPort()); // vip indicated Assert.assertEquals(8002, serverList.get(0).getInstanceInfo().getPort()); // vip indicated Assert.assertEquals(6002, serverList.get(0).getInstanceInfo().getSecurePort()); // client property indicated }
Example 5
Source File: RibbonConfiguration.java From haven-platform with Apache License 2.0 | 5 votes |
/** * Loads properties with prefix: DM-GATEWAY-WEB.ribbon * @return */ @Bean public IClientConfig ribbonClientConfig() { DefaultClientConfigImpl config = new DefaultClientConfigImpl(); config.loadProperties(SERVICEID); return config; }
Example 6
Source File: DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest.java From ribbon with Apache License 2.0 | 5 votes |
/** * Generic method to help with various tests * @param globalspecified if false, will clear property DiscoveryEnabledNIWSServerList.useIpAddr * @param global value of DiscoveryEnabledNIWSServerList.useIpAddr * @param clientspecified if false, will not set property on client config * @param client value of client.namespace.ribbon.UseIPAddrForServer */ private List<Server> testUsesIpAddr(boolean globalSpecified, boolean global, boolean clientSpecified, boolean client) throws Exception{ if (globalSpecified) { ConfigurationManager.getConfigInstance().setProperty("ribbon.UseIPAddrForServer", global); } else { ConfigurationManager.getConfigInstance().clearProperty("ribbon.UseIPAddrForServer"); } if (clientSpecified) { ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer", client); } else { ConfigurationManager.getConfigInstance().clearProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer"); } System.out.println("r = " + ConfigurationManager.getConfigInstance().getProperty("ribbon.UseIPAddrForServer")); System.out.println("d = " + ConfigurationManager.getConfigInstance().getProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer")); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.DeploymentContextBasedVipAddresses", "dummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.TargetRegion", "region"); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList("TESTVIP:8080"); DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance(); clientConfig.loadProperties("DiscoveryEnabled.testUsesIpAddr"); deList.initWithNiwsConfig(clientConfig); List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers(); Assert.assertEquals(2, serverList.size()); List<Server> servers = new ArrayList<Server>(); for (DiscoveryEnabledServer server : serverList) { servers.add((Server)server); } return servers; }
Example 7
Source File: DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java From ribbon with Apache License 2.0 | 4 votes |
/** * Tests case where two different clients want to use the same instance, one with overriden ports and one without * * @throws Exception for anything unexpected */ @Test public void testTwoInstancesDontStepOnEachOther() throws Exception{ // setup override client ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.DeploymentContextBasedVipAddresses", "dummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.IsSecure", "false"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.Port", "6001"); // override from 8001 ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.ForceClientPortConfiguration", "true"); // setup non override client ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.DeploymentContextBasedVipAddresses", "dummy"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.IsSecure", "false"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.Port", "6001"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.ForceClientPortConfiguration", "false"); // check override client DiscoveryEnabledNIWSServerList deList1 = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig1 = DefaultClientConfigImpl.class.newInstance(); clientConfig1.loadProperties("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1"); deList1.initWithNiwsConfig(clientConfig1); List<DiscoveryEnabledServer> serverList1 = deList1.getInitialListOfServers(); Assert.assertEquals(1, serverList1.size()); Assert.assertEquals(6001, serverList1.get(0).getPort()); // client property overridden Assert.assertEquals(6001, serverList1.get(0).getInstanceInfo().getPort()); // client property overridden Assert.assertEquals(7002, serverList1.get(0).getInstanceInfo().getSecurePort()); // 7002 is the secure default // check non-override client DiscoveryEnabledNIWSServerList deList2 = new DiscoveryEnabledNIWSServerList(); DefaultClientConfigImpl clientConfig2 = DefaultClientConfigImpl.class.newInstance(); clientConfig2.loadProperties("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2"); deList2.initWithNiwsConfig(clientConfig2); List<DiscoveryEnabledServer> serverList2 = deList2.getInitialListOfServers(); Assert.assertEquals(1, serverList2.size()); Assert.assertEquals(8001, serverList2.get(0).getPort()); // client property indicated in ii Assert.assertEquals(8001, serverList2.get(0).getInstanceInfo().getPort()); // client property indicated in ii Assert.assertEquals(7002, serverList2.get(0).getInstanceInfo().getSecurePort()); // 7002 is the secure default }
Example 8
Source File: SubsetFilterTest.java From ribbon with Apache License 2.0 | 4 votes |
@Test public void testFiltering() { DefaultClientConfigImpl config = new DefaultClientConfigImpl(); config.loadProperties("SubsetFilerTest"); ServerListSubsetFilter<Server> filter = new ServerListSubsetFilter<Server>(config); LoadBalancerStats stats = new LoadBalancerStats("default"); stats.initWithNiwsConfig(config); filter.setLoadBalancerStats(stats); Object[][] serverStats = { {"server0", 0, 0}, {"server1", 0, 0}, {"server2", 0, 0}, {"server3", 0, 0}, {"server4", 0, 0}, {"server5", 0, 0}, {"server6", 0, 0}, {"server7", 0, 0}, {"server8", 0, 0}, {"server9", 0, 0} }; List<Server> list = getServersAndStats(stats, serverStats); List<Server> filtered = filter.getFilteredListOfServers(list); // first filtering, should get 5 servers assertEquals(filtered.size(), 5); Server s1 = filtered.get(0); Server s2 = filtered.get(1); Server s3 = filtered.get(2); Server s4 = filtered.get(3); Server s5 = filtered.get(4); // failure count > threshold DummyServerStats stats1 = (DummyServerStats) stats.getSingleServerStat(s1); stats1.setConnectionFailureCount(3); // active requests count > threshold DummyServerStats stats2 = (DummyServerStats) stats.getSingleServerStat(s2); stats2.setActiveRequestsCount(3); // will be forced eliminated after sorting DummyServerStats stats3 = (DummyServerStats) stats.getSingleServerStat(s3); stats3.setActiveRequestsCount(2); // will be forced eliminated after sorting DummyServerStats stats4 = (DummyServerStats) stats.getSingleServerStat(s4); stats4.setConnectionFailureCount(1); // filter again, this time some servers will be eliminated filtered = filter.getFilteredListOfServers(list); assertEquals(5, filtered.size()); assertTrue(!filtered.contains(s1)); assertTrue(!filtered.contains(s2)); assertTrue(filtered.contains(s3)); assertTrue(!filtered.contains(s4)); assertTrue(filtered.contains(s5)); // Not enough healthy servers, just get whatever is available List<Server> lastFiltered = filter.getFilteredListOfServers(Lists.newArrayList(filtered)); assertEquals(5, lastFiltered.size()); }
Example 9
Source File: ZoneAwareLoadBalancerTest.java From ribbon with Apache License 2.0 | 4 votes |
@Test public void testChooseZone() throws Exception { ConfigurationManager.getConfigInstance().setProperty("niws.loadbalancer.serverStats.activeRequestsCount.effectiveWindowSeconds", 10); DefaultClientConfigImpl config = new DefaultClientConfigImpl(); config.loadProperties("testChooseZone"); ZoneAwareLoadBalancer<Server> balancer = new ZoneAwareLoadBalancer<Server>(); balancer.init(); IRule globalRule = new RoundRobinRule(); balancer.setRule(globalRule); LoadBalancerStats loadBalancerStats = balancer.getLoadBalancerStats(); loadBalancerStats.initWithNiwsConfig(config); assertNotNull(loadBalancerStats); List<Server> servers = new ArrayList<Server>(); 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")); balancer.setServersList(servers); balancer.setUpServerList(servers); assertTrue(balancer.getLoadBalancer("us-east-1a").getRule() instanceof RoundRobinRule); assertNotSame(globalRule, balancer.getLoadBalancer("us-east-1a").getRule()); // System.out.println("=== LB Stats at testChooseZone 1: " + loadBalancerStats); testChooseServer(balancer, "us-east-1a", "us-east-1b", "us-east-1c"); loadBalancerStats.incrementActiveRequestsCount(createServer(1, "c")); loadBalancerStats.incrementActiveRequestsCount(createServer(3, "c")); loadBalancerStats.incrementActiveRequestsCount(createServer(3, "c")); loadBalancerStats.decrementActiveRequestsCount(createServer(3, "c")); assertEquals(2, loadBalancerStats.getActiveRequestsCount("us-east-1c")); assertEquals(0.5d, loadBalancerStats.getActiveRequestsPerServer("us-east-1c"), 0.0001d); testChooseServer(balancer, "us-east-1a", "us-east-1b"); for (int i = 0; i < 3; i++) { loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "a")); } assertEquals(1, loadBalancerStats.getCircuitBreakerTrippedCount("us-east-1a")); loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(2, "b")); assertEquals(0, loadBalancerStats.getCircuitBreakerTrippedCount("us-east-1b")); // loadPerServer on both zone a and b should still be 0 testChooseServer(balancer, "us-east-1a", "us-east-1b"); // make a load on zone a loadBalancerStats.incrementActiveRequestsCount(createServer(2, "a")); assertEquals(1d/3, loadBalancerStats.getActiveRequestsPerServer("us-east-1a"), 0.0001); // zone c will be dropped as the worst zone testChooseServer(balancer, "us-east-1b", "us-east-1a"); Thread.sleep(15000); assertEquals(0, loadBalancerStats.getCircuitBreakerTrippedCount("us-east-1a")); assertEquals(3, loadBalancerStats.getSingleServerStat(createServer(1, "a")).getSuccessiveConnectionFailureCount()); assertEquals(0, loadBalancerStats.getActiveRequestsCount("us-east-1c")); assertEquals(0, loadBalancerStats.getSingleServerStat(createServer(1, "c")).getActiveRequestsCount()); loadBalancerStats.clearSuccessiveConnectionFailureCount(createServer(1, "a")); assertEquals(0, loadBalancerStats.getSingleServerStat(createServer(1, "a")).getSuccessiveConnectionFailureCount()); assertEquals(0, loadBalancerStats.getCircuitBreakerTrippedCount("us-east-1a")); loadBalancerStats.decrementActiveRequestsCount(createServer(2, "a")); assertEquals(0, loadBalancerStats.getActiveRequestsPerServer("us-east-1b"), 0.000001); assertEquals(0, loadBalancerStats.getActiveRequestsPerServer("us-east-1c"), 0.000001); assertEquals(0, loadBalancerStats.getActiveRequestsPerServer("us-east-1a"), 0.000001); testChooseServer(balancer, "us-east-1a", "us-east-1b", "us-east-1c"); List<Server> emptyList = Collections.emptyList(); Map<String, List<Server>> map = new HashMap<String, List<Server>>(); map.put("us-east-1a", emptyList); map.put("us-east-1b", emptyList); balancer.setServerListForZones(map); testChooseServer(balancer, "us-east-1a", "us-east-1b", "us-east-1c"); }