Skip to content

Commit f1a0e3a

Browse files
committed
More checking in a test
1 parent f613106 commit f1a0e3a

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

temporal-sdk/src/test/java/io/temporal/client/nexus/NexusOperationHandleTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.nexusrpc.handler.ServiceImpl;
1313
import io.temporal.api.nexus.v1.Endpoint;
1414
import io.temporal.client.NexusClient;
15+
import io.temporal.client.NexusOperationException;
1516
import io.temporal.client.NexusOperationExecutionDescription;
1617
import io.temporal.client.NexusOperationFailedException;
1718
import io.temporal.client.NexusOperationHandle;
@@ -281,17 +282,37 @@ public void cancel(OperationContext context, OperationCancelDetails details) {
281282
@Test
282283
public void getResultPropagatesOperationFailure() {
283284
UntypedNexusOperationHandle handle = startOperation(TestNexusServiceImpl.FAIL_PREFIX + "boom");
285+
String operationId = handle.getNexusOperationId();
284286

285287
try {
286288
handle.getResult(String.class);
287289
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.
292292
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);
295316
}
296317
}
297318

0 commit comments

Comments
 (0)