-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathElasticsearchControllerSpec.scala
68 lines (61 loc) · 2.26 KB
/
ElasticsearchControllerSpec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.github.j5ik2o.dockerController.elasticsearch
import co.elastic.clients.elasticsearch.ElasticsearchClient
import co.elastic.clients.json.jackson.JacksonJsonpMapper
import co.elastic.clients.transport.rest_client.RestClientTransport
import com.github.j5ik2o.dockerController.{ DockerController, DockerControllerSpecSupport, WaitPredicates }
import org.elasticsearch.client.{
RequestOptions,
RestClient,
RestClientBuilder,
RestHighLevelClient,
RestHighLevelClientBuilder
}
import org.scalatest.freespec.AnyFreeSpec
import org.apache.http.HttpHost
import org.apache.http.client.methods.RequestBuilder.options
import org.elasticsearch.client.core.MainRequest
import scala.concurrent.duration.{ Duration, DurationInt }
import scala.util.control.NonFatal
class ElasticsearchControllerSpec extends AnyFreeSpec with DockerControllerSpecSupport {
val testTimeFactor: Int = sys.env.getOrElse("TEST_TIME_FACTOR", "1").toInt
logger.debug(s"testTimeFactor = $testTimeFactor")
val hostPort1: Int = temporaryServerPort()
val hostPort2: Int = temporaryServerPort()
val controller: ElasticsearchController = ElasticsearchController(dockerClient)(hostPort1, hostPort2)
override protected val dockerControllers: Vector[DockerController] = Vector(controller)
override protected val waitPredicatesSettings: Map[DockerController, WaitPredicateSetting] =
Map(
controller -> WaitPredicateSetting(
Duration.Inf,
WaitPredicates.forListeningHostTcpPort(
dockerHost,
hostPort1,
(30 * testTimeFactor).seconds,
Some((20 * testTimeFactor).seconds)
)
)
)
"ElasticsearchController" - {
"run" in {
var httpClient: RestClient = null
var transport: RestClientTransport = null
try {
httpClient = RestClient
.builder(
new HttpHost("localhost", hostPort1)
).build()
transport = new RestClientTransport(
httpClient,
new JacksonJsonpMapper()
)
val esClient = new ElasticsearchClient(transport)
esClient.ping()
} finally {
if (transport != null)
transport.close()
if (httpClient != null)
httpClient.close()
}
}
}
}