Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 902B1200D6D for ; Tue, 19 Dec 2017 05:12:11 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 8ED53160C29; Tue, 19 Dec 2017 04:12:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D57B7160C05 for ; Tue, 19 Dec 2017 05:12:10 +0100 (CET) Received: (qmail 97040 invoked by uid 500); 19 Dec 2017 04:12:09 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 97031 invoked by uid 99); 19 Dec 2017 04:12:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Dec 2017 04:12:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D15E0DFC27; Tue, 19 Dec 2017 04:12:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hadrian@apache.org To: commits@activemq.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: [AMQ-6601] AMQ with master and slave broker, shutting down slave causes dead-lock. Date: Tue, 19 Dec 2017 04:12:06 +0000 (UTC) archived-at: Tue, 19 Dec 2017 04:12:11 -0000 Repository: activemq Updated Branches: refs/heads/master 04eedc3bc -> b40e5f93b [AMQ-6601] AMQ with master and slave broker, shutting down slave causes dead-lock. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b40e5f93 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b40e5f93 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b40e5f93 Branch: refs/heads/master Commit: b40e5f93bdfdecad84f880edce23c4ae8af9a76d Parents: 04eedc3 Author: Carlo Dapor Authored: Sat Mar 4 21:01:34 2017 +0100 Committer: Hadrian Zbarcea Committed: Mon Dec 18 23:08:22 2017 -0500 ---------------------------------------------------------------------- .../activemq/osgi/ActiveMQServiceFactory.java | 5 +- .../usecases/TwoBrokersStopSlaveTest.java | 81 ++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/b40e5f93/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java ---------------------------------------------------------------------- diff --git a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java index 29b02d6..c57d65c 100644 --- a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java +++ b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java @@ -137,8 +137,11 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory { brokerContext.setApplicationContext(ctx); broker.setBrokerContext(brokerContext); + broker.setStartAsync(true); broker.start(); - broker.waitUntilStarted(); + + if (!broker.isSlave()) + broker.waitUntilStarted(); brokers.put(pid, broker); } catch (Exception e) { throw new ConfigurationException(null, "Cannot start the broker", e); http://git-wip-us.apache.org/repos/asf/activemq/blob/b40e5f93/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokersStopSlaveTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokersStopSlaveTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokersStopSlaveTest.java new file mode 100644 index 0000000..e82a389 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokersStopSlaveTest.java @@ -0,0 +1,81 @@ +/** + * 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.usecases; + +import junit.framework.TestCase; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.store.PersistenceAdapter; +import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; + +import java.io.File; +import java.net.URI; + +/** + * @author Carlo Dapor + */ +public class TwoBrokersStopSlaveTest extends TestCase { + private final static File KahaDbDirectory = new File("target/TwoBrokersStopSlaveTest"); + + public void testStartMasterAndSlaveShutdownSlaveFirst() throws Exception { + BrokerService masterBroker = createBroker("masterBroker", 9100); + BrokerService slaveBroker = createBroker("slaveBroker", 9101); + + Thread.sleep(1_000L); + + assertTrue(masterBroker.isPersistent()); + assertTrue(slaveBroker.isPersistent()); + assertFalse(masterBroker.isSlave()); + assertTrue(slaveBroker.isSlave()); + + // stop slave broker + slaveBroker.stop(); + slaveBroker.waitUntilStopped(); + + masterBroker.stop(); + } + + protected BrokerService createBroker(final String brokerName, final int port) throws Exception { + String connectorUrl = "tcp://localhost:" + port; + + BrokerService broker = BrokerFactory.createBroker(new URI("broker://()/localhost")); + broker.setBrokerName(brokerName); + broker.addConnector(connectorUrl); + broker.setUseShutdownHook(false); + broker.setPersistent(true); + + PersistenceAdapter adapter = new KahaDBPersistenceAdapter(); + // brokers must acquire exclusive lock KahaDB + adapter.setDirectory(KahaDbDirectory); + broker.setPersistenceAdapter(adapter); + broker.setStartAsync(true); + broker.start(); + + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectorUrl); + factory.createConnection(); + + // If the slave broker also is waiting to fully start up, it achieves that by acquiring the exclusive lock. + // But then, it can never be shut down before becoming master. + // This behaviour is filed as issue 6601, cf. https://issues.apache.org/jira/browse/AMQ-6601 + if (!broker.isSlave()) + broker.waitUntilStarted(); + + return broker; + } + +}