elasticsearch,elastic4s,Scala,elasticsearch,Elastic4s" /> elasticsearch,elastic4s,Scala,elasticsearch,Elastic4s" />

Scala 基于docker容器的库支持elastic4s

Scala 基于docker容器的库支持elastic4s,scala,elasticsearch,elastic4s,Scala,elasticsearch,Elastic4s,我正在使用elastic4s,并且对使用基于docker容器的测试环境进行我的elastic搜索感兴趣 很少有像这样的库:和,但我找不到如何集成到这些库中,有人使用过基于docker容器的测试环境吗 目前我的规范非常简单: class ElasticSearchApiServiceSpec extends FreeSpec { implicit val defaultPatience = PatienceConfig(timeout = Span(100, Seconds), interv

我正在使用elastic4s,并且对使用基于docker容器的测试环境进行我的elastic搜索感兴趣

很少有像这样的库:和,但我找不到如何集成到这些库中,有人使用过基于docker容器的测试环境吗

目前我的规范非常简单:

class ElasticSearchApiServiceSpec extends FreeSpec {

  implicit val defaultPatience = PatienceConfig(timeout = Span(100, Seconds), interval = Span(50, Millis))

  val configuration: Configuration = app.injector.instanceOf[Configuration]

  val elasticSearchApiService = new ElasticSearchApiService(configuration)

  override protected def beforeAll(): Unit = {
    elasticSearchApiService.elasticClient.execute {
      index into s"peopleIndex/person" doc StringDocumentSource(PeopleFactory.rawStringGoodPerson)
    }
    // since ES is eventually
    Thread.sleep(3000)
  }

  override protected def afterAll(): Unit = {
    elasticSearchApiService.elasticClient.execute {
      deleteIndex("peopleIndex")
    }
  }

  "ElasticSearchApiService Tests" - {

    "elastic search service should retrieve person info properly - case existing person" in {
      val personInfo = elasticSearchApiService.getPersonInfo("2324").futureValue

      personInfo.get.name shouldBe "john"
    }
  }

}

当我运行它时,我会从终端在后台运行弹性搜索,但我现在想使用容器,这样它就不那么依赖了。

我想你不想依赖本地机器上运行的ES服务器来进行测试。然后最简单的方法是使用
testcontainers scala
GenericContainer
以这种方式运行:

class GenericContainerSpec extends FlatSpec with ForAllTestContainer {
    override val container = GenericContainer("docker.elastic.co/elasticsearch/elasticsearch:5.5.1",
        exposedPorts = Seq(9200),
        waitStrategy = Wait.forHttp("/")
    )

    "GenericContainer" should "start ES and expose 9200 port" in {
       assert(Source.fromInputStream(
          new URL(
            s"http://${container.containerIpAddress}:${container.mappedPort(9200)}/_status")
            .openConnection()
            .getInputStream)
           .mkString
           .contains("ES server is successfully installed"))
    }
}