瀏覽代碼

SONAR-7908 allow web followers to index docs into Elasticsearch

tags/6.1-RC1
Simon Brandhof 7 年之前
父節點
當前提交
42f5097916
共有 42 個檔案被更改,包括 59 行新增309 行删除
  1. 0
    2
      server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
  2. 0
    49
      server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java
  3. 0
    23
      server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java
  4. 0
    61
      server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java
  5. 14
    32
      server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java
  6. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java
  7. 0
    2
      server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
  8. 0
    1
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
  9. 1
    2
      server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
  10. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
  11. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java
  12. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java
  13. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStepTest.java
  14. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java
  15. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
  16. 2
    13
      server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
  17. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
  18. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
  19. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
  20. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
  21. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
  22. 6
    29
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
  23. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
  24. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
  25. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
  26. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
  27. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java
  28. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
  29. 0
    1
      server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java
  30. 2
    14
      server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
  31. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
  32. 0
    2
      server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
  33. 16
    18
      server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
  34. 0
    6
      server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
  35. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
  36. 1
    11
      server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
  37. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
  38. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
  39. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
  40. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
  41. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
  42. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java

+ 0
- 2
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java 查看文件

@@ -44,7 +44,6 @@ import org.sonar.ce.CeHttpModule;
import org.sonar.ce.CeQueueModule;
import org.sonar.ce.CeTaskCommonsModule;
import org.sonar.ce.db.ReadOnlyPropertiesDao;
import org.sonar.ce.es.EsIndexerEnabler;
import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
import org.sonar.ce.settings.ProjectSettingsFactory;
import org.sonar.ce.user.CeUserSession;
@@ -398,7 +397,6 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {

private static Object[] startupComponents() {
return new Object[] {
EsIndexerEnabler.class,
LogServerId.class,
ServerLifecycleNotifier.class,
PurgeCeActivities.class,

+ 0
- 49
server/sonar-ce/src/main/java/org/sonar/ce/es/EsIndexerEnabler.java 查看文件

@@ -1,49 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact 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.ce.es;

import org.picocontainer.Startable;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.IndexerStartupTask;

/**
* Replaces the {@link IndexerStartupTask} to enable indexers but without triggering a full
* indexation (it's the WebServer's responsibility).
*/
public class EsIndexerEnabler implements Startable {

private final BaseIndexer[] indexers;

public EsIndexerEnabler(BaseIndexer[] indexers) {
this.indexers = indexers;
}

@Override
public void start() {
for (BaseIndexer indexer : indexers) {
indexer.setEnabled(true);
}
}

@Override
public void stop() {
// nothing to do at stop
}
}

+ 0
- 23
server/sonar-ce/src/main/java/org/sonar/ce/es/package-info.java 查看文件

@@ -1,23 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.ce.es;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 61
server/sonar-ce/src/test/java/org/sonar/ce/es/EsIndexerEnablerTest.java 查看文件

@@ -1,61 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact 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.ce.es;

import org.junit.After;
import org.junit.Test;
import org.sonar.server.activity.index.ActivityIndexer;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.issue.index.IssueAuthorizationIndexer;
import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.test.index.TestIndexer;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.view.index.ViewIndexer;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class EsIndexerEnablerTest {
private TestIndexer testIndexer = mock(TestIndexer.class);
private IssueAuthorizationIndexer issueAuthorizationIndexer = mock(IssueAuthorizationIndexer.class);
private IssueIndexer issueIndexer = mock(IssueIndexer.class);
private UserIndexer userIndexer = mock(UserIndexer.class);
private ViewIndexer viewIndexer = mock(ViewIndexer.class);
private ActivityIndexer activityIndexer = mock(ActivityIndexer.class);
private EsIndexerEnabler underTest = new EsIndexerEnabler(new BaseIndexer[]{testIndexer, issueAuthorizationIndexer, issueIndexer, userIndexer, viewIndexer, activityIndexer});

@After
public void tearDown() {
underTest.stop();

}

@Test
public void start_enables_all_indexers() {
underTest.start();

verify(testIndexer).setEnabled(true);
verify(issueAuthorizationIndexer).setEnabled(true);
verify(issueIndexer).setEnabled(true);
verify(userIndexer).setEnabled(true);
verify(viewIndexer).setEnabled(true);
verify(activityIndexer).setEnabled(true);
}
}

+ 14
- 32
server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java 查看文件

@@ -37,17 +37,6 @@ public abstract class BaseIndexer implements Startable {
protected final EsClient esClient;
private volatile long lastUpdatedAt = -1L;

/**
* Indexers are disabled during server startup, to avoid too many consecutive refreshes of the same index
* An example is RegisterQualityProfiles. If {@link org.sonar.server.activity.index.ActivityIndexer} is enabled by
* default during startup, then each new activated rule generates a bulk request with a single document and then
* asks for index refresh -> big performance hit.
*
* Indices are populated and refreshed when all startup components have been executed. See
* {@link IndexerStartupTask}
*/
private boolean enabled = false;

protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
String dateFieldName) {
this.indexName = indexName;
@@ -59,23 +48,21 @@ public abstract class BaseIndexer implements Startable {
}

public void index(final IndexerTask task) {
if (enabled) {
final long requestedAt = System.currentTimeMillis();
Future submit = executor.submit(() -> {
if (lastUpdatedAt == -1L) {
lastUpdatedAt = esClient.getMaxFieldValue(indexName, typeName, dateFieldName);
}
if (requestedAt > lastUpdatedAt) {
long l = task.index(lastUpdatedAt);
// l can be 0 if no documents were indexed
lastUpdatedAt = Math.max(l, lastUpdatedAt);
}
});
try {
Uninterruptibles.getUninterruptibly(submit);
} catch (ExecutionException e) {
Throwables.propagate(e);
final long requestedAt = System.currentTimeMillis();
Future submit = executor.submit(() -> {
if (lastUpdatedAt == -1L) {
lastUpdatedAt = esClient.getMaxFieldValue(indexName, typeName, dateFieldName);
}
if (requestedAt > lastUpdatedAt) {
long l = task.index(lastUpdatedAt);
// l can be 0 if no documents were indexed
lastUpdatedAt = Math.max(l, lastUpdatedAt);
}
});
try {
Uninterruptibles.getUninterruptibly(submit);
} catch (ExecutionException e) {
Throwables.propagate(e);
}
}

@@ -85,11 +72,6 @@ public abstract class BaseIndexer implements Startable {

protected abstract long doIndex(long lastUpdatedAt);

public BaseIndexer setEnabled(boolean b) {
this.enabled = b;
return this;
}

@Override
public void start() {
// nothing to do at startup

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java 查看文件

@@ -61,20 +61,20 @@ public class IndexerStartupTask {
public void execute() {
if (!settings.getBoolean("sonar.internal.es.disableIndexes")) {
LOG.info("Index activities");
activityIndexer.setEnabled(true).index();
activityIndexer.index();

LOG.info("Index issues");
issueAuthorizationIndexer.setEnabled(true).index();
issueIndexer.setEnabled(true).index();
issueAuthorizationIndexer.index();
issueIndexer.index();

LOG.info("Index tests");
testIndexer.setEnabled(true).index();
testIndexer.index();

LOG.info("Index users");
userIndexer.setEnabled(true).index();
userIndexer.index();

LOG.info("Index views");
viewIndexer.setEnabled(true).index();
viewIndexer.index();
}
}


+ 0
- 2
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java 查看文件

@@ -20,7 +20,6 @@
package org.sonar.server.platform.platformlevel;

import org.sonar.server.app.ProcessCommandWrapper;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.IndexerStartupTask;
import org.sonar.server.issue.filter.RegisterIssueFilters;
import org.sonar.server.platform.ServerLifecycleNotifier;
@@ -80,7 +79,6 @@ public class PlatformLevelStartup extends PlatformLevel {
getOptional(IndexerStartupTask.class).ifPresent(IndexerStartupTask::execute);
get(ServerLifecycleNotifier.class).notifyStart();
get(ProcessCommandWrapper.class).notifyOperational();
getAll(BaseIndexer.class).forEach(i -> i.setEnabled(true));
}
});


+ 0
- 1
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java 查看文件

@@ -89,7 +89,6 @@ public class RegisterQualityProfiles {
Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
DbSession session = dbClient.openSession(false);
try {
activeRuleIndexer.setEnabled(true);
List<ActiveRuleChange> changes = new ArrayList<>();
ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
for (String language : profilesByLanguage.keySet()) {

+ 1
- 2
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java 查看文件

@@ -106,8 +106,7 @@ public class RegisterRules implements Startable {
List<RuleDto> activeRules = processRemainingDbRules(allRules.values(), session);
List<ActiveRuleChange> changes = removeActiveRulesOnStillExistingRepositories(session, activeRules, context);
session.commit();
ruleIndexer.setEnabled(true).index();
activeRuleIndexer.setEnabled(true);
ruleIndexer.index();
activeRuleIndexer.index(changes);
profiler.stopDebug();
} finally {

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java 查看文件

@@ -89,7 +89,7 @@ public class RuleCreator {
}

dbSession.commit();
ruleIndexer.setEnabled(true).index();
ruleIndexer.index();
return customRuleKey;
}


+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java 查看文件

@@ -96,7 +96,7 @@ public class RuleUpdater {
update(dbSession, context.rule);
updateParameters(dbSession, update, context);
dbSession.commit();
ruleIndexer.setEnabled(true).index();
ruleIndexer.index();
return true;
}


+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java 查看文件

@@ -58,7 +58,6 @@ public class ActivityServiceTest {
DbClient dbClient = db.getDbClient();
ActivityIndexer indexer = new ActivityIndexer(dbClient, es.client());
// indexers are disabled by default
indexer.setEnabled(true);
service = new ActivityService(dbClient, indexer, userSession);
}


+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStepTest.java 查看文件

@@ -89,7 +89,6 @@ public class ApplyPermissionsStepTest extends BaseStepTest {
dbSession = dbClient.openSession(false);

issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());
issueAuthorizationIndexer.setEnabled(true);

step = new ApplyPermissionsStep(dbClient, dbIdsRepository, issueAuthorizationIndexer, new PermissionRepository(dbClient, settings), treeRootHolder);
}

+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java 查看文件

@@ -55,7 +55,6 @@ public class IndexTestsStepTest extends BaseStepTest {
@Override
protected ComputationStep step() {
TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
testIndexer.setEnabled(true);
return new IndexTestsStep(testIndexer, treeRootHolder);
}


+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java 查看文件

@@ -82,7 +82,6 @@ public class IssueServiceMediumTest {
session = db.openSession(false);
service = tester.get(IssueService.class);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
}

@After

+ 2
- 13
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java 查看文件

@@ -53,19 +53,10 @@ public class IssueIndexerTest {
@Test
public void index_nothing() {
IssueIndexer indexer = createIndexer();
indexer.index(Iterators.<IssueDoc>emptyIterator());
indexer.index(Iterators.emptyIterator());
assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0L);
}

@Test
public void index_nothing_if_disabled() {
dbTester.prepareDbUnit(getClass(), "index.xml");

createIndexer().setEnabled(false).index();

assertThat(esTester.countDocuments("issues", "issue")).isEqualTo(0);
}

@Test
public void index() {
dbTester.prepareDbUnit(getClass(), "index.xml");
@@ -165,9 +156,7 @@ public class IssueIndexerTest {
}

private IssueIndexer createIndexer() {
IssueIndexer indexer = new IssueIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
indexer.setEnabled(true);
return indexer;
return new IssueIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}

private void addIssue(String projectUuid, String issueKey) throws Exception {

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java 查看文件

@@ -89,9 +89,7 @@ public class QProfileBackuperMediumTest {
db = tester.get(DbClient.class);
dbSession = db.openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);

// create pre-defined rules
RuleDto xooRule1 = newXooX1().setSeverity("MINOR").setLanguage("xoo");

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java 查看文件

@@ -73,9 +73,7 @@ public class QProfileCopierMediumTest {
index = tester.get(ActiveRuleIndex.class);
copier = tester.get(QProfileCopier.class);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);

// create pre-defined rules
RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");

+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java 查看文件

@@ -79,7 +79,6 @@ public class QProfileExportersTest {
exporters = tester.get(QProfileExporters.class);
loader = tester.get(QProfileLoader.class);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
}

@After

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java 查看文件

@@ -78,9 +78,7 @@ public class QProfileFactoryMediumTest {
factory = tester.get(QProfileFactory.class);
activeRuleIndex = tester.get(ActiveRuleIndex.class);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
}

@After

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java 查看文件

@@ -108,9 +108,7 @@ public class RuleActivatorMediumTest {
ruleActivator = tester.get(RuleActivator.class);
activeRuleIndex = tester.get(ActiveRuleIndex.class);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);

// create pre-defined rules
RuleDto javaRule = newDto(RuleKey.of("squid", "j1"))

+ 6
- 29
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java 查看文件

@@ -21,7 +21,6 @@ package org.sonar.server.qualityprofile.index;

import com.google.common.collect.Iterators;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.MapSettings;
@@ -47,7 +46,6 @@ import static org.sonar.server.qualityprofile.index.ActiveRuleDocTesting.newDoc;
import static org.sonar.server.rule.index.RuleIndexDefinition.INDEX;
import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;


public class ActiveRuleIndexerTest {

static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
@@ -63,28 +61,11 @@ public class ActiveRuleIndexerTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);

ActiveRuleIndexer indexer;

@Before
public void setUp() {
indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
indexer.setEnabled(true);
}
private ActiveRuleIndexer indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());

@Test
public void index_nothing() {
indexer.index(Iterators.<ActiveRuleDoc>emptyIterator());
assertThat(esTester.countDocuments(INDEX, TYPE_ACTIVE_RULE)).isZero();
}

@Test
public void index_nothing_if_disabled() {
dbTester.prepareDbUnit(getClass(), "index.xml");

ActiveRuleIndexer indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
indexer.setEnabled(false);
indexer.index();

indexer.index(Iterators.emptyIterator());
assertThat(esTester.countDocuments(INDEX, TYPE_ACTIVE_RULE)).isZero();
}

@@ -111,8 +92,7 @@ public class ActiveRuleIndexerTest {

assertThat(esTester.getIds(INDEX, TYPE_ACTIVE_RULE)).containsOnly(
ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2).toString(),
ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3).toString()
);
ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3).toString());
}

@Test
@@ -133,13 +113,11 @@ public class ActiveRuleIndexerTest {
indexer.index(Arrays.asList(
ActiveRuleChange.createFor(ACTIVATED, activeRuleKey1),
ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey2),
ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey3)
));
ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey3)));

assertThat(esTester.getIds(INDEX, TYPE_ACTIVE_RULE)).containsOnly(
activeRuleKey1.toString(),
activeRuleKey4.toString()
);
activeRuleKey4.toString());
}

@Test
@@ -173,8 +151,7 @@ public class ActiveRuleIndexerTest {

assertThat(esTester.getIds(INDEX, TYPE_ACTIVE_RULE)).containsOnly(
activeRule.getKey().toString(),
activeRule2.getKey().toString()
);
activeRule2.getKey().toString());
}

