Skip to content

Commit 20b8141

Browse files
committed
fix: rw plugins not subscribed to execute pipeline
1 parent 22c804f commit 20b8141

11 files changed

Lines changed: 74 additions & 71 deletions

File tree

aws_advanced_python_wrapper/pep249_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DbApiMethod(Enum):
6363
CURSOR_NEXT = (30, "Cursor.__next__", False)
6464
CURSOR_LASTROWID = (31, "Cursor.lastrowid", False)
6565

66-
# AWS Advaced Python Wrapper Methods for
66+
# AWS Advanced Python Wrapper Methods for the execution pipelines.
6767
CONNECT = (32, "connect", True)
6868
FORCE_CONNECT = (33, "force_connect", True)
6969
INIT_HOST_PROVIDER = (34, "init_host_provider", True)

aws_advanced_python_wrapper/read_write_splitting_plugin.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ class ReadWriteSplittingConnectionManager(Plugin):
4949
DbApiMethod.CONNECT.method_name,
5050
DbApiMethod.NOTIFY_CONNECTION_CHANGED.method_name,
5151
DbApiMethod.CONNECTION_SET_READ_ONLY.method_name,
52+
53+
DbApiMethod.CONNECTION_COMMIT.method_name,
54+
DbApiMethod.CONNECTION_AUTOCOMMIT.method_name,
55+
DbApiMethod.CONNECTION_AUTOCOMMIT_SETTER.method_name,
56+
DbApiMethod.CONNECTION_IS_READ_ONLY.method_name,
57+
DbApiMethod.CONNECTION_SET_READ_ONLY.method_name,
58+
DbApiMethod.CONNECTION_ROLLBACK.method_name,
59+
60+
DbApiMethod.CURSOR_EXECUTE.method_name,
61+
DbApiMethod.CURSOR_FETCHONE.method_name,
62+
DbApiMethod.CURSOR_FETCHMANY.method_name,
63+
DbApiMethod.CURSOR_FETCHALL.method_name
5264
}
5365
_POOL_PROVIDER_CLASS_NAME = "aws_advanced_python_wrapper.sql_alchemy_connection_provider.SqlAlchemyPooledConnectionProvider"
5466

@@ -390,32 +402,29 @@ def _close_connection_if_idle(self, internal_conn: Optional[Connection]):
390402
current_conn = self._plugin_service.current_connection
391403
driver_dialect = self._plugin_service.driver_dialect
392404

405+
if internal_conn == current_conn:
406+
# Connection is in use, do not close
407+
return
408+
393409
try:
394-
if internal_conn != current_conn and self._is_connection_usable(
395-
internal_conn, driver_dialect
396-
):
410+
if self._is_connection_usable(internal_conn, driver_dialect):
397411
driver_dialect.execute(DbApiMethod.CONNECTION_CLOSE.method_name, lambda: internal_conn.close())
398-
if internal_conn == self._writer_connection:
399-
self._writer_connection = None
400-
self._writer_host_info = None
401-
if internal_conn == self._reader_connection:
402-
self._reader_connection = None
403-
self._reader_host_info = None
404412
except Exception:
405413
# Ignore exceptions during cleanup - connection might already be dead
406414
pass
415+
finally:
416+
if internal_conn == self._writer_connection:
417+
self._writer_connection = None
418+
self._writer_host_info = None
419+
if internal_conn == self._reader_connection:
420+
self._reader_connection = None
421+
self._reader_host_info = None
407422

408423
def _close_idle_connections(self):
409424
logger.debug("ReadWriteSplittingPlugin.ClosingInternalConnections")
410425
self._close_connection_if_idle(self._reader_connection)
411426
self._close_connection_if_idle(self._writer_connection)
412427

413-
# Always clear cached references even if connections couldn't be closed
414-
self._reader_connection = None
415-
self._reader_host_info = None
416-
self._writer_connection = None
417-
self._writer_host_info = None
418-
419428
@staticmethod
420429
def log_and_raise_exception(log_msg: str):
421430
logger.error(log_msg)
@@ -450,7 +459,7 @@ def host_list_provider_service(self) -> Optional[HostListProviderService]:
450459
...
451460

452461
@host_list_provider_service.setter
453-
def host_list_provider_service(self, new_value: int) -> None:
462+
def host_list_provider_service(self, new_value: HostListProviderService) -> None:
454463
"""The setter for the 'host_list_provider_service' attribute."""
455464
...
456465

