|
11 | 11 | import org.junit.jupiter.api.Test; |
12 | 12 | import org.junit.jupiter.api.condition.EnabledIf; |
13 | 13 | import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
| 14 | +import software.amazon.awssdk.services.lambda.model.OperationStatus; |
14 | 15 | import software.amazon.awssdk.services.sts.StsClient; |
15 | 16 |
|
16 | 17 | @EnabledIf("isEnabled") |
@@ -260,4 +261,66 @@ void testCallbackExample() throws Exception { |
260 | 261 | assertNotNull(execution.getOperation("log-callback-command")); |
261 | 262 | assertNotNull(execution.getOperation("process-approval")); |
262 | 263 | } |
| 264 | + |
| 265 | + @Test |
| 266 | + void testCallbackExampleWithFailure() throws Exception { |
| 267 | + var runner = CloudDurableTestRunner.create( |
| 268 | + arn("callback-example"), ApprovalRequest.class, String.class); |
| 269 | + |
| 270 | + // Start async execution |
| 271 | + var execution = runner.startAsync(new ApprovalRequest("Purchase order", 5000.0)); |
| 272 | + |
| 273 | + // Wait for callback to appear |
| 274 | + execution.pollUntil(exec -> exec.hasCallback("approval")); |
| 275 | + |
| 276 | + // Get callback ID |
| 277 | + var callbackId = execution.getCallbackId("approval"); |
| 278 | + assertNotNull(callbackId); |
| 279 | + |
| 280 | + // Fail the callback using AWS SDK |
| 281 | + var lambda = software.amazon.awssdk.services.lambda.LambdaClient.create(); |
| 282 | + lambda.sendDurableExecutionCallbackFailure(req -> req |
| 283 | + .callbackId(callbackId) |
| 284 | + .error(err -> err |
| 285 | + .errorType("ApprovalRejected") |
| 286 | + .errorMessage("Approval rejected by manager"))); |
| 287 | + |
| 288 | + // Wait for execution to complete |
| 289 | + var result = execution.pollUntilComplete(); |
| 290 | + assertEquals(ExecutionStatus.FAILED, result.getStatus()); |
| 291 | + |
| 292 | + // Verify the callback operation shows failure |
| 293 | + var approvalOp = execution.getOperation("approval"); |
| 294 | + assertNotNull(approvalOp); |
| 295 | + var callbackDetails = approvalOp.getCallbackDetails(); |
| 296 | + assertNotNull(callbackDetails); |
| 297 | + assertNotNull(callbackDetails.error()); |
| 298 | + // Error message is redacted in the response, just verify error exists |
| 299 | + assertTrue(callbackDetails.error().toString().contains("ErrorObject")); |
| 300 | + } |
| 301 | + |
| 302 | + @Test |
| 303 | + void testCallbackExampleWithTimeout() throws Exception { |
| 304 | + var runner = CloudDurableTestRunner.create( |
| 305 | + arn("callback-example"), ApprovalRequest.class, String.class); |
| 306 | + |
| 307 | + // Start async execution with 10 second timeout |
| 308 | + var execution = runner.startAsync(new ApprovalRequest("Purchase order", 5000.0, 10)); |
| 309 | + |
| 310 | + // Wait for callback to appear |
| 311 | + execution.pollUntil(exec -> exec.hasCallback("approval")); |
| 312 | + |
| 313 | + // Get callback ID but don't complete it - let it timeout |
| 314 | + var callbackId = execution.getCallbackId("approval"); |
| 315 | + assertNotNull(callbackId); |
| 316 | + |
| 317 | + // Wait for execution to complete (should timeout after 10 seconds) |
| 318 | + var result = execution.pollUntilComplete(); |
| 319 | + assertEquals(ExecutionStatus.FAILED, result.getStatus()); |
| 320 | + |
| 321 | + // Verify the callback operation shows timeout status |
| 322 | + var approvalOp = execution.getOperation("approval"); |
| 323 | + assertNotNull(approvalOp); |
| 324 | + assertEquals(OperationStatus.TIMED_OUT, approvalOp.getStatus()); |
| 325 | + } |
263 | 326 | } |
0 commit comments