@@ -23,10 +23,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
23
23
import io.floodplain.kotlindsl.message.empty
24
24
import io.floodplain.kotlindsl.source
25
25
import io.floodplain.kotlindsl.stream
26
+ import io.floodplain.test.InstantiatedContainer
26
27
import kotlinx.coroutines.delay
27
28
import kotlinx.coroutines.withTimeout
28
29
import org.junit.Test
29
- import org.testcontainers.containers.GenericContainer
30
30
import org.testcontainers.shaded.com.fasterxml.jackson.databind.node.NullNode
31
31
import java.net.URI
32
32
import java.net.http.HttpClient
@@ -42,25 +42,12 @@ class TestElasticSearch {
42
42
43
43
private val objectMapper = ObjectMapper ()
44
44
45
- class KGenericContainer (imageName : String ) : GenericContainer<KGenericContainer>(imageName)
46
- var address: String? = " localhost"
47
- var port: Int? = 0
48
- var container: GenericContainer <* >? = null
49
-
50
- init {
51
- container = KGenericContainer (" docker.elastic.co/elasticsearch/elasticsearch-oss:7.7.0" )
52
- .apply {
53
- withExposedPorts(9200 )
54
- .withEnv(" discovery.type" , " single-node" )
55
- }
56
- container?.start()
57
- address = container?.getHost()
58
- port = container?.getFirstMappedPort()
59
- }
45
+ private val container = InstantiatedContainer (" docker.elastic.co/elasticsearch/elasticsearch-oss:7.7.0" ,
46
+ 9200 , mapOf (" discovery.type" to " single-node" ))
60
47
61
48
@Test
62
49
fun testElasticInsert () {
63
- val uri = " http://$address : $port "
50
+ val uri = " http://${container.host} : ${container.exposedPort} "
64
51
stream {
65
52
source(" sometopic" ) {
66
53
val config = elasticSearchConfig(" elasticName" , uri)
@@ -116,7 +103,9 @@ class TestElasticSearch {
116
103
}
117
104
118
105
private fun queryUUIDHits (query : String ): Int {
119
- val node = queryUUID(" http://$address :$port " , " q=$query " )
106
+ val uri = " http://${container.host} :${container.exposedPort} "
107
+
108
+ val node = queryUUID(uri, " q=$query " )
120
109
logger.info(" Query uri: $node " )
121
110
val error = node.get(" error" )
122
111
if (error == null || error is NullNode ) {
0 commit comments