Пример #1
0
 @Before
 public void setUp() {
   es.truncateIndices();
   db.truncateTables();
   underTest = new TestIndexer(new DbClient(db.database(), db.myBatis()), es.client());
   underTest.setEnabled(true);
 }
Пример #2
0
  @Test
  public void index_tests_from_project() throws Exception {
    db.prepareDbUnit(getClass(), "db.xml");

    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));

    underTest.index("PROJECT_UUID");
    assertThat(countDocuments()).isEqualTo(3);
  }
Пример #3
0
  @Test
  public void index_nothing_from_unknown_project() throws Exception {
    db.prepareDbUnit(getClass(), "db.xml");

    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));

    underTest.index("UNKNOWN");
    assertThat(countDocuments()).isZero();
  }
Пример #4
0
  @Test
  public void delete_file_uuid() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F1", "T2", "U112");
    indexTest("P1", "F2", "T1", "U121");

    underTest.deleteByFile("F1");

    List<SearchHit> hits = getDocuments();
    Map<String, Object> document = hits.get(0).getSource();
    assertThat(hits).hasSize(1);
    assertThat(document.get(FIELD_NAME)).isEqualTo("NAME_1");
    assertThat(document.get(FIELD_FILE_UUID)).isEqualTo("F2");
  }
Пример #5
0
  @Test
  public void delete_by_project_uuid() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F1", "T2", "U112");
    indexTest("P1", "F2", "T1", "U121");
    indexTest("P2", "F3", "T1", "U231");

    underTest.deleteByProject("P1");

    List<SearchHit> hits = getDocuments();
    assertThat(hits).hasSize(1);
    Map<String, Object> document = hits.get(0).getSource();
    assertThat(hits).hasSize(1);
    assertThat(document.get(FIELD_PROJECT_UUID)).isEqualTo("P2");
  }
Пример #6
0
  public void execute() {
    if (!settings.getBoolean("sonar.internal.es.disableIndexes")) {
      LOG.info("Index activities");
      activityIndexer.setEnabled(true).index();

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

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

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

      LOG.info("Index views");
      viewIndexer.setEnabled(true).index();
    }
  }
Пример #7
0
  /**
   * File F1 in project P1 has one test -> to be updated File F2 in project P1 has one test ->
   * untouched
   */
  @Test
  public void update_already_indexed_test() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F2", "T1", "U121");

    FileSourcesUpdaterHelper.Row dbRow =
        TestResultSetIterator.toRow(
            "P1",
            "F1",
            new Date(),
            Arrays.asList(
                DbFileSources.Test.newBuilder()
                    .setUuid("U111")
                    .setName("NAME_1")
                    .setStatus(DbFileSources.Test.TestStatus.FAILURE)
                    .setMsg("NEW_MESSAGE_1")
                    .setStacktrace("NEW_STACKTRACE_1")
                    .setExecutionTimeMs(123_456L)
                    .addCoveredFile(
                        DbFileSources.Test.CoveredFile.newBuilder()
                            .setFileUuid("MAIN_UUID_1")
                            .addCoveredLine(42))
                    .build()));
    underTest.index(Iterators.singletonIterator(dbRow));

    assertThat(countDocuments()).isEqualTo(2L);

    SearchResponse fileSearch =
        prepareSearch().setQuery(QueryBuilders.termQuery(FIELD_FILE_UUID, "F1")).get();
    assertThat(fileSearch.getHits().getTotalHits()).isEqualTo(1L);
    Map<String, Object> fields = fileSearch.getHits().getHits()[0].sourceAsMap();
    assertThat(fields)
        .contains(
            entry(FIELD_PROJECT_UUID, "P1"),
            entry(FIELD_FILE_UUID, "F1"),
            entry(FIELD_TEST_UUID, "U111"),
            entry(FIELD_NAME, "NAME_1"),
            entry(FIELD_STATUS, "FAILURE"),
            entry(FIELD_MESSAGE, "NEW_MESSAGE_1"),
            entry(FIELD_STACKTRACE, "NEW_STACKTRACE_1"),
            entry(FIELD_DURATION_IN_MS, 123_456));
  }
 @Override
 protected ComputationStep step() {
   TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
   testIndexer.setEnabled(true);
   return new IndexTestsStep(testIndexer, treeRootHolder);
 }