in order to wrap call to System.currentTimeMillis().
That is needed to bypass the condition
"if (requestedAt > lastUpdatedAt)" in tests.
import java.util.Iterator;
import javax.annotation.Nullable;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.measure.ProjectMeasuresIndexerIterator;
private final DbClient dbClient;
- public ProjectMeasuresIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES, FIELD_ANALYSED_AT);
+ public ProjectMeasuresIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES, FIELD_ANALYSED_AT);
this.dbClient = dbClient;
}
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.picocontainer.Startable;
+import org.sonar.api.utils.System2;
public abstract class BaseIndexer implements Startable {
+ private final System2 system2;
private final ThreadPoolExecutor executor;
private final String indexName;
private final String typeName;
- private final String dateFieldName;
protected final EsClient esClient;
+ private final String dateFieldName;
private volatile long lastUpdatedAt = -1L;
- protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
+ protected BaseIndexer(System2 system2, EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
String dateFieldName) {
+ this.system2 = system2;
this.indexName = indexName;
this.typeName = typeName;
this.dateFieldName = dateFieldName;
}
public void index(final IndexerTask task) {
- final long requestedAt = System.currentTimeMillis();
+ final long requestedAt = system2.now();
Future submit = executor.submit(() -> {
if (lastUpdatedAt == -1L) {
lastUpdatedAt = esClient.getMaxFieldValue(indexName, typeName, dateFieldName);
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
private final DbClient dbClient;
- public IssueIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_ISSUE, FIELD_ISSUE_TECHNICAL_UPDATED_AT);
+ public IssueIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_ISSUE, FIELD_ISSUE_TECHNICAL_UPDATED_AT);
this.dbClient = dbClient;
}
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
private final DbClient dbClient;
- public ActiveRuleIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_ACTIVE_RULE, FIELD_ACTIVE_RULE_UPDATED_AT);
+ public ActiveRuleIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_ACTIVE_RULE, FIELD_ACTIVE_RULE_UPDATED_AT);
this.dbClient = dbClient;
}
import java.util.Iterator;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
private final DbClient dbClient;
- public RuleIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_RULE, FIELD_RULE_UPDATED_AT);
+ public RuleIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_RULE, FIELD_RULE_UPDATED_AT);
this.dbClient = dbClient;
}
*/
package org.sonar.server.test.index;
-import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
-import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
-import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
-import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
-
import java.util.Iterator;
import javax.annotation.Nullable;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.EsClient;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
+import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
+import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
+
/**
* Add to Elasticsearch index {@link TestIndexDefinition} the rows of
* db table FILE_SOURCES of type TEST that are not indexed yet
private final DbClient dbClient;
- public TestIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 0L, INDEX, TYPE, FIELD_UPDATED_AT);
+ public TestIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 0L, INDEX, TYPE, FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
import java.util.Iterator;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
private final DbClient dbClient;
- public UserIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, UserIndexDefinition.FIELD_UPDATED_AT);
+ public UserIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, UserIndexDefinition.FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
import java.util.List;
import java.util.Map;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
private final DbClient dbClient;
- public ViewIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, "updatedAt");
+ public ViewIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, "updatedAt");
this.dbClient = dbClient;
}
public class IssuesActionTest {
- final static String PROJECT_KEY = "struts";
- static final String PROJECT_UUID = "ABCD";
+ private static final String PROJECT_KEY = "struts";
+ private static final String PROJECT_UUID = "ABCD";
+ private static final String MODULE_KEY = "struts-core";
+ private static final String MODULE_UUID = "BCDE";
+ private final static String FILE_KEY = "Action.java";
+ private static final String FILE_UUID = "CDEF";
- final static String MODULE_KEY = "struts-core";
- static final String MODULE_UUID = "BCDE";
-
- final static String FILE_KEY = "Action.java";
- static final String FILE_UUID = "CDEF";
+ private System2 system2 = System2.INSTANCE;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
private IssueIndexer issueIndexer;
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es);
private ServerFileSystem fs = mock(ServerFileSystem.class);
-
- WsTester tester;
-
- IssuesAction issuesAction;
+ private WsTester tester;
+ private IssuesAction issuesAction;
@Before
public void before() {
- issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule);
- issueIndexer = new IssueIndexer(null, es.client());
+ issueIndex = new IssueIndex(es.client(), system2, userSessionRule);
+ issueIndexer = new IssueIndexer(system2, null, es.client());
issuesAction = new IssuesAction(db.getDbClient(), issueIndex, userSessionRule, new ComponentFinder(db.getDbClient()));
tester = new WsTester(new BatchWs(new BatchIndex(fs), issuesAction));
public class ComponentCleanerServiceTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(
@Rule
public ExpectedException expectedException = ExpectedException.none();
- DbClient dbClient = db.getDbClient();
- DbSession dbSession = db.getSession();
-
- PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client());
- IssueIndexer issueIndexer = new IssueIndexer(dbClient, es.client());
- TestIndexer testIndexer = new TestIndexer(dbClient, es.client());
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
-
- ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
+ private DbClient dbClient = db.getDbClient();
+ private DbSession dbSession = db.getSession();
+ private PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client());
+ private IssueIndexer issueIndexer = new IssueIndexer(system2, dbClient, es.client());
+ private TestIndexer testIndexer = new TestIndexer(system2, dbClient, es.client());
+ private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
+ private ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
- ComponentCleanerService underTest = new ComponentCleanerService(dbClient, issueIndexer, testIndexer, projectMeasuresIndexer, mockResourceTypes,
+ private ComponentCleanerService underTest = new ComponentCleanerService(dbClient, issueIndexer, testIndexer, projectMeasuresIndexer, mockResourceTypes,
new ComponentFinder(dbClient));
@Test
public class ComponentServiceTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- ComponentDbTester componentDb = new ComponentDbTester(dbTester);
- DbClient dbClient = dbTester.getDbClient();
- DbSession dbSession = dbTester.getSession();
-
- I18nRule i18n = new I18nRule();
+ private ComponentDbTester componentDb = new ComponentDbTester(dbTester);
+ private DbClient dbClient = dbTester.getDbClient();
+ private DbSession dbSession = dbTester.getSession();
+ private I18nRule i18n = new I18nRule();
+ private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
-
- ComponentService underTest;
+ private ComponentService underTest;
@Before
public void setUp() {
i18n.put("qualifier.TRK", "Project");
- underTest = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient), projectMeasuresIndexer);
+ underTest = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient), projectMeasuresIndexer);
}
@Test
public class ComponentServiceUpdateKeyTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
ComponentDbTester componentDb = new ComponentDbTester(db);
DbClient dbClient = db.getDbClient();
I18nRule i18n = new I18nRule();
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
+ ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
ComponentService underTest;
public void setUp() {
i18n.put("qualifier.TRK", "Project");
- underTest = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient), projectMeasuresIndexer);
+ underTest = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient), projectMeasuresIndexer);
}
@Test
public class DefaultRubyComponentServiceTest {
+ private System2 system2 = mock(System2.class);
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
private DbSession dbSession = db.getSession();
private ResourceDao resourceDao = dbClient.resourceDao();
- private ComponentService componentService = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient),
- new ProjectMeasuresIndexer(dbClient, es.client()));
+ private ComponentService componentService = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()));
private PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
private FavoriteService favoriteService = mock(FavoriteService.class);
public class ProjectMeasuresIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(esTester);
- ProjectMeasuresIndexer underTest = new ProjectMeasuresIndexer(dbTester.getDbClient(), esTester.client());
+ ProjectMeasuresIndexer underTest = new ProjectMeasuresIndexer(system2, dbTester.getDbClient(), esTester.client());
@Test
public void index_nothing() {
static final String FROM = "my_";
static final String TO = "your_";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public ExpectedException expectedException = ExpectedException.none();
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
ComponentDbTester componentDb = new ComponentDbTester(db);
DbClient dbClient = db.getDbClient();
ComponentFinder componentFinder = new ComponentFinder(dbClient);
WsActionTester ws = new WsActionTester(
- new BulkUpdateKeyAction(dbClient, componentFinder, new ComponentService(dbClient, null, null, null, null, new ProjectMeasuresIndexer(dbClient, es.client())), userSession));
+ new BulkUpdateKeyAction(dbClient, componentFinder, new ComponentService(dbClient, null, null, null, null, new ProjectMeasuresIndexer(system2, dbClient, es.client())), userSession));
@Before
public void setUp() {
public class IndexTestsStepTest extends BaseStepTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new TestIndexDefinition(new MapSettings()));
@Override
protected ComputationStep step() {
- TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
+ TestIndexer testIndexer = new TestIndexer(system2, dbClient, esTester.client());
return new IndexTestsStep(testIndexer, treeRootHolder);
}
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ private System2 system2 = System2.INSTANCE;
IssueIndex index;
IssueIndexer issueIndexer;
@Before
public void setUp() {
- issueIndexer = new IssueIndexer(null, tester.client());
- viewIndexer = new ViewIndexer(null, tester.client());
+ issueIndexer = new IssueIndexer(system2, null, tester.client());
+ viewIndexer = new ViewIndexer(system2, null, tester.client());
System2 system = mock(System2.class);
when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
when(system.now()).thenReturn(System.currentTimeMillis());
public class IssueIndexTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester tester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
@Before
public void setUp() {
- issueIndexer = new IssueIndexer(null, tester.client());
- viewIndexer = new ViewIndexer(null, tester.client());
+ issueIndexer = new IssueIndexer(system2, null, tester.client());
+ viewIndexer = new ViewIndexer(system2, null, tester.client());
System2 system = mock(System2.class);
when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00"));
when(system.now()).thenReturn(System.currentTimeMillis());
private static final String A_PROJECT_UUID = "P1";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Test
public void index_nothing() {
}
private IssueIndexer createIndexer() {
- return new IssueIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
+ return new IssueIndexer(system2, new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}
private void addIssue(String projectUuid, String issueKey) throws Exception {
private static final String ACTION = "bulk_delete";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()),
@Rule
public ExpectedException expectedException = ExpectedException.none();
- WsTester ws;
- DbClient dbClient = db.getDbClient();
+ private WsTester ws;
+ private DbClient dbClient = db.getDbClient();
final DbSession dbSession = db.getSession();
- ResourceType resourceType;
+ private ResourceType resourceType;
@Before
public void setUp() {
ws = new WsTester(new ProjectsWs(
new BulkDeleteAction(
new ComponentCleanerService(dbClient,
- new IssueIndexer(dbClient, es.client()),
- new TestIndexer(dbClient, es.client()),
- new ProjectMeasuresIndexer(dbClient, es.client()),
+ new IssueIndexer(system2, dbClient, es.client()),
+ new TestIndexer(system2, dbClient, es.client()),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()),
mockResourceTypes,
new ComponentFinder(dbClient)),
dbClient,
private static final String ACTION = "delete";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(
@Rule
public ExpectedException expectedException = ExpectedException.none();
- WsTester ws;
-
- DbClient dbClient = db.getDbClient();
-
- final DbSession dbSession = db.getSession();
-
- ResourceType resourceType;
+ private WsTester ws;
+ private DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private ResourceType resourceType;
@Before
public void setUp() {
new DeleteAction(
new ComponentCleanerService(
dbClient,
- new IssueIndexer(dbClient, es.client()),
- new TestIndexer(dbClient, es.client()),
- new ProjectMeasuresIndexer(dbClient, es.client()),
+ new IssueIndexer(system2, dbClient, es.client()),
+ new TestIndexer(system2, dbClient, es.client()),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()),
mockResourceTypes,
new ComponentFinder(dbClient)),
new ComponentFinder(dbClient),
import org.junit.Test;
import org.sonar.api.config.MapSettings;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.System2;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
private static final String QUALITY_PROFILE_KEY1 = "qp1";
private static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester tester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@Before
public void setUp() {
- activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
- ruleIndexer = new RuleIndexer(null, tester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
+ ruleIndexer = new RuleIndexer(system2, null, tester.client());
index = new ActiveRuleIndex(tester.client());
}
public class ActiveRuleIndexerTest {
- static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
- static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+ private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final String QUALITY_PROFILE_KEY1 = "qp1";
+ private static final String QUALITY_PROFILE_KEY2 = "qp2";
- static final String QUALITY_PROFILE_KEY1 = "qp1";
- static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private ActiveRuleIndexer indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
+ private ActiveRuleIndexer indexer = new ActiveRuleIndexer(system2, dbTester.getDbClient(), esTester.client());
@Test
public void index_nothing() {
static final String LANGUAGE_1 = "xoo";
static final String LANGUAGE_2 = "foo";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
WsActionTester ws = new WsActionTester(new AddProjectAction(projectAssociationParameters,
qProfileProjectOperations, new ProjectAssociationFinder(new QProfileLookup(dbClient),
- new ComponentService(dbClient, null, userSession, null, new ComponentFinder(dbClient), new ProjectMeasuresIndexer(dbClient, es.client()))),
+ new ComponentService(dbClient, null, userSession, null, new ComponentFinder(dbClient), new ProjectMeasuresIndexer(system2, dbClient, es.client()))),
userSession));
@Before
public class CreateActionTest {
- static final String XOO_LANGUAGE = "xoo";
-
- static final RuleDto RULE = RuleTesting.newXooX1().setSeverity("MINOR").setLanguage(XOO_LANGUAGE);
+ private static final String XOO_LANGUAGE = "xoo";
+ private static final RuleDto RULE = RuleTesting.newXooX1().setSeverity("MINOR").setLanguage(XOO_LANGUAGE);
+ private System2 system2 = System2.INSTANCE;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
DbSession dbSession = dbTester.getSession();
RuleIndex ruleIndex = new RuleIndex(esTester.client());
- RuleIndexer ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ RuleIndexer ruleIndexer = new RuleIndexer(system2, dbClient, esTester.client());
ActiveRuleIndex activeRuleIndex = new ActiveRuleIndex(esTester.client());
- ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
+ ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(system2, dbClient, esTester.client());
ProfileImporter[] profileImporters = createImporters();
private static final RuleKey RULE_KEY2 = RuleKey.of("fake", "rule2");
private static final RuleKey RULE_KEY3 = RuleKey.of("fake", "rule3");
- private System2 system = mock(System2.class);;
+ private System2 system = mock(System2.class);
@org.junit.Rule
public DbTester dbTester = DbTester.create(system);
@Before
public void before() {
when(system.now()).thenReturn(DATE1.getTime());
- ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ ruleIndexer = new RuleIndexer(system, dbClient, esTester.client());
ruleIndex = new RuleIndex(esTester.client());
- activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system, dbClient, esTester.client());
}
@Test
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
+import org.sonar.api.utils.System2;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
public class RuleIndexTest {
- static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
- static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
- static final RuleKey RULE_KEY_4 = RuleKey.of("xoo", "x4");
+ private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+ private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final RuleKey RULE_KEY_4 = RuleKey.of("xoo", "x4");
+ private static final String QUALITY_PROFILE_KEY1 = "qp1";
+ private static final String QUALITY_PROFILE_KEY2 = "qp2";
- static final String QUALITY_PROFILE_KEY1 = "qp1";
- static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
@Rule
public EsTester tester = new EsTester(new RuleIndexDefinition(new MapSettings()));
- RuleIndex index;
- RuleIndexer ruleIndexer;
- ActiveRuleIndexer activeRuleIndexer;
+ private RuleIndex index;
+ private RuleIndexer ruleIndexer;
+ private ActiveRuleIndexer activeRuleIndexer;
@Before
public void setUp() {
- ruleIndexer = new RuleIndexer(null, tester.client());
- activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
+ ruleIndexer = new RuleIndexer(system2, null, tester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
index = new RuleIndex(tester.client());
}
import static com.google.common.collect.Sets.newHashSet;
import static org.assertj.core.api.Assertions.assertThat;
-
public class RuleIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- DbClient dbClient = dbTester.getDbClient();
-
- DbSession dbSession = dbTester.getSession();
+ public DbTester dbTester = DbTester.create(system2);
- RuleDto rule = new RuleDto()
+ private DbClient dbClient = dbTester.getDbClient();
+ private DbSession dbSession = dbTester.getSession();
+ private RuleDto rule = new RuleDto()
.setRuleKey("S001")
.setRepositoryKey("xoo")
.setConfigKey("S1")
}
private RuleIndexer createIndexer() {
- return new RuleIndexer(dbTester.getDbClient(), esTester.client());
+ return new RuleIndexer(system2, dbTester.getDbClient(), esTester.client());
}
}
private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
- System2 system2 = mock(System2.class);
+ private System2 system2 = mock(System2.class);
@Rule
public DbTester tester = DbTester.create(system2);
@Rule
public LogTester logTester = new LogTester();
- DbClient dbClient = tester.getDbClient();
- DbSession dbSession = tester.getSession();
- RuleDao ruleDao = new RuleDao();
- RuleIndexer ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ private DbClient dbClient = tester.getDbClient();
+ private DbSession dbSession = tester.getSession();
+ private RuleDao ruleDao = new RuleDao();
+ private RuleIndexer ruleIndexer = new RuleIndexer(system2, dbClient, esTester.client());
- ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(system2, dbClient, ruleIndexer);
+ private ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(system2, dbClient, ruleIndexer);
@Test
public void remove_overridden_debt() throws Exception {
public class TestIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
- private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());
+ private TestIndexer underTest = new TestIndexer(system2, db.getDbClient(), es.client());
@Test
public void index_tests() throws Exception {
@Before
public void setUp() {
- userIndexer = new UserIndexer(dbClient, es.client());
+ userIndexer = new UserIndexer(system2, dbClient, es.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
underTest = new UserUpdater(newUserNotifier, settings, dbClient,
userIndexer, system2, defaultOrganizationProvider);
public class UserIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
}
private UserIndexer createIndexer() {
- return new UserIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
+ return new UserIndexer(system2, new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}
}
public class ChangePasswordActionTest {
+ private System2 system2 = System2.INSTANCE;
private Settings settings = new MapSettings();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
groupDao.insert(session, GroupTesting.newGroupDto().setName("sonar-users"));
session.commit();
- UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
+ UserIndexer userIndexer = new UserIndexer(system2, dbClient, esTester.client());
userUpdater = new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2, defaultOrganizationProvider);
tester = new WsTester(new UsersWs(new ChangePasswordAction(userUpdater, userSessionRule)));
}
private static final String DEFAULT_GROUP_NAME = "sonar-users";
private Settings settings = new MapSettings().setProperty("sonar.defaultGroup", DEFAULT_GROUP_NAME);
+ private System2 system2 = new AlwaysIncreasingSystem2();
@Rule
- public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
@Before
public void setUp() {
- System2 system2 = new System2();
defaultGroupInDefaultOrg = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME);
- userIndexer = new UserIndexer(db.getDbClient(), esTester.client());
+ userIndexer = new UserIndexer(system2, db.getDbClient(), esTester.client());
index = new UserIndex(esTester.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
tester = new WsTester(new UsersWs(new CreateAction(db.getDbClient(),
public class DeactivateActionTest {
+ private System2 system2 = System2.INSTANCE;
private Settings settings = new MapSettings();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Before
public void setUp() {
- System2 system2 = new System2();
UserDao userDao = new UserDao(db.myBatis(), system2);
dbClient = new DbClient(db.database(), db.myBatis(), userDao, new GroupMembershipDao(), new UserTokenDao());
dbSession = db.getSession();
dbSession.commit();
- userIndexer = new UserIndexer(dbClient, esTester.client());
+ userIndexer = new UserIndexer(system2, dbClient, esTester.client());
index = new UserIndex(esTester.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
ws = new WsTester(new UsersWs(new DeactivateAction(
public class SearchActionTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
private UserIndex index = new UserIndex(esTester.client());
- private UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
+ private UserIndexer userIndexer = new UserIndexer(system2, dbClient, esTester.client());
private WsTester ws = new WsTester(new UsersWs(new SearchAction(index, dbClient, new UserJsonWriter(userSession))));
@Test
dbClient.groupDao().insert(session, newGroupDto().setName("sonar-users"));
session.commit();
- userIndexer = new UserIndexer(dbClient, esTester.client());
+ userIndexer = new UserIndexer(system2, dbClient, esTester.client());
tester = new WsTester(new UsersWs(new UpdateAction(
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2, defaultOrganizationProvider), userSessionRule,
new UserJsonWriter(userSessionRule), dbClient)));
*/
package org.sonar.server.view.index;
-import com.google.common.base.Function;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
public class ViewIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
- private ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client());
+ private ViewIndexer indexer = (ViewIndexer) new ViewIndexer(system2, dbClient, esTester.client());
@Test
public void index_nothing() {
List<ViewDoc> docs = esTester.getDocuments("views", "view", ViewDoc.class);
assertThat(docs).hasSize(4);
- Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, new Function<ViewDoc, String>() {
- @Override
- public String apply(ViewDoc doc) {
- return doc.uuid();
- }
- });
+ Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, ViewDoc::uuid);
assertThat(viewsByUuid.get("ABCD").projects()).containsOnly("JKLM");
assertThat(viewsByUuid.get("EFGH").projects()).containsOnly("KLMN", "JKLM");
List<ViewDoc> docs = esTester.getDocuments("views", "view", ViewDoc.class);
assertThat(docs).hasSize(2);
- Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, new Function<ViewDoc, String>() {
- @Override
- public String apply(ViewDoc doc) {
- return doc.uuid();
- }
- });
+ Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, ViewDoc::uuid);
assertThat(viewsByUuid.get("EFGH").projects()).containsOnly("KLMN", "JKLM");
assertThat(viewsByUuid.get("FGHI").projects()).containsOnly("JKLM");
@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule);
- IssueIndexer issueIndexer = new IssueIndexer(dbClient, esTester.client());
+ IssueIndexer issueIndexer = new IssueIndexer(system2, dbClient, esTester.client());
PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, esTester.client());
String viewUuid = "ABCD";