use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project hazelcast by hazelcast.
the class CommonElasticSinksTest method given_batchOfDocuments_whenWriteToElasticSink_then_batchOfDocumentsInIndex.
@Test
public void given_batchOfDocuments_whenWriteToElasticSink_then_batchOfDocumentsInIndex() throws IOException {
Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(elasticClientSupplier()).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).build();
int batchSize = 10_000;
TestItem[] items = new TestItem[batchSize];
for (int i = 0; i < batchSize; i++) {
items[i] = new TestItem("id" + i, "name" + i);
}
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items(items)).writeTo(elasticSink);
submitJob(p);
refreshIndex();
SearchResponse response = elasticClient.search(new SearchRequest("my-index"), DEFAULT);
TotalHits totalHits = response.getHits().getTotalHits();
assertThat(totalHits.value).isEqualTo(batchSize);
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project hazelcast by hazelcast.
the class ElasticSourcePTest method givenMultipleResults_when_runProcessor_then_useScrollIdInFollowupScrollRequest.
@Test
public void givenMultipleResults_when_runProcessor_then_useScrollIdInFollowupScrollRequest() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(3, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
SearchHit hit2 = new SearchHit(1, "id-1", new Text("ignored"), emptyMap(), emptyMap());
hit2.sourceRef(new BytesArray(HIT_SOURCE2));
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit2 }, new TotalHits(3, EQUAL_TO), Float.NaN));
SearchResponse response3 = mock(SearchResponse.class);
when(response3.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(3, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2, response3);
TestSupport testSupport = runProcessor();
testSupport.expectOutput(newArrayList(HIT_SOURCE, HIT_SOURCE2));
ArgumentCaptor<SearchScrollRequest> captor = forClass(SearchScrollRequest.class);
verify(mockClient, times(2)).scroll(captor.capture(), any());
SearchScrollRequest request = captor.getValue();
assertThat(request.scrollId()).isEqualTo(SCROLL_ID);
assertThat(request.scroll().keepAlive().getStringRep()).isEqualTo(KEEP_ALIVE);
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithCoLocation_then_useLocalNodeOnly.
@Test
public void when_runProcessorWithCoLocation_then_useLocalNodeOnly() throws Exception {
RestClient lowClient = mock(RestClient.class);
when(mockClient.getLowLevelClient()).thenReturn(lowClient);
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
TestSupport testSupport = runProcessorWithCoLocation(newArrayList(new Shard("my-index", 0, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1")));
testSupport.expectOutput(emptyList());
ArgumentCaptor<Collection<Node>> nodesCaptor = ArgumentCaptor.forClass(Collection.class);
verify(lowClient).setNodes(nodesCaptor.capture());
Collection<Node> nodes = nodesCaptor.getValue();
assertThat(nodes).hasSize(1);
Node node = nodes.iterator().next();
assertThat(node.getHost().toHostString()).isEqualTo("10.0.0.1:9200");
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project hazelcast by hazelcast.
the class ElasticSourcePTest method given_singleHit_when_runProcessor_then_produceSingleHit.
@Test
public void given_singleHit_when_runProcessor_then_produceSingleHit() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(1, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(1, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2);
TestSupport testSupport = runProcessor();
testSupport.expectOutput(newArrayList(HIT_SOURCE));
}
use of org.graylog.shaded.elasticsearch7.org.apache.lucene.search.TotalHits in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(emptyList());
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).search(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
Aggregations