Repository: activemq-artemis Updated Branches: refs/heads/master 043909bde -> 34aec3bc3
ARTEMIS-125 Shared backup server with disabled scale down policy does not activate itself. If standalone backup server with shared has defined scale-down policy but it's disabled then backup does not activate. Problem is that server is checking only whether scale down is defined but if it's enabled. This causes that server.stop() is called and backup does not activate. Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/0cd7874f Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/0cd7874f Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/0cd7874f Branch: refs/heads/master Commit: 0cd7874f834b3e4f558442949ce6ea182d65591b Parents: 043909b Author: mnovak <[email protected]> Authored: Thu May 28 16:53:31 2015 +0200 Committer: Clebert Suconic <[email protected]> Committed: Thu May 28 11:34:10 2015 -0400 ---------------------------------------------------------------------- .../impl/SharedStoreBackupActivation.java | 4 +- .../cluster/failover/SharedStoreBackupTest.java | 105 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0cd7874f/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java index ee6f2f3..8a558d5 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedStoreBackupActivation.java @@ -60,7 +60,9 @@ public final class SharedStoreBackupActivation extends Activation { activeMQServer.getNodeManager().startBackup(); - boolean scalingDown = sharedStoreSlavePolicy.getScaleDownPolicy() != null; + ScaleDownPolicy scaleDownPolicy = sharedStoreSlavePolicy.getScaleDownPolicy(); + + boolean scalingDown = scaleDownPolicy != null && scaleDownPolicy.isEnabled(); if (!activeMQServer.initialisePart1(scalingDown)) return; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0cd7874f/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/SharedStoreBackupTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/SharedStoreBackupTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/SharedStoreBackupTest.java new file mode 100644 index 0000000..15cb402 --- /dev/null +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/SharedStoreBackupTest.java @@ -0,0 +1,105 @@ +/** + * 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.artemis.tests.integration.cluster.failover; + +import org.apache.activemq.artemis.api.core.TransportConfiguration; +import org.apache.activemq.artemis.core.config.ScaleDownConfiguration; +import org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration; +import org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration; +import org.apache.activemq.artemis.core.server.impl.InVMNodeManager; +import org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer; +import org.apache.activemq.artemis.tests.util.TransportConfigurationUtils; +import org.junit.Assert; +import org.junit.Test; + +public class SharedStoreBackupTest extends FailoverTestBase +{ + + @Test + public void testStartSharedBackupWithScalingDownPolicyDisabled() throws Exception + { + System.out.println("is backup active: " + backupServer.isActive()); + liveServer.stop(); + // wait max 10s for backup to activate + Assert.assertTrue("Backup did not activate in 10s timeout.", waitForBackupToBecomeActive(backupServer, 10000)); + } + + /** + * Returns true if backup started in given timeout. False otherwise. + * @param backupServer backup server + * @param waitTimeout timeout in milliseconds + * @return returns true if backup started in given timeout. False otherwise + */ + private boolean waitForBackupToBecomeActive(TestableServer backupServer, long waitTimeout) throws Exception + { + + long startTime = System.currentTimeMillis(); + boolean isBackupStarted; + // wait given timeout for backup to activate + while (!(isBackupStarted = backupServer.isActive()) && System.currentTimeMillis() - startTime < waitTimeout) + { + Thread.sleep(300); + } + return isBackupStarted; + } + + @Override + protected void createConfigs() throws Exception + { + nodeManager = new InVMNodeManager(false); + TransportConfiguration liveConnector = getConnectorTransportConfiguration(true); + TransportConfiguration backupConnector = getConnectorTransportConfiguration(false); + System.out.println("backup config created - mnovak"); + backupConfig = + super.createDefaultConfig(false) + .clearAcceptorConfigurations() + .addAcceptorConfiguration(getAcceptorTransportConfiguration(false)) + .setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration().setFailbackDelay(1000) + .setScaleDownConfiguration(new ScaleDownConfiguration().setEnabled(false)) + .setRestartBackup(false)) + .addConnectorConfiguration(liveConnector.getName(), liveConnector) + .addConnectorConfiguration(backupConnector.getName(), backupConnector) + .addClusterConfiguration(basicClusterConnectionConfig(backupConnector.getName(), + liveConnector.getName())); + + backupServer = createTestableServer(backupConfig); + + liveConfig = + super.createDefaultConfig(false) + .clearAcceptorConfigurations() + .addAcceptorConfiguration(getAcceptorTransportConfiguration(true)) + .setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration().setFailbackDelay(1000) + .setFailoverOnServerShutdown(true)) + .addClusterConfiguration(basicClusterConnectionConfig(liveConnector.getName())) + .addConnectorConfiguration(liveConnector.getName(), liveConnector); + + liveServer = createTestableServer(liveConfig); + } + + @Override + protected TransportConfiguration getAcceptorTransportConfiguration(final boolean live) + { + return TransportConfigurationUtils.getInVMAcceptor(live); + } + + @Override + protected TransportConfiguration getConnectorTransportConfiguration(final boolean live) + { + return TransportConfigurationUtils.getInVMConnector(live); + } + +}
