Skip to content

Commit

Permalink
More test fixes, create directories on request in test directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 6c557b9 commit f634326
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Random;

import org.neo4j.test.extension.Inject;
Expand Down Expand Up @@ -110,10 +111,10 @@ void shouldGiveAClearErrorIfTheDestinationTxLogAlreadyExists()
}

@Test
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist()
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist() throws IOException
{
Path archive = testDirectory.file( "the-archive.dump" ).toPath();
Path destination = testDirectory.directory( "subdir/the-destination" ).toPath();
Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" );
NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, destination ) );
assertEquals( destination.getParent().toString(), noSuchFileException.getMessage() );
}
Expand All @@ -123,7 +124,7 @@ void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist()
{
Path archive = testDirectory.file( "the-archive.dump" ).toPath();
Path destination = testDirectory.file( "destination" ).toPath();
Path txLogsDestination = testDirectory.directory( "subdir/txLogs" ).toPath();
Path txLogsDestination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "txLogs" );
NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, txLogsDestination ) );
assertEquals( txLogsDestination.getParent().toString(), noSuchFileException.getMessage() );
}
Expand All @@ -133,7 +134,7 @@ void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsAFile()
throws IOException
{
Path archive = testDirectory.file( "the-archive.dump" ).toPath();
Path destination = testDirectory.directory( "subdir/the-destination" ).toPath();
Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" );
Files.write( destination.getParent(), new byte[0] );
FileSystemException exception = assertThrows( FileSystemException.class, () -> new Loader().load( archive, destination, destination ) );
assertEquals( destination.getParent().toString() + ": Not a directory", exception.getMessage() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public File[] listDatabaseFiles( FilenameFilter filter )
return files != null ? files : EMPTY_FILES_ARRAY;
}

@Override
public String toString()
{
return "DatabaseLayout{" + "databaseDirectory=" + databaseDirectory + '}';
}

@Override
public boolean equals( Object o )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ public File directory()
public File directory( String name )
{
File dir = new File( directory(), name );
if ( !fileSystem.fileExists( dir ) )
{
fileSystem.mkdir( dir );
}
createDirectory( dir );
return dir;
}

Expand All @@ -165,18 +162,19 @@ public File file( String name )

public File databaseDir()
{
return defaultDatabaseLayout.databaseDirectory();
return databaseLayout().databaseDirectory();
}

public DatabaseLayout databaseLayout()
{
createDirectory( defaultDatabaseLayout.databaseDirectory() );
return defaultDatabaseLayout;
}

public DatabaseLayout databaseLayout( File storeDir )
{
DatabaseLayout databaseLayout = new StoreLayout( storeDir ).databaseDirectory( DEFAULT_DATABASE_DIRECTORY );
databaseLayout.databaseDirectory().mkdirs();
createDirectory( defaultDatabaseLayout.databaseDirectory() );
return databaseLayout;
}

Expand Down Expand Up @@ -256,9 +254,7 @@ public void prepareDirectory( Class<?> testClass, String test ) throws IOExcepti
}
testDirectory = prepareDirectoryForTest( test );
storeLayout = new StoreLayout( testDirectory );
//TODO:do not create it by default?
defaultDatabaseLayout = storeLayout.databaseDirectory( DEFAULT_DATABASE_DIRECTORY );
fileSystem.mkdirs( defaultDatabaseLayout.databaseDirectory() );
}

public File prepareDirectoryForTest( String test ) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import java.util.function.Supplier;

