Search in sources :

Example 26 with ExecutionContext

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

the class SetDefaultAdminCommandIT method execute.

private void execute(String username) {
    final var command = new SetDefaultAdminCommand(new ExecutionContext(homeDir, confDir, out, err, fileSystem));
    CommandLine.populateCommand(command, username);
    command.execute();
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext)

Example 27 with ExecutionContext

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

the class DiagnosticsReportCommandTest method printUsageHelp.

@Test
void printUsageHelp() {
    final var baos = new ByteArrayOutputStream();
    final var command = new DiagnosticsReportCommand(new ExecutionContext(Path.of("."), Path.of(".")));
    try (var out = new PrintStream(baos)) {
        CommandLine.usage(command, new PrintStream(out), CommandLine.Help.Ansi.OFF);
    }
    assertThat(baos.toString().trim()).isEqualTo(String.format("Produces a zip/tar of the most common information needed for remote assessments.%n" + "%n" + "USAGE%n" + "%n" + "report [--expand-commands] [--force] [--list] [--verbose] [--pid=<pid>]%n" + "       [--to=<path>] [<classifier>...]%n" + "%n" + "DESCRIPTION%n" + "%n" + "Will collect information about the system and package everything in an archive.%n" + "If you specify 'all', everything will be included. You can also fine tune the%n" + "selection by passing classifiers to the tool, e.g 'logs tx threads'.%n" + "%n" + "PARAMETERS%n" + "%n" + "      [<classifier>...]     Default: [config, logs, metrics, plugins, ps,%n" + "                            sysprop, threads, tree, version]%n" + "%n" + "OPTIONS%n" + "%n" + "      --verbose           Enable verbose output.%n" + "      --expand-commands   Allow command expansion in config value evaluation.%n" + "      --list              List all available classifiers%n" + "      --force             Ignore disk full warning%n" + "      --to=<path>         Destination directory for reports. Defaults to a%n" + "                            system tmp directory.%n" + "      --pid=<pid>         Specify process id of running neo4j instance"));
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 28 with ExecutionContext

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

the class DiagnosticsReportCommandTest method listShouldDisplayAllClassifiers.

@Test
void listShouldDisplayAllClassifiers() throws Exception {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        PrintStream ps = new PrintStream(baos);
        String[] args = { "--list" };
        ctx = new ExecutionContext(homeDir, configDir, ps, System.err, fs);
        DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
        CommandLine.populateCommand(diagnosticsReportCommand, args);
        diagnosticsReportCommand.execute();
        assertThat(baos.toString()).isEqualTo(String.format("Finding running instance of neo4j%n" + "No running instance of neo4j was found. Online reports will be omitted.%n" + "If neo4j is running but not detected, you can supply the process id of the running instance with --pid%n" + "All available classifiers:%n" + "  config     include configuration file%n" + "  logs       include log files%n" + "  plugins    include a view of the plugin directory%n" + "  ps         include a list of running processes%n" + "  tree       include a view of the tree structure of the data directory%n" + "  tx         include transaction logs%n" + "  version    include version of neo4j%n"));
    }
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 29 with ExecutionContext

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

the class DiagnosticsReportCommandTest method setUp.

@BeforeEach
void setUp() throws Exception {
    homeDir = testDirectory.directory("home-dir");
    configDir = testDirectory.directory("config-dir");
    // Touch config
    configFile = configDir.resolve("neo4j.conf");
    Files.createFile(configFile);
    // To make sure files are resolved from the working directory
    originalUserDir = System.setProperty("user.dir", testDirectory.absolutePath().toString());
    ctx = new ExecutionContext(homeDir, configDir, System.out, System.err, fs);
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with ExecutionContext

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

the class LoadCommandTest method infoMustPrintArchiveMetaData.

@Test
void infoMustPrintArchiveMetaData() throws IOException {
    when(loader.getMetaData(archive)).thenReturn(new Loader.DumpMetaData("ZSTD", "42", "1337"));
    var baos = new ByteArrayOutputStream();
    try (PrintStream out = new PrintStream(baos)) {
        Path dir = Path.of(".");
        var command = new LoadCommand(new ExecutionContext(dir, dir, out, out, testDirectory.getFileSystem()), loader);
        CommandLine.populateCommand(command, "--info", "--from", archive.toAbsolutePath().toString());
        command.execute();
        out.flush();
    }
    String output = baos.toString();
    assertThat(output).contains("ZSTD", "42", "1337");
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) Loader(org.neo4j.dbms.archive.Loader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionContext (org.neo4j.cli.ExecutionContext)38 Test (org.junit.jupiter.api.Test)30 PrintStream (java.io.PrintStream)21 CheckConsistencyCommand (org.neo4j.consistency.CheckConsistencyCommand)13 Path (java.nio.file.Path)12 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)10 Config (org.neo4j.configuration.Config)8 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)8 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)5 LogProvider (org.neo4j.logging.LogProvider)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 CommandFailedException (org.neo4j.cli.CommandFailedException)4 MemoryRecommendationsCommand.bytesToString (org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString)4 FileSystem (java.nio.file.FileSystem)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.matchingJsonPath (com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath)1