Skip to content

Commit

Permalink
HSEARCH-4136 Use hibernate.search.backend.uris rather than hibernate.…
Browse files Browse the repository at this point in the history
…search.backend.hosts for tests in POMs

Signed-off-by: Yoann Rodière <yoann@hibernate.org>
  • Loading branch information
yrodiere committed Jan 12, 2021
1 parent 3f0f9d4 commit 50314d9
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 99 deletions.
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Expand Up @@ -210,31 +210,30 @@ A list of available versions for `test.elasticsearch.connection.version` can be

Alternatively, you can prevent the build from launching an Elasticsearch server automatically
and run Elasticsearch-related tests against your own server using the
`test.elasticsearch.connection.hosts` properties:
`test.elasticsearch.connection.uris` property:

```bash
./mvnw clean install -Dtest.elasticsearch.connection.hosts=localhost:9200
./mvnw clean install -Dtest.elasticsearch.connection.uris=http://localhost:9200
```

If you want to use HTTPS:

```bash
./mvnw clean install -Dtest.elasticsearch.connection.hosts=localhost:9200 \
-Dtest.elasticsearch.connection.protocol=https
./mvnw clean install -Dtest.elasticsearch.connection.uris=https://localhost:9200
```

If you want to run tests against a different Elasticsearch version (6.x for instance),
you will still have to select a profile among those listed above, and specify the version:

```bash
./mvnw clean install -Pelasticsearch-6.0 -Dtest.elasticsearch.connection.version=6.0.0 \
-Dtest.elasticsearch.connection.hosts=localhost:9200
-Dtest.elasticsearch.connection.uris=http://localhost:9200
```

You may also use authentication:

```bash
./mvnw clean install -Dtest.elasticsearch.connection.hosts=localhost:9200 \
./mvnw clean install -Dtest.elasticsearch.connection.uris=http://localhost:9200 \
-Dtest.elasticsearch.connection.username=ironman \
-Dtest.elasticsearch.connection.password=j@rV1s
```
Expand All @@ -244,7 +243,7 @@ against an Elasticsearch service on AWS.
You will need to execute something along the lines of:

