Search in sources :

Example 11 with ExecutionContext

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)");
}
Also used : MutuallyExclusiveArgsException(picocli.CommandLine.MutuallyExclusiveArgsException) ExecutionContext(org.neo4j.cli.ExecutionContext) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) Test(org.junit.jupiter.api.Test)

Example 12 with ExecutionContext

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");
}
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 13 with ExecutionContext

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)));
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) Test(org.junit.jupiter.api.Test)

Example 14 with ExecutionContext

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"));
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 15 with ExecutionContext

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());
    }
}
Also used : Path(java.nio.file.Path) ExecutionContext(org.neo4j.cli.ExecutionContext) FileSystem(java.nio.file.FileSystem) URI(java.net.URI) CommandFailedException(org.neo4j.cli.CommandFailedException) 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