Skip to content

Commit 8b362c7

Browse files
committed
Move repository-s3 fixture tests to QA third party project
This commit moves the repository-s3 fixture test added in #29296 in a new `qa/third-party/amazon-s3` project. This new project allows the REST integration tests to be executed using the real S3 service when all the required environment variables are provided. When no env var is provided, then the tests are executed using the fixture added in #29296. The REST tests located in the plugin project now only verify that the plugin is correctly loaded. The REST tests have been adapted to allow a bucket name and a base path to be specified as env vars. This way it is possible to run the tests with different base paths (could be anything, like a CI job name or a branch name) without multiplicating buckets. Related to #29349
1 parent 707ba28 commit 8b362c7

File tree

9 files changed

+302
-202
lines changed

9 files changed

+302
-202
lines changed

plugins/repository-s3/build.gradle

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.elasticsearch.gradle.test.AntFixture
2-
31
/*
42
* Licensed to Elasticsearch under one or more contributor
53
* license agreements. See the NOTICE file distributed with
@@ -66,28 +64,9 @@ test {
6664
exclude '**/*CredentialsTests.class'
6765
}
6866

69-
forbiddenApisTest {
70-
// we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
71-
bundledSignatures -= 'jdk-non-portable'
72-
bundledSignatures += 'jdk-internal'
73-
}
74-
75-
/** A task to start the AmazonS3Fixture which emulates a S3 service **/
76-
task s3Fixture(type: AntFixture) {
77-
dependsOn compileTestJava
78-
env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
79-
executable = new File(project.runtimeJavaHome, 'bin/java')
80-
args 'org.elasticsearch.repositories.s3.AmazonS3Fixture', baseDir, 'bucket_test'
81-
}
82-
8367
integTestCluster {
84-
dependsOn s3Fixture
85-
8668
keystoreSetting 's3.client.integration_test.access_key', "s3_integration_test_access_key"
8769
keystoreSetting 's3.client.integration_test.secret_key', "s3_integration_test_secret_key"
88-
89-
/* Use a closure on the string to delay evaluation until tests are executed */
90-
setting 's3.client.integration_test.endpoint', "http://${ -> s3Fixture.addressAndPort }"
9170
}
9271

