From 77eb2897cc04c1f135c5299e69750583e07739ba Mon Sep 17 00:00:00 2001 From: Pradeep Kunchala Date: Mon, 26 Jan 2026 15:44:41 +0530 Subject: [PATCH 1/3] Add test for VM transport behavior on broker restart --- .../VmTransportBrokerRestartTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 activemq-unit-tests/src/test/java/org/apache/activemq/VmTransportBrokerRestartTest.java diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/VmTransportBrokerRestartTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/VmTransportBrokerRestartTest.java new file mode 100644 index 00000000000..ceae4905c24 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/VmTransportBrokerRestartTest.java @@ -0,0 +1,82 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq; + +import jakarta.jms.TextMessage; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.test.annotations.ParallelTest; +import org.junit.After; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(ParallelTest.class) +public class VmTransportBrokerRestartTest extends EmbeddedBrokerTestSupport { + + @Override + protected BrokerService createBroker() throws Exception { + BrokerService broker = new BrokerService(); + + broker.setBrokerName("localhost"); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.addConnector("vm://localhost"); + + return broker; + } + + @Test + public void testSendReceiveAfterBrokerRestart() throws Exception { + + String firstMessage = "message-before-restart"; + template.convertAndSend(firstMessage); + + TextMessage receivedBefore = + (TextMessage) template.receive(destination); + + assertNotNull(receivedBefore); + assertEquals(firstMessage, receivedBefore.getText()); + + broker.stop(); + broker.waitUntilStopped(); + + broker = createBroker(); + startBroker(); + broker.waitUntilStarted(); + + connectionFactory = createConnectionFactory(); + template = createJmsTemplate(); + template.setDefaultDestination(destination); + template.afterPropertiesSet(); + + String secondMessage = "message-after-restart"; + template.convertAndSend(secondMessage); + + TextMessage receivedAfter = + (TextMessage) template.receive(destination); + + assertNotNull(receivedAfter); + assertEquals(secondMessage, receivedAfter.getText()); + } + + @After + public void cleanup() throws Exception { + if (broker != null) { + broker.stop(); + broker.waitUntilStopped(); + } + } +} \ No newline at end of file From dbc3ece26325108ce279dbce9e25eaa20c3d0a10 Mon Sep 17 00:00:00 2001 From: Pradeep Kunchala Date: Sat, 31 Jan 2026 10:07:33 +0530 Subject: [PATCH 2/3] Add Jolokia-based healthcheck for ActiveMQ container - HEALTHCHECK uses Jolokia search on Broker MBean - Ensures broker is running and accessible - Auth and Origin headers included for Jolokia security - Docker CI-ready and deterministic --- assembly/src/docker/Dockerfile | 16 +++++++++++++++- assembly/src/docker/entrypoint.sh | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) mode change 100755 => 100644 assembly/src/docker/entrypoint.sh diff --git a/assembly/src/docker/Dockerfile b/assembly/src/docker/Dockerfile index e5092d1a9aa..2b94287bd7c 100644 --- a/assembly/src/docker/Dockerfile +++ b/assembly/src/docker/Dockerfile @@ -29,10 +29,14 @@ ENV PATH $PATH:$ACTIVEMQ_HOME/bin ENV ACTIVEMQ_OPTS $ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config -Djetty.host=0.0.0.0 #WORKDIR $ACTIVEMQ_HOME +ENV ACTIVEMQ_ADMIN_USER=admin +ENV ACTIVEMQ_ADMIN_PASSWORD=admin + # activemq_dist can point to a directory or a tarball on the local system ARG activemq_dist=NOT_SET -COPY entrypoint.sh /usr/local/bin/entrypoint.sh +COPY src/docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh # Install build dependencies and activemq ADD $activemq_dist $ACTIVEMQ_INSTALL_PATH @@ -41,5 +45,15 @@ RUN set -x && \ rm -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-* EXPOSE 8161 61616 5672 61613 1883 61614 1099 + +STOPSIGNAL SIGTERM + +HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \ + CMD curl -sf \ + -u "${ACTIVEMQ_ADMIN_USER}:${ACTIVEMQ_ADMIN_PASSWORD}" \ + -H "Origin: http://127.0.0.1" \ + "http://127.0.0.1:8161/api/jolokia/search/org.apache.activemq:type=Broker,*" \ + >/dev/null || exit 1 + ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["activemq", "console"] diff --git a/assembly/src/docker/entrypoint.sh b/assembly/src/docker/entrypoint.sh old mode 100755 new mode 100644 index ad6ce1cf715..2acf56e3fdc --- a/assembly/src/docker/entrypoint.sh +++ b/assembly/src/docker/entrypoint.sh @@ -18,6 +18,8 @@ # limitations under the License. ################################################################################ +set -e + # Transport/connection security if [ -n "${ACTIVEMQ_CONNECTION_USER}" ]; then if [ -f "${ACTIVEMQ_HOME}/conf/connection.security.enabled" ]; then @@ -78,4 +80,12 @@ if [ -n "${ACTIVEMQ_WEB_USER}" ]; then fi fi +_term() { + echo "Received SIGTERM, stopping ActiveMQ..." + activemq stop + sleep 2 +} + +trap _term TERM INT + exec "$@" From cef7da94f5b3d583a4c018a9adb0f9201aff451e Mon Sep 17 00:00:00 2001 From: Pradeep Kunchala Date: Sun, 1 Feb 2026 15:01:41 +0530 Subject: [PATCH 3/3] Simplify Dockerfile healthcheck using HTTP endpoint --- assembly/src/docker/Dockerfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/assembly/src/docker/Dockerfile b/assembly/src/docker/Dockerfile index 2b94287bd7c..9e51d80e64e 100644 --- a/assembly/src/docker/Dockerfile +++ b/assembly/src/docker/Dockerfile @@ -29,9 +29,6 @@ ENV PATH $PATH:$ACTIVEMQ_HOME/bin ENV ACTIVEMQ_OPTS $ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config -Djetty.host=0.0.0.0 #WORKDIR $ACTIVEMQ_HOME -ENV ACTIVEMQ_ADMIN_USER=admin -ENV ACTIVEMQ_ADMIN_PASSWORD=admin - # activemq_dist can point to a directory or a tarball on the local system ARG activemq_dist=NOT_SET @@ -49,11 +46,7 @@ EXPOSE 8161 61616 5672 61613 1883 61614 1099 STOPSIGNAL SIGTERM HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \ - CMD curl -sf \ - -u "${ACTIVEMQ_ADMIN_USER}:${ACTIVEMQ_ADMIN_PASSWORD}" \ - -H "Origin: http://127.0.0.1" \ - "http://127.0.0.1:8161/api/jolokia/search/org.apache.activemq:type=Broker,*" \ - >/dev/null || exit 1 + CMD curl -s "http://127.0.0.1:8161"/ >/dev/null || exit 1 ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["activemq", "console"]