Skip to content

Commit

Permalink
Rename 'property'->'config' where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Feb 9, 2016
1 parent 9d3b785 commit 6ee1e64
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 335 deletions.
Expand Up @@ -84,7 +84,7 @@ public void run( String... args ) throws ToolFailureException, IOException
{ {
Args arguments = Args.withFlags( RECOVERY, PROP_OWNER ).parse( args ); Args arguments = Args.withFlags( RECOVERY, PROP_OWNER ).parse( args );
File storeDir = determineStoreDirectory( arguments ); File storeDir = determineStoreDirectory( arguments );
Config tuningConfiguration = readTuningConfiguration( arguments ); Config tuningConfiguration = readConfiguration( arguments );


attemptRecoveryOrCheckStateOfLogicalLogs( arguments, storeDir, tuningConfiguration ); attemptRecoveryOrCheckStateOfLogicalLogs( arguments, storeDir, tuningConfiguration );


Expand Down Expand Up @@ -143,25 +143,25 @@ private File determineStoreDirectory( Args arguments ) throws ToolFailureExcepti
return storeDir; return storeDir;
} }


private Config readTuningConfiguration( Args arguments ) throws ToolFailureException private Config readConfiguration( Args arguments ) throws ToolFailureException
{ {
Map<String,String> specifiedProperties = stringMap(); Map<String,String> specifiedConfig = stringMap();


String propertyFilePath = arguments.get( CONFIG, null ); String configFilePath = arguments.get( CONFIG, null );
if ( propertyFilePath != null ) if ( configFilePath != null )
{ {
File propertyFile = new File( propertyFilePath ); File configFile = new File( configFilePath );
try try
{ {
specifiedProperties = MapUtil.load( propertyFile ); specifiedConfig = MapUtil.load( configFile );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new ToolFailureException( String.format( "Could not read configuration properties file [%s]", throw new ToolFailureException( String.format( "Could not read configuration file [%s]",
propertyFilePath ), e ); configFilePath ), e );
} }
} }
return new Config( specifiedProperties, GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); return new Config( specifiedConfig, GraphDatabaseSettings.class, ConsistencyCheckSettings.class );
} }


private String usage() private String usage()
Expand Down
Expand Up @@ -19,16 +19,16 @@
*/ */
package org.neo4j.legacy.consistency; package org.neo4j.legacy.consistency;


import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Properties; import java.util.Properties;


import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.graphdb.factory.GraphDatabaseFactory;
Expand Down Expand Up @@ -113,12 +113,12 @@ public void passesOnConfigurationIfProvided() throws Exception
{ {
// given // given
File storeDir = storeDirectory.directory(); File storeDir = storeDirectory.directory();
File propertyFile = storeDirectory.file( "neo4j.conf" ); File configFile = storeDirectory.file( "neo4j.conf" );
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" ); properties.setProperty( ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" );
properties.store( new FileWriter( propertyFile ), null ); properties.store( new FileWriter( configFile ), null );


String[] args = {storeDir.getPath(), "-config", propertyFile.getPath()}; String[] args = {storeDir.getPath(), "-config", configFile.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class ); ConsistencyCheckService service = mock( ConsistencyCheckService.class );
PrintStream systemOut = mock( PrintStream.class ); PrintStream systemOut = mock( PrintStream.class );


Expand Down Expand Up @@ -154,11 +154,11 @@ public void exitWithFailureIndicatingCorrectUsageIfNoArgumentsSupplied() throws
} }


