Skip to content

Commit 43b10cf

Browse files
authored
Introduce qa subprojects of :modules:repository-s3 (#126274) (#126277)
Today we have some special-case test classes in `:modules:repository-s3` within the same source root as the regular tests, with some trickery to define separate Gradle tasks to run them with their special-case configs. This commit simplifies the build by just moving each of these classes into its own Gradle project.
1 parent db2be04 commit 43b10cf

File tree

9 files changed

+88
-63
lines changed

9 files changed

+88
-63
lines changed

Diff for: modules/repository-s3/build.gradle

-53
Original file line numberDiff line numberDiff line change
@@ -79,58 +79,11 @@ esplugin.bundleSpec.from('config/repository-s3') {
7979
into 'config'
8080
}
8181

82-
def testRepositoryCreds = tasks.register("testRepositoryCreds", Test) {
83-
include '**/RepositoryCredentialsTests.class'
84-
systemProperty 'es.allow_insecure_settings', 'true'
85-
classpath = sourceSets.test.runtimeClasspath
86-
testClassesDirs = sourceSets.test.output.classesDirs
87-
}
88-
89-
tasks.named('test').configure {
90-
// this is tested explicitly in separate test tasks
91-
exclude '**/RepositoryCredentialsTests.class'
92-
}
93-
94-
boolean useFixture = false
95-
String s3PermanentAccessKey = System.getenv("amazon_s3_access_key")
96-
String s3PermanentSecretKey = System.getenv("amazon_s3_secret_key")
97-
String s3PermanentBucket = System.getenv("amazon_s3_bucket")
98-
String s3PermanentBasePath = System.getenv("amazon_s3_base_path")
99-
100-
// If all these variables are missing then we are testing against the internal fixture instead, which has the following credentials hard-coded in.
101-
102-
if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3PermanentBasePath) {
103-
useFixture = true
104-
s3PermanentAccessKey = 's3_test_access_key'
105-
s3PermanentSecretKey = 's3_test_secret_key'
106-
s3PermanentBucket = 'bucket'
107-
s3PermanentBasePath = 'base_path'
108-
}
109-
11082
tasks.named("internalClusterTest").configure {
111-
// this is tested explicitly in a separate test task
112-
exclude '**/S3RepositoryThirdPartyTests.class'
11383
// TODO: remove once https://github.com/elastic/elasticsearch/issues/101608 is fixed
11484
systemProperty 'es.insecure_network_trace_enabled', 'true'
11585
}
11686

117-
// 3rd Party Tests, i.e. testing against a real S3 repository
118-
tasks.register("s3ThirdPartyTest", Test) {
119-
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
120-
SourceSet internalTestSourceSet = sourceSets.getByName(InternalClusterTestPlugin.SOURCE_SET_NAME)
121-
setTestClassesDirs(internalTestSourceSet.getOutput().getClassesDirs())
122-
setClasspath(internalTestSourceSet.getRuntimeClasspath())
123-
include '**/S3RepositoryThirdPartyTests.class'
124-
systemProperty("tests.use.fixture", Boolean.toString(useFixture))
125-
systemProperty 'test.s3.account', s3PermanentAccessKey
126-
systemProperty 'test.s3.key', s3PermanentSecretKey
127-
systemProperty 'test.s3.bucket', s3PermanentBucket
128-
nonInputProperties.systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + buildParams.testSeed
129-
130-
// test container accesses ~/.testcontainers.properties read
131-
systemProperty "tests.security.manager", "false"
132-
}
133-
13487
tasks.named("thirdPartyAudit").configure {
13588
ignoreMissingClasses(
13689
// classes are missing
@@ -153,9 +106,3 @@ tasks.named("thirdPartyAudit").configure {
153106
'javax.activation.DataHandler'
154107
)
155108
}
156-
157-
tasks.named("check").configure {
158-
dependsOn(tasks.withType(Test))
159-
dependsOn(testRepositoryCreds)
160-
}
161-

Diff for: modules/repository-s3/qa/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
apply plugin: 'elasticsearch.java'
9+
10+
dependencies {
11+
testImplementation project(':modules:repository-s3')
12+
testImplementation project(':test:framework')
13+
testImplementation project(':server')
14+
}
15+
16+
tasks.named("test").configure {
17+
systemProperty 'es.allow_insecure_settings', 'true'
18+
}

Diff for: modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java renamed to modules/repository-s3/qa/insecure-credentials/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java

-10
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.elasticsearch.test.rest.FakeRestRequest;
3333
import org.elasticsearch.watcher.ResourceWatcherService;
3434

35-
import java.security.AccessController;
36-
import java.security.PrivilegedAction;
3735
import java.util.Collection;
3836
import java.util.List;
3937
import java.util.concurrent.CountDownLatch;
@@ -51,14 +49,6 @@
5149
@SuppressForbidden(reason = "test requires to set a System property to allow insecure settings when running in IDE")
5250
public class RepositoryCredentialsTests extends ESSingleNodeTestCase {
5351

54-
static {
55-
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
56-
// required for client settings overwriting when running in IDE
57-
System.setProperty("es.allow_insecure_settings", "true");
58-
return null;
59-
});
60-
}
61-
6252
@Override
6353
protected Collection<Class<? extends Plugin>> getPlugins() {
6454
return List.of(ProxyS3RepositoryPlugin.class);

Diff for: modules/repository-s3/qa/third-party/build.gradle

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
apply plugin: 'elasticsearch.java'
9+
10+
dependencies {
11+
testImplementation project(':modules:repository-s3')
12+
testImplementation project(':test:fixtures:minio-fixture')
13+
testImplementation project(':test:framework')
14+
testImplementation project(':server')
15+
}
16+
17+
boolean useFixture = false
18+
String s3PermanentAccessKey = System.getenv("amazon_s3_access_key")
19+
String s3PermanentSecretKey = System.getenv("amazon_s3_secret_key")
20+
String s3PermanentBucket = System.getenv("amazon_s3_bucket")
21+
String s3PermanentBasePath = System.getenv("amazon_s3_base_path")
22+
23+
// If all these variables are missing then we are testing against the MinIO fixture instead, which has the following credentials hard-coded in.
24+
25+
if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3PermanentBasePath) {
26+
useFixture = true
27+
s3PermanentAccessKey = 's3_test_access_key'
28+
s3PermanentSecretKey = 's3_test_secret_key'
29+
s3PermanentBucket = 'bucket'
30+
s3PermanentBasePath = 'base_path'
31+
}
32+
33+
tasks.named("test").configure {
34+
systemProperty("tests.use.fixture", Boolean.toString(useFixture))
35+
systemProperty 'test.s3.account', s3PermanentAccessKey
36+
systemProperty 'test.s3.key', s3PermanentSecretKey
37+
systemProperty 'test.s3.bucket', s3PermanentBucket
38+
nonInputProperties.systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + buildParams.testSeed
39+
40+
// test container accesses ~/.testcontainers.properties read
41+
systemProperty "tests.security.manager", "false"
42+
}
43+
44+
tasks.register("s3ThirdPartyTest") {
45+
dependsOn "test"
46+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
apply plugin: 'elasticsearch.java'
9+
10+
dependencies {
11+
testImplementation project(':modules:repository-s3')
12+
testImplementation project(':test:framework')
13+
testImplementation project(':server')
14+
}
15+
16+
tasks.named("test").configure {
17+
systemProperty 'es.allow_insecure_settings', 'true'
18+
}

0 commit comments

Comments
 (0)