-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Versions used:
- testcontainers:
1.10.0 - Elasticsearch:
5.5.3
Error: No signature of method: static org.elasticsearch.client.RestClient.builder() is applicable for argument types: (org.testcontainers.shaded.org.apache.http.HttpHost)
In the following code, container.getHost() is not usable in the Elasticsearch RestClient.builder(...) because you are using a shaded dependency:
org.testcontainers.shaded.org.apache.http.HttpHost
Of course, I could just do as I was before 1.10.0 and ElasticsearchContainer:
HttpHost host = new HttpHost(
container.getContainerIpAddress(),
container.getMappedPort(9200)
)
This defeats the utility of your new module and the getHost() method and forces me to assume the default port set by ElasticsearchContainer.
import org.elasticsearch.client.RestClient
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.DependsOn
import org.springframework.context.annotation.Profile
import org.testcontainers.elasticsearch.ElasticsearchContainer
import org.testcontainers.shaded.org.apache.http.HttpHost
@Profile("integration")
@TestConfiguration
class IntegrationTestConfig {
@Value('${elasticsearch.version}')
String esVersion
@Bean(name = 'esContainer', initMethod = 'start', destroyMethod = 'stop')
ElasticsearchContainer esContainer() {
String dockerImageName = "docker.elastic.co/elasticsearch/elasticsearch:${esVersion}"
ElasticsearchContainer container = new ElasticsearchContainer(dockerImageName)
return container
}
@Bean(destroyMethod = 'close')
@DependsOn('esContainer')
RestClient restClient() {
ElasticsearchContainer container = esContainer()
HttpHost host = container.getHost()
RestClient restClient = RestClient.builder(host).setPathPrefix('/').build()
return restClient
}
}I will also point out that I do not have the ability to supply additional configuration with ElasticsearchContainer as you might expect or want:
If I attempt to extend the container configuration with .withEnv("ES_JAVA_OPTS", "-Xms1g -Xmx1g"), for example, I get the following problem:
Cannot assign 'GenericContainer' to 'ElasticsearchContainer'