Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticsearchContainer doesn't implement generics for GenericContainer methods #962

Closed
forgo opened this issue Nov 7, 2018 · 1 comment

Comments

@forgo
Copy link

forgo commented Nov 7, 2018

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'

@kiview
Copy link
Member

kiview commented Nov 7, 2018

Hi @forgo,
thanks a lot for your detailed issue description.

The shading issue is a duplicate of #958 and is fixed by #959.

I have to look into the generics issue, thanks for pointing this out as well.
I checked it out, you are right, thanks.

@kiview kiview changed the title Shaded HttpHost in ElasticsearchContainer not usable in RestClient ElasticsearchContainer doesn't implement generics for GenericContainer methods Nov 7, 2018
@rnorth rnorth added this to the 1.10.1 milestone Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants