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