From: Sébastien Lesaint Date: Tue, 17 May 2016 12:56:38 +0000 (+0200) Subject: SONAR-7422 add DefaultProcessCommand#reset() X-Git-Tag: 5.6-RC1~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5451c679ddca7f51755279be38adbff69365a339;p=sonarqube.git SONAR-7422 add DefaultProcessCommand#reset() --- diff --git a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java index dade6ab6265..7a4182d6cee 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java @@ -52,6 +52,15 @@ public class DefaultProcessCommands implements ProcessCommands { return new DefaultProcessCommands(directory, processNumber, false); } + /** + * Clears the shared memory space of the specified process number. + */ + public static void reset(File directory, int processNumber) { + try (DefaultProcessCommands processCommands = new DefaultProcessCommands(directory, processNumber, true)) { + // nothing else to do than open file and reset the space of specified process + } + } + @Override public boolean isUp() { return delegate.isUp(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java b/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java index 0b981e03ac0..80d510be988 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java @@ -126,7 +126,6 @@ public class DefaultProcessCommandsTest { DefaultProcessCommands.main(temp.newFolder(), processNumber); } - @Test public void main_fails_if_processNumber_is_MAX_PROCESSES() throws Exception { int processNumber = MAX_PROCESSES; @@ -154,6 +153,24 @@ public class DefaultProcessCommandsTest { DefaultProcessCommands.secondary(temp.newFolder(), processNumber); } + @Test + public void reset_fails_if_processNumber_is_less_than_0() throws Exception { + int processNumber = -2; + + expectProcessNumberNoValidIAE(processNumber); + + DefaultProcessCommands.reset(temp.newFolder(), processNumber); + } + + @Test + public void reset_fails_if_processNumber_is_higher_than_MAX_PROCESSES() throws Exception { + int processNumber = MAX_PROCESSES + 1; + + expectProcessNumberNoValidIAE(processNumber); + + DefaultProcessCommands.reset(temp.newFolder(), processNumber); + } + private void expectProcessNumberNoValidIAE(int processNumber) { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Process number " + processNumber + " is not valid");