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; } }
@BeforeClass public void setup() throws Exception{ mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); URI configStorURI = new URI("etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest"); when(mockConfigStore.getCurrentVersion()).thenReturn(version); when(mockConfigStore.getStoreURI()).thenReturn(configStorURI); }
public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (runtimeConfig.isPresent()) { return this.cs.getOwnImports(configKey, this.version, runtimeConfig); } return this.cs.getOwnImports(configKey, this.version); }
when(mockConfigStore.getCurrentVersion()).thenReturn(version); rootChildren.add(tag); rootChildren.add(tag2); when(mockConfigStore.getChildren(SingleLinkedListConfigKeyPath.ROOT, version)).thenReturn(rootChildren); when(mockConfigStore.getChildren(data, version)).thenReturn(dataChildren); when(mockConfigStore.getChildren(databases, version)).thenReturn(databasesChildren); when(mockConfigStore.getChildren(identity, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(tag, version)).thenReturn(tagChildren); when(mockConfigStore.getChildren(highPriorityTag, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(espressoTag, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(tag2, version)).thenReturn(tag2Children); when(mockConfigStore.getChildren(nertzTag2, version)).thenReturn(emptyList); identityImports.add(espressoTag); identityImports.add(highPriorityTag); when(mockConfigStore.getOwnImports(identity, version)).thenReturn(identityImports); when(mockConfigStore.getOwnImports(espressoTag, version)).thenReturn(espressoImports);
@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); }
@Test public void testNonRootTopology() { Assert.assertEquals(mockConfigStore.getCurrentVersion(), version); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(this.mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology);
/** * {@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); }
private static void checkMatchingSchemeAndAuthority(URI configKeyURI, ConfigStore cs) { Preconditions.checkNotNull(configKeyURI, "input can not be null"); Preconditions.checkNotNull(cs, "input can not be null"); Preconditions.checkArgument(configKeyURI.getScheme().equals(cs.getStoreURI().getScheme()), "Scheme name not match"); boolean authorityCheck = configKeyURI.getAuthority() == null || configKeyURI.getAuthority().equals(cs.getStoreURI().getAuthority()); Preconditions.checkArgument(authorityCheck, "Authority not match"); }
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * </p> */ @Override public Collection<ConfigKeyPath> getChildren(ConfigKeyPath configKey) { return this.cs.getChildren(configKey, this.version); }
when(mockConfigStore.getCurrentVersion()).thenReturn(version); rootChildren.add(tag); rootChildren.add(tag2); when(mockConfigStore.getChildren(SingleLinkedListConfigKeyPath.ROOT, version)).thenReturn(rootChildren); when(mockConfigStore.getChildren(data, version)).thenReturn(dataChildren); when(mockConfigStore.getChildren(databases, version)).thenReturn(databasesChildren); when(mockConfigStore.getChildren(identity, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(tag, version)).thenReturn(tagChildren); when(mockConfigStore.getChildren(highPriorityTag, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(espressoTag, version)).thenReturn(emptyList); when(mockConfigStore.getChildren(tag2, version)).thenReturn(tag2Children); when(mockConfigStore.getChildren(nertzTag2, version)).thenReturn(emptyList); identityImports.add(espressoTag); identityImports.add(highPriorityTag); when(mockConfigStore.getOwnImports(identity, version)).thenReturn(identityImports); when(mockConfigStore.getOwnImports(espressoTag, version)).thenReturn(espressoImports);
@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"); } }
@Test public void testSelfImportSelf() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag); // self import self addConfigStoreImports(mockConfigStore, version, tag, tag); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(tag); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag") > 0); } }
/** * {@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; }
/** * * @param configKeyURI - URI provided by client , which could missing authority/store root directory * @param cs - ConfigStore corresponding to the input URI. Require input URI's scheme/authority name * match ConfigStore's scheme/authority * @return - {@link ConfigKeyPath} for the relative path */ public static ConfigKeyPath buildConfigKeyPath(URI configKeyURI, ConfigStore cs) { checkMatchingSchemeAndAuthority(configKeyURI, cs); // Example store root is etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest URI relative = cs.getStoreURI().relativize(configKeyURI); return getConfigKeyPath(relative.getPath()); }
public static void addConfigStoreChildren(ConfigStore mockup, String version, ConfigKeyPath parent, ConfigKeyPath... configKeyPaths) { List<ConfigKeyPath> children = new ArrayList<ConfigKeyPath>(); for (ConfigKeyPath p : configKeyPaths) { children.add(p); } when(mockup.getChildren(parent, version)).thenReturn(children); }
if (this.policy == VersionStabilityPolicy.CROSS_JVM_STABILITY) { throw new RuntimeException(String.format("with policy set to %s, can not connect to unstable config store %s", VersionStabilityPolicy.CROSS_JVM_STABILITY, cs.getStoreURI())); String currentVersion = cs.getCurrentVersion(); LOG.info("Current config store version number: " + currentVersion);
when(mockConfigStore.getCurrentVersion()).thenReturn(version);
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)); }
private ConfigStoreAccessor getConfigStoreAccessor(URI configKeyURI) throws ConfigStoreFactoryDoesNotExistsException, ConfigStoreCreationException, VersionDoesNotExistException { URI matchedFloorKey = getMatchedFloorKeyFromCache(configKeyURI); ConfigStoreAccessor result; if (matchedFloorKey != null) { result = this.configStoreAccessorMap.get(matchedFloorKey); return result; } result = createNewConfigStoreAccessor(configKeyURI); ConfigStore cs = result.configStore; // put default root URI in cache as well for the URI which missing authority if (configKeyURI.getAuthority() == null) { // configKeyURI is missing authority/configstore root "etl-hdfs:///datasets/a1/a2" try { this.configStoreAccessorMap.put(new URI(configKeyURI.getScheme(), null, "/", null, null), result); } catch (URISyntaxException e) { // should not come here throw new RuntimeException("Can not build URI based on " + configKeyURI); } } else { // need to check Config Store's root is the prefix of input configKeyURI if (!ConfigClientUtils.isAncestorOrSame(configKeyURI, cs.getStoreURI())) { throw new RuntimeException( String.format("Config Store root URI %s is not the prefix of input %s", cs.getStoreURI(), configKeyURI)); } } // put to cache this.configStoreAccessorMap.put(cs.getStoreURI(), result); return result; }
public static void addConfigStoreImports(ConfigStore mockup, String version, ConfigKeyPath self, ConfigKeyPath... configKeyPaths) { List<ConfigKeyPath> ownImports = new ArrayList<ConfigKeyPath>(); for (ConfigKeyPath p : configKeyPaths) { ownImports.add(p); } when(mockup.getOwnImports(self, version)).thenReturn(ownImports); }