|
12 | 12 | import io.nexusrpc.handler.ServiceImpl; |
13 | 13 | import io.temporal.api.nexus.v1.Endpoint; |
14 | 14 | import io.temporal.client.NexusClient; |
| 15 | +import io.temporal.client.NexusOperationException; |
15 | 16 | import io.temporal.client.NexusOperationExecutionDescription; |
16 | 17 | import io.temporal.client.NexusOperationFailedException; |
17 | 18 | import io.temporal.client.NexusOperationHandle; |
@@ -281,17 +282,37 @@ public void cancel(OperationContext context, OperationCancelDetails details) { |
281 | 282 | @Test |
282 | 283 | public void getResultPropagatesOperationFailure() { |
283 | 284 | UntypedNexusOperationHandle handle = startOperation(TestNexusServiceImpl.FAIL_PREFIX + "boom"); |
| 285 | + String operationId = handle.getNexusOperationId(); |
284 | 286 |
|
285 | 287 | try { |
286 | 288 | handle.getResult(String.class); |
287 | 289 | Assert.fail("expected getResult to throw because the operation handler failed"); |
288 | | - } catch (RuntimeException e) { |
289 | | - // The DataConverter wraps the proto Failure into a Java exception. Either the message |
290 | | - // carries the handler's reason, or one of the cause links does. |
291 | | - String combined = collectMessages(e); |
| 290 | + } catch (NexusOperationException e) { |
| 291 | + // Outer: NexusOperationFailedException carrying the failed operation's ID. |
292 | 292 | Assert.assertTrue( |
293 | | - "expected exception chain to mention the handler failure, got: " + combined, |
294 | | - combined.contains("intentional failure")); |
| 293 | + "expected NexusOperationFailedException, got " + e.getClass().getSimpleName(), |
| 294 | + e instanceof NexusOperationFailedException); |
| 295 | + Assert.assertEquals(operationId, e.getOperationId()); |
| 296 | + Assert.assertTrue( |
| 297 | + "expected outer message to reference the operation ID, got: " + e.getMessage(), |
| 298 | + e.getMessage() != null && e.getMessage().contains(operationId)); |
| 299 | + |
| 300 | + // The full cause chain: dataConverter.failureToException(...) translates the proto Failure |
| 301 | + // into a Java exception. Walk every link and verify the handler's reason surfaces somewhere. |
| 302 | + boolean foundHandlerFailure = false; |
| 303 | + for (Throwable c = e.getCause(); c != null; c = c.getCause()) { |
| 304 | + if (c.getMessage() != null && c.getMessage().contains("intentional failure")) { |
| 305 | + foundHandlerFailure = true; |
| 306 | + break; |
| 307 | + } |
| 308 | + if (c.getCause() == c) { |
| 309 | + break; |
| 310 | + } |
| 311 | + } |
| 312 | + Assert.assertTrue( |
| 313 | + "expected cause chain to include the handler's failure message, got: " |
| 314 | + + collectMessages(e), |
| 315 | + foundHandlerFailure); |
295 | 316 | } |
296 | 317 | } |
297 | 318 |
|
|
0 commit comments