aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-09 15:17:04 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-10-09 16:51:58 +0200
commit2150b151dd4bde7d0dad93c08b6c1ea3bc47a3af (patch)
tree4f828a983358006ba3eaf9d8e9cdb2ccd743bec4 /server
parent199acf48e9b9b0732e38d350fb22a344383be6ca (diff)
downloadsonarqube-2150b151dd4bde7d0dad93c08b6c1ea3bc47a3af.tar.gz
sonarqube-2150b151dd4bde7d0dad93c08b6c1ea3bc47a3af.zip
Change default number of ES shards
- Use 5 shards by default on each index - Do not change the default number of ES shards on cluster mode
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/issue/ScmAccountToUserLoader.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java21
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java63
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java24
14 files changed, 91 insertions, 134 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/ScmAccountToUserLoader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/ScmAccountToUserLoader.java
index 6eb42c29ba8..5a65e60d7b3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/ScmAccountToUserLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/ScmAccountToUserLoader.java
@@ -21,7 +21,8 @@ package org.sonar.server.computation.issue;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
-import com.google.common.collect.Collections2;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Ordering;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -38,7 +39,7 @@ import org.sonar.server.util.cache.CacheLoader;
*/
public class ScmAccountToUserLoader implements CacheLoader<String, String> {
- private static final Logger log = Loggers.get(ScmAccountToUserLoader.class);
+ private static final Logger LOGGER = Loggers.get(ScmAccountToUserLoader.class);
private final UserIndex index;
public ScmAccountToUserLoader(UserIndex index) {
@@ -54,8 +55,8 @@ public class ScmAccountToUserLoader implements CacheLoader<String, String> {
if (!users.isEmpty()) {
// multiple users are associated to the same SCM account, for example
// the same email
- Collection<String> logins = Collections2.transform(users, UserDocToLogin.INSTANCE);
- log.warn(String.format("Multiple users share the SCM account '%s': %s", scmAccount, Joiner.on(", ").join(logins)));
+ Collection<String> logins = FluentIterable.from(users).transform(UserDocToLogin.INSTANCE).toSortedList(Ordering.natural());
+ LOGGER.warn(String.format("Multiple users share the SCM account '%s': %s", scmAccount, Joiner.on(", ").join(logins)));
}
return null;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
index 68604e722b3..7f9a599cba0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
@@ -38,6 +38,8 @@ import static java.lang.String.format;
public class NewIndex {
+ public static final int DEFAULT_NUMBER_OF_SHARDS = 5;
+
public void refreshHandledByIndexer() {
getSettings().put("index.refresh_interval", "-1");
}
@@ -300,11 +302,11 @@ public class NewIndex {
boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
int shards = settings.getInt(format("sonar.search.%s.shards", indexName));
if (shards == 0) {
- shards = (clusterMode ? 4 : 1);
+ shards = DEFAULT_NUMBER_OF_SHARDS;
}
int replicas = settings.getInt(format("sonar.search.%s.replicas", indexName));
if (replicas == 0) {
- replicas = (clusterMode ? 1 : 0);
+ replicas = clusterMode ? 1 : 0;
}
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards);
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
index 25be407be28..697eb839f64 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
@@ -20,6 +20,7 @@
package org.sonar.server.test.index;
+import com.google.common.collect.ImmutableMap;
import org.sonar.api.config.Settings;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
@@ -58,6 +59,8 @@ public class TestIndexDefinition implements IndexDefinition {
nestedMapping.createIntegerField(FIELD_COVERED_FILE_LINES);
NewIndex.NewIndexType mapping = index.createType(TYPE);
+ mapping.setAttribute("_id", ImmutableMap.of("path", FIELD_TEST_UUID));
+ mapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", FIELD_PROJECT_UUID));
mapping.stringFieldBuilder(FIELD_PROJECT_UUID).build();
mapping.stringFieldBuilder(FIELD_FILE_UUID).build();
mapping.stringFieldBuilder(FIELD_TEST_UUID).build();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java
index c05e98cbde6..019eb7a94ff 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexDefinitionTest.java
@@ -21,7 +21,6 @@ package org.sonar.server.activity.index;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessProperties;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
@@ -29,32 +28,20 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ActivityIndexDefinitionTest {
- IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
+ IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
@Test
public void define() {
ActivityIndexDefinition def = new ActivityIndexDefinition(new Settings());
- def.define(context);
+ def.define(underTest);
- assertThat(context.getIndices()).hasSize(1);
- NewIndex index = context.getIndices().get("activities");
+ assertThat(underTest.getIndices()).hasSize(1);
+ NewIndex index = underTest.getIndices().get("activities");
assertThat(index).isNotNull();
assertThat(index.getTypes().keySet()).containsOnly("activity");
// no cluster by default
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("1");
+ assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("0");
}
-
- @Test
- public void enable_cluster() {
- Settings settings = new Settings();
- settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
- ActivityIndexDefinition def = new ActivityIndexDefinition(settings);
- def.define(context);
-
- NewIndex index = context.getIndices().get("activities");
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("4");
- assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("1");
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java
index 43c000cafae..7edacd02f5e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java
@@ -20,6 +20,9 @@
package org.sonar.server.batch;
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -35,8 +38,6 @@ import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.ws.WsTester;
-import java.io.ByteArrayInputStream;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -68,21 +69,17 @@ public class UsersActionTest {
es.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER,
new UserDoc().setLogin("ada.lovelace").setName("Ada Lovelace").setActive(false),
new UserDoc().setLogin("grace.hopper").setName("Grace Hopper").setActive(true));
-
userSessionRule.login("sonarqtech").setGlobalPermissions(GlobalPermissions.PREVIEW_EXECUTION);
WsTester.TestRequest request = tester.newGetRequest("batch", "users").setParam("logins", "ada.lovelace,grace.hopper");
ByteArrayInputStream input = new ByteArrayInputStream(request.execute().output());
-
- User user = User.parseDelimitedFrom(input);
- assertThat(user.getLogin()).isEqualTo("ada.lovelace");
- assertThat(user.getName()).isEqualTo("Ada Lovelace");
-
- user = User.parseDelimitedFrom(input);
- assertThat(user.getLogin()).isEqualTo("grace.hopper");
- assertThat(user.getName()).isEqualTo("Grace Hopper");
-
+ User user1 = User.parseDelimitedFrom(input);
+ User user2 = User.parseDelimitedFrom(input);
assertThat(User.parseDelimitedFrom(input)).isNull();
+
+ List<User> users = Arrays.asList(user1, user2);
+ assertThat(users).extracting("login").containsOnly("ada.lovelace", "grace.hopper");
+ assertThat(users).extracting("name").containsOnly("Ada Lovelace", "Grace Hopper");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java
index 40c58734445..c224a280608 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java
@@ -63,7 +63,7 @@ public class ScmAccountToUserLoaderTest {
ScmAccountToUserLoader loader = new ScmAccountToUserLoader(index);
assertThat(loader.load("charlie")).isNull();
- assertThat(logTester.logs(LoggerLevel.WARN)).contains("Multiple users share the SCM account 'charlie': charlie, another.charlie");
+ assertThat(logTester.logs(LoggerLevel.WARN)).contains("Multiple users share the SCM account 'charlie': another.charlie, charlie");
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
index a64c75666fe..5f6f46bd20f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
@@ -20,12 +20,11 @@
package org.sonar.server.es;
import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.junit.Test;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@@ -147,20 +146,20 @@ public class NewIndexTest {
}
@Test
- public void one_shard_and_zero_replica_by_default() {
+ public void default_shards_and_replicas() {
NewIndex index = new NewIndex("issues");
index.setShards(new org.sonar.api.config.Settings());
- assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("1");
+ assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("0");
}
@Test
- public void four_shards_and_one_replica_by_default_on_cluster() {
+ public void five_shards_and_one_replica_by_default_on_cluster() {
NewIndex index = new NewIndex("issues");
org.sonar.api.config.Settings settings = new org.sonar.api.config.Settings();
settings.setProperty("sonar.cluster.activate", "true");
index.setShards(settings);
- assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo("4");
+ assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(index.getSettings().get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)).isEqualTo("1");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
index 869df3280d1..17d87380951 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDefinitionTest.java
@@ -21,7 +21,6 @@ package org.sonar.server.issue.index;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessProperties;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
@@ -29,32 +28,20 @@ import static org.assertj.core.api.Assertions.assertThat;
public class IssueIndexDefinitionTest {
- IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
+ IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
@Test
public void define() {
IssueIndexDefinition def = new IssueIndexDefinition(new Settings());
- def.define(context);
+ def.define(underTest);
- assertThat(context.getIndices()).hasSize(1);
- NewIndex issuesIndex = context.getIndices().get("issues");
+ assertThat(underTest.getIndices()).hasSize(1);
+ NewIndex issuesIndex = underTest.getIndices().get("issues");
assertThat(issuesIndex).isNotNull();
assertThat(issuesIndex.getTypes().keySet()).containsOnly("issue", "authorization");
// no cluster by default
- assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo("1");
+ assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(issuesIndex.getSettings().get("index.number_of_replicas")).isEqualTo("0");
}
-
- @Test
- public void enable_cluster() {
- Settings settings = new Settings();
- settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
- IssueIndexDefinition def = new IssueIndexDefinition(settings);
- def.define(context);
-
- NewIndex issuesIndex = context.getIndices().get("issues");
- assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo("4");
- assertThat(issuesIndex.getSettings().get("index.number_of_replicas")).isEqualTo("1");
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
index d0aa16dc19c..9c9892ed56a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
@@ -19,16 +19,16 @@
*/
package org.sonar.server.platform.monitoring;
+import java.util.LinkedHashMap;
+import java.util.Map;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
+import org.sonar.server.es.NewIndex;
import org.sonar.server.issue.index.IssueIndexDefinition;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
public class EsMonitorTest {
@@ -75,7 +75,7 @@ public class EsMonitorTest {
assertThat(indicesAttributes).hasSize(1);
Map indexAttributes = (Map)indicesAttributes.values().iterator().next();
assertThat(indexAttributes.get("Docs")).isEqualTo(0L);
- assertThat(indexAttributes.get("Shards")).isEqualTo(1);
+ assertThat(indexAttributes.get("Shards")).isEqualTo(NewIndex.DEFAULT_NUMBER_OF_SHARDS);
assertThat(indexAttributes.get("Store Size")).isNotNull();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
index 8cfeabdfe34..b9a16562834 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
@@ -20,6 +20,8 @@
package org.sonar.server.test.index;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
@@ -27,9 +29,6 @@ import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
-import java.util.Arrays;
-import java.util.List;
-
import static org.assertj.core.api.Assertions.assertThat;
public class TestIndexTest {
@@ -46,10 +45,10 @@ public class TestIndexTest {
@Test
public void coveredFiles() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- newTestDoc("1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
- newTestDoc("2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+ newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
+ newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
- List<CoveredFileDoc> result = underTest.coveredFiles("uuid-1");
+ List<CoveredFileDoc> result = underTest.coveredFiles("1");
assertThat(result).hasSize(3);
assertThat(result).extractingResultOf("fileUuid").containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
@@ -59,22 +58,22 @@ public class TestIndexTest {
@Test
public void searchByTestFileUuid() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- newTestDoc("1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
- newTestDoc("1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")),
- newTestDoc("2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+ newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
+ newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")),
+ newTestDoc("3", "TESTFILE2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
- List<TestDoc> result = underTest.searchByTestFileUuid("file-uuid-1", searchOptions()).getDocs();
+ List<TestDoc> result = underTest.searchByTestFileUuid("TESTFILE1", searchOptions()).getDocs();
assertThat(result).hasSize(2);
- assertThat(result).extractingResultOf("name").containsOnly("name-1");
+ assertThat(result).extractingResultOf("name").containsOnly("name-1", "name-2");
}
@Test
public void searchBySourceFileUuidAndLineNumber() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- newTestDoc("1", newCoverageBlock("10"), newCoverageBlock("11"), newCoverageBlock("12")),
- newTestDoc("2", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
- newTestDoc("3", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+ newTestDoc("1", "TESTFILE1", newCoverageBlock("10"), newCoverageBlock("11"), newCoverageBlock("12")),
+ newTestDoc("2", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
+ newTestDoc("3", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
List<TestDoc> result = underTest.searchBySourceFileUuidAndLineNumber("main-uuid-5", 82, searchOptions()).getDocs();
@@ -85,13 +84,13 @@ public class TestIndexTest {
@Test
public void searchByTestUuid() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- newTestDoc("1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
- newTestDoc("2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+ newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
+ newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
- TestDoc test = underTest.searchByTestUuid("uuid-1");
+ TestDoc test = underTest.searchByTestUuid("1");
- assertThat(test.testUuid()).isEqualTo("uuid-1");
- assertThat(test.fileUuid()).isEqualTo("file-uuid-1");
+ assertThat(test.testUuid()).isEqualTo("1");
+ assertThat(test.fileUuid()).isEqualTo("TESTFILE1");
assertThat(test.name()).isEqualTo("name-1");
assertThat(test.durationInMs()).isEqualTo(1L);
assertThat(test.status()).isEqualTo("status-1");
@@ -103,13 +102,13 @@ public class TestIndexTest {
@Test
public void searchByTestUuid_with_SearchOptions() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- newTestDoc("1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
- newTestDoc("2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+ newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
+ newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
- List<TestDoc> result = underTest.searchByTestUuid("uuid-1", searchOptions()).getDocs();
+ List<TestDoc> result = underTest.searchByTestUuid("1", searchOptions()).getDocs();
assertThat(result).hasSize(1);
- assertThat(result.get(0).testUuid()).isEqualTo("uuid-1");
+ assertThat(result.get(0).testUuid()).isEqualTo("1");
}
private CoveredFileDoc newCoverageBlock(String id) {
@@ -118,16 +117,16 @@ public class TestIndexTest {
.setCoveredLines(Arrays.asList(25, 33, 82));
}
- private TestDoc newTestDoc(String id, CoveredFileDoc... coveredFiles) {
+ private TestDoc newTestDoc(String testUuid, String fileUuid, CoveredFileDoc... coveredFiles) {
return new TestDoc()
- .setUuid("uuid-" + id)
- .setName("name-" + id)
- .setMessage("message-" + id)
- .setStackTrace("stacktrace-" + id)
- .setStatus("status-" + id)
- .setDurationInMs(Long.valueOf(id))
- .setFileUuid("file-uuid-" + id)
- .setProjectUuid("project-uuid-" + id)
+ .setUuid(testUuid)
+ .setProjectUuid("project-" + fileUuid)
+ .setName("name-" + testUuid)
+ .setMessage("message-" + testUuid)
+ .setStackTrace("stacktrace-" + testUuid)
+ .setStatus("status-" + testUuid)
+ .setDurationInMs(Long.valueOf(testUuid))
+ .setFileUuid(fileUuid)
.setCoveredFiles(Arrays.asList(coveredFiles));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
index 13b778a2ce3..1290f7b4b45 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
@@ -171,6 +171,10 @@ public class TestIndexerTest {
indexTest("P1", "F2", "T1", "U121");
indexTest("P2", "F3", "T1", "U231");
+ for (SearchHit hit : getDocuments()) {
+ System.out.println("BEFORE " + hit.getSourceAsString());
+ }
+
underTest.deleteByProject("P1");
List<SearchHit> hits = getDocuments();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
index 096c9bb316c..4280af90d3b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
@@ -80,6 +80,7 @@ public class ListActionTest {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
new TestDoc()
.setUuid(TestFile1.UUID)
+ .setProjectUuid(TestFile1.PROJECT_UUID)
.setName(TestFile1.NAME)
.setFileUuid(TestFile1.FILE_UUID)
.setDurationInMs(TestFile1.DURATION_IN_MS)
@@ -103,6 +104,7 @@ public class ListActionTest {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
new TestDoc()
.setUuid(TestFile1.UUID)
+ .setProjectUuid(TestFile1.PROJECT_UUID)
.setName(TestFile1.NAME)
.setFileUuid(TestFile1.FILE_UUID)
.setDurationInMs(TestFile1.DURATION_IN_MS)
@@ -125,6 +127,7 @@ public class ListActionTest {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
new TestDoc()
.setUuid(TestFile1.UUID)
+ .setProjectUuid(TestFile1.PROJECT_UUID)
.setName(TestFile1.NAME)
.setFileUuid(TestFile1.FILE_UUID)
.setDurationInMs(TestFile1.DURATION_IN_MS)
@@ -163,6 +166,7 @@ public class ListActionTest {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
new TestDoc()
.setUuid(TestFile1.UUID)
+ .setProjectUuid(TestFile1.PROJECT_UUID)
.setName(TestFile1.NAME)
.setFileUuid(TestFile1.FILE_UUID)
.setDurationInMs(TestFile1.DURATION_IN_MS)
@@ -172,6 +176,7 @@ public class ListActionTest {
.setStackTrace(TestFile1.STACKTRACE),
new TestDoc()
.setUuid(TestFile2.UUID)
+ .setProjectUuid(TestFile2.PROJECT_UUID)
.setName(TestFile2.NAME)
.setFileUuid(TestFile2.FILE_UUID)
.setDurationInMs(TestFile2.DURATION_IN_MS)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
index 727deb08f3b..7c11b77bd6e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexDefinitionTest.java
@@ -21,7 +21,6 @@ package org.sonar.server.user.index;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessProperties;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
@@ -29,32 +28,20 @@ import static org.assertj.core.api.Assertions.assertThat;
public class UserIndexDefinitionTest {
- IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
+ IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
@Test
public void define() {
UserIndexDefinition def = new UserIndexDefinition(new Settings());
- def.define(context);
+ def.define(underTest);
- assertThat(context.getIndices()).hasSize(1);
- NewIndex index = context.getIndices().get("users");
+ assertThat(underTest.getIndices()).hasSize(1);
+ NewIndex index = underTest.getIndices().get("users");
assertThat(index).isNotNull();
assertThat(index.getTypes().keySet()).containsOnly("user");
// no cluster by default
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("1");
+ assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("0");
}
-
- @Test
- public void enable_cluster() {
- Settings settings = new Settings();
- settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
- UserIndexDefinition def = new UserIndexDefinition(settings);
- def.define(context);
-
- NewIndex index = context.getIndices().get("users");
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("4");
- assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("1");
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java
index 4fed312ce2b..481857e2788 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexDefinitionTest.java
@@ -22,7 +22,6 @@ package org.sonar.server.view.index;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessProperties;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
@@ -30,32 +29,19 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ViewIndexDefinitionTest {
- IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
+ IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
@Test
public void define() {
ViewIndexDefinition def = new ViewIndexDefinition(new Settings());
- def.define(context);
+ def.define(underTest);
- assertThat(context.getIndices()).hasSize(1);
- NewIndex index = context.getIndices().get("views");
+ assertThat(underTest.getIndices()).hasSize(1);
+ NewIndex index = underTest.getIndices().get("views");
assertThat(index).isNotNull();
assertThat(index.getTypes().keySet()).containsOnly("view");
- // no cluster by default
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("1");
+ assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo(String.valueOf(NewIndex.DEFAULT_NUMBER_OF_SHARDS));
assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("0");
}
-
- @Test
- public void enable_cluster() {
- Settings settings = new Settings();
- settings.setProperty(ProcessProperties.CLUSTER_ACTIVATE, true);
- ViewIndexDefinition def = new ViewIndexDefinition(settings);
- def.define(context);
-
- NewIndex index = context.getIndices().get("views");
- assertThat(index.getSettings().get("index.number_of_shards")).isEqualTo("4");
- assertThat(index.getSettings().get("index.number_of_replicas")).isEqualTo("1");
- }
}