@Test @Test
public void exitWithFailureIfConfigSpecifiedButPropertiesFileDoesNotExist() throws Exception public void exitWithFailureIfConfigSpecifiedButConfigFileDoesNotExist() throws Exception
{ {
// given // given
File propertyFile = storeDirectory.file( "nonexistent_file" ); File configFile = storeDirectory.file( "nonexistent_file" );
String[] args = {storeDirectory.directory().getPath(), "-config", propertyFile.getPath()}; String[] args = {storeDirectory.directory().getPath(), "-config", configFile.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class ); ConsistencyCheckService service = mock( ConsistencyCheckService.class );
PrintStream systemOut = mock( PrintStream.class ); PrintStream systemOut = mock( PrintStream.class );
ConsistencyCheckTool ConsistencyCheckTool = newConsistencyCheckToolWith( service, systemOut ); ConsistencyCheckTool ConsistencyCheckTool = newConsistencyCheckToolWith( service, systemOut );
Expand All @@ -172,7 +172,7 @@ public void exitWithFailureIfConfigSpecifiedButPropertiesFileDoesNotExist() thro
catch ( ConsistencyCheckTool.ToolFailureException e ) catch ( ConsistencyCheckTool.ToolFailureException e )
{ {
// then // then
assertThat( e.getMessage(), containsString( "Could not read configuration properties file" ) ); assertThat( e.getMessage(), containsString( "Could not read configuration file" ) );
assertThat( e.getCause(), instanceOf( IOException.class ) ); assertThat( e.getCause(), instanceOf( IOException.class ) );
} }


Expand Down
Expand Up @@ -103,7 +103,7 @@ void run( String... args ) throws ToolFailureException, IOException
} }


File storeDir = determineStoreDirectory( arguments ); File storeDir = determineStoreDirectory( arguments );
Config tuningConfiguration = readTuningConfiguration( arguments ); Config tuningConfiguration = readConfiguration( arguments );
boolean verbose = isVerbose( arguments ); boolean verbose = isVerbose( arguments );


attemptRecoveryOrCheckStateOfLogicalLogs( arguments, storeDir, tuningConfiguration ); attemptRecoveryOrCheckStateOfLogicalLogs( arguments, storeDir, tuningConfiguration );
Expand Down Expand Up @@ -201,25 +201,25 @@ private File determineStoreDirectory( Args arguments ) throws ToolFailureExcepti
return storeDir; return storeDir;
} }


private Config readTuningConfiguration( Args arguments ) throws ToolFailureException private Config readConfiguration( Args arguments ) throws ToolFailureException
{ {
Map<String,String> specifiedProperties = stringMap(); Map<String,String> specifiedConfig = stringMap();


String propertyFilePath = arguments.get( CONFIG, null ); String configFilePath = arguments.get( CONFIG, null );
if ( propertyFilePath != null ) if ( configFilePath != null )
{ {
File propertyFile = new File( propertyFilePath ); File configFile = new File( configFilePath );
try try
{ {
specifiedProperties = MapUtil.load( propertyFile ); specifiedConfig = MapUtil.load( configFile );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new ToolFailureException( String.format( "Could not read configuration properties file [%s]", throw new ToolFailureException( String.format( "Could not read configuration file [%s]",
propertyFilePath ), e ); configFilePath ), e );
} }
} }
return new Config( specifiedProperties, GraphDatabaseSettings.class, ConsistencyCheckSettings.class ); return new Config( specifiedConfig, GraphDatabaseSettings.class, ConsistencyCheckSettings.class );
} }


private String usage() private String usage()
Expand Down
Expand Up @@ -19,13 +19,6 @@
*/ */
package org.neo4j.consistency; package org.neo4j.consistency;


import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.ArgumentCaptor;

import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
Expand All @@ -34,6 +27,13 @@
import java.util.Collection; import java.util.Collection;
import java.util.Properties; import java.util.Properties;


import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.ArgumentCaptor;

import org.neo4j.consistency.ConsistencyCheckTool.ToolFailureException; import org.neo4j.consistency.ConsistencyCheckTool.ToolFailureException;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
Expand Down Expand Up @@ -66,6 +66,7 @@
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;

