/** * Stores the data in {@code config} into {@code file} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * @param config the data to store in the properties file. * @param file the file to store the properties in. */ public static void storeStrictly( Map<String, String> config, File file ) { try { store( config, file ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code writer} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown * as a {@link RuntimeException} instead. * * @param config the data to store in the properties file. * @param writer the {@link Writer} to store the properties in. */ public static void storeStrictly( Map<String, String> config, Writer writer ) { try { store( config, writer ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code stream} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * @param config the data to store in the properties file. * @param stream the {@link OutputStream} to store the properties in. */ public static void storeStrictly( Map<String, String> config, OutputStream stream ) { try { store( config, stream ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code file} in a standard java * {@link Properties} format. * @param config the data to store in the properties file. * @param file the file to store the properties in. * @throws IOException IO error. */ public static void store( Map<String, String> config, File file ) throws IOException { OutputStream stream = null; try { stream = new BufferedOutputStream( new FileOutputStream( file ) ); store( config, stream ); } finally { closeIfNotNull( stream ); } }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomAbsoluteLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); File otherLocation = testDirectory.directory( "otherLocation" ); Config customConfig = Config.defaults( logical_logs_location, otherLocation.getAbsolutePath() ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), customConfigFile ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }
@Test public void canSpecifyConfigFile() throws Throwable { // Given File configFile = tempDir.newFile( Config.DEFAULT_CONFIG_FILE_NAME ); Map<String,String> properties = stringMap( forced_kernel_id.name(), "ourcustomvalue" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); properties.putAll( connectorsOnRandomPortsConfig() ); store( properties, configFile ); // When ServerBootstrapper.start( bootstrapper, "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "--config-dir", configFile.getParentFile().getAbsolutePath() ); // Then assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "ourcustomvalue" ) ); }
@Test public void canOverrideConfigValues() throws Throwable { // Given File configFile = tempDir.newFile( Config.DEFAULT_CONFIG_FILE_NAME ); Map<String,String> properties = stringMap( forced_kernel_id.name(), "thisshouldnotshowup" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); properties.putAll( connectorsOnRandomPortsConfig() ); store( properties, configFile ); // When ServerBootstrapper.start( bootstrapper, "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "--config-dir", configFile.getParentFile().getAbsolutePath(), "-c", configOption( forced_kernel_id, "mycustomvalue" ) ); // Then assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "mycustomvalue" ) ); }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomRelativeLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); Config customConfig = Config.defaults( logical_logs_location, "otherLocation" ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), fs.openAsOutputStream( customConfigFile, false ) ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }
Path configFile = configDir.resolve( DEFAULT_CONFIG_FILE_NAME ); String databaseName = "mydb"; store( stringMap( data_directory.name(), homeDir.toString() ), configFile.toFile() ); File databaseDirectory = fromFile( configFile ).withHome( homeDir ).withSetting( active_database, databaseName ).build().get( database_path ); createDatabaseWithNativeIndexes( databaseDirectory );
@Test public void combineProvidedDbAndAdditionalConfig() throws Exception { // GIVEN int arrayBlockSize = 10; int stringBlockSize = 12; File dbConfig = file( "neo4j.properties" ); File additionalConfig = file( "additional.properties" ); store( stringMap( GraphDatabaseSettings.string_block_size.name(), String.valueOf( stringBlockSize ) ), dbConfig ); store( stringMap( GraphDatabaseSettings.array_block_size.name(), String.valueOf( arrayBlockSize ) ), additionalConfig ); List<String> nodeIds = nodeIds(); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--db-config", dbConfig.getAbsolutePath(), "--additional-config", additionalConfig.getAbsolutePath(), "--nodes", nodeData( true, Configuration.COMMAS, nodeIds, value -> true ).getAbsolutePath() ); // THEN NeoStores stores = dbRule.getGraphDatabaseAPI().getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); int headerSize = Standard.LATEST_RECORD_FORMATS.dynamic().getRecordHeaderSize(); assertEquals( arrayBlockSize + headerSize, stores.getPropertyStore().getArrayStore().getRecordSize() ); assertEquals( stringBlockSize + headerSize, stores.getPropertyStore().getStringStore().getRecordSize() ); }
@Test public void useProvidedAdditionalConfig() throws Exception { // GIVEN int arrayBlockSize = 10; int stringBlockSize = 12; File dbConfig = file( "neo4j.properties" ); store( stringMap( GraphDatabaseSettings.array_block_size.name(), String.valueOf( arrayBlockSize ), GraphDatabaseSettings.string_block_size.name(), String.valueOf( stringBlockSize ) ), dbConfig ); List<String> nodeIds = nodeIds(); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--additional-config", dbConfig.getAbsolutePath(), "--nodes", nodeData( true, Configuration.COMMAS, nodeIds, value -> true ).getAbsolutePath() ); // THEN NeoStores stores = dbRule.getGraphDatabaseAPI().getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); int headerSize = Standard.LATEST_RECORD_FORMATS.dynamic().getRecordHeaderSize(); assertEquals( arrayBlockSize + headerSize, stores.getPropertyStore().getArrayStore().getRecordSize() ); assertEquals( stringBlockSize + headerSize, stores.getPropertyStore().getStringStore().getRecordSize() ); }
@Test public void shouldRespectDbConfig() throws Exception { // GIVEN int arrayBlockSize = 10; int stringBlockSize = 12; File dbConfig = file( "neo4j.properties" ); store( stringMap( GraphDatabaseSettings.array_block_size.name(), String.valueOf( arrayBlockSize ), GraphDatabaseSettings.string_block_size.name(), String.valueOf( stringBlockSize ) ), dbConfig ); List<String> nodeIds = nodeIds(); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--db-config", dbConfig.getAbsolutePath(), "--nodes", nodeData( true, Configuration.COMMAS, nodeIds, value -> true ).getAbsolutePath() ); // THEN NeoStores stores = dbRule.getGraphDatabaseAPI().getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); int headerSize = Standard.LATEST_RECORD_FORMATS.dynamic().getRecordHeaderSize(); assertEquals( arrayBlockSize + headerSize, stores.getPropertyStore().getArrayStore().getRecordSize() ); assertEquals( stringBlockSize + headerSize, stores.getPropertyStore().getStringStore().getRecordSize() ); }
/** * Stores the data in {@code config} into {@code writer} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown * as a {@link RuntimeException} instead. * * @param config the data to store in the properties file. * @param writer the {@link Writer} to store the properties in. */ public static void storeStrictly( Map<String, String> config, Writer writer ) { try { store( config, writer ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code file} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * @param config the data to store in the properties file. * @param file the file to store the properties in. */ public static void storeStrictly( Map<String, String> config, File file ) { try { store( config, file ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code stream} in a standard java * {@link Properties} format. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * @param config the data to store in the properties file. * @param stream the {@link OutputStream} to store the properties in. */ public static void storeStrictly( Map<String, String> config, OutputStream stream ) { try { store( config, stream ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Stores the data in {@code config} into {@code file} in a standard java * {@link Properties} format. * @param config the data to store in the properties file. * @param file the file to store the properties in. * @throws IOException IO error. */ public static void store( Map<String, String> config, File file ) throws IOException { OutputStream stream = null; try { stream = new BufferedOutputStream( new FileOutputStream( file ) ); store( config, stream ); } finally { closeIfNotNull( stream ); } }