aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-18 11:39:30 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-18 11:39:30 +0200
commit08c51b67fa51b63205f89fb4b5038af13908b3c6 (patch)
tree364c2818e1da464fd5fec7c4e18283bd3c5c080d /server
parent894ba986e7ae960baa2b7f3c7bfae4127fd4e700 (diff)
downloadsonarqube-08c51b67fa51b63205f89fb4b5038af13908b3c6.tar.gz
sonarqube-08c51b67fa51b63205f89fb4b5038af13908b3c6.zip
SONAR-4898 - Fixed ElasticSearchTests
Diffstat (limited to 'server')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Process.java18
-rw-r--r--server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java4
2 files changed, 18 insertions, 4 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Process.java b/server/sonar-process/src/main/java/org/sonar/process/Process.java
index df605f8d172..eee4d3b92c1 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Process.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Process.java
@@ -140,18 +140,30 @@ public abstract class Process implements ProcessMXBean {
LOGGER.trace("Process[{}]::start() END", name);
}
- public final void terminate() {
+ public final void terminate(boolean waitForTermination) {
LOGGER.trace("Process[{}]::stop() START", name);
Runtime.getRuntime().removeShutdownHook(shutdownHook);
- new Thread(new Runnable() {
+ Thread terminating = new Thread(new Runnable() {
@Override
public void run() {
shutdown();
}
- }).start();
+ });
+ terminating.start();
+ if (waitForTermination) {
+ try {
+ terminating.join();
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Could not terminate process", e);
+ }
+ }
LOGGER.trace("Process[{}]::stop() END", name);
}
+ public final void terminate() {
+ terminate(false);
+ }
+
private void shutdown(){
LOGGER.trace("Process[{}]::shutdown() START", name);
this.onTerminate();
diff --git a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
index d0796df9b56..28451883656 100644
--- a/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
+++ b/server/sonar-search/src/test/java/org/sonar/search/ElasticSearchTest.java
@@ -84,6 +84,7 @@ public class ElasticSearchTest {
public void missing_properties() throws IOException, MBeanRegistrationException, InstanceNotFoundException {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "ES");
properties.setProperty(Process.PORT_PROPERTY, Integer.toString(freePort));
@@ -111,6 +112,7 @@ public class ElasticSearchTest {
public void can_connect() throws SocketException {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "ES");
properties.setProperty(ElasticSearch.ES_HOME_PROPERTY, tempDirectory.getAbsolutePath());
properties.setProperty(ElasticSearch.ES_PORT_PROPERTY, Integer.toString(freeESPort));
@@ -144,7 +146,7 @@ public class ElasticSearchTest {
// 2 assert that we can shut down ES
- elasticSearch.terminate();
+ elasticSearch.terminate(true);
try {
client.admin().cluster().prepareClusterStats().get().getStatus();
fail();