public static void clearDiscoveryClientConfig() { ConfigurationManager.getConfigInstance().clearProperty("eureka.client.refresh.interval"); ConfigurationManager.getConfigInstance().clearProperty("eureka.registration.enabled"); ConfigurationManager.getConfigInstance().clearProperty("eureka.fetchRemoteRegionsRegistry"); ConfigurationManager.getConfigInstance().clearProperty("eureka.myregion.availabilityZones"); ConfigurationManager.getConfigInstance().clearProperty("eureka.serviceUrl.default"); }
@Override protected void after() { if (client != null) { client.shutdown(); } for (DiscoveryClientResource resource : forkedDiscoveryClientResources) { resource.after(); } for (String property : SYSTEM_PROPERTY_TRACKER) { ConfigurationManager.getConfigInstance().clearProperty(property); } clearDiscoveryClientConfig(); }
@After public void tearDown() throws Exception { for (Pair<String, String> registeredApp : registeredApps) { System.out.println("Canceling application: " + registeredApp.first() + " from local registry."); registry.cancel(registeredApp.first(), registeredApp.second(), false); } serverContext.shutdown(); mockRemoteEurekaServer.stop(); remoteRegionApps.clear(); remoteRegionAppsDelta.clear(); ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegionUrls"); ConfigurationManager.getConfigInstance().clearProperty("eureka.deltaRetentionTimerIntervalInMs"); }
@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"); } }
@Test public void testString() throws Exception { DynamicStringProperty pString = new DynamicStringProperty("defaultString", "default-default"); HystrixPropertiesChainedArchaiusProperty.StringProperty fString = new HystrixPropertiesChainedArchaiusProperty.StringProperty("overrideString", pString); assertTrue("default-default".equals(fString.get())); ConfigurationManager.getConfigInstance().setProperty("defaultString", "default"); assertTrue("default".equals(fString.get())); ConfigurationManager.getConfigInstance().setProperty("overrideString", "override"); assertTrue("override".equals(fString.get())); ConfigurationManager.getConfigInstance().clearProperty("overrideString"); assertTrue("default".equals(fString.get())); ConfigurationManager.getConfigInstance().clearProperty("defaultString"); assertTrue("default-default".equals(fString.get())); }
@Test public void testIntegerInstanceDynamicOverrideOfEverything() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter().withMetricsRollingStatisticalWindowInMilliseconds(5000), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.metrics.rollingStats.timeInMilliseconds", 1234); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.TEST.metrics.rollingStats.timeInMilliseconds", 3456); // the instance specific dynamic property should take precedence over everything assertEquals(3456, properties.metricsRollingStatisticalWindowInMilliseconds().get().intValue()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.metrics.rollingStats.timeInMilliseconds"); ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.TEST.metrics.rollingStats.timeInMilliseconds"); }
@Test public void testAddCallback() throws Exception { final DynamicStringProperty node1 = new DynamicStringProperty("n1", "n1"); final HystrixPropertiesChainedArchaiusProperty.StringProperty node2 = new HystrixPropertiesChainedArchaiusProperty.StringProperty("n2", node1); final AtomicInteger callbackCount = new AtomicInteger(0); node2.addCallback(new Runnable() { @Override public void run() { callbackCount.incrementAndGet(); } }); assertTrue(0 == callbackCount.get()); assertTrue("n1".equals(node2.get())); assertTrue(0 == callbackCount.get()); ConfigurationManager.getConfigInstance().setProperty("n1", "n11"); assertTrue("n11".equals(node2.get())); assertTrue(0 == callbackCount.get()); ConfigurationManager.getConfigInstance().setProperty("n2", "n22"); assertTrue("n22".equals(node2.get())); assertTrue(1 == callbackCount.get()); ConfigurationManager.getConfigInstance().clearProperty("n1"); assertTrue("n22".equals(node2.get())); assertTrue(1 == callbackCount.get()); ConfigurationManager.getConfigInstance().setProperty("n2", "n222"); assertTrue("n222".equals(node2.get())); assertTrue(2 == callbackCount.get()); ConfigurationManager.getConfigInstance().clearProperty("n2"); assertTrue("n1".equals(node2.get())); assertTrue(3 == callbackCount.get()); }
@Test public void testBooleanInstanceDynamicOverrideOfEverything() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter().withCircuitBreakerForceClosed(false), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed", false); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.TEST.circuitBreaker.forceClosed", true); // the instance specific dynamic property should take precedence over everything assertEquals(true, properties.circuitBreakerForceClosed().get()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed"); ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.TEST.circuitBreaker.forceClosed"); }
@Test public void testChainingString() throws Exception { DynamicStringProperty node1 = new DynamicStringProperty("node1", "v1"); StringProperty node2 = new HystrixPropertiesChainedArchaiusProperty.StringProperty("node2", node1); HystrixPropertiesChainedArchaiusProperty.StringProperty node3 = new HystrixPropertiesChainedArchaiusProperty.StringProperty("node3", node2); assertTrue("" + node3.get(), "v1".equals(node3.get())); ConfigurationManager.getConfigInstance().setProperty("node1", "v11"); assertTrue("v11".equals(node3.get())); ConfigurationManager.getConfigInstance().setProperty("node2", "v22"); assertTrue("v22".equals(node3.get())); ConfigurationManager.getConfigInstance().clearProperty("node1"); assertTrue("v22".equals(node3.get())); ConfigurationManager.getConfigInstance().setProperty("node3", "v33"); assertTrue("v33".equals(node3.get())); ConfigurationManager.getConfigInstance().clearProperty("node2"); assertTrue("v33".equals(node3.get())); ConfigurationManager.getConfigInstance().setProperty("node2", "v222"); assertTrue("v33".equals(node3.get())); ConfigurationManager.getConfigInstance().clearProperty("node3"); assertTrue("v222".equals(node3.get())); ConfigurationManager.getConfigInstance().clearProperty("node2"); assertTrue("v1".equals(node3.get())); ConfigurationManager.getConfigInstance().setProperty("node2", "v2222"); assertTrue("v2222".equals(node3.get())); }
@Test public void testIntegerGlobalDynamicOverrideOfCodeDefault() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter(), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.metrics.rollingStats.timeInMilliseconds", 1234); // the global dynamic property should take precedence over the default assertEquals(1234, properties.metricsRollingStatisticalWindowInMilliseconds().get().intValue()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.metrics.rollingStats.timeInMilliseconds"); }
@Test public void testIntegerInstanceBuilderOverrideOfGlobalDynamicOverride() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter().withMetricsRollingStatisticalWindowInMilliseconds(5000), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.rollingStats.timeInMilliseconds", 3456); // the builder injected should take precedence over the global dynamic property assertEquals(5000, properties.metricsRollingStatisticalWindowInMilliseconds().get().intValue()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.rollingStats.timeInMilliseconds"); }
@Test public void testBoolean() throws Exception { DynamicBooleanProperty pBoolean = new DynamicBooleanProperty("defaultBoolean", true); HystrixPropertiesChainedArchaiusProperty.BooleanProperty fBoolean = new HystrixPropertiesChainedArchaiusProperty.BooleanProperty("overrideBoolean", pBoolean); System.out.println("pBoolean: " + pBoolean.get()); System.out.println("fBoolean: " + fBoolean.get()); assertTrue(fBoolean.get()); ConfigurationManager.getConfigInstance().setProperty("defaultBoolean", Boolean.FALSE); System.out.println("pBoolean: " + pBoolean.get()); System.out.println("fBoolean: " + fBoolean.get()); assertFalse(fBoolean.get()); ConfigurationManager.getConfigInstance().setProperty("overrideBoolean", Boolean.TRUE); assertTrue(fBoolean.get()); ConfigurationManager.getConfigInstance().clearProperty("overrideBoolean"); assertFalse(fBoolean.get()); ConfigurationManager.getConfigInstance().clearProperty("defaultBoolean"); assertTrue(fBoolean.get()); }
@Test public void testThreadPoolOnlyHasInstanceOverride() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter(), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.threadPoolKeyOverride", 1234); // it should be null assertEquals(null, properties.executionIsolationThreadPoolKeyOverride().get()); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.TEST.threadPoolKeyOverride", "testPool"); // now it should have a value assertEquals("testPool", properties.executionIsolationThreadPoolKeyOverride().get()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.threadPoolKeyOverride"); ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.TEST.threadPoolKeyOverride"); }
@Test public void testBooleanGlobalDynamicOverrideOfCodeDefault() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter(), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed", true); // the global dynamic property should take precedence over the default assertEquals(true, properties.circuitBreakerForceClosed().get()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed"); }
@Test public void testBooleanInstanceBuilderOverrideOfGlobalDynamicOverride1() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter().withCircuitBreakerForceClosed(true), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed", false); // the builder injected should take precedence over the global dynamic property assertEquals(true, properties.circuitBreakerForceClosed().get()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed"); }
@Test public void testInteger() throws Exception { DynamicIntegerProperty pInt = new DynamicIntegerProperty("defaultInt", -1); HystrixPropertiesChainedArchaiusProperty.IntegerProperty fInt = new HystrixPropertiesChainedArchaiusProperty.IntegerProperty("overrideInt", pInt); assertTrue(-1 == fInt.get()); ConfigurationManager.getConfigInstance().setProperty("defaultInt", 10); assertTrue(10 == fInt.get()); ConfigurationManager.getConfigInstance().setProperty("overrideInt", 11); assertTrue(11 == fInt.get()); ConfigurationManager.getConfigInstance().clearProperty("overrideInt"); assertTrue(10 == fInt.get()); ConfigurationManager.getConfigInstance().clearProperty("defaultInt"); assertTrue(-1 == fInt.get()); }
@Test public void testBooleanInstanceBuilderOverrideOfGlobalDynamicOverride2() throws Exception { HystrixCommandProperties properties = new TestPropertiesCommand(TestKey.TEST, new HystrixCommandProperties.Setter().withCircuitBreakerForceClosed(false), "unitTestPrefix"); ConfigurationManager.getConfigInstance().setProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed", true); // the builder injected should take precedence over the global dynamic property assertEquals(false, properties.circuitBreakerForceClosed().get()); // cleanup ConfigurationManager.getConfigInstance().clearProperty("unitTestPrefix.command.default.circuitBreaker.forceClosed"); }
@Test public void testChainingInteger() throws Exception { DynamicIntegerProperty node1 = new DynamicIntegerProperty("node1", 1); IntegerProperty node2 = new HystrixPropertiesChainedArchaiusProperty.IntegerProperty("node2", node1); HystrixPropertiesChainedArchaiusProperty.IntegerProperty node3 = new HystrixPropertiesChainedArchaiusProperty.IntegerProperty("node3", node2); assertTrue("" + node3.get(), 1 == node3.get()); ConfigurationManager.getConfigInstance().setProperty("node1", 11); assertTrue(11 == node3.get()); ConfigurationManager.getConfigInstance().setProperty("node2", 22); assertTrue(22 == node3.get()); ConfigurationManager.getConfigInstance().clearProperty("node1"); assertTrue(22 == node3.get()); ConfigurationManager.getConfigInstance().setProperty("node3", 33); assertTrue(33 == node3.get()); ConfigurationManager.getConfigInstance().clearProperty("node2"); assertTrue(33 == node3.get()); ConfigurationManager.getConfigInstance().setProperty("node2", 222); assertTrue(33 == node3.get()); ConfigurationManager.getConfigInstance().clearProperty("node3"); assertTrue(222 == node3.get()); ConfigurationManager.getConfigInstance().clearProperty("node2"); assertTrue(1 == node3.get()); ConfigurationManager.getConfigInstance().setProperty("node2", 2222); assertTrue(2222 == node3.get()); }
@Before public void setUp() throws Exception { ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion.global.appWhiteList"); ConfigurationManager.getConfigInstance().setProperty("eureka.responseCacheAutoExpirationInSeconds", "10"); ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion." + REMOTE_REGION_NAME + ".appWhiteList"); ConfigurationManager.getConfigInstance().setProperty("eureka.deltaRetentionTimerIntervalInMs", "600000"); ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegion.registryFetchIntervalInSeconds", "5");
public static void clearDiscoveryClientConfig() { ConfigurationManager.getConfigInstance().clearProperty("eureka.client.refresh.interval"); ConfigurationManager.getConfigInstance().clearProperty("eureka.registration.enabled"); ConfigurationManager.getConfigInstance().clearProperty("eureka.fetchRemoteRegionsRegistry"); ConfigurationManager.getConfigInstance().clearProperty("eureka.myregion.availabilityZones"); ConfigurationManager.getConfigInstance().clearProperty("eureka.serviceUrl.default"); }