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?"));
}
}
}
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"));
}
}
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"));
}
}
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"));
}
}
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);
}
}
Aggregations