aws_advanced_python_wrapper/resources/aws_advanced_python_wrapper_messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ UnknownDialect.AbortConnection=[UnknownDialect] abort_connection was called, but
462462
Wrapper.ConnectMethod=[Wrapper] Target driver should be a target driver's connect() method/function.
463463
Wrapper.RequiredTargetDriver=[Wrapper] Target driver is required.
464464
Wrapper.UnsupportedAttribute=[Wrapper] Target driver does not have the attribute: '{}'
465-
Wrapper.Properties=[Wrapper] "Connection Properties: "
465+
Wrapper.Properties=[Wrapper] "Connection Properties: {}"
466466

467467
WriterFailoverHandler.AlreadyWriter=[WriterFailoverHandler] Current reader connection is actually a new writer connection.
468468
WriterFailoverHandler.CurrentTopologyNone=[WriterFailoverHandler] Current topology cannot be None.

aws_advanced_python_wrapper/utils/telemetry/xray_telemetry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def set_success(self, success: bool):
5555

5656
def set_attribute(self, key: str, value: AttributeValue):
5757
if self._trace_entity is not None:
58-
self._trace_entity.put_annotation(key, value)
58+
# XRay only supports str, bool, int, float - not sequences
59+
if isinstance(value, (str, bool, int, float)):
60+
self._trace_entity.put_annotation(key, value)
5961

6062
def set_exception(self, exception: Exception):
6163
if self._trace_entity is not None and exception is not None:
@@ -90,8 +92,7 @@ def _clone_and_close_context(context: XRayTelemetryContext, trace_level: Telemet
9092

9193
clone._trace_entity.start_time = context._trace_entity.start_time
9294

93-
for key in context._trace_entity.annotations.items():
94-
value = context._trace_entity.annotations[key]
95+
for key, value in context._trace_entity.annotations.items():
9596
if key != TelemetryConst.TRACE_NAME_ANNOTATION and value is not None:
9697
clone.set_attribute(key, value)
9798

docs/examples/PGXRayTelemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
print("-- running application")
3030
logging.basicConfig(level=logging.DEBUG)
3131

32-
xray_recorder.configure(sampler=LocalSampler({"version": 1, "default": {"fixed_target": 1, "rate": 1.0}}))
32+
xray_recorder.configure(sampler=LocalSampler({"version": 1, "default": {"fixed_target": 1, "rate": 1.0}, "rules": []}))
3333
global_sdk_config.set_sdk_enabled(True)
3434

3535
with xray_recorder.in_segment("python_xray_telemetry_app") as segment:

tests/integration/container/utils/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _create() -> TestEnvironment:
102102
xray_recorder.configure(daemon_address=xray_daemon_endpoint,
103103
context_missing="IGNORE_ERROR",
104104
sampler=LocalSampler(
105-
{"version": 1, "default": {"fixed_target": 1, "rate": 1.0}}))
105+
{"version": 1, "default": {"fixed_target": 1, "rate": 1.0}, "rules": []}))
106106
global_sdk_config.set_sdk_enabled(True)
107107

108108
if TestEnvironmentFeatures.TELEMETRY_METRICS_ENABLED in env.get_features():

tests/integration/host/build.gradle.kts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,30 @@ repositories {
1313
}
1414

1515
dependencies {
16-
testImplementation("org.checkerframework:checker-qual:3.26.0")
17-
testImplementation("org.junit.platform:junit-platform-commons:1.9.0")
18-
testImplementation("org.junit.platform:junit-platform-engine:1.9.0")
19-
testImplementation("org.junit.platform:junit-platform-launcher:1.9.0")
20-
testImplementation("org.junit.platform:junit-platform-suite-engine:1.9.0")
21-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1")
22-
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.1")
16+
testImplementation("org.checkerframework:checker-qual:3.49.0")
17+
testImplementation("org.junit.platform:junit-platform-commons:1.11.4")
18+
testImplementation("org.junit.platform:junit-platform-engine:1.11.4")
19+
testImplementation("org.junit.platform:junit-platform-launcher:1.11.4")
20+
testImplementation("org.junit.platform:junit-platform-suite-engine:1.11.4")
21+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
22+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.4")
2323
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
2424

25-
testImplementation("org.apache.commons:commons-dbcp2:2.9.0")
26-
testImplementation("org.postgresql:postgresql:42.5.0")
27-
testImplementation("mysql:mysql-connector-java:8.0.31")
28-
testImplementation("org.springframework.boot:spring-boot-starter-jdbc:2.7.4")
29-
testImplementation("org.mockito:mockito-inline:4.8.0")
30-
testImplementation("software.amazon.awssdk:rds:2.20.49")
31-
testImplementation("software.amazon.awssdk:ec2:2.20.61")
32-
testImplementation("software.amazon.awssdk:secretsmanager:2.20.49")
25+
testImplementation("org.apache.commons:commons-dbcp2:2.12.0")
26+
testImplementation("org.postgresql:postgresql:42.7.5")
27+
testImplementation("com.mysql:mysql-connector-j:9.1.0")
28+
testImplementation("software.amazon.awssdk:rds:2.30.10")
29+
testImplementation("software.amazon.awssdk:ec2:2.30.10")
30+
testImplementation("software.amazon.awssdk:secretsmanager:2.30.10")
3331
// Note: all org.testcontainers dependencies should have the same version
34-
testImplementation("org.testcontainers:testcontainers:1.21.2")
35-
testImplementation("org.testcontainers:mysql:1.21.2")
36-
testImplementation("org.testcontainers:postgresql:1.21.2")
37-
testImplementation("org.testcontainers:junit-jupiter:1.21.2")
38-
testImplementation("org.testcontainers:toxiproxy:1.21.2")
39-
testImplementation("org.apache.poi:poi-ooxml:5.2.2")
40-
testImplementation("org.slf4j:slf4j-simple:2.0.3")
41-
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
32+
testImplementation("org.testcontainers:testcontainers:2.0.3")
33+
testImplementation("org.testcontainers:testcontainers-mysql:2.0.3")
34+
testImplementation("org.testcontainers:testcontainers-postgresql:2.0.3")
35+
testImplementation("org.testcontainers:testcontainers-toxiproxy:2.0.3")
36+
testImplementation("org.testcontainers:testcontainers-junit-jupiter:2.0.3")
37+
testImplementation("org.apache.poi:poi-ooxml:5.3.0")
38+
testImplementation("org.slf4j:slf4j-simple:2.0.16")
39+
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
4240
}
4341

