use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DumpCommandIT method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.
@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(databaseDirectory);
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
Path file = databaseLayout.databaseLockFile();
try (Closeable ignored = withPermissions(file, emptySet())) {
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
assertEquals("You do not have permission to dump the database.", commandFailed.getMessage());
}
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommandIT method shouldBeAbleToAttachToPidAndRunThreadDump.
@Test
void shouldBeAbleToAttachToPidAndRunThreadDump() throws IOException {
long pid = getPID();
assertThat(pid).isNotEqualTo(0);
// Write config file
Files.createFile(testDirectory.file("neo4j.conf"));
// write neo4j.pid file
Path run = testDirectory.directory("run");
Files.write(run.resolve("neo4j.pid"), String.valueOf(pid).getBytes());
// Run command, should detect running instance
try {
String[] args = { "threads", "--to=" + testDirectory.absolutePath() + "/reports" };
Path homeDir = testDirectory.homePath();
var ctx = new ExecutionContext(homeDir, homeDir, System.out, System.err, testDirectory.getFileSystem());
DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
CommandLine.populateCommand(diagnosticsReportCommand, args);
diagnosticsReportCommand.execute();
} catch (CommandFailedException e) {
if (e.getMessage().equals("Unknown classifier: threads")) {
// If we get attach API is not available for example in some IBM jdk installs, ignore this test
return;
}
throw e;
}
// Verify that we took a thread dump
Path reports = testDirectory.directory("reports");
Path[] files = FileUtils.listPaths(reports);
assertThat(files).isNotNull();
assertThat(files.length).isEqualTo(1);
Path report = files[0];
final URI uri = URI.create("jar:file:" + report.toUri().getRawPath());
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
String threadDump = Files.readString(fs.getPath("threaddump.txt"));
assertThat(threadDump).contains(DiagnosticsReportCommandIT.class.getCanonicalName());
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommandTest method exitIfConfigFileIsMissing.
@Test
void exitIfConfigFileIsMissing() throws IOException {
Files.delete(configFile);
String[] args = { "--list" };
DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
CommandLine.populateCommand(diagnosticsReportCommand, args);
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, diagnosticsReportCommand::execute);
assertThat(commandFailed.getMessage()).contains("Unable to find config file, tried: ");
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommandTest method printUnrecognizedClassifiers.
@Test
void printUnrecognizedClassifiers() throws Exception {
String[] args = { "logs", "tx", "invalid" };
DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
CommandLine.populateCommand(diagnosticsReportCommand, args);
CommandFailedException incorrectUsage = assertThrows(CommandFailedException.class, diagnosticsReportCommand::execute);
assertEquals("Unknown classifier: invalid", incorrectUsage.getMessage());
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DumpCommand method dump.
private void dump(DatabaseLayout databaseLayout, Path archive) {
Path databasePath = databaseLayout.databaseDirectory();
try {
var format = selectCompressionFormat(ctx.err());
var lockFile = databaseLayout.databaseLockFile().getFileName().toString();
var quarantineMarkerFile = databaseLayout.quarantineMarkerFile().getFileName().toString();
dumper.dump(databasePath, databaseLayout.getTransactionLogsDirectory(), archive, format, path -> oneOf(path, lockFile, quarantineMarkerFile));
} catch (FileAlreadyExistsException e) {
throw new CommandFailedException("Archive already exists: " + e.getMessage(), e);
} catch (NoSuchFileException e) {
if (Paths.get(e.getMessage()).toAbsolutePath().equals(databasePath)) {
throw new CommandFailedException("Database does not exist: " + databaseLayout.getDatabaseName(), e);
}
wrapIOException(e);
} catch (IOException e) {
wrapIOException(e);
}
}
Aggregations