Search in sources :

Example 1 with CommandFailedException

use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.

the class LoadCommandTest method shouldGiveAClearMessageIfTheDatabasesDirectoryIsNotWritable.

@Test
void shouldGiveAClearMessageIfTheDatabasesDirectoryIsNotWritable() throws IOException, IncorrectFormat {
    doThrow(AccessDeniedException.class).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertEquals("You do not have permission to load the database.", commandFailed.getMessage());
}
Also used : CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 2 with CommandFailedException

use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.

the class LoadCommandTest method shouldGiveAClearMessageIfTheArchiveDoesntExist.

@Test
void shouldGiveAClearMessageIfTheArchiveDoesntExist() throws IOException, IncorrectFormat {
    doThrow(new NoSuchFileException(archive.toString())).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertEquals("Archive does not exist: " + archive, commandFailed.getMessage());
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 3 with CommandFailedException

use of org.neo4j.cli.CommandFailedException 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 4 with CommandFailedException

use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.

the class LoadCommandTest method shouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.

@Test
void shouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws IOException, IncorrectFormat {
    doThrow(new FileSystemException("the-message")).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertEquals("Unable to load database: FileSystemException: the-message", commandFailed.getMessage());
}
Also used : FileSystemException(java.nio.file.FileSystemException) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 5 with CommandFailedException

use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.

the class LoadCommandTest method shouldGiveAClearMessageIfTheDatabaseAlreadyExists.

@Test
void shouldGiveAClearMessageIfTheDatabaseAlreadyExists() throws IOException, IncorrectFormat {
    doThrow(FileAlreadyExistsException.class).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertEquals("Database already exists: foo", commandFailed.getMessage());
}
Also used : CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Aggregations

CommandFailedException (org.neo4j.cli.CommandFailedException)34 Test (org.junit.jupiter.api.Test)20 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 Config (org.neo4j.configuration.Config)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 Closeable (java.io.Closeable)5 ExecutionContext (org.neo4j.cli.ExecutionContext)5 FileLockException (org.neo4j.kernel.internal.locker.FileLockException)5 NoSuchFileException (java.nio.file.NoSuchFileException)3 CheckConsistencyCommand (org.neo4j.consistency.CheckConsistencyCommand)3 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)2 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)2 DatabaseLocker (org.neo4j.kernel.internal.locker.DatabaseLocker)2 Locker (org.neo4j.kernel.internal.locker.Locker)2