Search in sources :

Example 1 with DatabaseLocker

use of org.neo4j.kernel.internal.locker.DatabaseLocker 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 2 with DatabaseLocker

use of org.neo4j.kernel.internal.locker.DatabaseLocker in project neo4j by neo4j.

the class DumpCommandIT method shouldRespectTheDatabaseLock.

@Test
void shouldRespectTheDatabaseLock() throws Exception {
    Path databaseDirectory = homeDir.resolve("data/databases/foo");
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        Locker locker = new DatabaseLocker(fileSystem, databaseLayout)) {
        locker.checkLock();
        CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("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 3 with DatabaseLocker

use of org.neo4j.kernel.internal.locker.DatabaseLocker in project neo4j by neo4j.

the class StoreInfoCommandTest method doesNotThrowWhenUsingAllAndSomeDatabasesLocked.

@Test
void doesNotThrowWhenUsingAllAndSomeDatabasesLocked() throws IOException {
    // given
    var currentFormat = RecordFormatSelector.defaultFormat();
    var barDbDirectory = homeDir.resolve("data/databases/bar");
    var barDbLayout = DatabaseLayout.ofFlat(barDbDirectory);
    fileSystem.mkdirs(barDbDirectory);
    prepareNeoStoreFile(currentFormat.storeVersion(), fooDbLayout);
    prepareNeoStoreFile(currentFormat.storeVersion(), barDbLayout);
    var databasesRoot = homeDir.resolve("data/databases");
    var expectedBar = expectedStructuredResult("bar", false, currentFormat.storeVersion(), currentFormat.introductionVersion(), null);
    var expectedFoo = expectedStructuredResult("foo", true, null, null, null);
    var expected = String.format("[%s,%s]", expectedBar, expectedFoo);
    // when
    try (Locker locker = new DatabaseLocker(fileSystem, fooDbLayout)) {
        locker.checkLock();
        CommandLine.populateCommand(command, args(databasesRoot, true, true));
        command.execute();
    }
    verify(out).println(expected);
}
Also used : DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Locker(org.neo4j.kernel.internal.locker.Locker) DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Test(org.junit.jupiter.api.Test)

Example 4 with DatabaseLocker

use of org.neo4j.kernel.internal.locker.DatabaseLocker in project neo4j by neo4j.

the class StoreInfoCommandTest method respectLockFiles.

@Test
void respectLockFiles() throws IOException {
    var currentFormat = RecordFormatSelector.defaultFormat();
    prepareNeoStoreFile(currentFormat.storeVersion(), fooDbLayout);
    try (Locker locker = new DatabaseLocker(fileSystem, fooDbLayout)) {
        locker.checkLock();
        CommandLine.populateCommand(command, fooDbDirectory.toAbsolutePath().toString());
        var exception = assertThrows(Exception.class, () -> command.execute());
        assertEquals("Failed to execute command as the database 'foo' is in use. Please stop it and try again.", exception.getMessage());
    }
}
Also used : DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Locker(org.neo4j.kernel.internal.locker.Locker) DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Test(org.junit.jupiter.api.Test)

Example 5 with DatabaseLocker

use of org.neo4j.kernel.internal.locker.DatabaseLocker in project neo4j by neo4j.

the class BatchInserterImplTest method testFailsOnExistingStoreLockFile.

@Test
void testFailsOnExistingStoreLockFile() throws IOException {
    try (Locker lock = new DatabaseLocker(fileSystem, databaseLayout)) {
        lock.checkLock();
        var e = assertThrows(FileLockException.class, () -> BatchInserters.inserter(databaseLayout, fileSystem));
        assertThat(e.getMessage()).startsWith("Unable to obtain lock on file");
    }
}
Also used : DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Locker(org.neo4j.kernel.internal.locker.Locker) DatabaseLocker(org.neo4j.kernel.internal.locker.DatabaseLocker) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 DatabaseLocker (org.neo4j.kernel.internal.locker.DatabaseLocker)5 Locker (org.neo4j.kernel.internal.locker.Locker)5 Path (java.nio.file.Path)2 CommandFailedException (org.neo4j.cli.CommandFailedException)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)2