```bash
./mvnw clean install -Dtest.elasticsearch.connection.hosts=<host:port> \
./mvnw clean install -Dtest.elasticsearch.connection.uris=http://<host:port> \
-Dtest.elasticsearch.connection.aws.signing.enabled=true \
-Dtest.elasticsearch.connection.aws.region=<Your AWS region ID> \
-Dtest.elasticsearch.connection.aws.credentials.type=static \
Expand All @@ -255,7 +254,7 @@ You will need to execute something along the lines of:
Or more simply, if your AWS credentials are already stored in `~/.aws/credentials`:

```bash
./mvnw clean install -Dtest.elasticsearch.connection.hosts=<host:port> \
./mvnw clean install -Dtest.elasticsearch.connection.uris=http://<host:port> \
-Dtest.elasticsearch.connection.aws.signing.enabled=true \
-Dtest.elasticsearch.connection.aws.region=<Your AWS region ID>
```
Expand Down
30 changes: 7 additions & 23 deletions Jenkinsfile
Expand Up @@ -371,8 +371,8 @@ Some useful filters: 'default', 'jdk', 'jdk-10', 'eclipse', 'postgresql', 'elast
}

environments.content.esAws.enabled.removeAll { buildEnv ->
buildEnv.endpointUrl = env.getProperty(buildEnv.endpointVariableName)
if (!buildEnv.endpointUrl) {
buildEnv.endpointUris = env.getProperty(buildEnv.endpointVariableName)
if (!buildEnv.endpointUris) {
echo "Skipping test ${buildEnv.tag} because environment variable '${buildEnv.endpointVariableName}' is not defined."
return true
}
Expand Down Expand Up @@ -580,8 +580,8 @@ stage('Non-default environments') {

// Test Elasticsearch integration with multiple versions in an AWS instance
environments.content.esAws.enabled.each { EsAwsBuildEnvironment buildEnv ->
if (!buildEnv.endpointHostAndPort) {
throw new IllegalStateException("Unexpected empty endpoint host")
if (!buildEnv.endpointUris) {
throw new IllegalStateException("Unexpected empty endpoint URI")
}
if (!buildEnv.awsRegion) {
throw new IllegalStateException("Unexpected empty AWS region")
Expand Down Expand Up @@ -615,8 +615,7 @@ stage('Non-default environments') {
--fail-fast \
-pl org.hibernate.search:hibernate-search-integrationtest-backend-elasticsearch,org.hibernate.search:hibernate-search-integrationtest-showcase-library \
${toElasticsearchVersionArgs(buildEnv.mavenProfile, buildEnv.version)} \
-Dtest.elasticsearch.connection.hosts=$buildEnv.endpointHostAndPort \
-Dtest.elasticsearch.connection.protocol=$buildEnv.endpointProtocol \
-Dtest.elasticsearch.connection.uris=$buildEnv.endpointUris \
-Dtest.elasticsearch.connection.aws.signing.enabled=true \
-Dtest.elasticsearch.connection.aws.region=$buildEnv.awsRegion \
"""
Expand Down Expand Up @@ -648,8 +647,7 @@ stage('Non-default environments') {
--fail-fast \
-pl org.hibernate.search:hibernate-search-integrationtest-backend-elasticsearch,org.hibernate.search:hibernate-search-integrationtest-showcase-library \
${toElasticsearchVersionArgs(buildEnv.mavenProfile, buildEnv.version)} \
-Dtest.elasticsearch.connection.hosts=$buildEnv.endpointHostAndPort \
-Dtest.elasticsearch.connection.protocol=$buildEnv.endpointProtocol \
-Dtest.elasticsearch.connection.uris=$buildEnv.endpointUris \
-Dtest.elasticsearch.connection.aws.signing.enabled=true \
-Dtest.elasticsearch.connection.aws.region=$buildEnv.awsRegion \
-Dtest.elasticsearch.connection.aws.credentials.type=static \
Expand Down Expand Up @@ -801,9 +799,7 @@ class EsLocalBuildEnvironment extends BuildEnvironment {
class EsAwsBuildEnvironment extends BuildEnvironment {
String version
String mavenProfile
String endpointUrl = null
String endpointHostAndPort = null
String endpointProtocol = null
String endpointUris = null
String awsRegion = null
boolean staticCredentials = false
@Override
Expand All @@ -821,18 +817,6 @@ class EsAwsBuildEnvironment extends BuildEnvironment {
String getLockedResourcesLabel() {
"es-aws-${nameEmbeddableVersion}"
}
String setEndpointUrl(String url) {
this.endpointUrl = url
if ( endpointUrl ) {
def matcher = endpointUrl =~ /^(?:(https?):\/\/)?(.*)$/
endpointProtocol = matcher[0][1]
endpointHostAndPort = matcher[0][2]
}
else {
endpointProtocol = null
endpointHostAndPort = null
}
}
}

void keepOnlyEnvironmentsMatchingFilter(String regex) {
Expand Down
Expand Up @@ -30,6 +30,11 @@ public static Map<String, String> properties(TestConfigurationProvider configura
}
properties.put( "hibernate.search.schema_management.strategy", "drop-and-create-and-drop" );
properties.put( "hibernate.search.automatic_indexing.synchronization.strategy", "sync" );

// Hack: override example properties from persistence.xml
properties.put( "hibernate.search.backend.hosts", "" );
properties.put( "hibernate.search.backend.protocol", "" );

return properties;
}

Expand Down
Expand Up @@ -36,9 +36,9 @@ public void cannotConnect() {
assertThatThrownBy(
() -> setupHelper.start()
.withBackendProperty(
ElasticsearchBackendSettings.HOSTS,
ElasticsearchBackendSettings.URIS,
// We just need a closed port, hopefully this one will generally be closed
"localhost:9199"
"http://localhost:9199"
)
.withIndex( StubMappedIndex.withoutFields() )
.setup(),
Expand Down
Expand Up @@ -165,8 +165,6 @@ public void uris_http() {

try ( ElasticsearchClientImplementor client = createClient(
properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, httpUrisFor( wireMockRule1 ) );
}
) ) {
Expand Down Expand Up @@ -228,8 +226,6 @@ public void pathPrefix_uris() {
try ( ElasticsearchClientImplementor client = createClient(
properties -> {
properties.accept( ElasticsearchBackendSettings.PATH_PREFIX, "bla/bla/bla" );
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, httpUrisFor( wireMockRule1 ) );
}
) ) {
Expand Down Expand Up @@ -291,8 +287,6 @@ public void uris_https() {

try ( ElasticsearchClientImplementor client = createClient(
properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, httpsUrisFor( wireMockRule1 ) );
}
) ) {
Expand Down Expand Up @@ -527,8 +521,6 @@ public void multipleURIs() {

try ( ElasticsearchClientImplementor client = createClient(
properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, httpsUrisFor( wireMockRule1, wireMockRule2 ) );
}
) ) {
Expand Down Expand Up @@ -861,8 +853,8 @@ public void authentication_http_password() {
@Test
public void uriAndProtocol() {
Consumer<BiConsumer<String, Object>> additionalProperties = properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null ); // remove HOSTS, keeping PROTOCOL
properties.accept( ElasticsearchBackendSettings.URIS, "http://is-not-called:12345" );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, "http" );
};

assertThatThrownBy( () -> createClient( additionalProperties ) )
Expand All @@ -879,8 +871,8 @@ public void uriAndProtocol() {
@Test
public void uriAndHosts() {
Consumer<BiConsumer<String, Object>> additionalProperties = properties -> {
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null ); // remove PROTOCOL, keeping HOSTS
properties.accept( ElasticsearchBackendSettings.URIS, "http://is-not-called:12345" );
properties.accept( ElasticsearchBackendSettings.HOSTS, "not-called-either:234" );
};

assertThatThrownBy( () -> createClient( additionalProperties ) )
Expand All @@ -897,8 +889,6 @@ public void uriAndHosts() {
@Test
public void differentProtocolsOnUris() {
Consumer<BiConsumer<String, Object>> additionalProperties = properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, "http://is-not-called:12345, https://neather-is:12345" );
};

Expand All @@ -914,8 +904,6 @@ public void differentProtocolsOnUris() {
@Test
public void emptyListOfUris() {
Consumer<BiConsumer<String, Object>> additionalProperties = properties -> {
properties.accept( ElasticsearchBackendSettings.HOSTS, null );
properties.accept( ElasticsearchBackendSettings.PROTOCOL, null );
properties.accept( ElasticsearchBackendSettings.URIS, Collections.emptyList() );
};

Expand Down Expand Up @@ -949,11 +937,21 @@ private ElasticsearchClientImplementor createClient(Consumer<BiConsumer<String,
.createBackendConfigurationProperties( testConfigurationProvider );

Map<String, Object> clientProperties = new HashMap<>( defaultBackendProperties );
// Redirect requests to Wiremock (rule 1 only by default)
clientProperties.put( ElasticsearchBackendSettings.HOSTS, httpHostAndPortFor( wireMockRule1 ) );
clientProperties.put( ElasticsearchBackendSettings.PROTOCOL, "http" );

// We won't target the provided ES instance, but Wiremock
clientProperties.remove( ElasticsearchBackendSettings.HOSTS );
clientProperties.remove( ElasticsearchBackendSettings.PROTOCOL );
clientProperties.remove( ElasticsearchBackendSettings.URIS );

// Per-test overrides
additionalProperties.accept( clientProperties::put );

// By default, target the Wiremock server 1 using HTTP
if ( !clientProperties.containsKey( ElasticsearchBackendSettings.HOSTS )
&& !clientProperties.containsKey( ElasticsearchBackendSettings.URIS ) ) {
clientProperties.put( ElasticsearchBackendSettings.URIS, httpUrisFor( wireMockRule1 ) );
}

ConfigurationPropertySource clientPropertySource = ConfigurationPropertySource.fromMap( clientProperties );

Map<String, Object> beanResolverConfiguration = new HashMap<>();
Expand Down
Expand Up @@ -194,11 +194,16 @@ private ElasticsearchClientImplementor createClient() {
new ElasticsearchTckBackendHelper().createDefaultBackendSetupStrategy()
.createBackendConfigurationProperties( testConfigurationProvider );

// Redirect requests to Wiremock
Map<String, Object> clientProperties = new HashMap<>( defaultBackendProperties );
// Redirect requests to Wiremock (rule 1 only by default)
clientProperties.put( ElasticsearchBackendSettings.HOSTS, hostAndPortFor( wireMockRule ) );
clientProperties.put( ElasticsearchBackendSettings.PROTOCOL, "http" );

// We won't target the provided ES instance, but Wiremock
clientProperties.remove( ElasticsearchBackendSettings.HOSTS );
clientProperties.remove( ElasticsearchBackendSettings.PROTOCOL );
clientProperties.remove( ElasticsearchBackendSettings.URIS );

// Target the Wiremock server using HTTP
clientProperties.put( ElasticsearchBackendSettings.URIS, httpUriFor( wireMockRule ) );

ConfigurationPropertySource clientPropertySource = ConfigurationPropertySource.fromMap( clientProperties );

BeanResolver beanResolver = testConfigurationProvider.createBeanResolverForTest();
Expand Down Expand Up @@ -228,8 +233,8 @@ private ElasticsearchRequest buildRequest(ElasticsearchRequest.Builder builder,
return builder.build();
}

private static String hostAndPortFor(WireMockRule rule) {
return "localhost:" + rule.port();
private static String httpUriFor(WireMockRule rule) {
return "http://localhost:" + rule.port();
}

private static UrlPathPattern urlPathLike(String path) {
Expand Down
Expand Up @@ -15,7 +15,7 @@ hibernate.max_fetch_depth = 5

# Hibernate Search properties:
hibernate.search.automatic_indexing.synchronization.strategy = sync
hibernate.search.backend.hosts = ${test.elasticsearch.connection.hosts}
hibernate.search.backend.uris = ${test.elasticsearch.connection.uris}
hibernate.search.backend.username = ${test.elasticsearch.connection.username}
hibernate.search.backend.password = ${test.elasticsearch.connection.password}
hibernate.search.backend.aws.signing.enabled = ${test.elasticsearch.connection.aws.signing.enabled}
Expand Down
Expand Up @@ -39,7 +39,7 @@
<property name="hibernate.search.automatic_indexing.strategy" value="none"/>
<property name="hibernate.search.schema_management.strategy" value="drop-and-create-and-drop"/>
<property name="hibernate.search.backend.type" value="elasticsearch" />
<property name="hibernate.search.backend.hosts" value="${test.elasticsearch.connection.hosts}" />
<property name="hibernate.search.backend.uris" value="${test.elasticsearch.connection.uris}" />
<property name="hibernate.search.backend.username" value="${test.elasticsearch.connection.username}" />
<property name="hibernate.search.backend.password" value="${test.elasticsearch.connection.password}" />
<property name="hibernate.search.backend.aws.signing.enabled" value="${test.elasticsearch.connection.aws.signing.enabled}" />
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/performance/backend/README.md
Expand Up @@ -27,7 +27,7 @@ You may set parameters:

```
java -jar integrationtest/performance/backend/elasticsearch/benchmarks.jar \
-jvmArgsPrepend -Dhosts=es1.mycompany.com \
-jvmArgsPrepend -Duris=http://es1.mycompany.com \
-jvmArgsPrepend -Dprotocol=https \
-i 10 -p batchSize=50
```
Expand Down
Expand Up @@ -39,7 +39,7 @@ protected ConfigurationPropertySource getDefaultBackendProperties(TemporaryFileH
Map<String, Object> map = new LinkedHashMap<>();

// Custom connection info is provided by setting system properties,
// e.g. "hosts" or "aws.signing.enabled".
// e.g. "uris" or "aws.signing.enabled".
map.put( ElasticsearchIndexSettings.ANALYSIS_CONFIGURER, ElasticsearchPerformanceAnalysisConfigurer.class );

map.put( ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS, IndexStatus.YELLOW );
Expand Down
3 changes: 1 addition & 2 deletions integrationtest/showcase/library/pom.xml
Expand Up @@ -131,8 +131,7 @@
<JDBC_USERNAME>${jdbc.user}</JDBC_USERNAME>
<JDBC_PASSWORD>${jdbc.pass}</JDBC_PASSWORD>
<JDBC_ISOLATION>${jdbc.isolation}</JDBC_ISOLATION>
<ELASTICSEARCH_HOSTS>${test.elasticsearch.connection.hosts}</ELASTICSEARCH_HOSTS>
<ELASTICSEARCH_PROTOCOL>${test.elasticsearch.connection.protocol}</ELASTICSEARCH_PROTOCOL>
<ELASTICSEARCH_URIS>${test.elasticsearch.connection.uris}</ELASTICSEARCH_URIS>
<ELASTICSEARCH_USERNAME>${test.elasticsearch.connection.username}</ELASTICSEARCH_USERNAME>
<ELASTICSEARCH_PASSWORD>${test.elasticsearch.connection.password}</ELASTICSEARCH_PASSWORD>
<ELASTICSEARCH_AWS_SIGNING_ENABLED>${test.elasticsearch.connection.aws.signing.enabled}</ELASTICSEARCH_AWS_SIGNING_ENABLED>
Expand Down
Expand Up @@ -3,8 +3,7 @@ spring.jpa:
hibernate.search:
backend:
type: elasticsearch # Only necessary because we have both the Elasticsearch and Lucene backend in the classpath
hosts: ${ELASTICSEARCH_HOSTS} # From environment variable
protocol: ${ELASTICSEARCH_PROTOCOL} # From environment variable
uris: ${ELASTICSEARCH_URIS} # From environment variable
username: ${ELASTICSEARCH_USERNAME} # From environment variable
password: ${ELASTICSEARCH_PASSWORD} # From environment variable
aws:
Expand Down
23 changes: 4 additions & 19 deletions jenkins/performance-elasticsearch.groovy
Expand Up @@ -52,8 +52,8 @@ stage('Configure') {
helper.generateNotificationProperty()
])

esAwsBuildEnv.endpointUrl = env.getProperty(esAwsBuildEnv.endpointVariableName)
if (!esAwsBuildEnv.endpointUrl) {
esAwsBuildEnv.endpointUris = env.getProperty(esAwsBuildEnv.endpointVariableName)
if (!esAwsBuildEnv.endpointUris) {
throw new IllegalStateException(
"Cannot run performance test because environment variable '$esAwsBuildEnv.endpointVariableName' is not defined."
)
Expand Down Expand Up @@ -101,8 +101,7 @@ lock(label: esAwsBuildEnv.lockedResourcesLabel) {
sh """ \
java \
-jar benchmarks.jar \
-jvmArgsAppend -Dhosts=$esAwsBuildEnv.endpointHostAndPort \
-jvmArgsAppend -Dprotocol=$esAwsBuildEnv.endpointProtocol \
-jvmArgsAppend -Duris=$esAwsBuildEnv.endpointUris \
-jvmArgsAppend -Daws.signing.enabled=true \
-jvmArgsAppend -Daws.region=$esAwsBuildEnv.awsRegion \
-jvmArgsAppend -Daws.credentials.type=static \
Expand All @@ -125,9 +124,7 @@ lock(label: esAwsBuildEnv.lockedResourcesLabel) {

class EsAwsBuildEnvironment {
String version
String endpointUrl = null
String endpointHostAndPort = null
String endpointProtocol = null
String endpointUris = null
String awsRegion = null
String getNameEmbeddableVersion() {
version.replaceAll('\\.', '')
Expand All @@ -138,16 +135,4 @@ class EsAwsBuildEnvironment {
String getLockedResourcesLabel() {
"es-aws-${nameEmbeddableVersion}"
}
String setEndpointUrl(String url) {
this.endpointUrl = url
if ( endpointUrl ) {
def matcher = endpointUrl =~ /^(?:(https?):\/\/)?(.*)$/
endpointProtocol = matcher[0][1]
endpointHostAndPort = matcher[0][2]
}
else {
endpointProtocol = null
endpointHostAndPort = null
}
}
}

0 comments on commit 50314d9

Please sign in to comment.