Skip to content

Commit

Permalink
More clenaup
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Nov 20, 2023
1 parent 4bce0e3 commit e3da4db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
3 changes: 0 additions & 3 deletions modules/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ if (useFixture) {
// ECS
tasks.register("yamlRestTestECS", RestIntegTestTask.class) {
description = "Runs tests using the ECS repository."
systemProperty("fixture.service.name.1", "S3Fixture")
systemProperty("fixture.service.name.2", "S3FixtureEcs")

systemProperty 'tests.rest.blacklist', [
'repository_s3/10_basic/*',
'repository_s3/20_repository_permanent_credentials/*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,34 @@
import java.util.List;
import java.util.Map;

import static fixture.s3.junit.S3HttpFixtureRule.S3FixtureType.S3Fixture;
import static fixture.s3.junit.S3HttpFixtureRule.S3FixtureType.S3FixtureEc2;
import static fixture.s3.junit.S3HttpFixtureRule.S3FixtureType.S3FixtureEcs;
import static fixture.s3.junit.S3HttpFixtureRule.S3FixtureType.S3FixtureSts;
import static fixture.s3.junit.S3HttpFixtureRule.S3FixtureType.S3FixtureWithToken;
import static fixture.s3.junit.S3HttpFixtureRule.Type.S3Fixture;
import static fixture.s3.junit.S3HttpFixtureRule.Type.S3FixtureEc2;
import static fixture.s3.junit.S3HttpFixtureRule.Type.S3FixtureEcs;
import static fixture.s3.junit.S3HttpFixtureRule.Type.S3FixtureSts;
import static fixture.s3.junit.S3HttpFixtureRule.Type.S3FixtureWithToken;

@ThreadLeakFilters(filters = { TestContainersThreadFilter.class })
@ThreadLeakAction({ ThreadLeakAction.Action.WARN, ThreadLeakAction.Action.INTERRUPT })
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class RepositoryS3ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("tests.s3.fixture", "true"));
private static final String TEST_TASK = System.getProperty("tests.task");
private static final S3HttpFixtureRule s3Environment = new S3HttpFixtureRule(USE_FIXTURE, resolveS3HttpFixtures());
private static final S3HttpFixtureRule s3Environment = new S3HttpFixtureRule(USE_FIXTURE, requiredS3Fixtures());
private static final String s3TemporarySessionToken = "session_token";

@SuppressForbidden(reason = "Forbidden method invocation: java.lang.System#getProperties()")
private static List<S3HttpFixtureRule.S3FixtureType> resolveS3HttpFixtures() {
return System.getProperties()
.entrySet()
.stream()
.filter(entry -> ((String) entry.getKey()).startsWith("fixture.service."))
.map(Map.Entry::getValue)
.map(Object::toString)
.map(S3HttpFixtureRule.S3FixtureType::valueOf)
.toList();
private static List<S3HttpFixtureRule.Type> requiredS3Fixtures() {
String testTaskName = TEST_TASK.substring(TEST_TASK.lastIndexOf(':') + 1);
switch (testTaskName) {
case "yamlRestTest":
return List.of(S3Fixture, S3FixtureEcs, S3FixtureWithToken, S3FixtureEc2);
case "yamlRestTestECS":
return List.of(S3Fixture, S3FixtureEcs);
case "yamlRestTestSTS":
return List.of(S3FixtureSts);
default:
return List.of();
}
}

public static ElasticsearchCluster cluster = configureCluster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@

public class S3HttpFixtureRule extends ExternalResource {
private final boolean enabled;
private final List<S3FixtureType> enabledFixtures;
private final List<Type> enabledFixtures;

private Map<S3FixtureType, S3HttpFixture> configuredFixtures = new HashMap<>();
private Map<Type, S3HttpFixture> configuredFixtures = new HashMap<>();

private void configureFixture(S3FixtureType fixtureType) throws Exception {
private void configureFixture(Type fixtureType) throws Exception {
InetSocketAddress inetSocketAddress = resolveLoopBackAddress();
int port = inetSocketAddress.getPort();

if (fixtureType == S3FixtureType.S3Fixture) {
if (fixtureType == Type.S3Fixture) {
S3HttpFixture fixture = new S3HttpFixture(
inetSocketAddress,
new String[] { "localhost", String.valueOf(port), "bucket", "base_path_integration_tests", "s3_test_access_key" }
);
configuredFixtures.put(S3FixtureType.S3Fixture, fixture);
} else if (fixtureType == S3FixtureType.S3FixtureEc2) {
configuredFixtures.put(Type.S3Fixture, fixture);
} else if (fixtureType == Type.S3FixtureEc2) {
S3HttpFixture fixture = new S3HttpFixtureWithEC2(
inetSocketAddress,
new String[] { "localhost", String.valueOf(port), "ec2_bucket", "ec2_base_path", "ec2_access_key", "ec2_session_token" }
);
configuredFixtures.put(S3FixtureType.S3FixtureEc2, fixture);
} else if (fixtureType == S3FixtureType.S3FixtureEcs) {
configuredFixtures.put(Type.S3FixtureEc2, fixture);
} else if (fixtureType == Type.S3FixtureEcs) {
S3HttpFixture fixture = new S3HttpFixtureWithECS(
inetSocketAddress,
new String[] { "localhost", String.valueOf(port), "ecs_bucket", "ecs_base_path", "ecs_access_key", "ecs_session_token" }
);
configuredFixtures.put(S3FixtureType.S3FixtureEcs, fixture);
} else if (fixtureType == S3FixtureType.S3FixtureSts) {
configuredFixtures.put(Type.S3FixtureEcs, fixture);
} else if (fixtureType == Type.S3FixtureSts) {
S3HttpFixture fixture = new S3HttpFixtureWithSTS(
inetSocketAddress,
new String[] {
Expand All @@ -62,8 +62,8 @@ private void configureFixture(S3FixtureType fixtureType) throws Exception {
"sts_session_token",
"Atza|IQEBLjAsAhRFiXuWpUXuRvQ9PZL3GMFcYevydwIUFAHZwXZXXXXXXXXJnrulxKDHwy87oGKPznh0D6bEQZTSCzyoCtL_8S07pLpr0zMbn6w1lfVZKNTBdDansFBmtGnIsIapjI6xKR02Yc_2bQ8LZbUXSGm6Ry6_BG7PrtLZtj_dfCTj92xNGed-CrKqjG7nPBjNIL016GGvuS5gSvPRUxWES3VYfm1wl7WTI7jn-Pcb6M-buCgHhFOzTQxod27L9CqnOLio7N3gZAGpsp6n1-AJBOCJckcyXe2c6uD0srOJeZlKUm2eTDVMf8IehDVI0r1QOnTV6KzzAI3OY87Vd_cVMQ" }
);
configuredFixtures.put(S3FixtureType.S3FixtureSts, fixture);
} else if (fixtureType == S3FixtureType.S3FixtureWithToken) {
configuredFixtures.put(Type.S3FixtureSts, fixture);
} else if (fixtureType == Type.S3FixtureWithToken) {
S3HttpFixture fixture = new S3HttpFixtureWithSessionToken(
inetSocketAddress,
new String[] {
Expand All @@ -74,24 +74,24 @@ private void configureFixture(S3FixtureType fixtureType) throws Exception {
"session_token_access_key",
"session_token" }
);
configuredFixtures.put(S3FixtureType.S3FixtureWithToken, fixture);
configuredFixtures.put(Type.S3FixtureWithToken, fixture);
}
}

public enum S3FixtureType {
public enum Type {
S3Fixture,
S3FixtureEcs,
S3FixtureEc2,
S3FixtureSts,
S3FixtureWithToken
}

public S3HttpFixtureRule(boolean enabled, List<S3FixtureType> enabledFixtures) {
public S3HttpFixtureRule(boolean enabled, List<Type> enabledFixtures) {
this.enabled = enabled;
this.enabledFixtures = enabledFixtures;
}

public String getAddress(S3FixtureType fixtureRuleType) {
public String getAddress(Type fixtureRuleType) {
return configuredFixtures.get(fixtureRuleType).getAddress();
}

Expand All @@ -102,7 +102,7 @@ protected void before() throws Throwable {
}

private void startFixtures() throws Exception {
for (S3FixtureType enabledFixture : enabledFixtures) {
for (Type enabledFixture : enabledFixtures) {
configureFixture(enabledFixture);
}
configuredFixtures.values().forEach(s3HttpFixture -> {
Expand Down

0 comments on commit e3da4db

Please sign in to comment.