use of com.hazelcast.jet.core.test.TestSupport in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest() 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);
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(newArrayList(HIT_SOURCE));
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).scroll(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
use of com.hazelcast.jet.core.test.TestSupport in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithParallelism_thenUseSlicingBasedOnGlobalValues.
@Test
public void when_runProcessorWithParallelism_thenUseSlicingBasedOnGlobalValues() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
TestSupport testSupport = runProcessor((r) -> RequestOptions.DEFAULT, emptyList(), true, false);
testSupport.localProcessorIndex(1);
testSupport.localParallelism(2);
testSupport.globalProcessorIndex(4);
testSupport.totalParallelism(6);
testSupport.expectOutput(emptyList());
ArgumentCaptor<SearchRequest> captor = forClass(SearchRequest.class);
verify(mockClient).search(captor.capture(), any());
SearchRequest request = captor.getValue();
SliceBuilder slice = request.source().slice();
// Slicing across all, should use global index / total parallelism
assertThat(slice.getId()).isEqualTo(4);
assertThat(slice.getMax()).isEqualTo(6);
}
use of com.hazelcast.jet.core.test.TestSupport in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithCoLocation_thenSearchShardsWithPreference.
@Test
public void when_runProcessorWithCoLocation_thenSearchShardsWithPreference() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
TestSupport processor = runProcessorWithCoLocation(newArrayList(new Shard("my-index", 0, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1"), new Shard("my-index", 1, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1"), new Shard("my-index", 2, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1")));
processor.expectOutput(emptyList());
ArgumentCaptor<SearchRequest> captor = forClass(SearchRequest.class);
verify(mockClient).search(captor.capture(), any());
SearchRequest request = captor.getValue();
assertThat(request.preference()).isEqualTo("_shards:0,1,2|_only_local");
}
use of com.hazelcast.jet.core.test.TestSupport in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessor_then_executeSearchRequestWithScroll.
@Test
public void when_runProcessor_then_executeSearchRequestWithScroll() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
TestSupport support = runProcessor();
support.expectOutput(emptyList());
ArgumentCaptor<SearchRequest> captor = forClass(SearchRequest.class);
verify(mockClient).search(captor.capture(), any());
SearchRequest request = captor.getValue();
assertThat(request.scroll().keepAlive().getStringRep()).isEqualTo(KEEP_ALIVE);
}
use of com.hazelcast.jet.core.test.TestSupport in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithCoLocationAndSlicing_thenUseSlicingBasedOnLocalValues.
@Test
public void when_runProcessorWithCoLocationAndSlicing_thenUseSlicingBasedOnLocalValues() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
TestSupport testSupport = runProcessor((r) -> RequestOptions.DEFAULT, newArrayList(new Shard("my-index", 0, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1"), new Shard("my-index", 1, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1"), new Shard("my-index", 2, Prirep.p, 42, "STARTED", "10.0.0.1", "10.0.0.1:9200", "es1")), true, true);
testSupport.localProcessorIndex(1);
testSupport.localParallelism(2);
testSupport.globalProcessorIndex(4);
testSupport.totalParallelism(6);
testSupport.expectOutput(emptyList());
ArgumentCaptor<SearchRequest> captor = forClass(SearchRequest.class);
verify(mockClient).search(captor.capture(), any());
SearchRequest request = captor.getValue();
SliceBuilder slice = request.source().slice();
// Slicing across single node, should use local values
assertThat(slice.getId()).isEqualTo(1);
assertThat(slice.getMax()).isEqualTo(2);
}
Aggregations