Search in sources :

Example 16 with ExecutionContext

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

the class DiagnosticsReportCommandIT method shouldHandleRotatedLogFiles.

@Test
void shouldHandleRotatedLogFiles() throws IOException {
    // Write config file and specify a custom name for the neo4j.log file.
    Path confFile = testDirectory.createFile("neo4j.conf");
    Files.write(confFile, singletonList(GraphDatabaseSettings.store_user_log_path.name() + "=custom.neo4j.log.name"));
    // Create some log files that should be found. debug.log has already been created during setup.
    Files.createFile(testDirectory.homePath().resolve("logs/debug.log.1.zip"));
    Files.createFile(testDirectory.homePath().resolve("logs/custom.neo4j.log.name"));
    Files.createFile(testDirectory.homePath().resolve("logs/custom.neo4j.log.name.1"));
    String[] args = { "logs", "--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();
    Path reports = testDirectory.directory("reports");
    Path[] files = FileUtils.listPaths(reports);
    assertThat(files.length).isEqualTo(1);
    try (FileSystem fileSystem = FileSystems.newFileSystem(files[0], null)) {
        Path logsDir = fileSystem.getPath("logs");
        assertTrue(Files.exists(logsDir.resolve("debug.log")));
        assertTrue(Files.exists(logsDir.resolve("debug.log.1.zip")));
        assertTrue(Files.exists(logsDir.resolve("custom.neo4j.log.name")));
        assertTrue(Files.exists(logsDir.resolve("custom.neo4j.log.name.1")));
    }
}
Also used : Path(java.nio.file.Path) ExecutionContext(org.neo4j.cli.ExecutionContext) FileSystem(java.nio.file.FileSystem) Test(org.junit.jupiter.api.Test)

Example 17 with ExecutionContext

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

the class MemoryRecommendationsCommandTest method includeAllDatabasesToMemoryRecommendations.

@Test
void includeAllDatabasesToMemoryRecommendations() throws IOException {
    PrintStream output = mock(PrintStream.class);
    Path homeDir = neo4jLayout.homeDirectory();
    Path configDir = homeDir.resolve("conf");
    Files.createDirectories(configDir);
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createFile(configFile);
    long totalPageCacheSize = 0;
    long totalLuceneIndexesSize = 0;
    for (int i = 0; i < 5; i++) {
        DatabaseLayout databaseLayout = neo4jLayout.databaseLayout("db" + i);
        createDatabaseWithNativeIndexes(homeDir, databaseLayout.getDatabaseName());
        long[] expectedSizes = calculatePageCacheFileSize(databaseLayout);
        totalPageCacheSize += expectedSizes[0];
        totalLuceneIndexesSize += expectedSizes[1];
    }
    DatabaseLayout systemLayout = neo4jLayout.databaseLayout(SYSTEM_DATABASE_NAME);
    long[] expectedSizes = calculatePageCacheFileSize(systemLayout);
    totalPageCacheSize += expectedSizes[0];
    totalLuceneIndexesSize += expectedSizes[1];
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    CommandLine.populateCommand(command, "--memory=8g");
    command.execute();
    final long expectedLuceneIndexesSize = totalLuceneIndexesSize;
    final long expectedPageCacheSize = totalPageCacheSize;
    verify(output).println(contains("Total size of lucene indexes in all databases: " + bytesToString(expectedLuceneIndexesSize)));
    verify(output).println(contains("Total size of data and native indexes in all databases: " + bytesToString(expectedPageCacheSize)));
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 18 with ExecutionContext

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

the class MemoryRecommendationsCommandTest method printUsageHelp.

@Test
void printUsageHelp() {
    final var baos = new ByteArrayOutputStream();
    final var command = new MemoryRecommendationsCommand(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("Print Neo4j heap and pagecache memory settings recommendations.%n" + "%n" + "USAGE%n" + "%n" + "memrec [--docker] [--expand-commands] [--verbose] [--memory=<size>]%n" + "%n" + "DESCRIPTION%n" + "%n" + "Print heuristic memory setting recommendations for the Neo4j JVM heap and%n" + "pagecache. The heuristic is based on the total memory of the system the command%n" + "is running on, or on the amount of memory specified with the --memory argument.%n" + "The heuristic assumes that the system is dedicated to running Neo4j. If this is%n" + "not the case, then use the --memory argument to specify how much memory can be%n" + "expected to be dedicated to Neo4j. The output is formatted such that it can be%n" + "copy-pasted into the neo4j.conf file.%n" + "%n" + "OPTIONS%n" + "%n" + "      --verbose           Enable verbose output.%n" + "      --expand-commands   Allow command expansion in config value evaluation.%n" + "      --memory=<size>     Recommend memory settings with respect to the given%n" + "                            amount of memory, instead of the total memory of%n" + "                            the system running the command.%n" + "      --docker            The recommended memory settings are produced in the%n" + "                            form of environment variables that can be directly%n" + "                            passed to Neo4j docker container."));
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 19 with ExecutionContext

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

the class DumpCommandTest method printUsageHelp.

@Test
void printUsageHelp() {
    final var baos = new ByteArrayOutputStream();
    final var command = new DumpCommand(new ExecutionContext(Path.of("."), Path.of(".")), mock(Dumper.class));
    try (var out = new PrintStream(baos)) {
        CommandLine.usage(command, new PrintStream(out), CommandLine.Help.Ansi.OFF);
    }
    assertThat(baos.toString().trim()).isEqualTo(String.format("Dump a database into a single-file archive.%n" + "%n" + "USAGE%n" + "%n" + "dump [--expand-commands] [--verbose] [--database=<database>] --to=<path>%n" + "%n" + "DESCRIPTION%n" + "%n" + "Dump a database into a single-file archive. The archive can be used by the load%n" + "command. <destination-path> can be a file or directory (in which case a file%n" + "called <database>.dump will be created). It is not possible to dump a database%n" + "that is mounted in a running Neo4j server.%n" + "%n" + "OPTIONS%n" + "%n" + "      --verbose           Enable verbose output.%n" + "      --expand-commands   Allow command expansion in config value evaluation.%n" + "      --database=<database>%n" + "                          Name of the database to dump.%n" + "                            Default: neo4j%n" + "      --to=<path>         Destination (file or folder) of database dump."));
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dumper(org.neo4j.dbms.archive.Dumper) Test(org.junit.jupiter.api.Test)

Example 20 with ExecutionContext

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

the class MemoryRecommendationsCommandTest method canPrintRecommendationsAsDockerEnvVariables.

@Test
void canPrintRecommendationsAsDockerEnvVariables() throws Exception {
    PrintStream output = mock(PrintStream.class);
    Path homeDir = testDirectory.homePath();
    Path configDir = homeDir.resolve("conf");
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createDirectories(configDir);
    store(stringMap(data_directory.name(), homeDir.toString()), configFile);
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    CommandLine.populateCommand(command, "--memory=8g", "--docker");
    String heap = bytesToString(recommendHeapMemory(gibiBytes(8)));
    String pagecache = bytesToString(recommendPageCacheMemory(gibiBytes(8), gibiBytes(2)));
    String offHeap = bytesToString(gibiBytes(2));
    command.execute();
    verify(output).println("EXPORT NEO4J_dbms_memory_heap_initial__size='" + heap + "'");
    verify(output).println("EXPORT NEO4J_dbms_memory_heap_max__size='" + heap + "'");
    verify(output).println("EXPORT NEO4J_dbms_memory_pagecache_size='" + pagecache + "'");
    verify(output).println("EXPORT NEO4J_dbms_memory_off__heap_max__size='" + offHeap + "'");
    verify(output).println("EXPORT NEO4J_dbms_jvm_additional='" + "-XX:+ExitOnOutOfMemoryError" + "'");
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) 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