Search in sources :

Example 11 with ContainerMatrixTest

use of org.graylog.testing.containermatrix.annotations.ContainerMatrixTest in project graylog2-server by Graylog2.

the class MessagesResourceIT method testInvalidQueryResponse.

@ContainerMatrixTest
void testInvalidQueryResponse() {
    sut.importElasticsearchFixture("messages-for-export.json", MessagesResourceIT.class);
    String allMessagesTimeRange = "{\"timerange\": {\"type\": \"absolute\", \"from\": \"2015-01-01T00:00:00\", \"to\": \"2015-01-01T23:59:59\"}}";
    Response r = given().spec(requestSpec).accept("text/csv").body(allMessagesTimeRange).expect().response().statusCode(200).contentType("text/csv").when().post("/views/search/messages");
    String[] resultLines = r.asString().split("\n");
    assertThat(resultLines).startsWith("\"timestamp\",\"source\",\"message\"").as("should contain header");
    assertThat(Arrays.copyOfRange(resultLines, 1, 5)).containsExactlyInAnyOrder("\"2015-01-01T04:00:00.000Z\",\"source-2\",\"Ho\"", "\"2015-01-01T03:00:00.000Z\",\"source-1\",\"Hi\"", "\"2015-01-01T02:00:00.000Z\",\"source-2\",\"He\"", "\"2015-01-01T01:00:00.000Z\",\"source-1\",\"Ha\"");
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 12 with ContainerMatrixTest

use of org.graylog.testing.containermatrix.annotations.ContainerMatrixTest in project graylog2-server by Graylog2.

the class CountsIT method totalSucceedsWithListOfIndicesLargerThan4Kilobytes.

@ContainerMatrixTest
public void totalSucceedsWithListOfIndicesLargerThan4Kilobytes() {
    final int numberOfIndices = 100;
    final String[] indexNames = new String[numberOfIndices];
    final String indexPrefix = "very_long_list_of_indices_0123456789_counts_it_";
    final IndexSet indexSet = mock(IndexSet.class);
    for (int i = 0; i < numberOfIndices; i++) {
        final String indexName = indexPrefix + i;
        client().createIndex(indexName);
        indexNames[i] = indexName;
    }
    when(indexSet.getManagedIndices()).thenReturn(indexNames);
    final String indicesString = String.join(",", indexNames);
    assertThat(indicesString.length()).isGreaterThanOrEqualTo(4096);
    assertThat(counts.total(indexSet)).isEqualTo(0L);
}
Also used : IndexSet(org.graylog2.indexer.IndexSet) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 13 with ContainerMatrixTest

use of org.graylog.testing.containermatrix.annotations.ContainerMatrixTest in project graylog2-server by Graylog2.

the class CountsIT method totalReturnsNumberOfMessages.

@ContainerMatrixTest
public void totalReturnsNumberOfMessages() {
    final BulkIndexRequest bulkIndexRequest = new BulkIndexRequest();
    final int count1 = 10;
    for (int i = 0; i < count1; i++) {
        final Map<String, Object> source = ImmutableMap.of("foo", "bar", "counter", i);
        bulkIndexRequest.addRequest(INDEX_NAME_1, source);
    }
    final int count2 = 5;
    for (int i = 0; i < count2; i++) {
        final Map<String, Object> source = ImmutableMap.of("foo", "bar", "counter", i);
        bulkIndexRequest.addRequest(INDEX_NAME_2, source);
    }
    client().bulkIndex(bulkIndexRequest);
    assertThat(counts.total()).isEqualTo(count1 + count2);
    assertThat(counts.total(indexSet1)).isEqualTo(count1);
    assertThat(counts.total(indexSet2)).isEqualTo(count2);
}
Also used : BulkIndexRequest(org.graylog.testing.elasticsearch.BulkIndexRequest) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 14 with ContainerMatrixTest

use of org.graylog.testing.containermatrix.annotations.ContainerMatrixTest in project graylog2-server by Graylog2.

the class CountsIT method totalThrowsElasticsearchExceptionIfIndexDoesNotExist.

@ContainerMatrixTest
public void totalThrowsElasticsearchExceptionIfIndexDoesNotExist() {
    final IndexSet indexSet = mock(IndexSet.class);
    when(indexSet.getManagedIndices()).thenReturn(new String[] { "does_not_exist" });
    try {
        counts.total(indexSet);
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        final String expectedErrorDetail = "Index not found for query: does_not_exist. Try recalculating your index ranges.";
        assertThat(e).hasMessageStartingWith("Fetching message count failed for indices [does_not_exist]").hasMessageEndingWith(expectedErrorDetail).hasNoSuppressedExceptions();
        assertThat(e.getErrorDetails()).containsExactly(expectedErrorDetail);
    }
}
Also used : IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) IndexSet(org.graylog2.indexer.IndexSet) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 15 with ContainerMatrixTest

use of org.graylog.testing.containermatrix.annotations.ContainerMatrixTest in project graylog2-server by Graylog2.

the class IndicesIT method getIndices.

@ContainerMatrixTest
public void getIndices() {
    final IndexSet indexSet = new TestIndexSet(indexSetConfig.toBuilder().indexPrefix("indices_it").build());
    final String index1 = createRandomIndex("indices_it_");
    final String index2 = createRandomIndex("indices_it_");
    client().closeIndex(index2);
    assertThat(indices.getIndices(indexSet)).containsOnly(index1, index2);
    assertThat(indices.getIndices(indexSet, "open", "close")).containsOnly(index1, index2);
    assertThat(indices.getIndices(indexSet, "open")).containsOnly(index1);
    assertThat(indices.getIndices(indexSet, "close")).containsOnly(index2);
}
Also used : TestIndexSet(org.graylog2.indexer.TestIndexSet) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Aggregations

ContainerMatrixTest (org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)23 ValidatableResponse (io.restassured.response.ValidatableResponse)14 IndexSet (org.graylog2.indexer.IndexSet)4 ZonedDateTime (java.time.ZonedDateTime)3 DateTime (org.joda.time.DateTime)3 BulkIndexRequest (org.graylog.testing.elasticsearch.BulkIndexRequest)2 TestIndexSet (org.graylog2.indexer.TestIndexSet)2 IndexRangeStats (org.graylog2.indexer.searches.IndexRangeStats)2 Response (io.restassured.response.Response)1 IndexNotFoundException (org.graylog2.indexer.IndexNotFoundException)1 IndexSetStatsCreator (org.graylog2.indexer.IndexSetStatsCreator)1 IndexSetStats (org.graylog2.rest.resources.system.indexer.responses.IndexSetStats)1 Order (org.junit.jupiter.api.Order)1 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)1