diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-17 14:56:38 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-05-18 11:33:46 +0200 |
commit | 5451c679ddca7f51755279be38adbff69365a339 (patch) | |
tree | 7e537cd4ee43e1749823a664d72a57387491dab2 /server/sonar-process/src | |
parent | 6392893e41bc802900c2023c87e64753c00ce887 (diff) | |
download | sonarqube-5451c679ddca7f51755279be38adbff69365a339.tar.gz sonarqube-5451c679ddca7f51755279be38adbff69365a339.zip |
SONAR-7422 add DefaultProcessCommand#reset()
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"); |