gemmellr commented on code in PR #5291: URL: https://github.com/apache/activemq-artemis/pull/5291#discussion_r1857035093
########## tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/MessageHandlerTest.java: ########## @@ -117,6 +119,49 @@ public void onMessage(final ClientMessage message) { session.close(); } + @Test + public void testMessageHandlerCloseTimeout() throws Exception { + // create Netty acceptor so client can use new onMessageCloseTimeout URL parameter + server.getRemotingService().createAcceptor("netty", "tcp://127.0.0.1:61616").start(); + final int TIMEOUT = 200; + locator = ActiveMQClient.createServerLocator("tcp://127.0.0.1:61616?onMessageCloseTimeout=" + TIMEOUT); + sf = createSessionFactory(locator); + ClientSession session = addClientSession(sf.createSession(false, true, true)); + session.createQueue(QueueConfiguration.of(QUEUE).setDurable(false)); + ClientProducer producer = session.createProducer(QUEUE); + producer.send(createTextMessage(session, "m")); + + ClientConsumer consumer = session.createConsumer(QUEUE, null, false); + + session.start(); + + CountDownLatch latch = new CountDownLatch(1); + AtomicBoolean messageHandlerFinished = new AtomicBoolean(false); + consumer.setMessageHandler(message -> { + latch.countDown(); + // don't just Thread.sleep() here because it will be interrupted on ClientConsumer.close() + while (!messageHandlerFinished.get()) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // ignore + } + } + messageHandlerFinished.set(true); Review Comment: I would use a different boolean for the looping and the completion checking, it would be much clearer, and also means the set(true) doesnt then seem like dead-code (it can only ever execute here if it is already true). The messageHandlerFinished.set(true); should also go in a try-finally so that the later assertFalse on it is guarding against unexpected-exits as well as the sole expected one being set up by the test. You could then also wait for it to trip before the test method exits. Maybe using a CDL instead of an AtomicBoolean actually to make that succinct and efficient. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact