public void stop() { messagesWaiter.waitNoMessages(); jobLock.lock(); try { if (backgroundJob != null) { backgroundJob.cancel(false); backgroundJob = null; } } finally { jobLock.unlock(); } processOutstandingAckOperations(); }
@Override public void run() { try { if (extendDeadline.getAndSet(false)) { int newDeadlineSec = computeDeadlineSeconds(); messageDeadlineSeconds.set(newDeadlineSec); extendDeadlines(); // Don't bother cancelling this when we stop. It'd just set an atomic boolean. systemExecutor.schedule( setExtendDeadline, newDeadlineSec - ackExpirationPadding.getSeconds(), TimeUnit.SECONDS); } processOutstandingAckOperations(); } catch (Throwable t) { // Catch everything so that one run failing doesn't prevent subsequent runs. logger.log(Level.WARNING, "failed to run periodic job", t); } } },
@Test public void testAck() throws Exception { dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE), NOOP_RUNNABLE); consumers.take().ack(); dispatcher.processOutstandingAckOperations(); assertThat(sentAcks).contains(TEST_MESSAGE.getAckId()); }
@Test public void testReceipt() throws Exception { dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE), NOOP_RUNNABLE); dispatcher.processOutstandingAckOperations(); assertThat(sentModAcks) .contains(ModAckItem.of(TEST_MESSAGE.getAckId(), Subscriber.MIN_ACK_DEADLINE_SECONDS)); }
@Test public void testNack() throws Exception { dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE), NOOP_RUNNABLE); consumers.take().nack(); dispatcher.processOutstandingAckOperations(); assertThat(sentModAcks).contains(ModAckItem.of(TEST_MESSAGE.getAckId(), 0)); }