import static org.neo4j.consistency.ConsistencyCheckTool.USE_LEGACY_CHECKER; import static org.neo4j.consistency.ConsistencyCheckTool.USE_LEGACY_CHECKER;
import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.ArrayUtil.concat; import static org.neo4j.helpers.ArrayUtil.concat;
Expand Down Expand Up @@ -142,12 +143,12 @@ public void passesOnConfigurationIfProvided() throws Exception
assumeFalse( "This test runs with mocked ConsistencyCheckService, doesn't work with the legacy checker " + assumeFalse( "This test runs with mocked ConsistencyCheckService, doesn't work with the legacy checker " +
"since it creates its own", useLegacyChecker ); "since it creates its own", useLegacyChecker );
File storeDir = storeDirectory.directory(); File storeDir = storeDirectory.directory();
File propertyFile = storeDirectory.file( "neo4j.conf" ); File configFile = storeDirectory.file( "neo4j.conf" );
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" ); properties.setProperty( ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" );
properties.store( new FileWriter( propertyFile ), null ); properties.store( new FileWriter( configFile ), null );


String[] args = {storeDir.getPath(), "-config", propertyFile.getPath()}; String[] args = {storeDir.getPath(), "-config", configFile.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class ); ConsistencyCheckService service = mock( ConsistencyCheckService.class );
PrintStream systemOut = mock( PrintStream.class ); PrintStream systemOut = mock( PrintStream.class );


Expand Down Expand Up @@ -184,11 +185,11 @@ public void exitWithFailureIndicatingCorrectUsageIfNoArgumentsSupplied() throws
} }


@Test @Test
public void exitWithFailureIfConfigSpecifiedButPropertiesFileDoesNotExist() throws Exception public void exitWithFailureIfConfigSpecifiedButConfigFileDoesNotExist() throws Exception
{ {
// given // given
File propertyFile = storeDirectory.file( "nonexistent_file" ); File configFile = storeDirectory.file( "nonexistent_file" );
String[] args = {storeDirectory.directory().getPath(), "-config", propertyFile.getPath()}; String[] args = {storeDirectory.directory().getPath(), "-config", configFile.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class ); ConsistencyCheckService service = mock( ConsistencyCheckService.class );
PrintStream systemOut = mock( PrintStream.class ); PrintStream systemOut = mock( PrintStream.class );


Expand All @@ -201,7 +202,7 @@ public void exitWithFailureIfConfigSpecifiedButPropertiesFileDoesNotExist() thro
catch ( ConsistencyCheckTool.ToolFailureException e ) catch ( ConsistencyCheckTool.ToolFailureException e )
{ {
// then // then
assertThat( e.getMessage(), containsString( "Could not read configuration properties file" ) ); assertThat( e.getMessage(), containsString( "Could not read configuration file" ) );
assertThat( e.getCause(), instanceOf( IOException.class ) ); assertThat( e.getCause(), instanceOf( IOException.class ) );
} }


Expand Down
Expand Up @@ -47,17 +47,17 @@ public static File getSharedTestTemporaryFolder()
{ {
try try
{ {
return createTempPropertyFile().getParentFile(); return createTempConfigFile().getParentFile();
} }
catch ( Exception e ) catch ( Exception e )
{ {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }
} }


public static File createTempPropertyFile() throws IOException public static File createTempConfigFile() throws IOException
{ {
File file = File.createTempFile( "neo4j", "properties" ); File file = File.createTempFile( "neo4j", "conf" );
file.delete(); file.delete();
return file; return file;
} }
Expand Down Expand Up @@ -96,20 +96,14 @@ private static void addRelativeProperty( File temporaryFolder, Map<String,String
properties.put( setting.name(), getRelativePath( temporaryFolder, setting ) ); properties.put( setting.name(), getRelativePath( temporaryFolder, setting ) );
} }


public static void writePropertiesToFile( String outerPropertyName, Map<String, String> properties, public static void writeConfigToFile( Map<String, String> properties, File file )
File propertyFile )
{ {
writePropertyToFile( outerPropertyName, asOneLine( properties ), propertyFile ); Properties props = loadProperties( file );
}

public static void writePropertiesToFile( Map<String, String> properties, File propertyFile )
{
Properties props = loadProperties( propertyFile );
for ( Map.Entry<String, String> entry : properties.entrySet() ) for ( Map.Entry<String, String> entry : properties.entrySet() )
{ {
props.setProperty( entry.getKey(), entry.getValue() ); props.setProperty( entry.getKey(), entry.getValue() );
} }
storeProperties( propertyFile, props ); storeProperties( file, props );
} }


public static String asOneLine( Map<String, String> properties ) public static String asOneLine( Map<String, String> properties )
Expand All @@ -123,19 +117,12 @@ public static String asOneLine( Map<String, String> properties )
return builder.toString(); return builder.toString();
} }


