Skip to content

Commit

Permalink
added log collection to dump/load backup/restore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyowen committed Aug 27, 2024
1 parent eb6f3eb commit 5f48de3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ private void testCanBackupAndRestore(boolean asDefaultUser, String password) thr
{
final String dbUser = "neo4j";
Path backupDir;
Path adminLogDir;

// BACKUP
// start a database and populate data
try(GenericContainer neo4j = createDBContainer( asDefaultUser, password ))
{
temporaryFolderManager.createFolderAndMountAsVolume(neo4j, "/logs");
Path dataDir = temporaryFolderManager.createFolderAndMountAsVolume(neo4j, "/data");
neo4j.start();
DatabaseIO dbio = new DatabaseIO( neo4j );
Expand All @@ -129,7 +131,7 @@ private void testCanBackupAndRestore(boolean asDefaultUser, String password) thr
"--include-metadata=all",
"--from=" + neoDBAddress,
"neo4j" );

adminLogDir = temporaryFolderManager.createNamedFolderAndMountAsVolume(adminBackup, "admin-logs", "/logs");
backupDir = temporaryFolderManager.createFolderAndMountAsVolume(adminBackup, "/backups");
adminBackup.start();

Expand Down Expand Up @@ -164,6 +166,7 @@ private void testCanBackupAndRestore(boolean asDefaultUser, String password) thr
"--overwrite-destination=true",
"--from-path=/backups/" + backupFile.getName(),
"neo4j" );
temporaryFolderManager.mountHostFolderAsVolume( adminRestore, adminLogDir, "/logs" );
temporaryFolderManager.mountHostFolderAsVolume( adminRestore, backupDir, "/backups" );
temporaryFolderManager.mountHostFolderAsVolume( adminRestore, dataDir, "/data" );
adminRestore.start();
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/com/neo4j/docker/neo4jadmin/TestDumpLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ private void shouldCreateDumpAndLoadDump( boolean asDefaultUser, String password
Path firstDataDir;
Path secondDataDir;
Path backupDir;
Path logs;
Path adminLogs;

// start a database and populate it
try(GenericContainer container = createDBContainer( asDefaultUser, password ))
{
logs = temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs");
firstDataDir = temporaryFolderManager.createNamedFolderAndMountAsVolume(container,"data1", "/data");
container.start();
DatabaseIO dbio = new DatabaseIO( container );
Expand All @@ -114,9 +117,10 @@ private void shouldCreateDumpAndLoadDump( boolean asDefaultUser, String password
// use admin container to create dump
try(GenericContainer admin = createAdminContainer( asDefaultUser ))
{
temporaryFolderManager.mountHostFolderAsVolume( admin, firstDataDir, "/data" );
adminLogs = temporaryFolderManager.createNamedFolderAndMountAsVolume(admin,"admin-logs", "/logs");
temporaryFolderManager.mountHostFolderAsVolume(admin, firstDataDir, "/data");
backupDir = temporaryFolderManager.createFolderAndMountAsVolume(admin, "/backups");
admin.withCommand( "neo4j-admin", "database", "dump", "neo4j", "--to-path=/backups" );
admin.withCommand("neo4j-admin", "database", "dump", "neo4j", "--to-path=/backups");
admin.start();
}
Assertions.assertTrue( backupDir.resolve( "neo4j.dump" ).toFile().exists(), "dump file not created");
Expand All @@ -126,6 +130,7 @@ private void shouldCreateDumpAndLoadDump( boolean asDefaultUser, String password
try(GenericContainer admin = createAdminContainer( asDefaultUser ))
{
secondDataDir = temporaryFolderManager.createNamedFolderAndMountAsVolume(admin, "data2", "/data");
temporaryFolderManager.mountHostFolderAsVolume(admin, adminLogs, "/logs");
temporaryFolderManager.mountHostFolderAsVolume( admin, backupDir, "/backups" );
admin.withCommand( "neo4j-admin", "database", "load", "neo4j", "--from-path=/backups" );
admin.start();
Expand All @@ -134,6 +139,7 @@ private void shouldCreateDumpAndLoadDump( boolean asDefaultUser, String password
// verify data in 2nd data directory by starting a database and verifying data we populated earlier
try(GenericContainer container = createDBContainer( asDefaultUser, password ))
{
temporaryFolderManager.mountHostFolderAsVolume(container, logs, "/logs");
temporaryFolderManager.mountHostFolderAsVolume( container, secondDataDir, "/data" );
container.start();
DatabaseIO dbio = new DatabaseIO( container );
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/neo4j/docker/utils/Neo4jWaitStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ protected void waitUntilReady()
String fullCommand =
"if [ -f /var/lib/neo4j/run/neo4j.pid ]; then\n" +
doThreadDumpCmd + "\n" +
"else\n" +
"echo \"could not dump threads, Neo4j is not running.\"\n" +
"fi";
"else\n" +
"echo >&2 \"could not dump threads, Neo4j is not running.\"\n" +
"fi";
Container.ExecResult threadDumpResponse = waitStrategyTarget.execInContainer("sh", "-c", fullCommand);
log.warn(threadDumpResponse.getStderr());
}
Expand Down

0 comments on commit 5f48de3

Please sign in to comment.