Search in sources :

Example 11 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class CommonElasticSourcesTest method given_multipleIndexes_when_readFromElasticSourceWithIndex_then_resultHasNoDocumentFromOtherIndex.

@Test
public void given_multipleIndexes_when_readFromElasticSourceWithIndex_then_resultHasNoDocumentFromOtherIndex() {
    indexDocument("my-index-1", of("name", "Frantisek"));
    indexDocument("my-index-2", of("name", "Vladimir"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index-1")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsOnlyOnce("Frantisek");
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) SearchHit(org.elasticsearch.search.SearchHit) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 12 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class LocalElasticSourcesTest method when_readFromElasticSource_then_shouldCloseAllCreatedClients.

@Test
public void when_readFromElasticSource_then_shouldCloseAllCreatedClients() throws IOException {
    indexDocument("my-index", of("name", "Frantisek"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(() -> {
        RestClientBuilder builder = spy(ElasticSupport.elasticClientSupplier().get());
        when(builder.build()).thenAnswer(invocation -> {
            Object result = invocation.callRealMethod();
            RestClient elasticClient = (RestClient) spy(result);
            ClientHolder.elasticClients.add(elasticClient);
            return elasticClient;
        });
        return builder;
    }).searchRequestFn(() -> new SearchRequest("my-index")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.logger());
    submitJob(p);
    for (RestClient elasticClient : ClientHolder.elasticClients) {
        verify(elasticClient).close();
    }
}
Also used : RestClient(org.elasticsearch.client.RestClient) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BatchSource(com.hazelcast.jet.pipeline.BatchSource) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collections.synchronizedList(java.util.Collections.synchronizedList) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) JetException(com.hazelcast.jet.JetException) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) After(org.junit.After) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) SearchRequest(org.elasticsearch.action.search.SearchRequest) RestClient(org.elasticsearch.client.RestClient) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

BatchSource (com.hazelcast.jet.pipeline.BatchSource)12 Pipeline (com.hazelcast.jet.pipeline.Pipeline)10 Test (org.junit.Test)10 Sinks (com.hazelcast.jet.pipeline.Sinks)9 SourceBuilder (com.hazelcast.jet.pipeline.SourceBuilder)6 List (java.util.List)6 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)5 IOException (java.io.IOException)5 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)5 SearchRequest (org.elasticsearch.action.search.SearchRequest)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 TestSources (com.hazelcast.jet.pipeline.test.TestSources)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 ConsumerEx (com.hazelcast.function.ConsumerEx)3 Job (com.hazelcast.jet.Job)3 Observable (com.hazelcast.jet.Observable)3 TestInClusterSupport (com.hazelcast.jet.TestInClusterSupport)3