4442
tasks.test {

tests/integration/host/src/test/java/integration/DriverHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.sql.DriverManager;
2121
import java.sql.SQLException;
2222
import java.util.logging.Logger;
23-
import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException;
2423

2524
public class DriverHelper {
2625

@@ -33,7 +32,7 @@ public static String getDriverProtocol(DatabaseEngine databaseEngine) {
3332
case PG:
3433
return "jdbc:postgresql://";
3534
default:
36-
throw new NotImplementedException(databaseEngine.toString());
35+
throw new UnsupportedOperationException(databaseEngine.toString());
3736
}
3837
}
3938

@@ -44,7 +43,7 @@ public static String getDriverClassname(DatabaseEngine databaseEngine) {
4443
case PG:
4544
return getDriverClassname(TestDriver.PG);
4645
default:
47-
throw new NotImplementedException(databaseEngine.toString());
46+
throw new UnsupportedOperationException(databaseEngine.toString());
4847
}
4948
}
5049

@@ -55,7 +54,7 @@ public static String getDriverClassname(TestDriver testDriver) {
5554
case PG:
5655
return "org.postgresql.Driver";
5756
default:
58-
throw new NotImplementedException(testDriver.toString());
57+
throw new UnsupportedOperationException(testDriver.toString());
5958
}
6059
}
6160

tests/integration/host/src/test/java/integration/host/TestEnvironment.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.testcontainers.containers.GenericContainer;
5151
import org.testcontainers.containers.Network;
5252
import org.testcontainers.containers.ToxiproxyContainer;
53-
import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException;
5453
import software.amazon.awssdk.services.rds.model.BlueGreenDeployment;
5554
import software.amazon.awssdk.services.rds.model.DBCluster;
5655
import software.amazon.awssdk.services.rds.model.DBInstance;
@@ -149,7 +148,7 @@ public static TestEnvironment build(TestEnvironmentRequest request) throws IOExc
149148
break;
150149

151150
default:
152-
throw new NotImplementedException(request.getDatabaseEngineDeployment().toString());
151+
throw new UnsupportedOperationException(request.getDatabaseEngineDeployment().toString());
153152
}
154153

155154
if (request.getFeatures().contains(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED)) {
@@ -272,7 +271,7 @@ private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR
272271
configureIamAccess(env);
273272
break;
274273
default:
275-
throw new NotImplementedException(request.getDatabaseEngineDeployment().toString());
274+
throw new UnsupportedOperationException(request.getDatabaseEngineDeployment().toString());
276275
}
277276

278277
return env;
@@ -404,7 +403,7 @@ private static void createDatabaseContainers(TestEnvironment env) {
404403
}
405404
break;
406405
default:
407-
throw new NotImplementedException(env.info.getRequest().getDatabaseInstances().toString());
406+
throw new UnsupportedOperationException(env.info.getRequest().getDatabaseInstances().toString());
408407
}
409408

