Search in sources :

Example 71 with Pipeline

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

the class CommonElasticSourcesTest method given_indexWithOneDocument_whenReadFromElasticSource_thenFinishWithOneResult.

@Test
public void given_indexWithOneDocument_whenReadFromElasticSource_thenFinishWithOneResult() {
    indexDocument("my-index", of("name", "Frantisek"));
    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).containsExactly("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 72 with Pipeline

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

the class CommonElasticSourcesTest method given_emptyIndex_when_readFromElasticSource_then_finishWithNoResults.

@Test
public void given_emptyIndex_when_readFromElasticSource_then_finishWithNoResults() throws IOException {
    // Ideally we would just create the index but it gives "field _id not found" when there are no documents
    // in the index, not sure if it is an Elastic bug or wrong setup
    // 
    // elasticClient.indices().create(new CreateIndexRequest("my-index"), DEFAULT);
    // Instead we index a document and delete it, ending up with index with correct settings applied
    indexDocument("my-index", of("name", "Frantisek"));
    deleteDocuments();
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index")).mapToItemFn(SearchHit::getSourceAsString).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).isEmpty();
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 73 with Pipeline

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

the class ElasticClientsTest method given_clientAsString_whenReadFromElasticSource_thenFinishSuccessfully.

@Test
public void given_clientAsString_whenReadFromElasticSource_thenFinishSuccessfully() {
    ElasticsearchContainer container = ElasticSupport.elastic.get();
    String httpHostAddress = container.getHttpHostAddress();
    indexDocument("my-index", ImmutableMap.of("name", "Frantisek"));
    Pipeline p = Pipeline.create();
    p.readFrom(ElasticSources.elastic(() -> ElasticClients.client(httpHostAddress), SearchHit::getSourceAsString)).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).hasSize(1);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 74 with Pipeline

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

the class BaseFileFormatTest method assertItemsInSource.

protected <T> void assertItemsInSource(int memberCount, FileSourceBuilder<T> source, ConsumerEx<List<T>> assertion) {
    if (useHadoop) {
        source.useHadoopForLocalFiles(true);
    }
    Pipeline p = Pipeline.create();
    p.readFrom(source.build()).apply(Assertions.assertCollected(assertion));
    HazelcastInstance[] instances = createHazelcastInstances(memberCount);
    try {
        instances[0].getJet().newJob(p).join();
    } finally {
        for (HazelcastInstance instance : instances) {
            instance.shutdown();
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 75 with Pipeline

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

the class AuthElasticSourcesTest method given_authenticatedClient_whenReadFromElasticSource_thenFinishSuccessfully.

@Test
public void given_authenticatedClient_whenReadFromElasticSource_thenFinishSuccessfully() {
    indexDocument("my-index", ImmutableMap.of("name", "Frantisek"));
    Pipeline p = Pipeline.create();
    p.readFrom(elasticSource(elasticClientSupplier())).writeTo(Sinks.list(results));
    submitJob(p);
}
Also used : 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