-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add S3 integration tests for searchable snapshots #52263
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|---|---|---|---|---|
| @@ -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 | ||||
tlrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| } | ||||
|
|
||||
| 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() | ||||
|
||||
| testFixtures.useFixture(':test:fixtures:s3-fixture') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-s3declarestestFixtures.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 :)
| 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(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.