DataDirsConfigImpl implements DataDirsConfig, ManageableServerComponent, StateDumpable { Path getRoot(String identifier) { if (identifier == null) { throw new NullPointerException("Data directory name is null"); } if (!dataRootMap.containsKey(identifier)) { throw new IllegalArgumentException(String.format("Data directory with name: %s is not present in server's configuration", identifier)); } return dataRootMap.get(identifier); } DataDirsConfigImpl(IParameterSubstitutor parameterSubstitutor, PathResolver pathResolver, Path metadataDir, Map<String, Path> dataDirectories);  DataDirsConfigImpl(IParameterSubstitutor parameterSubstitutor, PathResolver pathResolver, org.terracotta.data.config.DataDirectories dataDirectories);  DataDirsConfigImpl(IParameterSubstitutor parameterSubstitutor, PathResolver pathResolver, org.terracotta.data.config.DataDirectories dataDirectories, boolean skipIO); @Override DataDirs getDataDirectoriesForServer(PlatformConfiguration platformConfiguration); @Override void addDataDirectory(String name, String path); void addDataDirectory(String name, String path, boolean skipIO); @Override void validateDataDirectory(String name, String path); void validateDataDirectory(String name, String path, boolean skipIO); @Override void onManagementRegistryCreated(EntityManagementRegistry registry); @Override void onManagementRegistryClose(EntityManagementRegistry registry); @Override void addStateTo(StateDumpCollector dump); @Override void close(); long getDiskUsageByRootIdentifier(String identifier);  }
@Test public void getRoot() throws Exception { EntityManagementRegistry registry = mock(EntityManagementRegistry.class); EntityMonitoringService entityMonitoringService = mock(EntityMonitoringService.class); when(registry.getMonitoringService()).thenReturn(entityMonitoringService); when(entityMonitoringService.getConsumerId()).thenReturn(1L); when(entityMonitoringService.getServerName()).thenReturn("myServer"); String[] ids = {"a", "b"}; String[] dataRootPaths = new String[ids.length]; DataDirsConfigImpl dataRootConfig = configureDataRoot(ids, dataRootPaths); DataRootBinding[] bindings = new DataRootBinding[ids.length]; for (int i = 0; i < ids.length; i++) { bindings[i] = new DataRootBinding(ids[i], dataRootConfig.getRoot(ids[i])); } dataRootConfig.onManagementRegistryCreated(registry); for (int i = 0; i < ids.length; i++) { assertEquals(Paths.get(dataRootPaths[i]), dataRootConfig.getRoot(ids[i])); assertTrue(Files.exists(dataRootConfig.getRoot(ids[i]))); verify(registry).register(bindings[i]); } String postRegistry_Id = "postRegistry"; dataRootConfig.addDataDirectory(postRegistry_Id, folder.newFolder().getAbsolutePath()); DataRootBinding newBinding = new DataRootBinding(postRegistry_Id, dataRootConfig.getRoot(postRegistry_Id)); verify(registry).registerAndRefresh(newBinding); }
@Test public void testGetRootWitNull() throws Exception { String[] ids = {"a", "b"}; String[] dataRootPaths = new String[ids.length]; DataDirsConfigImpl dataRootConfig = configureDataRoot(ids, dataRootPaths); expectedException.expect(NullPointerException.class); dataRootConfig.getRoot(null); }
@Test public void testGetRootInvalidId() throws Exception { String[] ids = {"a", "b"}; String[] dataRootPaths = new String[ids.length]; DataDirsConfigImpl dataRootConfig = configureDataRoot(ids, dataRootPaths); expectedException.expect(IllegalArgumentException.class); dataRootConfig.getRoot("this_id_does_not_exists"); }
@Test public void testSubstitutablePaths() throws Exception { String[] ids = {"id"}; String configuredPath = folder.newFolder().getAbsolutePath(); DataRootMapping[] dataRootMappings = new DataRootMapping[ids.length]; dataRootMappings[0] = new DataRootMapping(); dataRootMappings[0].setName(ids[0]); dataRootMappings[0].setValue(configuredPath + "-%h"); DataDirsConfigImpl dataRootConfig = configureDataRoot(dataRootMappings); String hostName = ParameterSubstitutor.getHostName(); assertThat(dataRootConfig.getRoot(ids[0]), is(Paths.get(configuredPath + "-" + hostName))); }
@Test public void testRelativePathWithSourceSpecified() throws Exception { String[] ids = {"id"}; String[] dataRootPaths = new String[ids.length]; String source = folder.newFile("config.xml").getParent(); DataDirsConfigImpl dataRootConfig = configureDataRoot(ids, dataRootPaths, source); assertThat(dataRootConfig.getRoot(ids[0]).getParent(), is(Paths.get(source))); }
@Test @Ignore("Fails currently, need some fixes to be done in terracotta-configuration") public void testSourceAsURLIsIgnored() throws Exception { String[] ids = {"id"}; String[] dataRootPaths = new String[ids.length]; String source = new URL("http: DataDirsConfigImpl dataRootConfig = configureDataRoot(ids, dataRootPaths, source); assertThat(dataRootConfig.getRoot(ids[0]).getParent(), is(Paths.get("."))); }