Skip to content

Commit 4673f14

Browse files
committed
fix: adjusting tests to support httphost
1 parent ff71224 commit 4673f14

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

src/test/java/com/mtfelisb/flink/connectors/elasticsearch/sink/ElasticsearchSinkBuilderTest.java

+4-21
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package com.mtfelisb.flink.connectors.elasticsearch.sink;
2323

24+
import org.apache.http.HttpHost;
2425
import org.junit.jupiter.api.Test;
2526

2627
import static org.junit.Assert.assertEquals;
@@ -53,8 +54,7 @@ public void sinkBuilderSetEmitter() {
5354
Throwable exception = assertThrows(
5455
NullPointerException.class,
5556
() -> ElasticsearchSinkBuilder.<String>builder()
56-
.setPort(9200)
57-
.setHost("localhost")
57+
.setHttpHost(new HttpHost("localhost", 9200))
5858
.setPassword("password")
5959
.setUsername("username")
6060
.setEmitter(null)
@@ -66,7 +66,7 @@ public void sinkBuilderSetEmitter() {
6666
}
6767

6868
/**
69-
* The host should be declared to create
69+
* The httpHost should be declared to create
7070
* a valid ElasticsearchSink instance
7171
*
7272
*/
@@ -75,30 +75,13 @@ public void sinkBuilderSetHost() {
7575
Throwable exception = assertThrows(
7676
NullPointerException.class,
7777
() -> ElasticsearchSinkBuilder.<String>builder()
78-
.setHost(null)
78+
.setHttpHost(null)
7979
.build()
8080
);
8181

8282
assertEquals(null, exception.getMessage());
8383
}
8484

85-
/**
86-
* The host should be declared to create
87-
* a valid ElasticsearchSink instance
88-
*
89-
*/
90-
@Test
91-
public void sinkBuilderSetHostEmpty() {
92-
Throwable exception = assertThrows(
93-
IllegalStateException.class,
94-
() -> ElasticsearchSinkBuilder.<String>builder()
95-
.setHost("")
96-
.build()
97-
);
98-
99-
assertEquals("Host cannot be empty", exception.getMessage());
100-
}
101-
10285
/**
10386
* The username, if provided, cannot be null to create
10487
* a valid ElasticsearchSink instance

src/test/java/com/mtfelisb/flink/connectors/elasticsearch/sink/ElasticsearchSinkTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public void indexingByThresholdReached() throws Exception {
6060

6161
final ElasticsearchSink<DummyData> sink = ElasticsearchSinkBuilder.<DummyData>builder()
6262
.setThreshold(2L)
63-
.setHost(ES_CONTAINER.getHost())
64-
.setPort(ES_CONTAINER.getFirstMappedPort())
63+
.setHttpHost(HttpHost.create(ES_CONTAINER.getHttpHostAddress()))
6564
.setEmitter(
6665
(value, op, ctx) ->
6766
(BulkOperation.Builder) op
@@ -102,8 +101,7 @@ public void indexingByCheckpoint() throws Exception {
102101

103102
final ElasticsearchSink<DummyData> sink = ElasticsearchSinkBuilder.<DummyData>builder()
104103
.setThreshold(1000L)
105-
.setHost(ES_CONTAINER.getHost())
106-
.setPort(ES_CONTAINER.getFirstMappedPort())
104+
.setHttpHost(HttpHost.create(ES_CONTAINER.getHttpHostAddress()))
107105
.setEmitter(
108106
(value, op, ctx) ->
109107
(BulkOperation.Builder) op

src/test/java/com/mtfelisb/flink/connectors/elasticsearch/sink/NetworkConfigFactoryTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.mtfelisb.flink.connectors.elasticsearch.sink;
2323

2424
import co.elastic.clients.elasticsearch.ElasticsearchClient;
25+
import org.apache.http.HttpHost;
2526
import org.testcontainers.junit.jupiter.Testcontainers;
2627
import static org.junit.Assert.assertEquals;
2728
import static org.junit.Assert.assertThrows;
@@ -38,7 +39,7 @@ public class NetworkConfigFactoryTest extends ElasticsearchSinkBaseITCase {
3839
public void requiredHost() {
3940
Throwable exception = assertThrows(
4041
NullPointerException.class,
41-
() -> new NetworkConfigFactory(null, 9200, "username", "password"));
42+
() -> new NetworkConfigFactory(null, "username", "password"));
4243

4344
assertEquals(null, exception.getMessage());
4445
}
@@ -52,8 +53,7 @@ public void requiredHost() {
5253
@Test
5354
public void create() throws IOException {
5455
ElasticsearchClient esClient = new NetworkConfigFactory(
55-
ES_CONTAINER.getHost(),
56-
ES_CONTAINER.getFirstMappedPort(),
56+
HttpHost.create(ES_CONTAINER.getHttpHostAddress()),
5757
null,
5858
null
5959
).create();
@@ -70,8 +70,7 @@ public void create() throws IOException {
7070
@Test
7171
public void createWithUsernameAndPassword() throws IOException {
7272
ElasticsearchClient esClient = new NetworkConfigFactory(
73-
ES_AUTH_CONTAINER.getHost(),
74-
ES_AUTH_CONTAINER.getFirstMappedPort(),
73+
HttpHost.create(ES_CONTAINER.getHttpHostAddress()),
7574
"elastic",
7675
"generic-pass"
7776
).create();

0 commit comments

Comments
 (0)