From d5846dd97cfaed0149f1fb4968f14885173e5ea0 Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Mon, 2 Mar 2015 10:14:53 +0000 Subject: [PATCH] ACTIVEMQ6-84 - JMSServerManagerImpl.activated() doesn't get called when starting in standalone mode https://issues.apache.org/jira/browse/ACTIVEMQ6-84 fixed the start order of the components started by the bootstrap --- activemq-bootstrap/pom.xml | 23 +++++ .../activemq/integration/FileBroker.java | 27 +++++- .../apache/activemq/test/FileBrokerTest.java | 84 +++++++++++++++++++ .../activemq-configuration-nojms.xml | 73 ++++++++++++++++ .../test/resources/activemq-configuration.xml | 77 +++++++++++++++++ 5 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 activemq-bootstrap/src/test/java/org/apache/activemq/test/FileBrokerTest.java create mode 100644 activemq-bootstrap/src/test/resources/activemq-configuration-nojms.xml create mode 100644 activemq-bootstrap/src/test/resources/activemq-configuration.xml diff --git a/activemq-bootstrap/pom.xml b/activemq-bootstrap/pom.xml index 506a3b8dc8..d220646265 100644 --- a/activemq-bootstrap/pom.xml +++ b/activemq-bootstrap/pom.xml @@ -60,6 +60,29 @@ io.airlift airline + + junit + junit + test + + + org.apache.activemq + activemq-amqp-protocol + ${project.version} + test + + + org.apache.activemq + activemq-stomp-protocol + ${project.version} + test + + + org.apache.activemq + activemq-openwire-protocol + ${project.version} + test + diff --git a/activemq-bootstrap/src/main/java/org/apache/activemq/integration/FileBroker.java b/activemq-bootstrap/src/main/java/org/apache/activemq/integration/FileBroker.java index 82e05bfa5d..4bd444fd18 100644 --- a/activemq-bootstrap/src/main/java/org/apache/activemq/integration/FileBroker.java +++ b/activemq-bootstrap/src/main/java/org/apache/activemq/integration/FileBroker.java @@ -25,6 +25,7 @@ import org.apache.activemq.jms.server.config.impl.FileJMSConfiguration; import org.apache.activemq.spi.core.security.ActiveMQSecurityManager; import java.lang.management.ManagementFactory; +import java.util.ArrayList; import java.util.Map; /** @@ -64,8 +65,9 @@ public class FileBroker implements Broker components = fileDeploymentManager.buildService(securityManager, ManagementFactory.getPlatformMBeanServer()); + ArrayList componentsByStartOrder = getComponentsByStartOrder(components); ActiveMQBootstrapLogger.LOGGER.serverStarting(); - for (ActiveMQComponent component : components.values()) + for (ActiveMQComponent component : componentsByStartOrder) { component.start(); } @@ -93,6 +95,27 @@ public class FileBroker implements Broker @Override public boolean isStarted() { - return false; + return started; + } + + public Map getComponents() + { + return components; + } + + /* + * this makes sure the components are started in the correct order. Its simple at the mo as e only have core and jms but + * will need impproving if we get more. + * */ + public ArrayList getComponentsByStartOrder(Map components) + { + ArrayList activeMQComponents = new ArrayList(); + ActiveMQComponent jmsComponent = components.get("jms"); + if (jmsComponent != null) + { + activeMQComponents.add(jmsComponent); + } + activeMQComponents.add(components.get("core")); + return activeMQComponents; } } diff --git a/activemq-bootstrap/src/test/java/org/apache/activemq/test/FileBrokerTest.java b/activemq-bootstrap/src/test/java/org/apache/activemq/test/FileBrokerTest.java new file mode 100644 index 0000000000..f8c7c58342 --- /dev/null +++ b/activemq-bootstrap/src/test/java/org/apache/activemq/test/FileBrokerTest.java @@ -0,0 +1,84 @@ +/** + * 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.test; + +import org.apache.activemq.core.server.impl.ActiveMQServerImpl; +import org.apache.activemq.dto.ServerDTO; +import org.apache.activemq.integration.FileBroker; +import org.apache.activemq.jms.server.impl.JMSServerManagerImpl; +import org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Andy Taylor + */ +public class FileBrokerTest +{ + @Test + public void startWithJMS() throws Exception + { + ServerDTO serverDTO = new ServerDTO(); + serverDTO.configuration = "activemq-configuration.xml"; + FileBroker broker = null; + try + { + broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); + broker.start(); + JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); + Assert.assertNotNull(jmsServerManager); + Assert.assertTrue(jmsServerManager.isStarted()); + //this tells us the jms server is activated + Assert.assertTrue(jmsServerManager.getJMSStorageManager().isStarted()); + ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); + Assert.assertNotNull(activeMQServer); + Assert.assertTrue(activeMQServer.isStarted()); + Assert.assertTrue(broker.isStarted()); + } + finally + { + if (broker != null) + { + broker.stop(); + } + } + } + + @Test + public void startWithoutJMS() throws Exception + { + ServerDTO serverDTO = new ServerDTO(); + serverDTO.configuration = "activemq-configuration-nojms.xml"; + FileBroker broker = null; + try + { + broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); + broker.start(); + JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); + Assert.assertNull(jmsServerManager); + ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); + Assert.assertNotNull(activeMQServer); + Assert.assertTrue(activeMQServer.isStarted()); + Assert.assertTrue(broker.isStarted()); + } + finally + { + assert broker != null; + broker.stop(); + } + } +} diff --git a/activemq-bootstrap/src/test/resources/activemq-configuration-nojms.xml b/activemq-bootstrap/src/test/resources/activemq-configuration-nojms.xml new file mode 100644 index 0000000000..c4cbd62225 --- /dev/null +++ b/activemq-bootstrap/src/test/resources/activemq-configuration-nojms.xml @@ -0,0 +1,73 @@ + + + + + + ${data.dir:../data}/paging + + ${data.dir:../data}/bindings + + ${data.dir:../data}/journal + + 10 + + ${data.dir:../data}/large-messages + + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + tcp://${activemq.remoting.amqp.host:localhost}:${activemq.remoting.amqp.port:5672}?protocols=AMQP + + + tcp://${activemq.remoting.stomp.host:localhost}:${activemq.remoting.stomp.port:61613}?protocols=STOMP + + + tcp://${activemq.remoting.hornetq.host:localhost}:${activemq.remoting.hornetq.port:5445}?protocols=CORE,STOMP + + + + + + + + + + + + + + + jms.queue.DLQ + jms.queue.ExpiryQueue + 0 + 10485760 + 10 + BLOCK + + + + diff --git a/activemq-bootstrap/src/test/resources/activemq-configuration.xml b/activemq-bootstrap/src/test/resources/activemq-configuration.xml new file mode 100644 index 0000000000..219c0b2752 --- /dev/null +++ b/activemq-bootstrap/src/test/resources/activemq-configuration.xml @@ -0,0 +1,77 @@ + + + + + + + + + + ${data.dir:../data}/paging + + ${data.dir:../data}/bindings + + ${data.dir:../data}/journal + + 10 + + ${data.dir:../data}/large-messages + + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + tcp://${activemq.remoting.amqp.host:localhost}:${activemq.remoting.amqp.port:5672}?protocols=AMQP + + + tcp://${activemq.remoting.stomp.host:localhost}:${activemq.remoting.stomp.port:61613}?protocols=STOMP + + + tcp://${activemq.remoting.hornetq.host:localhost}:${activemq.remoting.hornetq.port:5445}?protocols=CORE,STOMP + + + + + + + + + + + + + + + jms.queue.DLQ + jms.queue.ExpiryQueue + 0 + 10485760 + 10 + BLOCK + + + +