Search in sources :

Example 21 with CommandFailedException

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

the class DumpCommandIT method shouldGiveAClearErrorIfTheArchiveAlreadyExists.

@Test
void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws Exception {
    doThrow(new FileAlreadyExistsException("the-archive-path")).when(dumper).dump(any(), any(), any(), any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
    assertEquals("Archive already exists: the-archive-path", commandFailed.getMessage());
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 22 with CommandFailedException

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

the class DumpCommandIT method shouldGiveAClearMessageIfTheDatabaseDoesntExist.

@Test
void shouldGiveAClearMessageIfTheDatabaseDoesntExist() {
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("bobo"));
    assertEquals("Database does not exist: bobo", commandFailed.getMessage());
}
Also used : CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 23 with CommandFailedException

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

the class DiagnosticsReportCommandTest method allHasToBeOnlyClassifier.

@Test
void allHasToBeOnlyClassifier() throws Exception {
    String[] args = { "all", "logs", "tx" };
    DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
    CommandLine.populateCommand(diagnosticsReportCommand, args);
    CommandFailedException incorrectUsage = assertThrows(CommandFailedException.class, diagnosticsReportCommand::execute);
    assertEquals("If you specify 'all' this has to be the only classifier. Found ['logs','tx'] as well.", incorrectUsage.getMessage());
}
Also used : CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 24 with CommandFailedException

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

the class DumpCommand method execute.

@Override
public void execute() {
    var databaseName = database.name();
    Path archive = buildArchivePath(databaseName, to.toAbsolutePath());
    var memoryTracker = EmptyMemoryTracker.INSTANCE;
    Config config = CommandHelpers.buildConfig(ctx, allowCommandExpansion);
    DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(databaseName);
    try {
        Validators.CONTAINS_EXISTING_DATABASE.validate(databaseLayout.databaseDirectory());
    } catch (IllegalArgumentException e) {
        throw new CommandFailedException("Database does not exist: " + databaseName, e);
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        if (fileSystem.fileExists(databaseLayout.file(StoreUpgrader.MIGRATION_DIRECTORY))) {
            throw new CommandFailedException("Store migration folder detected - A dump can not be taken during a store migration. Make sure " + "store migration is completed before trying again.");
        }
    } catch (IOException e) {
        wrapIOException(e);
    }
    try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
        checkDbState(databaseLayout, config, memoryTracker);
        dump(databaseLayout, archive);
    } catch (FileLockException e) {
        throw new CommandFailedException("The database is in use. Stop database '" + databaseName + "' and try again.", e);
    } catch (IOException e) {
        wrapIOException(e);
    } catch (CannotWriteException e) {
        throw new CommandFailedException("You do not have permission to dump the database.", e);
    }
}
Also used : Path(java.nio.file.Path) FileLockException(org.neo4j.kernel.internal.locker.FileLockException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 25 with CommandFailedException

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

the class LoadCommandTest method shouldThrowIfTheArchiveFormatIsInvalid.

@Test
void shouldThrowIfTheArchiveFormatIsInvalid() throws IOException, IncorrectFormat {
    doThrow(IncorrectFormat.class).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertThat(commandFailed.getMessage()).contains(archive.toString());
    assertThat(commandFailed.getMessage()).contains("valid Neo4j archive");
}
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