Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b988846

Browse files
author
Aaron Congo
committedJul 12, 2022
Implement integration test framework (#40)
- Added integration test framework classes and workflows so that integration tests can be run against an Aurora Postgres cluster or a standard Postgres container
1 parent 3ccffc3 commit b988846

19 files changed

+1948
-16
lines changed
 

‎.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
gradlew text eol=lf

‎.github/workflows/main.yml

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ concurrency:
1717

1818
jobs:
1919
build-driver:
20-
name: 'Run Tests'
20+
name: 'Run non-container integration tests'
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: 'Clone Repository'
23+
- name: 'Clone repository'
2424
uses: actions/checkout@v2
2525

2626
- name: 'Set up JDK 8'
@@ -34,7 +34,7 @@ jobs:
3434
- name: 'Generate code coverage report'
3535
run: ./gradlew jacocoTestReport
3636

37-
- name: 'Archive Test Results'
37+
- name: 'Archive test results'
3838
if: always()
3939
uses: actions/upload-artifact@v3
4040
with:
@@ -49,3 +49,80 @@ jobs:
4949
name: 'coverage-report'
5050
path: ./driver-proxy/build/reports/jacoco/test/
5151
retention-days: 3
52+
53+
aurora-postgres-integration-tests:
54+
concurrency: IntegrationTests
55+
name: 'Run Aurora Postgres container integration tests'
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: 'Clone repository'
59+
uses: actions/checkout@v2
60+
with:
61+
fetch-depth: 50
62+
- name: 'Set up JDK 8'
63+
uses: actions/setup-java@v1
64+
with:
65+
java-version: 8
66+
- name: 'Configure AWS credentials'
67+
uses: aws-actions/configure-aws-credentials@v1
68+
with:
69+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
70+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
71+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
72+
- name: 'Set up temp AWS credentials'
73+
run: |
74+
creds=($(aws sts get-session-token \
75+
--duration-seconds 3600 \
76+
--query 'Credentials.[AccessKeyId, SecretAccessKey, SessionToken]' \
77+
--output text \
78+
| xargs));
79+
echo "::add-mask::${creds[0]}"
80+
echo "::add-mask::${creds[1]}"
81+
echo "::add-mask::${creds[2]}"
82+
echo "TEMP_AWS_ACCESS_KEY_ID=${creds[0]}" >> $GITHUB_ENV
83+
echo "TEMP_AWS_SECRET_ACCESS_KEY=${creds[1]}" >> $GITHUB_ENV
84+
echo "TEMP_AWS_SESSION_TOKEN=${creds[2]}" >> $GITHUB_ENV
85+
- name: 'Run integration tests'
86+
run: |
87+
./gradlew --no-parallel --no-daemon test-integration-aurora-postgres
88+
env:
89+
AURORA_POSTGRES_CLUSTER_IDENTIFIER: ${{ secrets.AURORA_POSTGRES_CLUSTER_IDENTIFIER }}-${{ github.run_id }}
90+
AURORA_POSTGRES_USERNAME: ${{ secrets.AURORA_POSTGRES_USERNAME }}
91+
AURORA_POSTGRES_PASSWORD: ${{ secrets.AURORA_POSTGRES_PASSWORD }}
92+
AWS_ACCESS_KEY_ID: ${{ env.TEMP_AWS_ACCESS_KEY_ID }}
93+
AWS_SECRET_ACCESS_KEY: ${{ env.TEMP_AWS_SECRET_ACCESS_KEY }}
94+
AWS_SESSION_TOKEN: ${{ env.TEMP_AWS_SESSION_TOKEN }}
95+
- name: 'Archive junit results'
96+
if: always()
97+
uses: actions/upload-artifact@v2
98+
with:
99+
name: 'junit-report'
100+
path: ./driver-proxy/build/reports/tests/
101+
retention-days: 5
102+
103+
standard-postgres-integration-tests:
104+
concurrency: IntegrationTests
105+
name: 'Run Standard Postgres container integration tests'
106+
runs-on: ubuntu-latest
107+
steps:
108+
- name: 'Clone repository'
109+
uses: actions/checkout@v2
110+
with:
111+
fetch-depth: 50
112+
- name: 'Set up JDK 8'
113+
uses: actions/setup-java@v1
114+
with:
115+
java-version: 8
116+
- name: 'Run integration tests'
117+
run: |
118+
./gradlew --no-parallel --no-daemon test-integration-standard-postgres
119+
env:
120+
TEST_USERNAME: ${{ secrets.STANDARD_POSTGRES_USERNAME }}
121+
TEST_PASSWORD: ${{ secrets.STANDARD_POSTGRES_PASSWORD }}
122+
- name: 'Archive junit results'
123+
if: always()
124+
uses: actions/upload-artifact@v2
125+
with:
126+
name: 'junit-report'
127+
path: ./driver-proxy/build/reports/tests/
128+
retention-days: 5

‎driver-proxy/build.gradle.kts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,38 @@ plugins {
1919
dependencies {
2020
implementation("org.checkerframework:checker-qual:3.22.+")
2121

22+
testImplementation("org.junit.platform:junit-platform-commons:1.8.+")
23+
testImplementation("org.junit.platform:junit-platform-engine:1.8.+")
24+
testImplementation("org.junit.platform:junit-platform-launcher:1.8.+")
25+
testImplementation("org.junit.platform:junit-platform-suite-engine:1.8.+")
2226
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.+")
2327
testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.+")
2428
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
2529

30+
testImplementation("org.apache.commons:commons-dbcp2:2.8.0")
2631
testImplementation("org.postgresql:postgresql:42.+")
2732
testImplementation("mysql:mysql-connector-java:8.0.+")
2833
testImplementation("com.zaxxer:HikariCP:4.+") // version 4.+ is compatible with Java 8
2934
testImplementation("org.springframework.boot:spring-boot-starter-jdbc:2.7.+")
3035
testImplementation("org.mockito:mockito-inline:4.+")
36+
testImplementation("software.amazon.awssdk:rds:2.17.+")
37+
testImplementation("software.amazon.awssdk:ec2:2.17.+")
38+
testImplementation("org.testcontainers:testcontainers:1.17.+")
39+
testImplementation("org.testcontainers:mysql:1.17.+")
40+
testImplementation("org.testcontainers:postgresql:1.17.+")
41+
testImplementation("org.testcontainers:junit-jupiter:1.17.+")
42+
testImplementation("org.testcontainers:toxiproxy:1.17.+")
3143
}
3244

3345
tasks.check {
3446
dependsOn("jacocoTestCoverageVerification")
3547
}
3648

49+
tasks.test {
50+
filter.excludeTestsMatching("integration.host.*")
51+
filter.excludeTestsMatching("integration.container.*")
52+
}
53+
3754
checkstyle {
3855
// Checkstyle versions 7.x, 8.x, and 9.x are supported by JRE version 8 and above.
3956
toolVersion = "9.3"
@@ -122,3 +139,44 @@ tasks.getByName<Test>("test") {
122139

123140
systemProperty("java.util.logging.config.file", "${project.buildDir}/resources/test/logging-test.properties")
124141
}
142+
143+
// Run Aurora Postgres integrations tests in container
144+
tasks.register<Test>("test-integration-aurora-postgres") {
145+
group = "verification"
146+
filter.includeTestsMatching("integration.host.AuroraPostgresContainerTest.runTestInContainer")
147+
}
148+
149+
tasks.register<Test>("test-performance-aurora-postgres") {
150+
group = "verification"
151+
filter.includeTestsMatching("integration.host.AuroraPostgresContainerTest.runPerformanceTestInContainer")
152+
}
153+
154+
// Run standard Postgres tests in container
155+
tasks.register<Test>("test-integration-standard-postgres") {
156+
group = "verification"
157+
filter.includeTestsMatching("integration.host.StandardPostgresContainerTest.runTestInContainer")
158+
}
159+
160+
// Run Aurora Postgres integration tests in container with debugger
161+
tasks.register<Test>("debug-integration-aurora-postgres") {
162+
group = "verification"
163+
filter.includeTestsMatching("integration.host.AuroraPostgresContainerTest.debugTestInContainer")
164+
}
165+
166+
tasks.register<Test>("debug-performance-aurora-postgres") {
167+
group = "verification"
168+
filter.includeTestsMatching("testsuite.integration.host.AuroraPostgresContainerTest.debugPerformanceTestInContainer")
169+
}
170+
171+
// Run standard Postgres integration tests in container with debugger
172+
tasks.register<Test>("debug-integration-standard-postgres") {
173+
group = "verification"
174+
filter.includeTestsMatching("integration.host.StandardPostgresContainerTest.debugTestInContainer")
175+
}
176+
177+
tasks.withType<Test> {
178+
this.testLogging {
179+
this.showStandardStreams = true
180+
}
181+
useJUnitPlatform()
182+
}

‎driver-proxy/src/main/java/software/aws/rds/jdbc/proxydriver/ConnectionPluginManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void unlock() {
9898

9999
/**
100100
* Initialize a chain of {@link ConnectionPlugin} using their corresponding {@link ConnectionPluginFactory}. If
101-
* {@code PropertyKey.connectionPluginFactories} is provided by the user, initialize the chain with the given
101+
* {@code PropertyDefinition.PLUGINS} is provided by the user, initialize the chain with the given
102102
* connection plugins in the order they are specified.
103103
*
104104
* <p>The {@link DefaultConnectionPlugin} will always be initialized and attached as the last

‎driver-proxy/src/main/java/software/aws/rds/jdbc/proxydriver/PropertyDefinition.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,47 @@
1616

1717
public class PropertyDefinition {
1818

19-
public static final ProxyDriverProperty PLUGINS =
19+
public static final ProxyDriverProperty CLUSTER_INSTANCE_HOST_PATTERN =
2020
new ProxyDriverProperty(
21-
"proxyDriverPlugins", null, "Coma separated list of connection plugin codes");
21+
"clusterInstanceHostPattern",
22+
null,
23+
"The cluster instance DNS pattern that will be used to build a complete instance endpoint. "
24+
+ "A \"?\" character in this pattern should be used as a placeholder for cluster instance names. "
25+
+ "This pattern is required to be specified for IP address or custom domain connections to AWS RDS "
26+
+ "clusters. Otherwise, if unspecified, the pattern will be automatically created for AWS RDS clusters.");
2227

23-
public static final ProxyDriverProperty PROFILE_NAME =
28+
public static final ProxyDriverProperty ENABLE_CLUSTER_AWARE_FAILOVER =
2429
new ProxyDriverProperty(
25-
"proxyDriverProfileName", null, "Driver configuration profile name");
30+
"enableClusterAwareFailover", "true",
31+
"Enable/disable cluster-aware failover logic");
32+
33+
public static final ProxyDriverProperty LOG_UNCLOSED_CONNECTIONS =
34+
new ProxyDriverProperty(
35+
"proxyDriverLogUnclosedConnections", "false",
36+
"Allows the driver to track a point in the code where connection has been opened and never closed after");
2637

2738
public static final ProxyDriverProperty LOGGER_LEVEL =
2839
new ProxyDriverProperty(
2940
"proxyDriverLoggerLevel",
3041
null,
3142
"Logger level of the driver",
3243
false,
33-
new String[]{
44+
new String[] {
3445
"OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL"
3546
});
3647

37-
public static final ProxyDriverProperty LOG_UNCLOSED_CONNECTIONS =
48+
public static final ProxyDriverProperty PLUGINS =
3849
new ProxyDriverProperty(
39-
"proxyDriverLogUnclosedConnections", "false",
40-
"Allows the driver to track a point in the code where connection has been opened and never closed after");
50+
"proxyDriverPlugins", null, "Comma separated list of connection plugin codes");
51+
52+
public static final ProxyDriverProperty PROFILE_NAME =
53+
new ProxyDriverProperty(
54+
"proxyDriverProfileName", null, "Driver configuration profile name");
55+
56+
public static final ProxyDriverProperty USE_AWS_IAM =
57+
new ProxyDriverProperty(
58+
"useAwsIam", "false", "Set to true to use AWS IAM database authentication");
59+
4160

4261
private static final Map<String, ProxyDriverProperty> PROPS_BY_NAME =
4362
new HashMap<String, ProxyDriverProperty>();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* AWS JDBC Proxy Driver
3+
* Copyright Amazon.com Inc. or affiliates.
4+
* See the LICENSE file in the project root for more information.
5+
*/
6+
7+
plugins {
8+
java
9+
}
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
testImplementation("org.junit.platform:junit-platform-commons:1.8.2")
17+
testImplementation("org.junit.platform:junit-platform-engine:1.8.2")
18+
testImplementation("org.junit.platform:junit-platform-launcher:1.8.2")
19+
testImplementation("org.junit.platform:junit-platform-suite-engine:1.8.2")
20+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
21+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.2")
22+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
23+
24+
testImplementation("org.apache.commons:commons-dbcp2:2.8.0")
25+
testImplementation("org.postgresql:postgresql:42.+")
26+
testImplementation("mysql:mysql-connector-java:8.0.+")
27+
testImplementation("com.zaxxer:HikariCP:4.+") // version 4.+ is compatible with Java 8
28+
testImplementation("org.springframework.boot:spring-boot-starter-jdbc:2.7.+")
29+
testImplementation("org.mockito:mockito-inline:4.+")
30+
testImplementation("software.amazon.awssdk:rds:2.17.165")
31+
testImplementation("software.amazon.awssdk:ec2:2.17.165")
32+
testImplementation("org.testcontainers:testcontainers:1.17.+")
33+
testImplementation("org.testcontainers:mysql:1.17.+")
34+
testImplementation("org.testcontainers:postgresql:1.17.+")
35+
testImplementation("org.testcontainers:junit-jupiter:1.17.+")
36+
testImplementation("org.testcontainers:toxiproxy:1.17.+")
37+
38+
testImplementation(fileTree("./libs") { include("*.jar") })
39+
testImplementation(files("./test"))
40+
}
41+
42+
// Integration tests are run in a specific order.
43+
// To add more tests, see integration.container.aurora.postgres.AuroraPostgresTestSuite.java
44+
tasks.register<Test>("in-container-aurora-postgres") {
45+
filter.includeTestsMatching("integration.container.aurora.postgres.AuroraPostgresTestSuite")
46+
}
47+
48+
tasks.register<Test>("in-container-aurora-postgres-performance") {
49+
filter.includeTestsMatching("integration.container.aurora.postgres.AuroraPostgresPerformanceTest")
50+
}
51+
52+
// Integration tests are run in a specific order.
53+
// To add more tests, see integration.container.standard.postgres.StandardPostgresTestSuite.java
54+
tasks.register<Test>("in-container-standard-postgres") {
55+
filter.includeTestsMatching("integration.container.standard.postgres.StandardPostgresTestSuite")
56+
}
57+
58+
tasks.withType<Test> {
59+
outputs.upToDateWhen { false }
60+
useJUnitPlatform()
61+
}

0 commit comments

Comments
 (0)