aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-11 10:59:44 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-11 10:59:44 +0200
commitf4f68fce0f7c2fbe9cc8ff08555327f2618e483a (patch)
tree8706b0a2e3719297b227c988df26b7a495a6545a /server/sonar-server
parent5bd0129d6441675ac2d7e29f683f63535008039f (diff)
downloadsonarqube-f4f68fce0f7c2fbe9cc8ff08555327f2618e483a.tar.gz
sonarqube-f4f68fce0f7c2fbe9cc8ff08555327f2618e483a.zip
Fixed BaseIndex test
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java59
1 files changed, 44 insertions, 15 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java
index 604a925524f..96c2c660ab2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java
@@ -22,53 +22,82 @@ package org.sonar.server.search;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
-import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Settings;
import org.sonar.core.cluster.NullQueue;
+import org.sonar.process.MonitoredProcess;
+import org.sonar.process.NetworkUtils;
+import org.sonar.process.Props;
+import org.sonar.search.SearchServer;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
+import java.util.Properties;
import static org.fest.assertions.Assertions.assertThat;
public class BaseIndexTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @ClassRule
+ public static TemporaryFolder temp = new TemporaryFolder();
+ private static SearchServer searchServer;
+
+ SearchClient searchClient;
+ private static String clusterName;
+ private static Integer clusterPort;
+
+
+ @BeforeClass
+ public static void setupSearchEngine() {
+ clusterName = "cluster-mem-" + System.currentTimeMillis();
+ clusterPort = NetworkUtils.freePort();
+ Properties properties = new Properties();
+ properties.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
+ properties.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
+ properties.setProperty(MonitoredProcess.NAME_PROPERTY, "ES");
+ properties.setProperty("sonar.path.data", temp.getRoot().getAbsolutePath());
+ properties.setProperty("sonar.path.logs", temp.getRoot().getAbsolutePath());
+ properties.setProperty("sonar.path.temp", temp.getRoot().getAbsolutePath());
+ try {
+ searchServer = new SearchServer(new Props(properties), false, false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ searchServer.start();
+ }
- SearchClient node;
+ @AfterClass
+ public static void teardownSearchEngine() {
+ searchServer.terminate();
+ }
@Before
public void setup() throws IOException {
File dataDir = temp.newFolder();
Settings settings = new Settings();
+ settings.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
+ settings.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
settings.setProperty("sonar.path.home", dataDir.getAbsolutePath());
- settings.setProperty(IndexProperties.TYPE, IndexProperties.ES_TYPE.MEMORY.name());
- node = new SearchClient(settings);
- //node.start();
- }
-
- @After
- public void tearDown() {
- //node.stop();
+ searchClient = new SearchClient(settings);
}
@Test
public void can_load() {
- BaseIndex index = getIndex(this.node);
+ BaseIndex index = getIndex(this.searchClient);
assertThat(index).isNotNull();
}
@Test
public void creates_domain_index() {
- BaseIndex index = getIndex(this.node);
+ BaseIndex index = getIndex(this.searchClient);
IndicesExistsResponse indexExistsResponse = index.getClient().admin().indices()
.prepareExists(IndexDefinition.TEST.getIndexName()).execute().actionGet();