Skip to content

Commit

Permalink
Configure tx logs directory for server and test absolute location
Browse files Browse the repository at this point in the history
for consistency checker
  • Loading branch information
MishaDemianenko committed Nov 16, 2017
1 parent f5a5135 commit c67aa10
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
Expand Up @@ -67,20 +67,21 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.logical_logs_location;

public class ConsistencyCheckToolTest
{
private final TestDirectory storeDirectory = TestDirectory.testDirectory();
private final TestDirectory testDirectory = TestDirectory.testDirectory();
private final EphemeralFileSystemRule fs = new EphemeralFileSystemRule();

@Rule
public RuleChain ruleChain = RuleChain.outerRule( storeDirectory ).around( fs );
public RuleChain ruleChain = RuleChain.outerRule( testDirectory ).around( fs );

@Test
public void runsConsistencyCheck() throws Exception
{
// given
File storeDir = storeDirectory.directory();
File storeDir = testDirectory.directory();
String[] args = {storeDir.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class );

Expand Down Expand Up @@ -109,8 +110,8 @@ public void consistencyCheckerLogUseSystemTimezoneIfConfigurable() throws Except
provider.getLog( "test" ).info( "testMessage" );
return ConsistencyCheckService.Result.success( new File( StringUtils.EMPTY ) );
} );
File storeDir = storeDirectory.directory();
File configFile = storeDirectory.file( Config.DEFAULT_CONFIG_FILE_NAME );
File storeDir = testDirectory.directory();
File configFile = testDirectory.file( Config.DEFAULT_CONFIG_FILE_NAME );
Properties properties = new Properties();
properties.setProperty( GraphDatabaseSettings.log_timezone.name(), LogTimeZone.SYSTEM.name() );
properties.store( new FileWriter( configFile ), null );
Expand All @@ -129,7 +130,7 @@ public void consistencyCheckerLogUseSystemTimezoneIfConfigurable() throws Except
public void appliesDefaultTuningConfigurationForConsistencyChecker() throws Exception
{
// given
File storeDir = storeDirectory.directory();
File storeDir = testDirectory.directory();
String[] args = {storeDir.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class );

Expand All @@ -148,8 +149,8 @@ public void appliesDefaultTuningConfigurationForConsistencyChecker() throws Exce
public void passesOnConfigurationIfProvided() throws Exception
{
// given
File storeDir = storeDirectory.directory();
File configFile = storeDirectory.file( Config.DEFAULT_CONFIG_FILE_NAME );
File storeDir = testDirectory.directory();
File configFile = testDirectory.file( Config.DEFAULT_CONFIG_FILE_NAME );
Properties properties = new Properties();
properties.setProperty( ConsistencyCheckSettings.consistency_check_property_owners.name(), "true" );
properties.store( new FileWriter( configFile ), null );
Expand Down Expand Up @@ -192,8 +193,8 @@ public void exitWithFailureIndicatingCorrectUsageIfNoArgumentsSupplied() throws
public void exitWithFailureIfConfigSpecifiedButConfigFileDoesNotExist() throws Exception
{
// given
File configFile = storeDirectory.file( "nonexistent_file" );
String[] args = {storeDirectory.directory().getPath(), "-config", configFile.getPath()};
File configFile = testDirectory.file( "nonexistent_file" );
String[] args = {testDirectory.directory().getPath(), "-config", configFile.getPath()};
ConsistencyCheckService service = mock( ConsistencyCheckService.class );

try
Expand All @@ -217,18 +218,30 @@ public void failWhenStoreWasNonCleanlyShutdown() throws Exception
{
createGraphDbAndKillIt( Config.defaults() );

runConsistencyCheckToolWith( fs.get(), storeDirectory.graphDbDir().getAbsolutePath() );
runConsistencyCheckToolWith( fs.get(), testDirectory.graphDbDir().getAbsolutePath() );
}

@Test( expected = ToolFailureException.class )
public void failOnNotCleanlyShutdownStoreWithLogsInCustomLocation() throws Exception
public void failOnNotCleanlyShutdownStoreWithLogsInCustomRelativeLocation() throws Exception
{
File customConfigFile = storeDirectory.file( "customConfig" );
File otherLocation = storeDirectory.directory( "otherLocation" );
Config customConfig = Config.defaults( GraphDatabaseSettings.logical_logs_location, otherLocation.getName() );
File customConfigFile = testDirectory.file( "customConfig" );
Config customConfig = Config.defaults( logical_logs_location, "otherLocation" );
createGraphDbAndKillIt( customConfig );
MapUtil.store( customConfig.getRaw(), customConfigFile );
String[] args = {storeDirectory.graphDbDir().getPath(), "-config", customConfigFile.getPath()};
String[] args = {testDirectory.graphDbDir().getPath(), "-config", customConfigFile.getPath()};

runConsistencyCheckToolWith( fs.get(), args );
}

@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.graphDbDir().getPath(), "-config", customConfigFile.getPath()};

runConsistencyCheckToolWith( fs.get(), args );
}
Expand All @@ -255,7 +268,7 @@ private void createGraphDbAndKillIt( Config config ) throws Exception
{
final GraphDatabaseService db = new TestGraphDatabaseFactory()
.setFileSystem( fs.get() )
.newImpermanentDatabaseBuilder( storeDirectory.graphDbDir() )
.newImpermanentDatabaseBuilder( testDirectory.graphDbDir() )
.setConfig( config.getRaw() )
.newGraphDatabase();

Expand Down
Expand Up @@ -117,8 +117,7 @@ public CommunityNeoServer build() throws IOException
final File configFile = buildBefore();

Log log = logProvider.getLog( getClass() );
Config config = Config.fromFile( configFile ).withHome( configFile.getParentFile() )
.withServerDefaults().build();
Config config = Config.fromFile( configFile ).withServerDefaults().build();
config.setLogger( log );
return build( configFile, config, GraphDatabaseDependencies.newDependencies().userLogProvider( logProvider )
.monitors( new Monitors() ) );
Expand Down Expand Up @@ -207,6 +206,8 @@ public Map<String, String> createConfiguration( File temporaryFolder )
new File( temporaryFolder, "certificates" ).getAbsolutePath() );
properties.put( GraphDatabaseSettings.logs_directory.name(),
new File( temporaryFolder, "logs" ).getAbsolutePath() );
properties.put( GraphDatabaseSettings.logical_logs_location.name(),
new File( temporaryFolder, "transaction-logs" ).getAbsolutePath() );
properties.put( GraphDatabaseSettings.pagecache_memory.name(), "8m" );

for ( Object key : arbitraryProperties.keySet() )
Expand Down
Expand Up @@ -29,7 +29,6 @@

import java.io.IOException;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.server.CommunityNeoServer;
import org.neo4j.server.helpers.CommunityServerBuilder;
import org.neo4j.server.helpers.FunctionalTestHelper;
Expand Down Expand Up @@ -57,7 +56,6 @@ public static void allocateServer() throws IOException
server = CommunityServerBuilder.serverOnRandomPorts()
.usingDataDir( staticFolder.getRoot().getAbsolutePath() )
.withAutoIndexingEnabledForNodes( "foo", "bar" )
.withProperty( GraphDatabaseSettings.neo4j_home.name(), staticFolder.getRoot().getAbsolutePath() )
.build();
server.start();
functionalTestHelper = new FunctionalTestHelper( server );
Expand Down

0 comments on commit c67aa10

Please sign in to comment.