private void indexActiveRules(ActiveRuleDoc... docs) {

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java 查看文件

@@ -75,9 +75,7 @@ public class ChangeParentActionMediumTest {
wsTester = tester.get(WsTester.class);
session = db.openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
ruleIndex = tester.get(RuleIndex.class);
userSessionRule.login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
}

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java 查看文件

@@ -67,9 +67,7 @@ public class InheritanceActionMediumTest {
db = tester.get(DbClient.class);
session = db.openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);

wsTester = new WsTester(tester.get(QProfilesWs.class));
}

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java 查看文件

@@ -86,9 +86,7 @@ public class QProfilesWsMediumTest {
session = db.openSession(false);

ruIndexer = tester.get(RuleIndexer.class);
ruIndexer.setEnabled(true);
activeRuIndexer = tester.get(ActiveRuleIndexer.class);
activeRuIndexer.setEnabled(true);
}

@After

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java 查看文件

@@ -84,10 +84,8 @@ public class RegisterRulesTest {
public void before() {
when(system.now()).thenReturn(DATE1.getTime());
ruleIndexer = new RuleIndexer(dbClient, esTester.client());
ruleIndexer.setEnabled(true);
ruleIndex = new RuleIndex(esTester.client());
activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
activeRuleIndexer.setEnabled(true);
}

@Test

+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java 查看文件

@@ -71,7 +71,6 @@ public class RuleCreatorMediumTest {
tester.clearDbAndIndexes();
dbSession = tester.get(DbClient.class).openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
}

@After

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java 查看文件

@@ -66,8 +66,6 @@ public class RuleDeleterMediumTest {
@Before
public void before() {
tester.clearDbAndIndexes();
ruleIndexer.setEnabled(true);
activeRuleIndexer.setEnabled(true);
}

@After

+ 0
- 1
server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java 查看文件

@@ -60,7 +60,6 @@ public class RuleServiceMediumTest {
tester.clearDbAndIndexes();
dbSession = tester.get(DbClient.class).openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
}

@After

+ 2
- 14
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java 查看文件

@@ -69,20 +69,10 @@ public class RuleIndexerTest {
@Test
public void index_nothing() {
RuleIndexer indexer = createIndexer();
indexer.index(Iterators.<RuleDoc>emptyIterator());
indexer.index(Iterators.emptyIterator());
assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(0L);
}

@Test
public void index_nothing_if_disabled() {
dbClient.ruleDao().insert(dbSession, rule);
dbSession.commit();

createIndexer().setEnabled(false).index();

assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isZero();
}

@Test
public void index() {
dbClient.ruleDao().insert(dbSession, rule);
@@ -113,9 +103,7 @@ public class RuleIndexerTest {
}

private RuleIndexer createIndexer() {
RuleIndexer indexer = new RuleIndexer(dbTester.getDbClient(), esTester.client());
indexer.setEnabled(true);
return indexer;
return new RuleIndexer(dbTester.getDbClient(), esTester.client());
}

}

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java 查看文件

@@ -72,9 +72,7 @@ public class RulesWsMediumTest {
ws = tester.get(RulesWs.class);
session = tester.get(DbClient.class).openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
}

@After

+ 0
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java 查看文件

@@ -88,9 +88,7 @@ public class SearchActionMediumTest {
ws = tester.get(RulesWs.class);
dbSession = tester.get(DbClient.class).openSession(false);
ruleIndexer = tester.get(RuleIndexer.class);
ruleIndexer.setEnabled(true);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
activeRuleIndexer.setEnabled(true);
}

@After

+ 16
- 18
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java 查看文件

@@ -134,20 +134,19 @@ public class ShowActionMediumTest {

@Test
public void show_rule_with_overridden_debt() throws Exception {
RuleDto ruleDto =
RuleTesting.newDto(RuleKey.of("java", "S001"))
.setName("Rule S001")
.setDescription("Rule S001 <b>description</b>")
.setSeverity(MINOR)
.setStatus(RuleStatus.BETA)
.setConfigKey("InternalKeyS001")
.setLanguage("xoo")
.setDefaultRemediationFunction(null)
.setDefaultRemediationGapMultiplier(null)
.setDefaultRemediationBaseEffort(null)
.setRemediationFunction("LINEAR_OFFSET")
.setRemediationGapMultiplier("5d")
.setRemediationBaseEffort("10h");
RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001"))
.setName("Rule S001")
.setDescription("Rule S001 <b>description</b>")
.setSeverity(MINOR)
.setStatus(RuleStatus.BETA)
.setConfigKey("InternalKeyS001")
.setLanguage("xoo")
.setDefaultRemediationFunction(null)
.setDefaultRemediationGapMultiplier(null)
.setDefaultRemediationBaseEffort(null)
.setRemediationFunction("LINEAR_OFFSET")
.setRemediationGapMultiplier("5d")
.setRemediationBaseEffort("10h");
ruleDao.insert(session, ruleDto);
session.commit();
session.clearCache();
@@ -278,13 +277,12 @@ public class ShowActionMediumTest {
tester.get(ActiveRuleDao.class).insertParam(session, activeRuleDto, new ActiveRuleParamDto()
.setRulesParameterId(regexParam.getId())
.setKey(regexParam.getName())
.setValue(".*?")
);
.setValue(".*?"));
session.commit();
session.clearCache();

tester.get(RuleIndexer.class).setEnabled(true).index();
tester.get(ActiveRuleIndexer.class).setEnabled(true).index();
tester.get(RuleIndexer.class).index();
tester.get(ActiveRuleIndexer.class).index();

WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
.setParam("key", ruleDto.getKey().toString())

+ 0
- 6
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java 查看文件

@@ -30,7 +30,6 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.MapSettings;
@@ -66,11 +65,6 @@ public class TestIndexerTest {

private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());

@Before
public void setUp() {
underTest.setEnabled(true);
}

@Test
public void index_tests() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java 查看文件

@@ -90,7 +90,7 @@ public class UserUpdaterTest {

@Before
public void setUp() {
userIndexer = (UserIndexer) new UserIndexer(dbClient, es.client()).setEnabled(true);
userIndexer = new UserIndexer(dbClient, es.client());
userUpdater = new UserUpdater(newUserNotifier, settings, dbClient,
userIndexer, system2);


+ 1
- 11
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java 查看文件

@@ -64,17 +64,7 @@ public class UserIndexerTest {
assertThat(doc.updatedAt()).isEqualTo(1500000000000L);
}

@Test
public void do_nothing_if_disabled() {
dbTester.prepareDbUnit(getClass(), "index.xml");

createIndexer().setEnabled(false).index();
assertThat(esTester.countDocuments("users", "user")).isEqualTo(0);
}

private UserIndexer createIndexer() {
UserIndexer indexer = new UserIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
indexer.setEnabled(true);
return indexer;
return new UserIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}
}

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java 查看文件

@@ -95,7 +95,7 @@ public class ChangePasswordActionTest {
groupDao.insert(session, new GroupDto().setName("sonar-users"));
session.commit();

userIndexer = (UserIndexer) new UserIndexer(dbClient, esTester.client()).setEnabled(true);
userIndexer = new UserIndexer(dbClient, esTester.client());
index = new UserIndex(esTester.client());
userUpdater = new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2);
tester = new WsTester(new UsersWs(new ChangePasswordAction(userUpdater, userSessionRule)));

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java 查看文件

@@ -91,7 +91,7 @@ public class CreateActionTest {
groupDao.insert(session, new GroupDto().setName("sonar-users"));
session.commit();

userIndexer = (UserIndexer) new UserIndexer(dbClient, esTester.client()).setEnabled(true);
userIndexer = new UserIndexer(dbClient, esTester.client());
index = new UserIndex(esTester.client());
tester = new WsTester(new UsersWs(new CreateAction(dbClient,
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2),

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java 查看文件

@@ -79,7 +79,7 @@ public class DeactivateActionTest {
dbSession = db.getSession();
dbSession.commit();

userIndexer = (UserIndexer) new UserIndexer(dbClient, esTester.client()).setEnabled(true);
userIndexer = new UserIndexer(dbClient, esTester.client());
index = new UserIndex(esTester.client());
ws = new WsTester(new UsersWs(new DeactivateAction(
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2), userSessionRule,

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java 查看文件

@@ -70,7 +70,7 @@ public class SearchActionTest {
DbSession dbSession = db.getSession();

UserIndex index = new UserIndex(esTester.client());
UserIndexer userIndexer = (UserIndexer) new UserIndexer(dbClient, esTester.client()).setEnabled(true);
UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
WsTester ws = new WsTester(new UsersWs(new SearchAction(index, dbClient, new UserJsonWriter(userSession))));

@Test

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java 查看文件

@@ -76,7 +76,7 @@ public class UpdateActionTest {
dbClient.groupDao().insert(session, new GroupDto().setName("sonar-users"));
session.commit();

userIndexer = (UserIndexer) new UserIndexer(dbClient, esTester.client()).setEnabled(true);
userIndexer = new UserIndexer(dbClient, esTester.client());
tester = new WsTester(new UsersWs(new UpdateAction(
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2), userSessionRule,
new UserJsonWriter(userSessionRule), dbClient)));

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java 查看文件

@@ -68,7 +68,7 @@ public class ViewIndexerTest {

DbSession dbSession = dbTester.getSession();

ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client()).setEnabled(true);
private ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client());

@Test
public void index_nothing() {
@@ -146,8 +146,8 @@ public class ViewIndexerTest {
@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule);
IssueIndexer issueIndexer = (IssueIndexer) new IssueIndexer(dbClient, esTester.client()).setEnabled(true);
IssueAuthorizationIndexer issueAuthorizationIndexer = (IssueAuthorizationIndexer) new IssueAuthorizationIndexer(dbClient, esTester.client()).setEnabled(true);
IssueIndexer issueIndexer = new IssueIndexer(dbClient, esTester.client());
IssueAuthorizationIndexer issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());

String viewUuid = "ABCD";


Loading…
取消
儲存