|
14 | 14 | import dev.dbos.transact.exceptions.DBOSNonExistentWorkflowException; |
15 | 15 | import dev.dbos.transact.utils.DBUtils; |
16 | 16 | import dev.dbos.transact.utils.PgContainer; |
| 17 | +import dev.dbos.transact.workflow.ForkOptions; |
17 | 18 | import dev.dbos.transact.workflow.Queue; |
18 | 19 | import dev.dbos.transact.workflow.SendMessage; |
19 | 20 | import dev.dbos.transact.workflow.WorkflowState; |
@@ -386,4 +387,52 @@ public void testClientSendBulk() throws Exception { |
386 | 387 | assertEquals("1-msg1", handle1.getResult()); |
387 | 388 | assertEquals("2-msg2", handle2.getResult()); |
388 | 389 | } |
| 390 | + |
| 391 | + @Test |
| 392 | + public void testClientSendBulkSendToForks() throws Exception { |
| 393 | + // Parent is a running workflow; child is a fork (ENQUEUED, not executing) |
| 394 | + var parent = dbos.startWorkflow(() -> service.sendTest(99)); |
| 395 | + var childId = "fork-child-" + UUID.randomUUID(); |
| 396 | + dbos.forkWorkflow(parent.workflowId(), 0, new ForkOptions(childId)); |
| 397 | + |
| 398 | + var sysdb = DBOSTestAccess.getSystemDatabase(dbos); |
| 399 | + String key = UUID.randomUUID().toString(); |
| 400 | + |
| 401 | + try (var client = pgContainer.dbosClient()) { |
| 402 | + client.sendBulk( |
| 403 | + List.of(new SendMessage(parent.workflowId(), "fan-out", "test-topic", key)), |
| 404 | + DBOSClient.SendOptions.defaults().withSendToForks(true)); |
| 405 | + } |
| 406 | + |
| 407 | + // Parent receives the message and completes |
| 408 | + assertEquals("99-fan-out", parent.getResult()); |
| 409 | + |
| 410 | + // Fork also received the notification (verified via DB since it is not executing) |
| 411 | + assertEquals(1, sysdb.getAllNotifications(childId).size()); |
| 412 | + |
| 413 | + // Re-send with same key is idempotent — {key}::{dest} UUIDs dedup via ON CONFLICT DO NOTHING |
| 414 | + try (var client = pgContainer.dbosClient()) { |
| 415 | + client.sendBulk( |
| 416 | + List.of(new SendMessage(parent.workflowId(), "fan-out", "test-topic", key)), |
| 417 | + DBOSClient.SendOptions.defaults().withSendToForks(true)); |
| 418 | + } |
| 419 | + assertEquals(1, sysdb.getAllNotifications(childId).size()); |
| 420 | + } |
| 421 | + |
| 422 | + @Test |
| 423 | + public void testClientSendBulkPortableSerialization() throws Exception { |
| 424 | + var handle1 = dbos.startWorkflow(() -> service.sendTest(1)); |
| 425 | + var handle2 = dbos.startWorkflow(() -> service.sendTest(2)); |
| 426 | + |
| 427 | + try (var client = pgContainer.dbosClient()) { |
| 428 | + client.sendBulk( |
| 429 | + List.of( |
| 430 | + new SendMessage(handle1.workflowId(), "hello", "test-topic", null), |
| 431 | + new SendMessage(handle2.workflowId(), "world", "test-topic", null)), |
| 432 | + DBOSClient.SendOptions.portable()); |
| 433 | + } |
| 434 | + |
| 435 | + assertEquals("1-hello", handle1.getResult()); |
| 436 | + assertEquals("2-world", handle2.getResult()); |
| 437 | + } |
389 | 438 | } |
0 commit comments