Search in sources :

Example 1 with StoreLocker

use of org.neo4j.kernel.internal.StoreLocker in project neo4j by neo4j.

the class DumpCommandTest method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.

@Test
public void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
    assumeFalse("We haven't found a way to reliably tests permissions on Windows", SystemUtils.IS_OS_WINDOWS);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker storeLocker = new StoreLocker(fileSystem)) {
        storeLocker.checkLock(databaseDirectory.toFile());
        try (Closeable ignored = withPermissions(databaseDirectory.resolve(StoreLocker.STORE_LOCK_FILENAME), emptySet())) {
            execute("foo.db");
            fail("expected exception");
        } catch (CommandFailed e) {
            assertThat(e.getMessage(), equalTo("you do not have permission to dump the database -- is Neo4j " + "running as a different user?"));
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) StoreLocker(org.neo4j.kernel.internal.StoreLocker) Closeable(java.io.Closeable) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 2 with StoreLocker

use of org.neo4j.kernel.internal.StoreLocker in project neo4j by neo4j.

the class DumpCommandTest method shouldRespectTheStoreLock.

@Test
public void shouldRespectTheStoreLock() throws Exception {
    Path databaseDirectory = homeDir.resolve("data/databases/foo.db");
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker storeLocker = new StoreLocker(fileSystem)) {
        storeLocker.checkLock(databaseDirectory.toFile());
        execute("foo.db");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
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) StoreLocker(org.neo4j.kernel.internal.StoreLocker) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 3 with StoreLocker

use of org.neo4j.kernel.internal.StoreLocker in project neo4j by neo4j.

the class LoadCommandTest method shouldRespectTheStoreLock.

@Test
public void shouldRespectTheStoreLock() throws IOException, IncorrectUsage {
    Path databaseDirectory = homeDir.resolve("data/databases/foo.db");
    Files.createDirectories(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker locker = new StoreLocker(fileSystem)) {
        locker.checkLock(databaseDirectory.toFile());
        execute("foo.db", "--force");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
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) StoreLocker(org.neo4j.kernel.internal.StoreLocker) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 4 with StoreLocker

use of org.neo4j.kernel.internal.StoreLocker in project neo4j by neo4j.

the class RestoreDatabaseCommandTest method forceShouldRespectStoreLock.

@Test
public void forceShouldRespectStoreLock() throws Exception {
    String databaseName = "to";
    Config config = configWith(Config.empty(), databaseName, directory.absolutePath().getAbsolutePath());
    File fromPath = new File(directory.absolutePath(), "from");
    File toPath = config.get(DatabaseManagementSystemSettings.database_path);
    int fromNodeCount = 10;
    int toNodeCount = 20;
    createDbAt(fromPath, fromNodeCount);
    createDbAt(toPath, toNodeCount);
    FileSystemAbstraction fs = fileSystemRule.get();
    try (StoreLocker storeLocker = new StoreLocker(fs)) {
        storeLocker.checkLock(toPath);
        new RestoreDatabaseCommand(fs, fromPath, config, databaseName, true).execute();
        fail("expected exception");
    } catch (Exception e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) StoreLocker(org.neo4j.kernel.internal.StoreLocker) File(java.io.File) Test(org.junit.Test)

Example 5 with StoreLocker

use of org.neo4j.kernel.internal.StoreLocker in project neo4j by neo4j.

the class BatchInserterImplTest method testFailsOnExistingStoreLockFile.

@Test
public void testFailsOnExistingStoreLockFile() throws IOException {
    // Given
    File parent = testDirectory.graphDbDir();
    try (FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction();
        StoreLocker lock = new StoreLocker(fileSystemAbstraction)) {
        lock.checkLock(parent);
        // Then
        expected.expect(StoreLockException.class);
        expected.expectMessage("Unable to obtain lock on store lock file");
        // When
        BatchInserters.inserter(parent.getAbsoluteFile(), fileSystemAbstraction);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) StoreLocker(org.neo4j.kernel.internal.StoreLocker) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 StoreLocker (org.neo4j.kernel.internal.StoreLocker)5 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)4 CommandFailed (org.neo4j.commandline.admin.CommandFailed)3 File (java.io.File)2 Path (java.nio.file.Path)2 Closeable (java.io.Closeable)1 Config (org.neo4j.kernel.configuration.Config)1