Search in sources :

Example 21 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class LoadCommandTest method shouldRespectTheDatabaseLock.

@Test
void shouldRespectTheDatabaseLock() throws IOException {
    Path databaseDirectory = homeDir.resolve("data/databases/foo");
    Files.createDirectories(databaseDirectory);
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        Locker locker = new DatabaseLocker(fileSystem, databaseLayout)) {
        locker.checkLock();
        CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> executeForce("foo"));
        assertEquals("The database is in use. Stop database 'foo' and try again.", commandFailed.getMessage());
    }
}
Also used : Path(java.nio.file.Path) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Locker(org.neo4j.kernel.internal.locker.Locker) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 22 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class LoadCommandTest method shouldHandleSymlinkToDatabaseDir.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldHandleSymlinkToDatabaseDir() throws IOException, CommandFailedException, IncorrectFormat {
    Path symDir = testDirectory.directory("path-to-links");
    Path realDatabaseDir = symDir.resolve("foo");
    Path dataDir = testDirectory.directory("some-other-path");
    Path databaseDir = dataDir.resolve("databases/foo");
    Path txLogsDir = dataDir.resolve(DEFAULT_TX_LOGS_ROOT_DIR_NAME);
    Path databasesDir = dataDir.resolve("databases");
    Files.createDirectories(realDatabaseDir);
    Files.createDirectories(databasesDir);
    Files.createSymbolicLink(databaseDir, realDatabaseDir);
    Files.write(configDir.resolve(Config.DEFAULT_CONFIG_FILE_NAME), singletonList(formatProperty(data_directory, dataDir)));
    execute("foo", archive);
    DatabaseLayout databaseLayout = createDatabaseLayout(dataDir, databasesDir, "foo", txLogsDir);
    verify(loader).load(any(), eq(databaseLayout));
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 23 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class ArchiveTest method dumpAndLoadTransactionLogsFromCustomLocations.

@ParameterizedTest
@EnumSource(CompressionFormat.class)
void dumpAndLoadTransactionLogsFromCustomLocations(CompressionFormat compressionFormat) throws IOException, IncorrectFormat {
    Path txLogsRoot = testDirectory.directory("txLogsRoot");
    DatabaseLayout testDatabaseLayout = layoutWithCustomTxRoot(txLogsRoot, "testDatabase");
    Files.createDirectories(testDatabaseLayout.databaseDirectory());
    Path txLogsDirectory = testDatabaseLayout.getTransactionLogsDirectory();
    Files.createDirectories(txLogsDirectory);
    Files.write(testDatabaseLayout.databaseDirectory().resolve("dbfile"), new byte[0]);
    Files.write(txLogsDirectory.resolve(TransactionLogFilesHelper.DEFAULT_NAME + ".0"), new byte[0]);
    Path archive = testDirectory.file("the-archive.dump");
    new Dumper().dump(testDatabaseLayout.databaseDirectory(), txLogsDirectory, archive, compressionFormat, alwaysFalse());
    Path newTxLogsRoot = testDirectory.directory("newTxLogsRoot");
    DatabaseLayout newDatabaseLayout = layoutWithCustomTxRoot(newTxLogsRoot, "the-new-database");
    new Loader().load(archive, newDatabaseLayout);
    Path expectedOutput = testDirectory.directory("expected-output");
    Files.write(expectedOutput.resolve("dbfile"), new byte[0]);
    Path expectedTxLogs = testDirectory.directory("expectedTxLogs");
    Files.write(expectedTxLogs.resolve(TransactionLogFilesHelper.DEFAULT_NAME + ".0"), new byte[0]);
    assertEquals(describeRecursively(expectedOutput), describeRecursively(newDatabaseLayout.databaseDirectory()));
    assertEquals(describeRecursively(expectedTxLogs), describeRecursively(newDatabaseLayout.getTransactionLogsDirectory()));
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class ArchiveTest method assertRoundTrips.

private void assertRoundTrips(Path oldDirectory, CompressionFormat compressionFormat) throws IOException, IncorrectFormat {
    Path archive = testDirectory.file("the-archive.dump");
    new Dumper().dump(oldDirectory, oldDirectory, archive, compressionFormat, alwaysFalse());
    Path newDirectory = testDirectory.file("the-new-directory");
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(newDirectory);
    new Loader().load(archive, databaseLayout);
    assertEquals(describeRecursively(oldDirectory), describeRecursively(newDirectory));
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 25 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class ArchiveTest method shouldExcludeFilesMatchedByTheExclusionPredicate.

@ParameterizedTest
@EnumSource(CompressionFormat.class)
void shouldExcludeFilesMatchedByTheExclusionPredicate(CompressionFormat compressionFormat) throws IOException, IncorrectFormat {
    Path directory = testDirectory.directory("a-directory");
    Files.createDirectories(directory);
    Files.write(directory.resolve("a-file"), new byte[0]);
    Files.write(directory.resolve("another-file"), new byte[0]);
    Path archive = testDirectory.file("the-archive.dump");
    new Dumper().dump(directory, directory, archive, compressionFormat, path -> path.getFileName().toString().equals("another-file"));
    Path txRootDirectory = testDirectory.directory("tx-root_directory");
    DatabaseLayout databaseLayout = layoutWithCustomTxRoot(txRootDirectory, "the-new-directory");
    new Loader().load(archive, databaseLayout);
    Path expectedOutput = testDirectory.directory("expected-output");
    Files.createDirectories(expectedOutput);
    Files.write(expectedOutput.resolve("a-file"), new byte[0]);
    assertEquals(describeRecursively(expectedOutput), describeRecursively(databaseLayout.databaseDirectory()));
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)108 Test (org.junit.jupiter.api.Test)66 Path (java.nio.file.Path)51 Config (org.neo4j.configuration.Config)35 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)24 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)19 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)17 PageCache (org.neo4j.io.pagecache.PageCache)17 IOException (java.io.IOException)16 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)16 Transaction (org.neo4j.graphdb.Transaction)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)9 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)9 CommandFailedException (org.neo4j.cli.CommandFailedException)8 ExecutionContext (org.neo4j.cli.ExecutionContext)8 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)8 Closeable (java.io.Closeable)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7