Search in sources :

Example 31 with ExecutionContext

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

the class LoadCommandTest method buildCommand.

private LoadCommand buildCommand() {
    PrintStream out = mock(PrintStream.class);
    PrintStream err = mock(PrintStream.class);
    FileSystemAbstraction fileSystem = testDirectory.getFileSystem();
    return new LoadCommand(new ExecutionContext(homeDir, configDir, out, err, fileSystem), loader);
}
Also used : PrintStream(java.io.PrintStream) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ExecutionContext(org.neo4j.cli.ExecutionContext)

Example 32 with ExecutionContext

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

the class LoadCommandTest method printUsageHelp.

@Test
void printUsageHelp() {
    var baos = new ByteArrayOutputStream();
    var command = new LoadCommand(new ExecutionContext(Path.of("."), Path.of(".")), loader);
    try (var out = new PrintStream(baos)) {
        CommandLine.usage(command, new PrintStream(out), CommandLine.Help.Ansi.OFF);
    }
    assertThat(baos.toString().trim()).isEqualTo(String.format("Load a database from an archive created with the dump command.%n" + "%n" + "USAGE%n" + "%n" + "load [--expand-commands] [--force] [--info] [--verbose] [--database=<database>]%n" + "     --from=<path>%n" + "%nDESCRIPTION%n" + "%n" + "Load a database from an archive. <archive-path> must be an archive created with%n" + "the dump command. <database> is the name of the database to create. Existing%n" + "databases can be replaced by specifying --force. It is not possible to replace%n" + "a database that is mounted in a running Neo4j server. If --info is specified,%n" + "then the database is not loaded, but information (i.e. file count, byte count,%n" + "and format of load file) about the archive is printed instead.%n" + "%n" + "OPTIONS%n" + "%n" + "      --verbose           Enable verbose output.%n" + "      --expand-commands   Allow command expansion in config value evaluation.%n" + "      --from=<path>       Path to archive created with the dump command.%n" + "      --database=<database>%n" + "                          Name of the database to load.%n" + "                            Default: neo4j%n" + "      --force             If an existing database should be replaced.%n" + "      --info              Print meta-data information about the archive file,%n" + "                            instead of loading the contained database."));
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 33 with ExecutionContext

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

the class CheckConsistencyCommandIT method failsWhenInconsistenciesAreFound.

@Test
void failsWhenInconsistenciesAreFound() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    when(consistencyCheckService.runFullConsistencyCheck(any(DatabaseLayout.class), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(true), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.failure(Path.of("/the/report/path"), new ConsistencySummaryStatistics()));
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> {
        CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--verbose");
        checkConsistencyCommand.execute();
    });
    assertThat(commandFailed.getMessage()).contains(Path.of("/the/report/path").toString());
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ExecutionContext(org.neo4j.cli.ExecutionContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) CommandFailedException(org.neo4j.cli.CommandFailedException) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.jupiter.api.Test)

Example 34 with ExecutionContext

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

the class CheckConsistencyCommandIT method runsConsistencyChecker.

@Test
void runsConsistencyChecker() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    DatabaseLayout databaseLayout = neo4jLayout.databaseLayout("mydb");
    when(consistencyCheckService.runFullConsistencyCheck(eq(databaseLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.success(null, null));
    CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb");
    checkConsistencyCommand.execute();
    verify(consistencyCheckService).runFullConsistencyCheck(eq(databaseLayout), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(false), any(), any(ConsistencyFlags.class));
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ExecutionContext(org.neo4j.cli.ExecutionContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) Test(org.junit.jupiter.api.Test)

Example 35 with ExecutionContext

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

the class CheckConsistencyCommandIT method consistencyCheckerRespectDatabaseLock.

@Test
void consistencyCheckerRespectDatabaseLock() throws CannotWriteException, IOException {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
    DatabaseLayout databaseLayout = neo4jLayout.databaseLayout("mydb");
    testDirectory.getFileSystem().mkdirs(databaseLayout.databaseDirectory());
    try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
        CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--verbose");
        CommandFailedException exception = assertThrows(CommandFailedException.class, checkConsistencyCommand::execute);
        assertThat(exception.getCause()).isInstanceOf(FileLockException.class);
        assertThat(exception.getMessage()).isEqualTo("The database is in use. Stop database 'mydb' and try again.");
    }
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) 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