BizDBPropertySource extends RefreshablePropertySource { @Override protected void refresh() { Iterable<ServerConfig> dbConfigs = serverConfigRepository.findAll(); Map<String, Object> newConfigs = Maps.newHashMap(); for (ServerConfig config : dbConfigs) { if (Objects.equals(ConfigConsts.CLUSTER_NAME_DEFAULT, config.getCluster())) { newConfigs.put(config.getKey(), config.getValue()); } } String dataCenter = getCurrentDataCenter(); for (ServerConfig config : dbConfigs) { if (Objects.equals(dataCenter, config.getCluster())) { newConfigs.put(config.getKey(), config.getValue()); } } if (!Strings.isNullOrEmpty(System.getProperty(ConfigConsts.APOLLO_CLUSTER_KEY))) { String cluster = System.getProperty(ConfigConsts.APOLLO_CLUSTER_KEY); for (ServerConfig config : dbConfigs) { if (Objects.equals(cluster, config.getCluster())) { newConfigs.put(config.getKey(), config.getValue()); } } } for (Map.Entry<String, Object> config: newConfigs.entrySet()){ String key = config.getKey(); Object value = config.getValue(); if (this.source.get(key) == null) { logger.info("Load config from DB : {} = {}", key, value); } else if (!Objects.equals(this.source.get(key), value)) { logger.info("Load config from DB : {} = {}. Old value = {}", key, value, this.source.get(key)); } this.source.put(key, value); } } BizDBPropertySource(String name, Map<String, Object> source);  BizDBPropertySource();   }
@Test public void testGetClusterConfig() { propertySource.refresh(); assertEquals(propertySource.getProperty(clusterConfigKey), clusterConfigValue); }
@Test public void testGetDcConfig() { propertySource.refresh(); assertEquals(propertySource.getProperty(dcConfigKey), dcConfigValue); }
@Test public void testGetDefaultConfig() { propertySource.refresh(); assertEquals(propertySource.getProperty(defaultKey), defaultValue); }
@Test public void testGetNull() { propertySource.refresh(); assertNull(propertySource.getProperty("noKey")); }