void () { AtomicInteger counter = new AtomicInteger(0); Random random = new Random(); Supplier<LoggingTask> taskFactory = () -> new LoggingTask(counter.incrementAndGet(), (thiz, other) -> { return switch (random.nextInt(4)) { case 0 -> thiz; case 1 -> other; case 2 -> new LoggingTask(counter.incrementAndGet(), thiz.tryMergeWithFn); default -> null; }; }); SubmissionReceipt lastSubmissionReceipt = myQueue.addTask(taskFactory.get()); for (int i = 0; i < 100; i++) { SubmissionReceipt submissionReceipt = myQueue.addTask(taskFactory.get()); assertFalse("old=" + lastSubmissionReceipt + " new=" + submissionReceipt, lastSubmissionReceipt.isAfter(submissionReceipt)); assertEquals(submissionReceipt, myQueue.getLatestSubmissionReceipt()); lastSubmissionReceipt = submissionReceipt; } }