使用Elastic4S 7.x中的本地节点运行单元测试

使用Elastic4S 7.x中的本地节点运行单元测试,elastic4s,Elastic4s,我正在将我的系统升级到Elasticsearch/Elastic4S 7.3,但是我的单元测试遇到了一个问题。希望我错过了一些明显的东西 目前(使用E4S 6.1.4),我使用ClassLocalNodeProvider为测试提供一个本地http客户端(在Travis中为每个GitHib pull请求远程运行) 在E4S 7.x中,似乎没有直接替换LocalNode(?) 在下面的代码中,我确实尝试过用ClientProvider替换ClassLocalNodeProvider,但是看起来我需要

我正在将我的系统升级到Elasticsearch/Elastic4S 7.3,但是我的单元测试遇到了一个问题。希望我错过了一些明显的东西

目前(使用E4S 6.1.4),我使用ClassLocalNodeProvider为测试提供一个本地http客户端(在Travis中为每个GitHib pull请求远程运行)

在E4S 7.x中,似乎没有直接替换LocalNode(?)

在下面的代码中,我确实尝试过用ClientProvider替换ClassLocalNodeProvider,但是看起来我需要为客户端提供一个具体的定义:ElasticClient(我的ElasticClientProvider类的ES7版本需要的是ElasticClient而不是HttpClient)


E4S不再支持LocalNode,我现在使用Docker插件来创建一个香草ES节点来运行测试。在本地工作,尚未与Travis或Concourse测试。容器确实需要一段时间才能启动,然后在具有动态分配的端口号的localhost上运行

import org.testcontainers.elasticsearch.ElasticsearchContainer  

val container = new ElasticsearchContainer()
container.setDockerImageName("docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.0")
container.start()

val host = container.getHttpHostAddress()
val client: ElasticClient = new ElasticClient(JavaClient(ElasticsearchClientUri(s"http://${host}?ssl=false")))

我使用的ElasticClient构造函数在E4S中不再工作,下面的替换示例代码(可能更简洁)是
val containerHost=container.getHttpHostAddress()val host=containerHost.split(“:”).headOption.getOrElse(“localhost”)val port=Try(containerHost.split(“:”).lastOption.getOrElse(“9200”).toInt)。getOrElse(9200)val-elEndpoint:ElasticNodeEndpoint=new-ElasticNodeEndpoint(“http”,主机,端口,无)val-eProps:ElasticProperties=new-ElasticProperties(endpoints=Seq(elEndpoint))val-client:ElasticClient=new-ElasticClient(JavaClient(eProps))
import org.testcontainers.elasticsearch.ElasticsearchContainer  

val container = new ElasticsearchContainer()
container.setDockerImageName("docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.0")
container.start()

val host = container.getHttpHostAddress()
val client: ElasticClient = new ElasticClient(JavaClient(ElasticsearchClientUri(s"http://${host}?ssl=false")))