Skip to content

Commit

Permalink
Run REST tests against a cluster running on docker
Browse files Browse the repository at this point in the history
  • Loading branch information
alpar-t committed Feb 28, 2019
1 parent 63413a8 commit 36ad7e7
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ public void apply(Project project) {
(name, port) -> postProcessFixture.getExtensions()
.getByType(ExtraPropertiesExtension.class).set(name, port)
);

// Make it possible to have the both fixture and what's using it in a single place
extension.fixtures.add(project);
}

extension.fixtures.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));
extension.fixtures
.matching(fixtureProject -> fixtureProject.equals(project) == false)
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));

if (dockerComposeSupported(project) == false) {
project.getLogger().warn(
"Tests for {} require docker-compose at /usr/local/bin/docker-compose or /usr/bin/docker-compose " +
Expand Down
37 changes: 32 additions & 5 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.MavenFilteringHack
import org.elasticsearch.gradle.VersionProperties
import com.carrotsearch.gradle.junit4.RandomizedTestingTask

apply plugin: 'base'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.test.fixtures'

configurations {
Expand Down Expand Up @@ -96,15 +97,41 @@ preProcessFixture {
dependsOn taskName("copy", true, "Dockerfile")
dependsOn taskName("copy", false, "DockerContext")
dependsOn taskName("copy", false, "Dockerfile")
doLast {
file("${buildDir}/repo").mkdirs();
file("${buildDir}/repo").setWritable(true, false)
file("${buildDir}/oss-repo").mkdirs();
file("${buildDir}/oss-repo").setWritable(true, false)
}
}

postProcessFixture.doLast {
println "docker default distro is on port: ${ext."test.fixtures.elasticsearch-default.tcp.9200"}, " +
"oss is on: ${ext."test.fixtures.elasticsearch-oss.tcp.9200"}"
["oss", "default"].each { flavor ->
println "Waiting for cluster status for $flavor"
println new URL("http://localhost:${ext."test.fixtures.elasticsearch-${flavor}-1.tcp.9200"}/_cluster/health?wait_for_nodes=>=1&wait_for_status=yellow").getText()
}
}

configurations {
restSpec
}
dependencies {
restSpec "org.elasticsearch:rest-api-spec:${version}"
}

task copyRestTests(type: Sync) {
from { zipTree(configurations.restSpec.singleFile) }
into sourceSets.test.output.resourcesDir
}
processTestResources.dependsOn copyRestTests

task integTest(type: RandomizedTestingTask) {
parallelism = '1'
include '**/*IT.class'
dependsOn postProcessFixture
}

// TODO: Add some actual tests, this will just check that the TPC port in the container is up
check.dependsOn postProcessFixture
check.dependsOn integTest

void addBuildDockerImage(final boolean oss) {
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
Expand Down
94 changes: 88 additions & 6 deletions distribution/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,103 @@
# Only used for testing the docker images
version: '3'
services:
elasticsearch-default:
elasticsearch-default-1:
build:
context: ./build/docker
dockerfile: Dockerfile
environment:
- node.name=elasticsearch-default-1
- cluster.initial_master_nodes=elasticsearch-default-1,elasticsearch-default-2
- discovery.seed_hosts=elasticsearch-default-2:9300
- cluster.name=elasticsearch-default
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/repo:/tmp/es-repo
ports:
- "9200"
elasticsearch-oss:
ulimits:
memlock:
soft: -1
hard: -1
elasticsearch-default-2:
build:
context: ./build/docker
environment:
- node.name=elasticsearch-default-2
- cluster.initial_master_nodes=elasticsearch-default-1,elasticsearch-default-2
- discovery.seed_hosts=elasticsearch-default-1:9300
- cluster.name=elasticsearch-default
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/repo:/tmp/es-repo
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
elasticsearch-oss-1:
build:
context: ./build/oss-docker
environment:
- node.name=elasticsearch-oss-1
- cluster.initial_master_nodes=elasticsearch-oss-1,elasticsearch-oss-2
- discovery.seed_hosts=elasticsearch-oss-2:9300
- cluster.name=elasticsearch-oss
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/oss-repo:/tmp/es-repo
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
elasticsearch-oss-2:
build:
context: ./build/oss-docker
dockerfile: Dockerfile
environment:
- node.name=elasticsearch-oss-2
- cluster.initial_master_nodes=elasticsearch-oss-1,elasticsearch-oss-2
- discovery.seed_hosts=elasticsearch-oss-1:9300
- cluster.name=elasticsearch-oss
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/oss-repo:/tmp/es-repo
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.elasticsearch.docker.test;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;

public class DockerYmlTestSuiteIT extends ESClientYamlSuiteTestCase {

public DockerYmlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return createParameters();
}

@Override
protected String getTestRestCluster() {
String distribution = System.getProperty("tests.distribution", "default");
if (distribution.equals("oss") == false && distribution.equals("default") == false) {
throw new IllegalArgumentException("supported values for tests.distribution are oss or default but it was " + distribution);
}
return new StringBuilder()
.append("localhost:")
.append(getProperty("test.fixtures.elasticsearch-" + distribution + "-1.tcp.9200"))
.append(",")
.append("localhost:")
.append(getProperty("test.fixtures.elasticsearch-" + distribution + "-2.tcp.9200"))
.toString();
}

private String getProperty(String key) {
String port = System.getProperty(key);
if (port == null) {
throw new IllegalStateException("Could not find system properties from test.fixtures. " +
"This test expects to run with the elasticsearch.test.fixtures Gradle plugin");
}
return port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ public void initClient() throws IOException {
assert clusterHosts == null;
assert hasXPack == null;
assert nodeVersions == null;
String cluster = System.getProperty("tests.rest.cluster");
if (cluster == null) {
throw new RuntimeException("Must specify [tests.rest.cluster] system property with a comma delimited list of [host:port] "
+ "to which to send REST requests");
}
String cluster = getTestRestCluster();
String[] stringUrls = cluster.split(",");
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
for (String stringUrl : stringUrls) {
Expand Down Expand Up @@ -180,6 +176,15 @@ public void initClient() throws IOException {
assert hasXPack != null;
assert nodeVersions != null;
}

protected String getTestRestCluster() {
String cluster = System.getProperty("tests.rest.cluster");
if (cluster == null) {
throw new RuntimeException("Must specify [tests.rest.cluster] system property with a comma delimited list of [host:port] "
+ "to which to send REST requests");
}
return cluster;
}

/**
* Helper class to check warnings in REST responses with sensitivity to versions
Expand Down

0 comments on commit 36ad7e7

Please sign in to comment.