|
16 | 16 | import dev.dbos.transact.workflow.WorkflowState; |
17 | 17 |
|
18 | 18 | import java.time.Duration; |
| 19 | +import java.util.function.BooleanSupplier; |
19 | 20 |
|
20 | 21 | import com.zaxxer.hikari.HikariDataSource; |
21 | 22 | import org.junit.jupiter.api.AutoClose; |
@@ -301,6 +302,58 @@ public void testDynamicConcurrencyTakesEffect() throws Exception { |
301 | 302 | assertEquals(2, h3.getResult()); |
302 | 303 | } |
303 | 304 |
|
| 305 | + @Test |
| 306 | + public void testDynamicQueueMapUpdatedOnRegister() throws Exception { |
| 307 | + dbos.launch(); |
| 308 | + var qs = DBOSTestAccess.getQueueService(dbos); |
| 309 | + |
| 310 | + assertFalse(qs.findDynamicQueue("q-map-reg").isPresent()); |
| 311 | + |
| 312 | + dbos.registerQueue("q-map-reg", QueueOptions.setConcurrency(5)); |
| 313 | + awaitCondition(() -> qs.findDynamicQueue("q-map-reg").isPresent()); |
| 314 | + |
| 315 | + assertEquals(5, qs.findDynamicQueue("q-map-reg").get().concurrency()); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + public void testDynamicQueueMapUpdatedOnUpdate() throws Exception { |
| 320 | + dbos.launch(); |
| 321 | + var qs = DBOSTestAccess.getQueueService(dbos); |
| 322 | + |
| 323 | + dbos.registerQueue("q-map-upd", QueueOptions.setConcurrency(5)); |
| 324 | + awaitCondition(() -> qs.findDynamicQueue("q-map-upd").isPresent()); |
| 325 | + |
| 326 | + dbos.updateQueue("q-map-upd", QueueOptions.setConcurrency(10)); |
| 327 | + awaitCondition( |
| 328 | + () -> |
| 329 | + qs.findDynamicQueue("q-map-upd") |
| 330 | + .filter(q -> Integer.valueOf(10).equals(q.concurrency())) |
| 331 | + .isPresent()); |
| 332 | + |
| 333 | + assertEquals(10, qs.findDynamicQueue("q-map-upd").get().concurrency()); |
| 334 | + } |
| 335 | + |
| 336 | + @Test |
| 337 | + public void testDynamicQueueMapUpdatedOnDelete() throws Exception { |
| 338 | + dbos.launch(); |
| 339 | + var qs = DBOSTestAccess.getQueueService(dbos); |
| 340 | + |
| 341 | + dbos.registerQueue("q-map-del", QueueOptions.empty()); |
| 342 | + awaitCondition(() -> qs.findDynamicQueue("q-map-del").isPresent()); |
| 343 | + |
| 344 | + dbos.deleteQueue("q-map-del"); |
| 345 | + awaitCondition(() -> qs.findDynamicQueue("q-map-del").isEmpty()); |
| 346 | + } |
| 347 | + |
| 348 | + private static void awaitCondition(BooleanSupplier condition) throws InterruptedException { |
| 349 | + long deadline = System.currentTimeMillis() + 2000; |
| 350 | + while (!condition.getAsBoolean()) { |
| 351 | + if (System.currentTimeMillis() > deadline) |
| 352 | + throw new AssertionError("Condition not met within 2s"); |
| 353 | + Thread.sleep(50); |
| 354 | + } |
| 355 | + } |
| 356 | + |
304 | 357 | @Test |
305 | 358 | public void testRegisterQueueValidation() throws Exception { |
306 | 359 | dbos.launch(); |
|
0 commit comments