Java Code Examples for com.netflix.config.DynamicPropertyFactory#getInstance()

The following examples show how to use com.netflix.config.DynamicPropertyFactory#getInstance() . 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: TestRegistry.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegistryUtilGetHostName(@Mocked InetAddress ethAddress) {
  new Expectations(NetUtils.class) {
    {
      NetUtils.getHostName();
      result = "testHostName";
    }
  };
  String host = RegistrationManager.getPublishHostName();
  Assert.assertEquals("testHostName", host);

  inMemoryConfig.addProperty(RegistrationManager.PUBLISH_ADDRESS, "127.0.0.1");
  Assert.assertEquals("127.0.0.1", RegistrationManager.getPublishHostName());

  new Expectations(DynamicPropertyFactory.getInstance()) {
    {
      ethAddress.getHostName();
      result = "testHostName";
      NetUtils.ensureGetInterfaceAddress("eth100");
      result = ethAddress;
    }
  };
  inMemoryConfig.addProperty(RegistrationManager.PUBLISH_ADDRESS, "{eth100}");
  Assert.assertEquals("testHostName", RegistrationManager.getPublishHostName());
}
 
Example 2
Source File: RouterDistributorTest.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  TestDistributer TestDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          TestDistributer);
}
 
Example 3
Source File: ArchaiusUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void setProperty(String key, Object value) {
  // ensure have instance
  DynamicPropertyFactory.getInstance();

  ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
      .getBackingConfigurationSource();
  if (value != null) {
    config.getConfiguration(0).setProperty(key, value);
    return;
  }

  config.getConfiguration(0).clearProperty(key);
}
 
Example 4
Source File: PriorityPropertyManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public PriorityPropertyManager() {
  // make sure create a DynamicPropertyFactory instance
  // otherwise will cause wrong order of configurationListeners
  DynamicPropertyFactory.getInstance();

  ConfigurationManager.getConfigInstance().addConfigurationListener(configurationListener);
}
 
Example 5
Source File: RouterDistributorTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  RouterDistributor<ServiceIns, ServiceIns> testDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          testDistributer);
}
 
Example 6
Source File: TestServletConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetServletUrlPattern() {
  DynamicPropertyFactory.getInstance();
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, "/*");
  Assert.assertEquals("/*", ServletConfig.getServletUrlPattern());
}
 
Example 7
Source File: DynamicPropertiesImpl.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private DynamicPropertyFactory propertyFactoryInstance() {
  return DynamicPropertyFactory.getInstance();
}