use of org.graylog.testing.elasticsearch.BulkIndexRequest in project graylog2-server by Graylog2.
the class ClientES7 method bulkIndex.
@Override
public void bulkIndex(BulkIndexRequest bulkIndexRequest) {
final BulkRequest bulkRequest = new BulkRequest();
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
bulkIndexRequest.requests().forEach((indexName, documents) -> documents.forEach(doc -> bulkRequest.add(createIndexRequest(indexName, doc))));
client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
}
use of org.graylog.testing.elasticsearch.BulkIndexRequest 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);
}
use of org.graylog.testing.elasticsearch.BulkIndexRequest in project graylog2-server by Graylog2.
the class CountsIT method totalReturnsZeroWithNoIndices.
@ContainerMatrixTest
@Order(2)
public void totalReturnsZeroWithNoIndices() {
final BulkIndexRequest bulkIndexRequest = new BulkIndexRequest();
for (int i = 0; i < 10; i++) {
final Map<String, Object> source = ImmutableMap.of("foo", "bar", "counter", i);
bulkIndexRequest.addRequest(INDEX_NAME_3, source);
}
client().bulkIndex(bulkIndexRequest);
// Simulate no indices for the second index set.
when(indexSet2.getManagedIndices()).thenReturn(new String[0]);
assertThat(counts.total(indexSet1)).isEqualTo(0L);
assertThat(counts.total(indexSet2)).isEqualTo(0L);
assertThat(counts.total(indexSet3)).isEqualTo(10L);
// Simulate no indices for all index sets.
when(indexSetRegistry.getManagedIndices()).thenReturn(new String[0]);
assertThat(counts.total()).isEqualTo(0L);
}
Aggregations