-
Notifications
You must be signed in to change notification settings - Fork 692
/
Copy pathDockerTests.scala
42 lines (34 loc) · 1.09 KB
/
DockerTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.sksamuel.elastic4s.testkit
import com.sksamuel.elastic4s.http.JavaClient
import com.sksamuel.elastic4s.{ElasticClient, ElasticDsl, ElasticProperties}
import scala.util.Try
trait DockerTests extends ElasticDsl with ClientProvider {
val elasticHost = sys.env.getOrElse("ES_HOST", "127.0.0.1")
val elasticPort = sys.env.getOrElse(
"ES_PORT",
// use obscure ports for the tests to reduce the risk of interfering with existing elastic installations/containers
"39227"
)
val client = ElasticClient(JavaClient(ElasticProperties(s"http://$elasticHost:$elasticPort")))
protected def deleteIdx(indexName: String): Unit = {
Try {
client.execute {
ElasticDsl.deleteIndex(indexName)
}.await
}
}
protected def createIdx(name: String) = Try {
client.execute {
createIndex(name)
}.await
}
protected def createIdx(name: String, shards: Int) = Try {
client.execute {
createIndex(name).shards(shards)
}.await
}
protected def cleanIndex(indexName: String): Unit = {
deleteIdx(indexName)
createIdx(indexName)
}
}