Search in sources :

Example 6 with CommandFailedException

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

the class CheckConsistencyCommandIT method backupNeedsToBePath.

@Test
void backupNeedsToBePath() {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    Path backupPath = homeDir.resolve("dir/does/not/exist");
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> {
        CommandLine.populateCommand(checkConsistencyCommand, "--backup=" + backupPath);
        checkConsistencyCommand.execute();
    });
    assertThat(commandFailed.getMessage()).contains("Report directory path doesn't exist or not a directory");
}
Also used : Path(java.nio.file.Path) ExecutionContext(org.neo4j.cli.ExecutionContext) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 7 with CommandFailedException

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

the class DumpCommandIT method shouldGiveAClearMessageIfTheArchivesParentDoesntExist.

@Test
void shouldGiveAClearMessageIfTheArchivesParentDoesntExist() throws Exception {
    doThrow(new NoSuchFileException(archive.getParent().toString())).when(dumper).dump(any(), any(), any(), any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
    assertEquals("Unable to dump database: NoSuchFileException: " + archive.getParent(), commandFailed.getMessage());
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 8 with CommandFailedException

use of org.neo4j.cli.CommandFailedException 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());
    }
}
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 9 with CommandFailedException

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

the class DumpCommandIT method databaseThatRequireRecoveryIsNotDumpable.

@Test
void databaseThatRequireRecoveryIsNotDumpable() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, testDirectory.getFileSystem()).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).withStoreId(StoreId.UNKNOWN).build();
    try (Lifespan ignored = new Lifespan(logFiles)) {
        LogFile logFile = logFiles.getLogFile();
        LogEntryWriter writer = logFile.getTransactionLogWriter().getWriter();
        writer.writeStartEntry(0x123456789ABCDEFL, logFile.getLogFileInformation().getLastEntryId() + 1, BASE_TX_CHECKSUM, new byte[] { 0 });
    }
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
    assertThat(commandFailed.getMessage()).startsWith("Active logical log detected, this might be a source of inconsistencies.");
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 10 with CommandFailedException

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

the class DumpCommandIT method shouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.

@Test
void shouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws Exception {
    doThrow(new IOException("the-message")).when(dumper).dump(any(), any(), any(), any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
    assertEquals("Unable to dump database: IOException: the-message", commandFailed.getMessage());
}
Also used : IOException(java.io.IOException) 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