import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.Service;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -97,7 +97,7 @@ public Class<OnlineBackupSettings> getSettingsClass()
@Override
public Lifecycle newInstance( KernelContext context, Dependencies dependencies )
{
if ( !isCausalClusterInstance( context ) && isDefaultDatabase( dependencies.neoStoreDataSource() ) )
if ( !isCausalClusterInstance( context ) && isDefaultDatabase( dependencies.neoStoreDataSource(), dependencies.getConfig() ) )
{
return new OnlineBackupKernelExtension( dependencies.getConfig(), dependencies.getGraphDatabaseAPI(),
dependencies.logService().getInternalLogProvider(), dependencies.monitors(), dependencies.neoStoreDataSource(),
Expand All @@ -106,9 +106,9 @@ public Lifecycle newInstance( KernelContext context, Dependencies dependencies )
return new LifecycleAdapter();
}

private static boolean isDefaultDatabase( NeoStoreDataSource neoStoreDataSource )
private static boolean isDefaultDatabase( NeoStoreDataSource neoStoreDataSource, Config config )
{
return DatabaseManager.DEFAULT_DATABASE_NAME.equals( neoStoreDataSource.getDatabaseName() );
return neoStoreDataSource.getDatabaseName().equals( config.get( GraphDatabaseSettings.active_database ) );
}

private static boolean isCausalClusterInstance( KernelContext kernelContext )
Expand Down
18 changes: 8 additions & 10 deletions enterprise/backup/src/test/java/org/neo4j/backup/BackupIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public class BackupIT
private final RandomRule random = new RandomRule();

@Rule
public final RuleChain ruleChain = RuleChain.outerRule( testDir )
.around( fileSystemRule )
public final RuleChain ruleChain = RuleChain.outerRule( fileSystemRule )
.around( testDir )
.around( pageCacheRule )
.around( SuppressOutput.suppressAll() )
.around( random );
Expand All @@ -116,7 +116,6 @@ public class BackupIT
public String recordFormatName;

private File serverStorePath;
private File serverDatabasePath;
private File otherServerPath;
private File backupDatabasePath;
private List<ServerInterface> servers;
Expand All @@ -132,7 +131,6 @@ public void before()
{
servers = new ArrayList<>();
serverStorePath = testDir.storeDir( "server" );
serverDatabasePath = testDir.databaseDir( serverStorePath );
otherServerPath = testDir.directory( "server2" );
backupDatabasePath = testDir.databaseDir( "backedup-serverdb" );
}
Expand Down Expand Up @@ -202,7 +200,7 @@ public void backedUpDatabaseContainsChecksumOfLastTx() throws Exception
server = null;
PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() );

long firstChecksum = lastTxChecksumOf( serverDatabasePath, pageCache );
long firstChecksum = lastTxChecksumOf( serverStorePath, pageCache );
assertEquals( firstChecksum, lastTxChecksumOf( backupDatabasePath, pageCache ) );

addMoreData( serverStorePath );
Expand All @@ -212,7 +210,7 @@ public void backedUpDatabaseContainsChecksumOfLastTx() throws Exception
shutdownServer( server );
server = null;

long secondChecksum = lastTxChecksumOf( serverDatabasePath, pageCache );
long secondChecksum = lastTxChecksumOf( serverStorePath, pageCache );
assertEquals( secondChecksum, lastTxChecksumOf( backupDatabasePath, pageCache ) );
assertTrue( firstChecksum != secondChecksum );
}
Expand Down Expand Up @@ -296,19 +294,19 @@ public void makeSureStoreIdIsEnforced()
// Data should be OK, but store id check should prevent that.
try
{
backup.incremental( backupDatabasePath.getPath() );
backup.incremental( serverStorePath.getPath() );
fail( "Shouldn't work" );
}
catch ( RuntimeException e )
{
assertThat(e.getCause(), instanceOf(MismatchingStoreIdException.class));
assertThat( e.getCause(), instanceOf( MismatchingStoreIdException.class ) );
}
shutdownServer( server );
// Just make sure incremental backup can be received properly from
// server A, even after a failed attempt from server B
DbRepresentation furtherRepresentation = addMoreData( serverStorePath );
server = startServer( serverStorePath, backupPort );
backup.incremental( backupDatabasePath.getPath() );
backup.incremental( serverStorePath.getPath() );
assertTrue( "Should be consistent", backup.isConsistent() );
assertEquals( furtherRepresentation, getDbRepresentation() );
shutdownServer( server );
Expand Down Expand Up @@ -773,6 +771,6 @@ private DbRepresentation getDbRepresentation()
Config config = Config.builder()
.withSetting( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.withSetting( GraphDatabaseSettings.active_database, backupDatabasePath.getName() ).build();
return DbRepresentation.of( backupDatabasePath.getParentFile(), config );
return DbRepresentation.of( backupDatabasePath , config );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void haShouldFailToStartWithOldStore()
MigrationTestUtils.find23FormatStoreDirectory( databaseDirectory );

new TestHighlyAvailableGraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( storeDirectory )
.newEmbeddedDatabaseBuilder( databaseDirectory )
.setConfig( ClusterSettings.server_id, "1" )
.setConfig( ClusterSettings.initial_hosts, "localhost:9999" )
.newGraphDatabase();
Expand Down

0 comments on commit f634326

Please sign in to comment.