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 diff --git a/assembly/src/docker/Dockerfile b/assembly/src/docker/Dockerfile index e5092d1a9aa..ef35273a09d 100644 --- a/assembly/src/docker/Dockerfile +++ b/assembly/src/docker/Dockerfile @@ -32,7 +32,10 @@ ENV ACTIVEMQ_OPTS $ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging. # 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 +RUN groupadd -r activemq && useradd -r -g activemq -m activemq + +COPY src/docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh && chown activemq:activemq /usr/local/bin/entrypoint.sh # Install build dependencies and activemq ADD $activemq_dist $ACTIVEMQ_INSTALL_PATH @@ -40,6 +43,14 @@ RUN set -x && \ cp -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-* $ACTIVEMQ_HOME && \ rm -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-* +RUN ls -l $ACTIVEMQ_HOME && \ + chown -R activemq:activemq $ACTIVEMQ_HOME + EXPOSE 8161 61616 5672 61613 1883 61614 1099 + +STOPSIGNAL SIGTERM + +USER activemq + 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 "$@"