### Question:
DumpCommand implements AdminCommand { @Override public void execute( String[] args ) throws IncorrectUsage, CommandFailed { String database = arguments.parse( args ).get( ARG_DATABASE ); Path archive = calculateArchive( database, arguments.getMandatoryPath( "to" ) ); Config config = buildConfig( database ); Path databaseDirectory = canonicalPath( getDatabaseDirectory( config ) ); DatabaseLayout databaseLayout = DatabaseLayout.of( databaseDirectory.toFile() ); Path transactionLogsDirectory = canonicalPath( getTransactionalLogsDirectory( config ) ); try { Validators.CONTAINS_EXISTING_DATABASE.validate( databaseLayout.databaseDirectory() ); } catch ( IllegalArgumentException e ) { throw new CommandFailed( "database does not exist: " + database, e ); } try ( Closeable ignored = StoreLockChecker.check( databaseLayout.getStoreLayout() ) ) { checkDbState( databaseLayout, config ); dump( database, databaseLayout, transactionLogsDirectory, archive ); } catch ( StoreLockException e ) { throw new CommandFailed( "the database is in use -- stop Neo4j and try again", e ); } catch ( IOException e ) { wrapIOException( e ); } catch ( CannotWriteException e ) { throw new CommandFailed( "you do not have permission to dump the database -- is Neo4j running as a different user?", e ); } } DumpCommand( Path homeDir, Path configDir, Dumper dumper, PrintStream output ); @Override void execute( String[] args ); static Arguments arguments();  }### Answer:
@Test void shouldReleaseTheStoreLockAfterDumping() throws Exception { execute( "foo.db" ); assertCanLockStore( databaseDirectory ); }
@Test @DisabledOnOs( OS.WINDOWS ) void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception { StoreLayout storeLayout = DatabaseLayout.of( databaseDirectory.toFile() ).getStoreLayout(); try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); StoreLocker storeLocker = new StoreLocker( fileSystem, storeLayout ) ) { storeLocker.checkLock(); try ( Closeable ignored = withPermissions( storeLayout.storeLockFile().toPath(), emptySet() ) ) { assumeFalse( storeLayout.storeLockFile().canWrite() ); CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db" ) ); assertEquals( commandFailed.getMessage(), "you do not have permission to dump the database -- is Neo4j running as a different user?" ); } } }
@Test void shouldObjectIfTheArchiveArgumentIsMissing() { IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> new DumpCommand( homeDir, configDir, null, output ).execute( new String[]{"--database=something"} ) ); assertEquals( "Missing argument 'to'", exception.getMessage() ); }
@Test void shouldGiveAClearMessageIfTheDatabaseDoesntExist() { CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "bobo.db" ) ); assertEquals( "database does not exist: bobo.db", commandFailed.getMessage() ); }
@Test void shouldRespectTheStoreLock() throws Exception { Path databaseDirectory = homeDir.resolve( "data/databases/foo.db" ); StoreLayout storeLayout = DatabaseLayout.of( databaseDirectory.toFile() ).getStoreLayout(); try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); StoreLocker storeLocker = new StoreLocker( fileSystem, storeLayout ) ) { storeLocker.checkLock(); CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db" ) ); assertEquals( "the database is in use -- stop Neo4j and try again", commandFailed.getMessage() ); } }
@Test void databaseThatRequireRecoveryIsNotDumpable() throws IOException { File logFile = new File( databaseDirectory.toFile(), TransactionLogFiles.DEFAULT_NAME + ".0" ); try ( FileWriter fileWriter = new FileWriter( logFile ) ) { fileWriter.write( "brb" ); } CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db" ) ); assertThat( commandFailed.getMessage(), startsWith( "Active logical log detected, this might be a source of inconsistencies." ) ); }