From f4f68fce0f7c2fbe9cc8ff08555327f2618e483a Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 11 Aug 2014 10:59:44 +0200 Subject: [PATCH] Fixed BaseIndex test --- .../sonar/server/search/BaseIndexTest.java | 59 ++++++++++++++----- 1 file 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(); -- 2.39.5