Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit c499488

Browse files
committed
fix: handle exceptions in AbstractTestBase
The CFN handler framework automatically handles certain exceptions and returns a failed response. Changing test_handleRequest_base to do the same.
1 parent ef0c3d0 commit c499488

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

aws-rds-cfn-test-common/src/main/java/software/amazon/rds/test/common/core/AbstractTestBase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import software.amazon.awssdk.awscore.AwsResponse;
1010
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
1111
import software.amazon.awssdk.awscore.exception.AwsServiceException;
12+
import software.amazon.cloudformation.exceptions.BaseHandlerException;
1213
import software.amazon.cloudformation.proxy.HandlerErrorCode;
1314
import software.amazon.cloudformation.proxy.OperationStatus;
1415
import software.amazon.cloudformation.proxy.ProgressEvent;
@@ -109,7 +110,12 @@ protected ProgressEvent<ModelT, ContextT> test_handleRequest_base(
109110
builder.clientRequestToken(newClientRequestToken());
110111
builder.stackId(newStackId());
111112

112-
final ProgressEvent<ModelT, ContextT> response = invokeHandleRequest(builder.build(), context);
113+
ProgressEvent<ModelT, ContextT> response;
114+
try {
115+
response = invokeHandleRequest(builder.build(), context);
116+
} catch (final BaseHandlerException e) {
117+
response = ProgressEvent.defaultFailureHandler(e, e.getErrorCode());
118+
}
113119
expect.accept(response);
114120

115121
return response;

aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/CreateHandlerTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,16 +720,14 @@ public void handleRequest_CreateDBCluster_HandleException(
720720
public void handleRequest_CreateDBCluster_DBClusterInTerminalState() {
721721
final CallbackContext context = new CallbackContext();
722722

723-
Assertions.assertThatThrownBy(() -> {
724-
test_handleRequest_base(
725-
context,
726-
() -> DBCLUSTER_ACTIVE.toBuilder()
727-
.status(DBClusterStatus.InaccessibleEncryptionCredentials.toString())
728-
.build(),
729-
() -> RESOURCE_MODEL,
730-
expectFailed(HandlerErrorCode.NotStabilized)
731-
);
732-
}).isInstanceOf(CfnNotStabilizedException.class);
723+
test_handleRequest_base(
724+
context,
725+
() -> DBCLUSTER_ACTIVE.toBuilder()
726+
.status(DBClusterStatus.InaccessibleEncryptionCredentials.toString())
727+
.build(),
728+
() -> RESOURCE_MODEL,
729+
expectFailed(HandlerErrorCode.NotStabilized)
730+
);
733731

734732
verify(rdsProxy.client(), times(1)).createDBCluster(any(CreateDbClusterRequest.class));
735733
}

aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/CreateHandlerTest.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,18 +1344,16 @@ public void handleRequest_CreateDBInstance_OptionGroupInTerminalState() {
13441344
final CallbackContext context = new CallbackContext();
13451345
context.setCreated(false);
13461346

1347-
Assertions.assertThatThrownBy(() -> {
1348-
test_handleRequest_base(
1349-
context,
1350-
() -> DB_INSTANCE_ACTIVE.toBuilder()
1351-
.optionGroupMemberships(OptionGroupMembership.builder()
1352-
.status(OptionGroupStatus.Failed.toString())
1353-
.optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT)
1354-
.build()).build(),
1355-
() -> RESOURCE_MODEL_BLDR().build(),
1356-
expectFailed(HandlerErrorCode.NotStabilized)
1357-
);
1358-
}).isInstanceOf(CfnNotStabilizedException.class);
1347+
test_handleRequest_base(
1348+
context,
1349+
() -> DB_INSTANCE_ACTIVE.toBuilder()
1350+
.optionGroupMemberships(OptionGroupMembership.builder()
1351+
.status(OptionGroupStatus.Failed.toString())
1352+
.optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT)
1353+
.build()).build(),
1354+
() -> RESOURCE_MODEL_BLDR().build(),
1355+
expectFailed(HandlerErrorCode.NotStabilized)
1356+
);
13591357

13601358
verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class));
13611359
}
@@ -1365,18 +1363,16 @@ public void handleRequest_CreateDBInstance_DomainMembershipInTerminalState() {
13651363
final CallbackContext context = new CallbackContext();
13661364
context.setCreated(false);
13671365

1368-
Assertions.assertThatThrownBy(() -> {
1369-
test_handleRequest_base(
1370-
context,
1371-
() -> DB_INSTANCE_ACTIVE.toBuilder()
1372-
.domainMemberships(DomainMembership.builder()
1373-
.status(DomainMembershipStatus.Failed.toString())
1374-
.domain("domain")
1375-
.build()).build(),
1376-
() -> RESOURCE_MODEL_BLDR().build(),
1377-
expectFailed(HandlerErrorCode.NotStabilized)
1378-
);
1379-
}).isInstanceOf(CfnNotStabilizedException.class);
1366+
test_handleRequest_base(
1367+
context,
1368+
() -> DB_INSTANCE_ACTIVE.toBuilder()
1369+
.domainMemberships(DomainMembership.builder()
1370+
.status(DomainMembershipStatus.Failed.toString())
1371+
.domain("domain")
1372+
.build()).build(),
1373+
() -> RESOURCE_MODEL_BLDR().build(),
1374+
expectFailed(HandlerErrorCode.NotStabilized)
1375+
);
13801376

13811377
verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class));
13821378
}

aws-rds-integration/src/test/java/software/amazon/rds/integration/CreateHandlerTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,17 @@ public void handleRequest_CreateIntegration_withTerminalFailureState_returnFailu
160160
// Integration goes from CREATING -> ACTIVE, when everything is normal
161161
Queue<Integration> transitions = new ConcurrentLinkedQueue<>();
162162
transitions.add(INTEGRATION_CREATING);
163-
Assertions.assertThatThrownBy(() ->
164-
test_handleRequest_base(
165-
new CallbackContext(),
166-
() -> {
167-
if (transitions.size() > 0) {
168-
return transitions.remove();
169-
}
170-
return INTEGRATION_FAILED;
171-
},
172-
() -> INTEGRATION_ACTIVE_MODEL, // unused
173-
expectFailed(HandlerErrorCode.NotStabilized) // unused
174-
)
175-
).isInstanceOf(CfnNotStabilizedException.class);
163+
test_handleRequest_base(
164+
new CallbackContext(),
165+
() -> {
166+
if (transitions.size() > 0) {
167+
return transitions.remove();
168+
}
169+
return INTEGRATION_FAILED;
170+
},
171+
() -> INTEGRATION_ACTIVE_MODEL, // unused
172+
expectFailed(HandlerErrorCode.NotStabilized)
173+
);
176174

177175
verify(rdsProxy.client(), times(1)).createIntegration(
178176
ArgumentMatchers. <CreateIntegrationRequest>argThat(req -> Objects.equals(req.integrationName(), INTEGRATION_NAME) &&

0 commit comments

Comments
 (0)