Search in sources :

Example 66 with Pipeline

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

the class CommonElasticSourcesTest method given_sourceCreatedByFactoryMethod3_whenReadFromElasticSource_thenFinishWithOneResult.

@Test
public void given_sourceCreatedByFactoryMethod3_whenReadFromElasticSource_thenFinishWithOneResult() {
    indexDocument("my-index-1", of("name", "Frantisek"));
    indexDocument("my-index-2", of("name", "Vladimir"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = ElasticSources.elastic(elasticClientSupplier(), () -> new SearchRequest("my-index-1"), hit -> (String) hit.getSourceAsMap().get("name"));
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsExactly("Frantisek");
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 67 with Pipeline

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

the class CommonElasticSourcesTest method given_documents_when_readFromElasticSourceWithQuery_then_resultHasMatchingDocuments.

@Test
public void given_documents_when_readFromElasticSourceWithQuery_then_resultHasMatchingDocuments() {
    indexDocument("my-index", of("name", "Frantisek"));
    indexDocument("my-index", of("name", "Vladimir"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index").source(new SearchSourceBuilder().query(QueryBuilders.matchQuery("name", "Frantisek")))).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) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Example 68 with Pipeline

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

the class CommonElasticSourcesTest method given_multipleDocuments_when_readFromElasticSourceWithScroll_then_resultHasAllDocuments.

@Test
public void given_multipleDocuments_when_readFromElasticSourceWithScroll_then_resultHasAllDocuments() throws IOException {
    indexBatchOfDocuments("my-index");
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> {
        SearchRequest sr = new SearchRequest("my-index");
        // needs to scroll 5 times
        sr.source().size(10).query(matchAllQuery());
        return sr;
    }).mapToItemFn(SearchHit::getSourceAsString).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).hasSize(BATCH_SIZE);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 69 with Pipeline

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

the class CommonElasticSourcesTest method given_multipleIndexes_when_readFromElasticSourceWithIndexWildcard_then_resultDocumentsFromAllIndexes.

@Test
public void given_multipleIndexes_when_readFromElasticSourceWithIndexWildcard_then_resultDocumentsFromAllIndexes() {
    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-*")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsOnlyOnce("Frantisek", "Vladimir");
}
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 70 with Pipeline

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

the class CommonElasticSourcesTest method given_nonExistingIndex_whenReadFromElasticSource_thenThrowException.

@Test
public void given_nonExistingIndex_whenReadFromElasticSource_thenThrowException() {
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("non-existing-index")).mapToItemFn(SearchHit::getSourceAsString).retries(// we expect the exception -> faster test
    0).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ResponseException.class).hasStackTraceContaining("no such index [non-existing-index]");
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchHit(org.elasticsearch.search.SearchHit) ResponseException(org.elasticsearch.client.ResponseException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)379 Test (org.junit.Test)300 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)142 QuickTest (com.hazelcast.test.annotation.QuickTest)142 Job (com.hazelcast.jet.Job)125 Sinks (com.hazelcast.jet.pipeline.Sinks)107 Category (org.junit.experimental.categories.Category)100 HazelcastInstance (com.hazelcast.core.HazelcastInstance)94 JobConfig (com.hazelcast.jet.config.JobConfig)86 Assert.assertEquals (org.junit.Assert.assertEquals)73 List (java.util.List)72 NightlyTest (com.hazelcast.test.annotation.NightlyTest)65 Before (org.junit.Before)64 Entry (java.util.Map.Entry)61 TestSources (com.hazelcast.jet.pipeline.test.TestSources)58 Assert.assertTrue (org.junit.Assert.assertTrue)50 Sources (com.hazelcast.jet.pipeline.Sources)49 IOException (java.io.IOException)48 BeforeClass (org.junit.BeforeClass)48 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)42