diff --git a/community/command-line/src/main/java/org/neo4j/commandline/admin/AdminTool.java b/community/command-line/src/main/java/org/neo4j/commandline/admin/AdminTool.java index f7c73c3016566..b4c461c3f8550 100644 --- a/community/command-line/src/main/java/org/neo4j/commandline/admin/AdminTool.java +++ b/community/command-line/src/main/java/org/neo4j/commandline/admin/AdminTool.java @@ -32,6 +32,10 @@ public class AdminTool { + + static final int STATUS_SUCCESS = 0; + public static final int STATUS_ERROR = 1; + public static void main( String[] args ) throws IOException { Path homeDir = Paths.get( System.getenv().getOrDefault( "NEO4J_HOME", "" ) ); @@ -159,7 +163,7 @@ private void failure() private void failure( String message, Exception e ) { - failure( message, e, 1 ); + failure( message, e, STATUS_ERROR ); } private void failure( String message, Exception e, int code ) @@ -179,6 +183,6 @@ private void failure( String message, int code ) private void success() { - outsideWorld.exit( 0 ); + outsideWorld.exit( STATUS_SUCCESS ); } } diff --git a/community/command-line/src/test/java/org/neo4j/commandline/admin/AdminToolTest.java b/community/command-line/src/test/java/org/neo4j/commandline/admin/AdminToolTest.java index 92992ff384913..b80c4f836e343 100644 --- a/community/command-line/src/test/java/org/neo4j/commandline/admin/AdminToolTest.java +++ b/community/command-line/src/test/java/org/neo4j/commandline/admin/AdminToolTest.java @@ -38,6 +38,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import static org.neo4j.commandline.admin.AdminTool.STATUS_ERROR; +import static org.neo4j.commandline.admin.AdminTool.STATUS_SUCCESS; public class AdminToolTest { @@ -56,7 +58,7 @@ public void shouldExit0WhenEverythingWorks() OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( new CannedLocator( new NullCommandProvider() ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "null" ); - verify( outsideWorld ).exit( 0 ); + verify( outsideWorld ).exit( STATUS_SUCCESS ); } @Test @@ -75,7 +77,7 @@ public void shouldProvideFeedbackWhenNoCommandIsProvided() new AdminTool( new NullCommandLocator(), new NullBlockerLocator(), outsideWorld, false ).execute( null, null ); verify( outsideWorld ).stdErrLine( "you must provide a command" ); verify( outsideWorld ).stdErrLine( "usage: neo4j-admin " ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -89,7 +91,7 @@ public void shouldProvideFeedbackIfTheCommandThrowsARuntimeException() new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld ).stdErrLine( "unexpected error: the-exception-message" ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -131,7 +133,7 @@ public void shouldProvideFeedbackIfTheCommandFails() new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld ).stdErrLine( "command failed: the-failure-message" ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -174,7 +176,7 @@ public void shouldProvideFeedbackIfTheCommandReportsAUsageProblem() .execute( null, null, "exception" ); InOrder inOrder = inOrder( outsideWorld ); inOrder.verify( outsideWorld ).stdErrLine( "the-usage-message" ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -195,7 +197,7 @@ public void shouldBlockDumpIfABlockerSaysSo() throws IncorrectUsage .execute( null, null, "command" ); verify( outsideWorld ).stdErrLine( "command failed: the explanation" ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -220,7 +222,7 @@ public void shouldBlockDumpIfOneBlockerOutOfManySaysSo() throws IncorrectUsage .execute( null, null, "command" ); verify( outsideWorld ).stdErrLine( "command failed: trueBlocker explanation" ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } @Test @@ -253,7 +255,7 @@ public void helpArgumentShouldAlwaysPrintHelp() throws CommandFailed, IncorrectU verifyNoMoreInteractions( command ); verify( outsideWorld ).stdErrLine( "unknown argument: --help" ); verify( outsideWorld ).stdErrLine( "usage: neo4j-admin command " ); - verify( outsideWorld ).exit( 1 ); + verify( outsideWorld ).exit( STATUS_ERROR ); } private CannedLocator cannedCommand( final String name, AdminCommand command ) diff --git a/enterprise/backup/src/main/java/org/neo4j/backup/OnlineBackupCommand.java b/enterprise/backup/src/main/java/org/neo4j/backup/OnlineBackupCommand.java index bad751fc42329..ecbd93593f318 100644 --- a/enterprise/backup/src/main/java/org/neo4j/backup/OnlineBackupCommand.java +++ b/enterprise/backup/src/main/java/org/neo4j/backup/OnlineBackupCommand.java @@ -85,6 +85,8 @@ public static Arguments arguments() return arguments; } + static final int STATUS_CC_ERROR = 2; + static final int STATUS_CC_INCONSISTENT = 3; static final int MAX_OLD_BACKUPS = 1000; private final BackupService backupService; private final Path homeDir; @@ -249,7 +251,7 @@ public void execute( String[] args ) throws IncorrectUsage, CommandFailed if ( !ccResult.isSuccessful() ) { throw new CommandFailed( String.format( "Inconsistencies found. See '%s' for details.", - ccResult.reportFile() ), 3 ); + ccResult.reportFile() ), STATUS_CC_INCONSISTENT ); } } catch ( Throwable e ) @@ -258,7 +260,8 @@ public void execute( String[] args ) throws IncorrectUsage, CommandFailed { throw (CommandFailed) e; } - throw new CommandFailed( "Failed to do consistency check on backup: " + e.getMessage(), e, 2 ); + throw new CommandFailed( "Failed to do consistency check on backup: " + e.getMessage(), e, + STATUS_CC_ERROR ); } } diff --git a/enterprise/backup/src/test/java/org/neo4j/backup/OnlineBackupCommandTest.java b/enterprise/backup/src/test/java/org/neo4j/backup/OnlineBackupCommandTest.java index c07288a5ec701..c7a53fde4caae 100644 --- a/enterprise/backup/src/test/java/org/neo4j/backup/OnlineBackupCommandTest.java +++ b/enterprise/backup/src/test/java/org/neo4j/backup/OnlineBackupCommandTest.java @@ -68,6 +68,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.neo4j.backup.OnlineBackupCommand.MAX_OLD_BACKUPS; +import static org.neo4j.backup.OnlineBackupCommand.STATUS_CC_ERROR; +import static org.neo4j.backup.OnlineBackupCommand.STATUS_CC_INCONSISTENT; +import static org.neo4j.commandline.admin.AdminTool.STATUS_ERROR; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.cypher_planner; public class OnlineBackupCommandTest @@ -172,7 +175,7 @@ public void nonExistingBackupDirThrows() throws CommandFailed, IncorrectUsage, B final String path = path( "/Idontexist/sasdfasdfa" ); expected.expect( CommandFailed.class ); expected.expectMessage( "Directory '" + path + "' does not exist." ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( backupDir( path ), "--name=mybackup" ); } @@ -255,7 +258,7 @@ public void inconsistentCCIsReportedWithExitCode3() throws Exception expected.expect( CommandFailed.class ); expected.expectMessage( "Inconsistencies found. See '" + path + "' for details." ); - expected.expect( exitCode( 3 ) ); + expected.expect( exitCode( STATUS_CC_INCONSISTENT ) ); execute( "--check-consistency=true", backupDir(), "--name=mybackup" ); } @@ -269,7 +272,7 @@ public void errorInCCIsReportedWithExitCode2() throws Exception expected.expect( CommandFailed.class ); expected.expectMessage( "Failed to do consistency check on backup: craassh" ); - expected.expect( exitCode( 2 ) ); + expected.expect( exitCode( STATUS_CC_ERROR ) ); execute( "--check-consistency=true", backupDir(), "--name=mybackup" ); } @@ -370,7 +373,7 @@ public void failToRenameIsReported() throws Exception expected.expectMessage( "Failed to move old backup out of the way: kaboom" ); expected.expect( CommandFailed.class ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( "--cc-report-dir=" + dir.getParent(), backupDir( dir.getParent() ), "--name=" + dir.getName() ); @@ -424,7 +427,7 @@ public void shouldNotFallbackToFullIfSpecified() throws Exception expected.expectMessage( "Backup failed: nah-ah" ); expected.expect( CommandFailed.class ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( "--fallback-to-full=false", backupDir( dir.getParent() ), "--name=" + dir.getName() ); } @@ -474,7 +477,7 @@ public void renamingOldBackupIncrementsOnlySoFar() throws Exception expected.expect( CommandFailed.class ); expected.expectMessage( "ailed to move old backup out of the way: too many old backups." ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( "--cc-report-dir=" + dir.getParent(), backupDir( dir.getParent() ), "--name=" + dir.getName() ); } @@ -504,7 +507,7 @@ public void fullFailureIsReported() throws Exception expected.expect( CommandFailed.class ); expected.expectMessage( "Backup failed: nope" ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( backupDir( dir.getParent() ), "--name=" + dir.getName() ); } @@ -523,7 +526,7 @@ public void reportDirMustExist() throws Exception final String path = path( "/aalivnmoimzlckmvPDK" ); expected.expect( CommandFailed.class ); expected.expectMessage( "Directory '" + path + "' does not exist." ); - expected.expect( exitCode( 1 ) ); + expected.expect( exitCode( STATUS_ERROR ) ); execute( "--check-consistency", backupDir(), "--name=mybackup", "--cc-report-dir=" + path ); }