Search in sources :

Example 1 with ElasticsearchContainer

use of org.testcontainers.elasticsearch.ElasticsearchContainer in project beam by apache.

the class ElasticsearchIOTestUtils method createTestContainer.

static ElasticsearchContainer createTestContainer(String imageTag) {
    ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch").withTag(imageTag)).withEnv("xpack.security.enabled", "false");
    container.withStartupTimeout(Duration.ofMinutes(3));
    return container;
}
Also used : ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer)

Example 2 with ElasticsearchContainer

use of org.testcontainers.elasticsearch.ElasticsearchContainer in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException.

@Test
public void given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException() {
    ElasticsearchContainer container = ElasticSupport.secureElastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> client("elastic", "WrongPassword", containerIp, port)).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).retries(0).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ElasticsearchStatusException.class).hasStackTraceContaining("unable to authenticate user [elastic]");
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 3 with ElasticsearchContainer

use of org.testcontainers.elasticsearch.ElasticsearchContainer 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 4 with ElasticsearchContainer

use of org.testcontainers.elasticsearch.ElasticsearchContainer in project hazelcast by hazelcast.

the class ElasticSupport method secureElasticClientSupplier.

public static SupplierEx<RestClientBuilder> secureElasticClientSupplier() {
    ElasticsearchContainer container = elastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    return () -> client("elastic", "SuperSecret", containerIp, port);
}
Also used : ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer)

Example 5 with ElasticsearchContainer

use of org.testcontainers.elasticsearch.ElasticsearchContainer in project hazelcast by hazelcast.

the class AuthElasticSourcesTest method given_clientWithoutAuthentication_whenReadFromElasticSource_then_failWithAuthenticationException.

@Test
public void given_clientWithoutAuthentication_whenReadFromElasticSource_then_failWithAuthenticationException() {
    ElasticsearchContainer container = ElasticSupport.secureElastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    Pipeline p = Pipeline.create();
    p.readFrom(elasticSource(() -> client(containerIp, port))).writeTo(Sinks.list(results));
    assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ResponseException.class).hasStackTraceContaining("missing authentication credentials");
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

ElasticsearchContainer (org.testcontainers.elasticsearch.ElasticsearchContainer)8 Pipeline (com.hazelcast.jet.pipeline.Pipeline)5 Test (org.junit.Test)5 TestItem (com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem)2 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 ResponseException (org.elasticsearch.client.ResponseException)2 SearchHit (org.elasticsearch.search.SearchHit)1