Search in sources :

Example 1 with TestItem

use of com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem 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 2 with TestItem

use of com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully.

@Test
public void given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully() throws IOException {
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(elasticClientSupplier()).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    submitJob(p);
    assertSingleDocument();
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 3 with TestItem

use of com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_clientWithoutAuthentication_whenWriteToElasticSink_thenFailWithAuthenticationException.

@Test
public void given_clientWithoutAuthentication_whenWriteToElasticSink_thenFailWithAuthenticationException() {
    ElasticsearchContainer container = ElasticSupport.secureElastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> client(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("missing authentication credentials");
}
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)

Aggregations

TestItem (com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)3 IndexRequest (org.elasticsearch.action.index.IndexRequest)3 Test (org.junit.Test)3 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)2 ElasticsearchContainer (org.testcontainers.elasticsearch.ElasticsearchContainer)2