public static void writePropertyToFile( String name, String value, File propertyFile ) private static void storeProperties( File file, Properties properties )
{
Properties properties = loadProperties( propertyFile );
properties.setProperty( name, value );
storeProperties( propertyFile, properties );
}

private static void storeProperties( File propertyFile, Properties properties )
{ {
OutputStream out = null; OutputStream out = null;
try try
{ {
out = new FileOutputStream( propertyFile ); out = new FileOutputStream( file );
properties.store( out, "" ); properties.store( out, "" );
} }
catch ( IOException e ) catch ( IOException e )
Expand All @@ -148,15 +135,15 @@ private static void storeProperties( File propertyFile, Properties properties )
} }
} }


private static Properties loadProperties( File propertyFile ) private static Properties loadProperties( File file )
{ {
Properties properties = new Properties(); Properties properties = new Properties();
if ( propertyFile.exists() ) if ( file.exists() )
{ {
InputStream in = null; InputStream in = null;
try try
{ {
in = new FileInputStream( propertyFile ); in = new FileInputStream( file );
properties.load( in ); properties.load( in );
} }
catch ( IOException e ) catch ( IOException e )
Expand Down Expand Up @@ -186,7 +173,7 @@ private static void safeClose( Closeable closeable )
} }
} }


public static File createTempPropertyFile( File parentDir ) throws IOException public static File createTempConfigFile( File parentDir ) throws IOException
{ {
File file = new File( parentDir, "test-" + new Random().nextInt() + ".properties" ); File file = new File( parentDir, "test-" + new Random().nextInt() + ".properties" );
file.deleteOnExit(); file.deleteOnExit();
Expand Down
Expand Up @@ -51,14 +51,14 @@ public class BaseServerConfigLoaderTest
public void shouldRetainRegistrationOrderOfThirdPartyJaxRsPackages() throws IOException public void shouldRetainRegistrationOrderOfThirdPartyJaxRsPackages() throws IOException
{ {
// given // given
File propertyFile = PropertyFileBuilder.builder( folder.getRoot() ) File configFile = ConfigFileBuilder.builder( folder.getRoot() )
.withNameValue( ServerSettings.third_party_packages.name(), .withNameValue( ServerSettings.third_party_packages.name(),
"org.neo4j.extension.extension1=/extension1,org.neo4j.extension.extension2=/extension2," + "org.neo4j.extension.extension1=/extension1,org.neo4j.extension.extension2=/extension2," +
"org.neo4j.extension.extension3=/extension3" ) "org.neo4j.extension.extension3=/extension3" )
.build(); .build();


// when // when
Config config = configLoader.loadConfig( null, propertyFile, log ); Config config = configLoader.loadConfig( null, configFile, log );


// then // then
List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages ); List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages );
Expand All @@ -71,13 +71,13 @@ public void shouldRetainRegistrationOrderOfThirdPartyJaxRsPackages() throws IOEx
} }


@Test @Test
public void shouldWorkFineWhenSpecifiedPropertiesFileDoesNotExist() public void shouldWorkFineWhenSpecifiedConfigFileDoesNotExist()
{ {
// Given // Given
File nonExistentFilePropertiesFile = new File( "/tmp/" + System.currentTimeMillis() ); File nonExistentConfigFile = new File( "/tmp/" + System.currentTimeMillis() );


// When // When
Config config = configLoader.loadConfig( null, nonExistentFilePropertiesFile, log ); Config config = configLoader.loadConfig( null, nonExistentConfigFile, log );


// Then // Then
assertNotNull( config ); assertNotNull( config );
Expand Down

0 comments on commit 6ee1e64

Please sign in to comment.