diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java index ccd6248f2a0d9..8e069a688d094 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java @@ -52,11 +52,9 @@ public class ConsistencyCheckTool public static void main( String[] args ) throws IOException { - ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(), - new DefaultFileSystemAbstraction(), System.err ); try { - tool.run( args ); + runConsistencyCheckTool( args ); } catch ( ToolFailureException e ) { @@ -64,6 +62,14 @@ public static void main( String[] args ) throws IOException } } + public static ConsistencyCheckService.Result runConsistencyCheckTool( String[] args ) + throws ToolFailureException, IOException + { + ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(), + new DefaultFileSystemAbstraction(), System.err ); + return tool.run( args ); + } + private final ConsistencyCheckService consistencyCheckService; private final PrintStream systemError; private final FileSystemAbstraction fs; @@ -76,7 +82,7 @@ public static void main( String[] args ) throws IOException this.systemError = systemError; } - void run( String... args ) throws ToolFailureException, IOException + ConsistencyCheckService.Result run( String... args ) throws ToolFailureException, IOException { Args arguments = Args.withFlags( PROP_OWNER, VERBOSE ).parse( args ); @@ -89,7 +95,7 @@ void run( String... args ) throws ToolFailureException, IOException LogProvider logProvider = FormattedLogProvider.toOutputStream( System.out ); try { - consistencyCheckService.runFullConsistencyCheck( storeDir, tuningConfiguration, + return consistencyCheckService.runFullConsistencyCheck( storeDir, tuningConfiguration, ProgressMonitorFactory.textual( System.err ), logProvider, fs, verbose ); } catch ( ConsistencyCheckIncompleteException e ) @@ -103,18 +109,16 @@ private boolean isVerbose( Args arguments ) return arguments.getBoolean( VERBOSE, false, true ); } - private void checkDbState( File storeDir, Config tuningConfiguration ) + private void checkDbState( File storeDir, Config tuningConfiguration ) throws ToolFailureException { try ( PageCache pageCache = StandalonePageCacheFactory.createPageCache( fs, tuningConfiguration ) ) { if ( new RecoveryRequiredChecker( fs, pageCache ).isRecoveryRequiredAt( storeDir ) ) { - systemError.print( Strings.joinAsLines( + throw new ToolFailureException( Strings.joinAsLines( "Active logical log detected, this might be a source of inconsistencies.", "Please recover database before running the consistency check.", "To perform recovery please start database and perform clean shutdown." ) ); - - exit(); } } catch ( IOException e ) @@ -172,7 +176,7 @@ private String usage() ); } - class ToolFailureException extends Exception + static class ToolFailureException extends Exception { ToolFailureException( String message ) { @@ -185,14 +189,18 @@ class ToolFailureException extends Exception } void exitTool() + { + printMessage(); + exit(); + } + + void printMessage() { System.err.println( getMessage() ); if ( getCause() != null ) { getCause().printStackTrace( System.err ); } - - exit(); } }