use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.
the class CheckConsistencyCommandIT method databaseAndBackupAreMutuallyExclusive.
@Test
void databaseAndBackupAreMutuallyExclusive() throws Exception {
ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
when(consistencyCheckService.runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
MutuallyExclusiveArgsException incorrectUsage = assertThrows(MutuallyExclusiveArgsException.class, () -> {
CommandLine.populateCommand(checkConsistencyCommand, "--database=foo", "--backup=bar");
checkConsistencyCommand.execute();
});
assertThat(incorrectUsage.getMessage()).contains("--database=<database>, --backup=<path> are mutually exclusive (specify only one)");
}
use of org.neo4j.cli.ExecutionContext 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");
}
use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.
the class CheckConsistencyCommandIT method passesOnCheckParameters.
@Test
void passesOnCheckParameters() throws Exception {
ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
when(consistencyCheckService.runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--check-graph=false", "--check-indexes=false", "--check-index-structure=true");
checkConsistencyCommand.execute();
verify(consistencyCheckService).runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), any(), eq(new ConsistencyFlags(false, false, true)));
}
use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.
the class AdminToolTest method shouldPrintEnvironmentVariablesInHelpUsage.
@Test
void shouldPrintEnvironmentVariablesInHelpUsage() {
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
try (PrintStream out = new PrintStream(outBuffer);
PrintStream err = new PrintStream(errBuffer)) {
assertEquals(2, AdminTool.execute(new ExecutionContext(directory.homePath(), directory.directory("conf"), out, err, directory.getFileSystem())));
}
String outString = outBuffer.toString();
assertTrue(outString.contains("Environment variables"));
assertTrue(outString.contains("NEO4J_HOME"));
assertTrue(outString.contains("NEO4J_CONF"));
}
use of org.neo4j.cli.ExecutionContext 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());
}
}
Aggregations