diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-05-10 13:48:20 -0500 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-06-03 20:21:22 +0200 |
commit | 722ba533d1150a1878d504c1ea55ee22f2c983ef (patch) | |
tree | 71ab477a2e5f3b1847795b13ef5514e347765f1a /server/sonar-process/src/test | |
parent | c89f7855ce40b50860f7388fb0b909aa5fedb58f (diff) | |
download | sonarqube-722ba533d1150a1878d504c1ea55ee22f2c983ef.tar.gz sonarqube-722ba533d1150a1878d504c1ea55ee22f2c983ef.zip |
SONAR-12043 Refactor CeServer
* Improves waiting operations: no pooling, no additional threads
* Any number of threads can wait for stop (actually required if both stop and hard stop threads end up waiting)
* Prevents potentially multiple invocations of 'stopProcessing' by 'stop()' and the 'CeMainThread' after a hard stop
Diffstat (limited to 'server/sonar-process/src/test')
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java deleted file mode 100644 index befedf89c0c..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.process; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; -import org.sonar.test.TestUtils; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.process.ProcessUtils.awaitTermination; - -public class ProcessUtilsTest { - - @Rule - public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60)); - - @Test - public void private_constructor() { - assertThat(TestUtils.hasOnlyPrivateConstructors(ProcessUtils.class)).isTrue(); - } - - @Test - public void awaitTermination_does_not_fail_on_null_Thread_argument() { - awaitTermination(null); - } - - @Test - public void awaitTermination_does_not_wait_on_currentThread() { - awaitTermination(Thread.currentThread()); - } - - @Test - public void awaitTermination_ignores_interrupted_exception_of_current_thread() throws InterruptedException { - final EverRunningThread runningThread = new EverRunningThread(); - final Thread safeJoiner = new Thread(() -> awaitTermination(runningThread)); - final Thread simpleJoiner = new Thread(() -> { - try { - runningThread.join(); - } catch (InterruptedException e) { - System.err.println("runningThread interruption detected in SimpleJoiner"); - } - }); - runningThread.start(); - safeJoiner.start(); - simpleJoiner.start(); - - // interrupt safeJoiner _before simpleJoiner to work around some arbitrary sleep delay_ which should not stop watching - safeJoiner.interrupt(); - - // interrupting simpleJoiner which should stop - simpleJoiner.interrupt(); - - while (simpleJoiner.isAlive()) { - // wait for simpleJoiner to stop - } - - // safeJoiner must still be alive - assertThat(safeJoiner.isAlive()).isTrue(); - - // stop runningThread - runningThread.stopIt(); - - while (runningThread.isAlive()) { - // wait for runningThread to stop - } - - // wait for safeJoiner to stop because runningThread has stopped, if it doesn't, the test will fail with a timeout - safeJoiner.join(); - } - - private static class EverRunningThread extends Thread { - private volatile boolean stop = false; - - @Override - public void run() { - while (!stop) { - // infinite loop! - } - } - - public void stopIt() { - this.stop = true; - } - } - -} |