410409
switch (env.info.getRequest().getDatabaseEngine()) {
@@ -453,7 +452,7 @@ private static void createDatabaseContainers(TestEnvironment env) {
453452
break;
454453

455454
default:
456-
throw new NotImplementedException(env.info.getRequest().getDatabaseEngine().toString());
455+
throw new UnsupportedOperationException(env.info.getRequest().getDatabaseEngine().toString());
457456
}
458457
}
459458

@@ -489,7 +488,7 @@ private static void createDbCluster(TestEnvironment env) {
489488
createDbCluster(env, env.numOfInstances);
490489
break;
491490
default:
492-
throw new NotImplementedException(env.info.getRequest().getDatabaseEngine().toString());
491+
throw new UnsupportedOperationException(env.info.getRequest().getDatabaseEngine().toString());
493492
}
494493
}
495494

@@ -852,7 +851,7 @@ private static String getDbEngine(TestEnvironmentRequest request) {
852851
case RDS_MULTI_AZ_INSTANCE:
853852
return getRdsEngine(request);
854853
default:
855-
throw new NotImplementedException(request.getDatabaseEngineDeployment().toString());
854+
throw new UnsupportedOperationException(request.getDatabaseEngineDeployment().toString());
856855
}
857856
}
858857

@@ -863,7 +862,7 @@ private static String getAuroraDbEngine(TestEnvironmentRequest request) {
863862
case PG:
864863
return "aurora-postgresql";
865864
default:
866-
throw new NotImplementedException(request.getDatabaseEngine().toString());
865+
throw new UnsupportedOperationException(request.getDatabaseEngine().toString());
867866
}
868867
}
869868

@@ -874,7 +873,7 @@ private static String getRdsEngine(TestEnvironmentRequest request) {
874873
case PG:
875874
return "postgres";
876875
default:
877-
throw new NotImplementedException(request.getDatabaseEngine().toString());
876+
throw new UnsupportedOperationException(request.getDatabaseEngine().toString());
878877
}
879878
}
880879

@@ -889,7 +888,7 @@ private static String getDbEngineVersion(String engineName, TestEnvironment env)
889888
systemPropertyVersion = config.pgVersion;
890889
break;
891890
default:
892-
throw new NotImplementedException(request.getDatabaseEngine().toString());
891+
throw new UnsupportedOperationException(request.getDatabaseEngine().toString());
893892
}
894893
return findEngineVersion(env, engineName, systemPropertyVersion);
895894
}
@@ -919,7 +918,7 @@ private static int getPort(TestEnvironmentRequest request) {
919918
case PG:
920919
return 5432;
921920
default:
922-
throw new NotImplementedException(request.getDatabaseEngine().toString());
921+
throw new UnsupportedOperationException(request.getDatabaseEngine().toString());
923922
}
924923
}
925924

@@ -1148,7 +1147,7 @@ private static String getContainerBaseImageName(TestEnvironmentRequest request)
11481147
case PYTHON_3_13:
11491148
return "python:3.13";
11501149
default:
1151-
throw new NotImplementedException(request.getTargetPythonVersion().toString());
1150+
throw new UnsupportedOperationException(request.getTargetPythonVersion().toString());
11521151
}
11531152
}
11541153

@@ -1315,7 +1314,7 @@ public void close() throws Exception {
13151314
// do nothing
13161315
break;
13171316
default:
1318-
throw new NotImplementedException(this.info.getRequest().getDatabaseEngineDeployment().toString());
1317+
throw new UnsupportedOperationException(this.info.getRequest().getDatabaseEngineDeployment().toString());
13191318
}
13201319
}
13211320

@@ -1490,7 +1489,7 @@ private static void preCreateEnvironment(int currentEnvIndex) {
14901489
configureIamAccess(env);
14911490
break;
14921491
default:
1493-
throw new NotImplementedException(env.info.getRequest().getDatabaseEngineDeployment().toString());
1492+
throw new UnsupportedOperationException(env.info.getRequest().getDatabaseEngineDeployment().toString());
14941493
}
14951494
return env;
14961495

tests/integration/host/src/test/java/integration/util/AuroraTestUtility.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import java.util.logging.Logger;
5050
import java.util.stream.Collectors;
5151
import org.checkerframework.checker.nullness.qual.Nullable;
52-
import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException;
5352
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
5453
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
5554
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
@@ -897,7 +896,7 @@ public String getDbInstanceClass(TestEnvironmentRequest request) {
897896
case RDS_MULTI_AZ_CLUSTER:
898897
return "db.m5d.large";
899898
default:
900-
throw new NotImplementedException(request.getDatabaseEngineDeployment().toString());
899+
throw new UnsupportedOperationException(request.getDatabaseEngineDeployment().toString());
901900
}
902901
}
903902

0 commit comments

Comments
 (0)