9372
thirdPartyAudit.excludes = [

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class S3Repository extends BlobStoreRepository {
156156

157157
String bucket = BUCKET_SETTING.get(metadata.settings());
158158
if (bucket == null) {
159-
throw new RepositoryException(metadata.name(), "No bucket defined for s3 gateway");
159+
throw new RepositoryException(metadata.name(), "No bucket defined for s3 repository");
160160
}
161161

162162
boolean serverSideEncryption = SERVER_SIDE_ENCRYPTION_SETTING.get(metadata.settings());

plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/10_basic.yml

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -11,183 +11,3 @@
1111
nodes.info: {}
1212

1313
- match: { nodes.$master.plugins.0.name: repository-s3 }
14-
---
15-
"Snapshot/Restore with repository-s3":
16-
17-
# Register repository
18-
- do:
19-
snapshot.create_repository:
20-
repository: repository
21-
body:
22-
type: s3
23-
settings:
24-
bucket: "bucket_test"
25-
client: "integration_test"
26-
canned_acl: "public-read"
27-
storage_class: "standard"
28-
29-
- match: { acknowledged: true }
30-
31-
# Get repository
32-
- do:
33-
snapshot.get_repository:
34-
repository: repository
35-
36-
- match: {repository.settings.bucket : "bucket_test"}
37-
- match: {repository.settings.client : "integration_test"}
38-
- match: {repository.settings.canned_acl : "public-read"}
39-
- match: {repository.settings.storage_class : "standard"}
40-
- is_false: repository.settings.access_key
41-
- is_false: repository.settings.secret_key
42-
43-
# Index documents
44-
- do:
45-
bulk:
46-
refresh: true
47-
body:
48-
- index:
49-
_index: docs
50-
_type: doc
51-
_id: 1
52-
- snapshot: one
53-
- index:
54-
_index: docs
55-
_type: doc
56-
_id: 2
57-
- snapshot: one
58-
- index:
59-
_index: docs
60-
_type: doc
61-
_id: 3
62-
- snapshot: one
63-
64-
- do:
65-
count:
66-
index: docs
67-
68-
- match: {count: 3}
69-
70-
# Create a first snapshot
71-
- do:
72-
snapshot.create:
73-
repository: repository
74-
snapshot: snapshot-one
75-
wait_for_completion: true
76-
77-
- match: { snapshot.snapshot: snapshot-one }
78-
- match: { snapshot.state : SUCCESS }
79-
- match: { snapshot.include_global_state: true }
80-
- match: { snapshot.shards.failed : 0 }
81-
82-
- do:
83-
snapshot.status:
84-
repository: repository
85-
snapshot: snapshot-one
86-
87-
- is_true: snapshots
88-
- match: { snapshots.0.snapshot: snapshot-one }
89-
- match: { snapshots.0.state : SUCCESS }
90-
91-
# Index more documents
92-
- do:
93-
bulk:
94-
refresh: true
95-
body:
96-
- index:
97-
_index: docs
98-
_type: doc
99-
_id: 4
100-
- snapshot: two
101-
- index:
102-
_index: docs
103-
_type: doc
104-
_id: 5
105-
- snapshot: two
106-
- index:
107-
_index: docs
108-
_type: doc
109-
_id: 6
110-
- snapshot: two
111-
- index:
112-
_index: docs
113-
_type: doc
114-
_id: 7
115-
- snapshot: two
116-
117-
- do:
118-
count:
119-
index: docs
120-
121-
- match: {count: 7}
122-
123-
# Create a second snapshot
124-
- do:
125-
snapshot.create:
126-
repository: repository
127-
snapshot: snapshot-two
128-
wait_for_completion: true
129-
130-
- match: { snapshot.snapshot: snapshot-two }
131-
- match: { snapshot.state : SUCCESS }
132-
- match: { snapshot.shards.failed : 0 }
133-
134-
- do:
135-
snapshot.get:
136-
repository: repository
137-
snapshot: snapshot-one,snapshot-two
138-
139-
- is_true: snapshots
140-
- match: { snapshots.0.state : SUCCESS }
141-
- match: { snapshots.1.state : SUCCESS }
142-
143-
# Delete the index
144-
- do:
145-
indices.delete:
146-
index: docs
147-
148-
# Restore the second snapshot
149-
- do:
150-
snapshot.restore:
151-
repository: repository
152-
snapshot: snapshot-two
153-
wait_for_completion: true
154-
155-
- do:
156-
count:
157-
index: docs
158-
159-
- match: {count: 7}
160-
161-
# Delete the index again
162-
- do:
163-
indices.delete:
164-
index: docs
165-
166-
# Restore the first snapshot
167-
- do:
168-
snapshot.restore:
169-
repository: repository
170-
snapshot: snapshot-one
171-
wait_for_completion: true
172-
173-
- do:
174-
count:
175-
index: docs
176-
177-
- match: {count: 3}
178-
179-
# Remove the snapshots
180-
- do:
181-
snapshot.delete:
182-
repository: repository
183-
snapshot: snapshot-two
184-
185-
- do:
186-
snapshot.delete:
187-
repository: repository
188-
snapshot: snapshot-one
189-
190-
# Remove our repository
191-
- do:
192-
snapshot.delete_repository:
193-
repository: repository

qa/third-party/amazon-s3/build.gradle

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.elasticsearch.gradle.MavenFilteringHack
21+
import org.elasticsearch.gradle.test.AntFixture
22+
23+
apply plugin: 'elasticsearch.standalone-rest-test'
24+
apply plugin: 'elasticsearch.rest-test'
25+
26+
dependencies {
27+
testCompile project(path: ':plugins:repository-s3', configuration: 'runtime')
28+
}
29+
30+
integTestCluster {
31+
plugin ':plugins:repository-s3'
32+
}
33+
34+
forbiddenApisTest {
35+
// we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
36+
bundledSignatures -= 'jdk-non-portable'
37+
bundledSignatures += 'jdk-internal'
38+
}
39+
40+
boolean useFixture = false
41+
42+
String s3AccessKey = System.getenv("amazon_s3_access_key")
43+
String s3SecretKey = System.getenv("amazon_s3_secret_key")
44+
String s3Bucket = System.getenv("amazon_s3_bucket")
45+
String s3BasePath = System.getenv("amazon_s3_base_path")
46+
47+
if (!s3AccessKey && !s3SecretKey && !s3Bucket && !s3BasePath) {
48+
s3AccessKey = 's3_integration_test_access_key'
49+
s3SecretKey = 's3_integration_test_secret_key'
50+
s3Bucket = 'bucket_test'
51+
s3BasePath = 'integration_test'
52+
useFixture = true
53+
}
54+
55+
/** A task to start the AmazonS3Fixture which emulates a S3 service **/
56+
task s3Fixture(type: AntFixture) {
57+
dependsOn compileTestJava
58+
env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
59+
executable = new File(project.runtimeJavaHome, 'bin/java')
60+
args 'org.elasticsearch.repositories.s3.AmazonS3Fixture', baseDir, s3Bucket
61+
}
62+
63+
Map<String, Object> expansions = [
64+
'bucket': s3Bucket,
65+
'base_path': s3BasePath
66+
]
67+
processTestResources {
68+
inputs.properties(expansions)
69+
MavenFilteringHack.filter(it, expansions)
70+
}
71+
72+
integTestCluster {
73+
keystoreSetting 's3.client.integration_test.access_key', s3AccessKey
74+
keystoreSetting 's3.client.integration_test.secret_key', s3SecretKey
75+
76+
if (useFixture) {
77+
dependsOn s3Fixture
78+
/* Use a closure on the string to delay evaluation until tests are executed */
79+
setting 's3.client.integration_test.endpoint', "http://${-> s3Fixture.addressAndPort}"
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.repositories.s3;
21+
22+
import com.carrotsearch.randomizedtesting.annotations.Name;
23+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
24+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
25+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
26+
27+
public class AmazonS3RepositoryClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
28+
29+
public AmazonS3RepositoryClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
30+
super(testCandidate);
31+
}
32+
33+
@ParametersFactory
34+
public static Iterable<Object[]> parameters() throws Exception {
35+
return ESClientYamlSuiteTestCase.createParameters();
36+
}
37+
}

0 commit comments

Comments
 (0)