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);
}
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."));
}
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());
}
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));
}
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.");
}
}
Aggregations