/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * </p> */ @Override public Config getOwnConfig(ConfigKeyPath configKey) { return this.cs.getOwnConfig(configKey, this.version); }
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * if the internal {@link ConfigStore} is {@link ConfigStoreWithBatchFetches}, otherwise, will call * configuration store for each config key path and put the result into {@link Map} * </p> */ @Override public Map<ConfigKeyPath, Config> getOwnConfigs(Collection<ConfigKeyPath> configKeys) { if (this.cs instanceof ConfigStoreWithBatchFetches) { ConfigStoreWithBatchFetches batchStore = (ConfigStoreWithBatchFetches) this.cs; return batchStore.getOwnConfigs(configKeys, this.version); } Map<ConfigKeyPath, Config> result = new HashMap<>(); for (ConfigKeyPath configKey : configKeys) { result.put(configKey, this.cs.getOwnConfig(configKey, this.version)); } return result; }
@Test public void testSystemPropertyResolution() { ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); ConfigStoreTopologyInspector mockTopology = mock(ConfigStoreTopologyInspector.class, Mockito.RETURNS_SMART_NULLS); ConfigStoreBackedValueInspector valueInspector = new ConfigStoreBackedValueInspector(mockConfigStore, version, mockTopology); ConfigKeyPath testConfigKeyPath = SingleLinkedListConfigKeyPath.ROOT.createChild("a"); when(mockConfigStore.getOwnConfig(testConfigKeyPath.getParent(), version)).thenReturn(ConfigFactory.empty()); when(mockConfigStore.getOwnConfig(testConfigKeyPath, version)).thenReturn( ConfigFactory.parseString("configProp = ${?" + VALUE_INSPECTOR_SYS_PROP_KEY + "}")); Assert.assertEquals(valueInspector.getResolvedConfig(testConfigKeyPath).getString("configProp"), VALUE_INSPECTOR_SYS_PROP_VALUE); }
private void mockupConfigValueForKey(ConfigKeyPath configKey){ final String generalKey = "generalKey"; Map<String, String> valueMap = new HashMap<>(); // key in all the nodes valueMap.put(generalKey, "valueOf_" +generalKey +"_"+configKey.getOwnPathName() ); // key in self node valueMap.put("keyOf_" + configKey.getOwnPathName(), "valueOf_" + configKey.getOwnPathName()); when(mockConfigStore.getOwnConfig(configKey, version)).thenReturn(ConfigFactory.parseMap(valueMap)); }
@Test public void testResolveConfigOverridingInChild() { ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); ConfigStoreTopologyInspector mockTopology = mock(ConfigStoreTopologyInspector.class, Mockito.RETURNS_SMART_NULLS); ConfigStoreBackedValueInspector valueInspector = new ConfigStoreBackedValueInspector(mockConfigStore, version, mockTopology); ConfigKeyPath keyPathA = SingleLinkedListConfigKeyPath.ROOT.createChild("a"); ConfigKeyPath keyPathA_Slash_B = keyPathA.createChild("b"); when(mockConfigStore.getOwnConfig(keyPathA.getParent(), version)).thenReturn(ConfigFactory.empty()); when(mockConfigStore.getOwnConfig(keyPathA, version)).thenReturn( ConfigFactory.parseString("key1 = value1InA \n key2 = ${key1}")); when(mockConfigStore.getOwnConfig(keyPathA_Slash_B, version)).thenReturn( ConfigFactory.parseString("key1 = value1InB")); Assert.assertEquals(valueInspector.getResolvedConfig(keyPathA_Slash_B).getString("key2"), "value1InB"); } }
private void mockupConfigValues(){ // mock up the configuration values for root Map<String, String> rootMap = new HashMap<>(); rootMap.put("keyInRoot", "valueInRoot"); when(mockConfigStore.getOwnConfig(SingleLinkedListConfigKeyPath.ROOT, version)).thenReturn(ConfigFactory.parseMap(rootMap)); Collection<ConfigKeyPath> currentLevel = mockConfigStore.getChildren(SingleLinkedListConfigKeyPath.ROOT, version); while(!currentLevel.isEmpty()){ Collection<ConfigKeyPath> nextLevel = new ArrayList<ConfigKeyPath>(); for(ConfigKeyPath p: currentLevel){ mockupConfigValueForKey(p); nextLevel.addAll(mockConfigStore.getChildren(p, version)); } currentLevel = nextLevel; } }
rootMap.put("keyOf_Root", "valueOf_Root"); rootMap.put("generalKey", "generalValue_root"); // keys will be overwrite when(mockConfigStore.getOwnConfig(SingleLinkedListConfigKeyPath.ROOT, version)).thenReturn(ConfigFactory.parseMap(rootMap)); dataMap.put("keyOf_data", "valueOf_data"); dataMap.put("generalKey", "generalValue_data"); when(mockConfigStore.getOwnConfig(data, version)).thenReturn(ConfigFactory.parseMap(dataMap)); databasesMap.put("keyOf_databases", "valueOf_databases"); databasesMap.put("generalKey", "generalValue_data_databases"); when(mockConfigStore.getOwnConfig(databases, version)).thenReturn(ConfigFactory.parseMap(databasesMap)); identityMap.put("keyOf_identity", "valueOf_identity"); identityMap.put("generalKey", "generalValue_data_databases_identity"); when(mockConfigStore.getOwnConfig(identity, version)).thenReturn(ConfigFactory.parseMap(identityMap)); tagMap.put("keyOf_tag", "valueOf_tag"); tagMap.put("generalKey", "generalValue_tag"); when(mockConfigStore.getOwnConfig(tag, version)).thenReturn(ConfigFactory.parseMap(tagMap)); espressoTagMap.put("keyOf_espressoTag", "valueOf_espressoTag"); espressoTagMap.put("generalKey", "generalValue_tag_espressoTag"); when(mockConfigStore.getOwnConfig(espressoTag, version)).thenReturn(ConfigFactory.parseMap(espressoTagMap)); highPriorityTagMap.put("keyOf_highPriorityTag", "valueOf_highPriorityTag"); highPriorityTagMap.put("generalKey", "generalValue_tag_highPriorityTag"); when(mockConfigStore.getOwnConfig(highPriorityTag, version)).thenReturn(ConfigFactory.parseMap(highPriorityTagMap)); tag2Map.put("keyOf_tag2", "valueOf_tag2");
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * </p> */ @Override public Config getOwnConfig(ConfigKeyPath configKey) { return this.cs.getOwnConfig(configKey, this.version); }
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * if the internal {@link ConfigStore} is {@link ConfigStoreWithBatchFetches}, otherwise, will call * configuration store for each config key path and put the result into {@link Map} * </p> */ @Override public Map<ConfigKeyPath, Config> getOwnConfigs(Collection<ConfigKeyPath> configKeys) { if (this.cs instanceof ConfigStoreWithBatchFetches) { ConfigStoreWithBatchFetches batchStore = (ConfigStoreWithBatchFetches) this.cs; return batchStore.getOwnConfigs(configKeys, this.version); } Map<ConfigKeyPath, Config> result = new HashMap<>(); for (ConfigKeyPath configKey : configKeys) { result.put(configKey, this.cs.getOwnConfig(configKey, this.version)); } return result; }