Skip to content

Commit ca597f1

Browse files
authored
Update Queue Dedupe test (#235)
Fixes #154
1 parent 7beee8a commit ca597f1

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

transact/src/test/java/dev/dbos/transact/queue/QueuesTest.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.dbos.transact.queue;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
45
import static org.junit.jupiter.api.Assertions.assertThrows;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
67

@@ -86,21 +87,67 @@ public void testQueuedWorkflow() throws Exception {
8687
@Test
8788
public void testDedupeId() throws Exception {
8889

89-
Queue firstQ = new Queue("firstQueue").withConcurrency(1).withWorkerConcurrency(1);
90+
Queue firstQ = new Queue("firstQueue");
9091
DBOS.registerQueue(firstQ);
9192

9293
ServiceQ serviceQ = DBOS.registerWorkflows(ServiceQ.class, new ServiceQImpl());
9394
DBOS.launch();
9495

96+
// pause queue service for test validation
9597
var qs = DBOSTestAccess.getQueueService();
9698
qs.pause();
9799

98-
var options = new StartWorkflowOptions().withQueue(firstQ).withDeduplicationId("dedupe");
99-
DBOS.startWorkflow(() -> serviceQ.simpleQWorkflow("inputq"), options);
100+
var options = new StartWorkflowOptions().withQueue(firstQ);
101+
var dedupeId = "dedupeId";
102+
var h1 =
103+
DBOS.startWorkflow(
104+
() -> serviceQ.simpleQWorkflow("abc"), options.withDeduplicationId(dedupeId));
105+
var s1 = h1.getStatus();
106+
assertEquals(s1.queueName(), firstQ.name());
107+
assertEquals(s1.deduplicationId(), dedupeId);
108+
109+
// enqueue with different dedupe ID should be fine
110+
var dedupeId2 = "different-dedupeId";
111+
var h2 =
112+
DBOS.startWorkflow(
113+
() -> serviceQ.simpleQWorkflow("def"), options.withDeduplicationId(dedupeId2));
114+
var s2 = h2.getStatus();
115+
assertEquals(s2.queueName(), firstQ.name());
116+
assertEquals(s2.deduplicationId(), dedupeId2);
117+
118+
// enqueue with no dedupe ID should be fine
119+
var h3 = DBOS.startWorkflow(() -> serviceQ.simpleQWorkflow("ghi"), options);
120+
var s3 = h3.getStatus();
121+
assertEquals(s3.queueName(), firstQ.name());
122+
assertNull(s3.deduplicationId());
100123

101124
assertThrows(
102125
RuntimeException.class,
103-
() -> DBOS.startWorkflow(() -> serviceQ.simpleQWorkflow("id"), options));
126+
() ->
127+
DBOS.startWorkflow(
128+
() -> serviceQ.simpleQWorkflow("jkl"), options.withDeduplicationId(dedupeId)));
129+
130+
// enable queue service to run
131+
qs.unpause();
132+
133+
// wait for initial workflow with initial dedupe ID to finish
134+
h1.getResult();
135+
h2.getResult();
136+
h3.getResult();
137+
138+
var h4 =
139+
DBOS.startWorkflow(
140+
() -> serviceQ.simpleQWorkflow("jkl"), options.withDeduplicationId(dedupeId));
141+
h4.getResult();
142+
143+
var rows = DBUtils.getWorkflowRows(dataSource);
144+
assertEquals(4, rows.size());
145+
146+
for (var row : rows) {
147+
assertEquals("SUCCESS", row.status());
148+
assertEquals("firstQueue", row.queueName());
149+
assertNull(row.deduplicationId());
150+
}
104151
}
105152

106153
@RetryingTest(3)

0 commit comments

Comments
 (0)