11package com .github .j5ik2o .dockerController .elasticsearch
22
3- import com .github .j5ik2o .dockerController .{ DockerController , DockerControllerSpecSupport , WaitPredicates }
4- import org .elasticsearch .client .{ RequestOptions , RestClient , RestHighLevelClient }
3+ import co .elastic .clients .elasticsearch .ElasticsearchClient
4+ import co .elastic .clients .json .jackson .JacksonJsonpMapper
5+ import co .elastic .clients .transport .rest_client .RestClientTransport
6+ import com .github .j5ik2o .dockerController .{DockerController , DockerControllerSpecSupport , WaitPredicates }
7+ import org .elasticsearch .client .{RequestOptions , RestClient , RestClientBuilder , RestHighLevelClient , RestHighLevelClientBuilder }
58import org .scalatest .freespec .AnyFreeSpec
69import org .apache .http .HttpHost
10+ import org .apache .http .client .methods .RequestBuilder .options
11+ import org .elasticsearch .client .core .MainRequest
712
8- import scala .concurrent .duration .{ Duration , DurationInt }
13+ import scala .concurrent .duration .{Duration , DurationInt }
914import scala .util .control .NonFatal
1015
1116class ElasticsearchControllerSpec extends AnyFreeSpec with DockerControllerSpecSupport {
@@ -25,29 +30,32 @@ class ElasticsearchControllerSpec extends AnyFreeSpec with DockerControllerSpecS
2530 WaitPredicates .forListeningHostTcpPort(
2631 dockerHost,
2732 hostPort1,
28- (3 * testTimeFactor).seconds,
29- Some ((10 * testTimeFactor).seconds)
33+ (30 * testTimeFactor).seconds,
34+ Some ((20 * testTimeFactor).seconds)
3035 )
3136 )
3237 )
3338
3439 " ElasticsearchController" - {
3540 " run" in {
36- var client : RestHighLevelClient = null
41+ var httpClient : RestClient = null
42+ var transport : RestClientTransport = null
3743 try {
38- client = new RestHighLevelClient (
39- RestClient .builder(
40- new HttpHost (dockerHost, hostPort1, " http" ),
41- new HttpHost (dockerHost, hostPort2, " http" )
42- )
44+ httpClient = RestClient .builder(
45+ new HttpHost (" localhost" , hostPort1)
46+ ).build()
47+ transport = new RestClientTransport (
48+ httpClient,
49+ new JacksonJsonpMapper ()
4350 )
44- val result = client.ping(RequestOptions .DEFAULT )
45- assert(result)
46- } catch {
47- case NonFatal (ex) =>
48- ex.printStackTrace()
49- fail(" occurred error" , ex)
50- } finally if (client != null ) client.close()
51+ val esClient = new ElasticsearchClient (transport)
52+ esClient.ping()
53+ } finally {
54+ if (transport != null )
55+ transport.close()
56+ if (httpClient != null )
57+ httpClient.close()
58+ }
5159 }
5260 }
5361}
0 commit comments