diff options
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java | 9 | ||||
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java | 19 |
2 files changed, 27 insertions, 1 deletions
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"); |