Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ public void handle(final HttpExchange exchange) throws IOException {

final int start = Integer.parseInt(matcher.group(1));
final int end = Integer.parseInt(matcher.group(2));
final int length = end - start;

final BytesReference rangeBlob = blob.slice(start, end + 1 - start);
exchange.getResponseHeaders().add("Content-Type", "application/octet-stream");
exchange.getResponseHeaders().add("Content-Range",
String.format(Locale.ROOT, "bytes=%d-%d/%d", start, end, blob.length()));
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), length);
exchange.getResponseBody().write(BytesReference.toBytes(blob), start, length);
exchange.getResponseHeaders().add("Content-Range", String.format(Locale.ROOT, "bytes %d-%d/%d",
start, end, rangeBlob.length()));
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), rangeBlob.length());
rangeBlob.writeTo(exchange.getResponseBody());
}
} else {
exchange.sendResponseHeaders(RestStatus.NOT_FOUND.getStatus(), -1);
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugin/searchable-snapshots/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ gradle.projectsEvaluated {
.findAll { it.path.startsWith(project.path + ":qa") }
.each { check.dependsOn it.check }
}

configurations {
testArtifacts.extendsFrom testRuntime
}

task testJar(type: Jar) {
appendix 'test'
from sourceSets.test.output
include '**/*TestCase.class'
}

artifacts {
testArtifacts testJar
}
12 changes: 11 additions & 1 deletion x-pack/plugin/searchable-snapshots/qa/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'

dependencies {
testCompile project(path: xpackModule('searchable-snapshots'), configuration: 'testArtifacts')
}

final File repoDir = file("$buildDir/testclusters/repo")

integTest.runner {
systemProperty 'tests.path.repo', repoDir
}

testClusters.integTest {
testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic'
setting 'path.repo', repoDir.absolutePath
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.searchablesnapshots.rest;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.xpack.searchablesnapshots.AbstractSearchableSnapshotsRestTestCase;

public class FsSearchableSnapshotsIT extends AbstractSearchableSnapshotsRestTestCase {

@Override
protected String repositoryType() {
return FsRepository.TYPE;
}

@Override
protected Settings repositorySettings() {
final Settings.Builder settings = Settings.builder();
settings.put("location", System.getProperty("tests.path.repo"));
if (randomBoolean()) {
settings.put("compress", randomBoolean());
}
if (randomBoolean()) {
settings.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES);
}
return settings.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.searchablesnapshots.rest;

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

public class SearchableSnapshotsRestIT extends ESClientYamlSuiteTestCase {
public class SearchableSnapshotsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

public SearchableSnapshotsRestIT(final ClientYamlTestCandidate testCandidate) {
public SearchableSnapshotsClientYamlTestSuiteIT(final ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}

Expand Down
82 changes: 82 additions & 0 deletions x-pack/plugin/searchable-snapshots/qa/s3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import org.elasticsearch.gradle.info.BuildParams

import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE

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

final Project fixture = project(':test:fixtures:s3-fixture')
final Project repositoryPlugin = project(':plugins:repository-s3')

dependencies {
testCompile project(path: xpackModule('searchable-snapshots'), configuration: 'testArtifacts')
testCompile repositoryPlugin
testCompile fixture
}

boolean useFixture = false
String s3AccessKey = System.getenv("amazon_s3_access_key")
String s3SecretKey = System.getenv("amazon_s3_secret_key")
String s3Bucket = System.getenv("amazon_s3_bucket")
String s3BasePath = System.getenv("amazon_s3_base_path")

if (!s3AccessKey && !s3SecretKey && !s3Bucket && !s3BasePath) {
s3AccessKey = 'access_key'
s3SecretKey = 'secret_key'
s3Bucket = 'bucket'
s3BasePath = 'base_path'
useFixture = true

} else if (!s3AccessKey || !s3SecretKey || !s3Bucket || !s3BasePath) {
throw new IllegalArgumentException("not all options specified to run against external S3 service are present")
}

if (useFixture) {
preProcessFixture {
dependsOn fixture.jar
doLast {
file("${testFixturesDir}/shared").mkdirs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why all this is required. We seem to be effectively defining a new test fixture here. Why isn't we can't just use the existing s3-fixture like we do for other tests?

testFixtures.useFixture(':test:fixtures:s3-fixture')

Copy link
Member Author

@tlrx tlrx Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This QA test depends on repository-s3 project which already uses many S3 fixtures and the test fixtures plugin prevented me from reusing the existing one. Since I wanted to avoid any mention to searchables snapshots in open source code I added the current configuration. Do you think there's a better way to do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define a separate service in the s3-fixture compose file to be used here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define a separate service in the s3-fixture compose file to be used here.

Sorry if I wasn't clear, I tried this solution and got a failure. Before doing what is coded in this PR I tried to define a separate service in the /test/fixtures/s3-fixture/docker-compose.yml file:

...
  s3-fixture-generic:
    build:
      context: .
      args:
        fixtureClass: fixture.s3.S3HttpFixture
        port: 80
        bucket: "bucket"
        basePath: "base_path"
        accessKey: "access_key"
      dockerfile: ./testfixtures_shared/shared/Dockerfile
    volumes:
      - ./testfixtures_shared/shared:/fixture/shared
    ports:
      - "80"

and tried to declare the usage of this fixture in the qa:s3 build file like this:

if (useFixture) {
  testFixtures.useFixture(':test:fixtures:s3-fixture', 's3-fixture-generic')
}

But it failed with the following error:

Build file '/x-pack/plugin/searchable-snapshots/qa/s3/build.gradle' line: 36

* What went wrong:
A problem occurred evaluating project ':x-pack:plugin:searchable-snapshots:qa:s3'.
> Projects :plugins:repository-s3 and :x-pack:plugin:searchable-snapshots:qa:s3 both claim all services from :test:fixtures:s3-fixture. This is not supported because it breaks running in parallel. Configure specific services in docker-compose.yml for each and add the service name to `useFixture`

In order to allow parallel test execution and to try to reuse as much as possible the existing code, I went with declaring a docker-compose.yml file in this qa:s3project that reuses the existing DockerFile and code from the test fixture.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. The problem here is that :plugins:repository-s3 declares testFixtures.useFixture(':test:fixtures:s3-fixture') which means "give me all services of the s3-fixture project. If we add a new service which that project doesn't need, we now need to be explicit say exactly which services it does need. So you'll need to modify that build script and call useFixture(':test:fixtures:s3-fixture', 's3-fixture') and so on for each service required in the compose yaml.

I apologize for the back and forth, I just want to avoid us reimplementing a bunch of logic that our test fixtures plugin does for us if possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that :plugins:repository-s3 declares testFixtures.useFixture(':test:fixtures:s3-fixture')

Thanks for spotting this @mark-vieira, I should have seen it by myself. I pushed 331408a to correct the fixtures.

I apologize for the back and forth, I just want to avoid us reimplementing a bunch of logic that our test fixtures plugin does for us if possible.

Nothing to apologize, I pinged you because I was suspecting something wrong and you spotted it 👍. I'm happy to not add another docker-compose.yml file to the mix :)

project.copy {
from fixture.jar
from fixture.configurations.runtimeClasspath
from fixture.projectDir.toPath().resolve("Dockerfile")
into "${testFixturesDir}/shared"
}
}
}

testFixtures.useFixture()
}

integTest {
dependsOn repositoryPlugin.bundlePlugin
runner {
systemProperty 'test.s3.bucket', s3Bucket
systemProperty 'test.s3.base_path', s3BasePath + "_searchable_snapshots_tests"
}
}

testClusters.integTest {
testDistribution = 'DEFAULT'
plugin file(repositoryPlugin.bundlePlugin.archiveFile)

keystore 's3.client.searchable_snapshots.access_key', s3AccessKey
keystore 's3.client.searchable_snapshots.secret_key', s3SecretKey

if (useFixture) {
def fixtureAddress = { fixtureName ->
assert useFixture: 'closure should not be used without a fixture'
int ephemeralPort = postProcessFixture.ext."test.fixtures.${fixtureName}.tcp.80"
assert ephemeralPort > 0
'127.0.0.1:' + ephemeralPort
}

setting 's3.client.searchable_snapshots.protocol', 'http'
setting 's3.client.searchable_snapshots.endpoint', { "${-> fixtureAddress('s3-fixture-for-searchable-snapshots')}" }, IGNORE_VALUE
} else {
println "Using an external service to test " + project.name
}
}
16 changes: 16 additions & 0 deletions x-pack/plugin/searchable-snapshots/qa/s3/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:
s3-fixture-for-searchable-snapshots:
build:
context: .
args:
fixtureClass: fixture.s3.S3HttpFixture
port: 80
bucket: "bucket"
basePath: "base_path_searchable_snapshots_tests"
accessKey: "access_key"
dockerfile: ./testfixtures_shared/shared/Dockerfile
volumes:
- ./testfixtures_shared/shared:/fixture/shared
ports:
- "80"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.searchablesnapshots.s3;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.searchablesnapshots.AbstractSearchableSnapshotsRestTestCase;

import static org.hamcrest.Matchers.blankOrNullString;
import static org.hamcrest.Matchers.not;

public class S3SearchableSnapshotsIT extends AbstractSearchableSnapshotsRestTestCase {

@Override
protected String repositoryType() {
return "s3";
}

@Override
protected Settings repositorySettings() {
final String bucket = System.getProperty("test.s3.bucket");
assertThat(bucket, not(blankOrNullString()));

final String basePath = System.getProperty("test.s3.base_path");
assertThat(basePath, not(blankOrNullString()));

return Settings.builder()
.put("client", "searchable_snapshots")
.put("bucket", bucket)
.put("base_path", basePath)
.build();
}
}
Loading