Exemplo n.º 1
0
  @Test
  public void searchBySourceFileUuidAndLineNumber() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("10"),
            newCoveredFileDoc("11"),
            newCoveredFileDoc("12")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "3",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<TestDoc> result =
        underTest.searchBySourceFileUuidAndLineNumber("main-uuid-5", 82, searchOptions()).getDocs();

    assertThat(result).hasSize(2);
    assertThat(result).extractingResultOf("name").containsOnly("name-2", "name-3");
  }
Exemplo n.º 2
0
  @Test
  public void coveredFiles() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<CoveredFileDoc> result = underTest.coveredFiles("1");

    assertThat(result).hasSize(3);
    assertThat(result)
        .extractingResultOf("fileUuid")
        .containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
    assertThat(result.get(0).coveredLines()).containsOnly(25, 33, 82);
  }
Exemplo n.º 3
0
  @Test
  public void getNullableByTestUuid() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    Optional<TestDoc> result = underTest.getNullableByTestUuid("1");

    assertThat(result).isPresent();
    TestDoc test = result.get();
    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");
    assertThat(test.message()).isEqualTo("message-1");
    assertThat(test.coveredFiles()).hasSize(3);
    assertThat(test.coveredFiles())
        .extractingResultOf("fileUuid")
        .containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
  }
Exemplo n.º 4
0
  @Test
  public void searchByTestUuid_with_SearchOptions() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<TestDoc> result = underTest.searchByTestUuid("1", searchOptions()).getDocs();

    assertThat(result).hasSize(1);
    assertThat(result.get(0).testUuid()).isEqualTo("1");
  }
  private static IndexReader build(Random random, TestIndex index) throws IOException {
    /* build an index */

    Document doc = new Document();
    Field idField = newField(random, "id", "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
    Field randField =
        newField(random, "rand", "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
    Field bodyField =
        newField(random, "body", "", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);
    doc.add(idField);
    doc.add(randField);
    doc.add(bodyField);

    RandomIndexWriter writer =
        new RandomIndexWriter(
            random,
            index.index,
            newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random))
                .setOpenMode(OpenMode.CREATE)
                .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))
                .setMergePolicy(newLogMergePolicy()));
    _TestUtil.reduceOpenFiles(writer.w);
    while (true) {

      int minCount = 0;
      int maxCount = 0;

      for (int d = minId; d <= maxId; d++) {
        idField.setValue(pad(d));
        int r =
            index.allowNegativeRandomInts ? random.nextInt() : random.nextInt(Integer.MAX_VALUE);
        if (index.maxR < r) {
          index.maxR = r;
          maxCount = 1;
        } else if (index.maxR == r) {
          maxCount++;
        }

        if (r < index.minR) {
          index.minR = r;
          minCount = 1;
        } else if (r == index.minR) {
          minCount++;
        }
        randField.setValue(pad(r));
        bodyField.setValue("body");
        writer.addDocument(doc);
      }

      if (minCount == 1 && maxCount == 1) {
        // our subclasses rely on only 1 doc having the min or
        // max, so, we loop until we satisfy that.  it should be
        // exceedingly rare (Yonik calculates 1 in ~429,000)
        // times) that this loop requires more than one try:
        IndexReader ir = writer.getReader();
        writer.close();
        return ir;
      }

      // try again
      writer.deleteAll();
    }
  }
Exemplo n.º 6
0
  @Test
  public void getNullableByTestUuid_with_absent_value() {
    Optional<TestDoc> result = underTest.getNullableByTestUuid("unknown-uuid");

    assertThat(result).isAbsent();
  }