-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for Elasticsearch meter registry (#1434)
Tests the ElasticMeterRegistry against a running Elasticsearch instance in a docker container using testcontainers. Currently tested against Elasticsearch 6 and 7. See gh-1837 Closes gh-1429 Co-authored-by: Adrian Cole <adriancole@users.noreply.github.com> Co-authored-by: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
- Loading branch information
1 parent
7b5dbfe
commit 0fcd8ee
Showing
5 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...rc/test/java/io/micrometer/elastic/AbstractElasticsearchMeterRegistryIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Copyright 2019 Pivotal Software, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.elastic; | ||
|
||
import com.jayway.jsonpath.JsonPath; | ||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.ipc.http.HttpSender; | ||
import io.micrometer.core.ipc.http.HttpUrlConnectionSender; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.elasticsearch.ElasticsearchContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Base class for integration tests on {@link ElasticMeterRegistry}. | ||
* | ||
* @author Johnny Lim | ||
*/ | ||
abstract class AbstractElasticsearchMeterRegistryIntegrationTest { | ||
|
||
private static final String USER = "elastic"; | ||
private static final String PASSWORD = "changeme"; | ||
|
||
@Container | ||
private final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(getDockerImageName(getVersion())); | ||
|
||
private final HttpSender httpSender = new HttpUrlConnectionSender(); | ||
|
||
private String host; | ||
private ElasticMeterRegistry registry; | ||
|
||
protected abstract String getVersion(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
host = "http://" + elasticsearch.getHttpHostAddress(); | ||
|
||
ElasticConfig config = new ElasticConfig() { | ||
@Override | ||
public String get(String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Duration step() { | ||
return Duration.ofSeconds(10); | ||
} | ||
|
||
@Override | ||
public String host() { | ||
return host; | ||
} | ||
|
||
@Override | ||
public String userName() { | ||
return USER; | ||
} | ||
|
||
@Override | ||
public String password() { | ||
return PASSWORD; | ||
} | ||
}; | ||
registry = ElasticMeterRegistry.builder(config).build(); | ||
} | ||
|
||
@Test | ||
void indexTemplateShouldApply() throws Throwable { | ||
String response = sendHttpGet(host); | ||
String versionNumber = JsonPath.parse(response).read("$.version.number"); | ||
assertThat(versionNumber).isEqualTo(getVersion()); | ||
|
||
Counter counter = registry.counter("test.counter"); | ||
counter.increment(); | ||
|
||
registry.publish(); | ||
|
||
String indexName = registry.indexName(); | ||
String mapping = sendHttpGet(host + "/" + indexName + "/_mapping"); | ||
String countType = JsonPath.parse(mapping).read(getCountTypePath(indexName)); | ||
assertThat(countType).isEqualTo("double"); | ||
} | ||
|
||
protected String getCountTypePath(String indexName) { | ||
return "$." + indexName + ".mappings.doc.properties.count.type"; | ||
} | ||
|
||
private String sendHttpGet(String uri) throws Throwable { | ||
return httpSender.get(uri).withBasicAuthentication(USER, PASSWORD).send().body(); | ||
} | ||
|
||
private static String getDockerImageName(String version) { | ||
return "docker.elastic.co/elasticsearch/elasticsearch-oss:" + version; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...t/java/io/micrometer/elastic/ElasticsearchMeterRegistryElasticsearch6IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2019 Pivotal Software, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.elastic; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
/** | ||
* Integration tests on {@link ElasticMeterRegistry} for Elasticsearch 6. | ||
* | ||
* @author Johnny Lim | ||
*/ | ||
@Testcontainers | ||
@Tag("docker") | ||
class ElasticsearchMeterRegistryElasticsearch6IntegrationTest | ||
extends AbstractElasticsearchMeterRegistryIntegrationTest { | ||
|
||
@Override | ||
protected String getVersion() { | ||
return "6.8.6"; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...t/java/io/micrometer/elastic/ElasticsearchMeterRegistryElasticsearch7IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2019 Pivotal Software, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.elastic; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
/** | ||
* Integration tests on {@link ElasticMeterRegistry} for Elasticsearch 7. | ||
* | ||
* @author Johnny Lim | ||
*/ | ||
@Testcontainers | ||
@Tag("docker") | ||
class ElasticsearchMeterRegistryElasticsearch7IntegrationTest | ||
extends AbstractElasticsearchMeterRegistryIntegrationTest { | ||
|
||
@Override | ||
protected String getVersion() { | ||
return "7.5.2"; | ||
} | ||
|
||
@Override | ||
protected String getCountTypePath(String indexName) { | ||
return "$." + indexName + ".mappings.properties.count.type"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters