Skip to content

Commit 7402dfd

Browse files
authored
Introduce qa subprojects of :modules:repository-s3 (#126274)
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 88996bc commit 7402dfd

File tree

9 files changed

+88
-63
lines changed

9 files changed

+88
-63
lines changed

modules/repository-s3/build.gradle

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

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

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

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+
}

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);
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+
}
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)