Skip to content

Commit

Permalink
fix: new es test
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterZh6 committed Sep 29, 2024
1 parent 771fdc4 commit 2c3a607
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,7 @@
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.10.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.inlong.sort.tests.utils.FlinkContainerTestEnvJRE8;
import org.apache.inlong.sort.tests.utils.TestUtils;

import org.apache.http.HttpHost;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.Schema;
Expand All @@ -28,6 +29,7 @@
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.index.query.QueryBuilders;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -46,6 +48,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Objects;

public class Pulsar2ElasticsearchTest extends FlinkContainerTestEnvJRE8 {
Expand Down Expand Up @@ -78,8 +81,8 @@ public class Pulsar2ElasticsearchTest extends FlinkContainerTestEnvJRE8 {

@ClassRule
public static final ElasticsearchContainer ELASTICSEARCH =
new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.10.1"))
.withExposedPorts(9200)
new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.9.3"))
.withExposedPorts(9200, 9300)
.withNetwork(NETWORK)
.withNetworkAliases("elasticsearch")
.withLogConsumer(new Slf4jLogConsumer(ELASTICSEARCH_LOG));
Expand All @@ -106,9 +109,8 @@ private void initializePulsarTopic() {

private void initializeElasticsearchIndex() {
// 使用 Elasticsearch 客户端创建索引
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
new org.elasticsearch.client.RestClientBuilder.HttpHost("localhost", ELASTICSEARCH.getMappedPort(9200),
"http")))) {
try (RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", ELASTICSEARCH.getMappedPort(9200), "http")))) {
client.indices().create(new CreateIndexRequest("test-index"), RequestOptions.DEFAULT);
LOG.info("Created Elasticsearch index: test-index");
} catch (IOException e) {
Expand Down Expand Up @@ -142,9 +144,8 @@ public void testPulsarToElasticsearch() throws Exception {
}

// 查询 Elasticsearch 数据
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
new org.elasticsearch.client.RestClientBuilder.HttpHost("localhost", ELASTICSEARCH.getMappedPort(9200),
"http")))) {
try (RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", ELASTICSEARCH.getMappedPort(9200), "http")))) {
SearchRequest searchRequest = new SearchRequest("test-index");
searchRequest.source().query(QueryBuilders.matchAllQuery());
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Expand Down

0 comments on commit 2c3a607

Please sign in to comment.