diff options
| author | Alex Rudyy <orudyy@apache.org> | 2015-04-15 09:47:28 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2015-04-15 09:47:28 +0000 |
| commit | 0a0baee45ebcff44635907d457c4ff6810b09c87 (patch) | |
| tree | 8bfb0f9eddbc23cff88af69be80ab3ce7d47011c /qpid/java/bdbstore/jmx | |
| parent | 54aa3d7070da16ce55c28ccad3f7d0871479e461 (diff) | |
| download | qpid-python-0a0baee45ebcff44635907d457c4ff6810b09c87.tar.gz | |
QPID-6481: Move java source tree to top level
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1673693 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/jmx')
6 files changed, 0 insertions, 737 deletions
diff --git a/qpid/java/bdbstore/jmx/pom.xml b/qpid/java/bdbstore/jmx/pom.xml deleted file mode 100644 index b65d2f1671..0000000000 --- a/qpid/java/bdbstore/jmx/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-java-build</artifactId> - <version>0.32-SNAPSHOT</version> - <relativePath>../../pom.xml</relativePath> - </parent> - - <artifactId>qpid-bdbstore-jmx</artifactId> - <name>Qpid BDB Message Store JMX</name> - <description>BDB message store JMX implementation</description> - - <dependencies> - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-broker-core</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-broker-plugins-management-jmx</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-bdbstore</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>${log4j-version}</version> - </dependency> - - <dependency> - <groupId>com.sleepycat</groupId> - <artifactId>je</artifactId> - <version>${bdb-version}</version> - <scope>provided</scope> - </dependency> - - <!-- test dependencies --> - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-test-utils</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>qpid-broker-core</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - </build> - -</project> diff --git a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java b/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java deleted file mode 100644 index 66f133da12..0000000000 --- a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * 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.qpid.server.store.berkeleydb.jmx; - -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.management.JMException; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; -import javax.management.openmbean.TabularData; -import javax.management.openmbean.TabularDataSupport; -import javax.management.openmbean.TabularType; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.server.jmx.AMQManagedObject; -import org.apache.qpid.server.jmx.ManagedObject; -import org.apache.qpid.server.jmx.ManagedObjectRegistry; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.RemoteReplicationNode; -import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost; -import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode; -import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode; - -/** - * Management mbean for BDB HA. - */ -public class BDBHAMessageStoreManagerMBean extends AMQManagedObject implements ManagedBDBHAMessageStore -{ - private static final Logger LOGGER = LoggerFactory.getLogger(BDBHAMessageStoreManagerMBean.class); - - private static final TabularType GROUP_MEMBERS_TABLE; - private static final CompositeType GROUP_MEMBER_ROW; - private static final OpenType<?>[] GROUP_MEMBER_ATTRIBUTE_TYPES; - - static - { - try - { - GROUP_MEMBER_ATTRIBUTE_TYPES = new OpenType<?>[] {SimpleType.STRING, SimpleType.STRING}; - final String[] itemNames = new String[] {GRP_MEM_COL_NODE_NAME, GRP_MEM_COL_NODE_HOST_PORT}; - final String[] itemDescriptions = new String[] {"Unique node name", "Node host / port "}; - GROUP_MEMBER_ROW = new CompositeType("GroupMember", "Replication group member", - itemNames, - itemDescriptions, - GROUP_MEMBER_ATTRIBUTE_TYPES ); - GROUP_MEMBERS_TABLE = new TabularType("GroupMembers", "Replication group memebers", - GROUP_MEMBER_ROW, - new String[] {GRP_MEM_COL_NODE_NAME}); - } - catch (final OpenDataException ode) - { - throw new ExceptionInInitializerError(ode); - } - } - - private final BDBHAVirtualHostNode<?> _virtualHostNode; - private final String _objectName; - - protected BDBHAMessageStoreManagerMBean(BDBHAVirtualHostNode<?> virtualHostNode, ManagedObjectRegistry registry) throws JMException - { - super(ManagedBDBHAMessageStore.class, ManagedBDBHAMessageStore.TYPE, registry); - LOGGER.debug("Creating BDBHAMessageStoreManagerMBean for " + virtualHostNode.getName()); - _virtualHostNode = virtualHostNode; - _objectName = ObjectName.quote( virtualHostNode.getGroupName()); - register(); - } - - @Override - public String getObjectInstanceName() - { - return _objectName; - } - - @Override - public String getGroupName() - { - return _virtualHostNode.getGroupName(); - } - - @Override - public String getNodeName() - { - return _virtualHostNode.getName(); - } - - @Override - public String getNodeHostPort() - { - return _virtualHostNode.getAddress(); - } - - @Override - public String getHelperHostPort() - { - return _virtualHostNode.getHelperAddress(); - } - - @Override - public String getDurability() throws IOException, JMException - { - BDBHAVirtualHost<?> host = (BDBHAVirtualHost<?>)_virtualHostNode.getVirtualHost(); - if (host != null) - { - return host.getDurability(); - } - return null; - } - - - @Override - public boolean getCoalescingSync() throws IOException, JMException - { - BDBHAVirtualHost<?> host = (BDBHAVirtualHost<?>)_virtualHostNode.getVirtualHost(); - if (host != null) - { - return host.isCoalescingSync(); - } - return false; - } - - @Override - public String getNodeState() throws IOException, JMException - { - try - { - return _virtualHostNode.getRole().name(); - } - catch (RuntimeException e) - { - LOGGER.debug("Failed query node role", e); - throw new JMException(e.getMessage()); - } - } - - @Override - public boolean getDesignatedPrimary() throws IOException, JMException - { - return _virtualHostNode.isDesignatedPrimary(); - } - - @Override - public TabularData getAllNodesInGroup() throws IOException, JMException - { - final TabularDataSupport data = new TabularDataSupport(GROUP_MEMBERS_TABLE); - - Map<String, String> localNodeMap = new HashMap<String, String>(); - localNodeMap.put(GRP_MEM_COL_NODE_NAME, _virtualHostNode.getName()); - localNodeMap.put(GRP_MEM_COL_NODE_HOST_PORT, _virtualHostNode.getAddress()); - CompositeData localNodeData = new CompositeDataSupport(GROUP_MEMBER_ROW, localNodeMap); - data.put(localNodeData); - - @SuppressWarnings("rawtypes") - final Collection<? extends RemoteReplicationNode> members = _virtualHostNode.getRemoteReplicationNodes(); - for (RemoteReplicationNode<?> remoteNode : members) - { - BDBHARemoteReplicationNode<?> haReplicationNode = (BDBHARemoteReplicationNode<?>)remoteNode; - Map<String, String> nodeMap = new HashMap<String, String>(); - nodeMap.put(GRP_MEM_COL_NODE_NAME, haReplicationNode.getName()); - nodeMap.put(GRP_MEM_COL_NODE_HOST_PORT, haReplicationNode.getAddress()); - - CompositeData memberData = new CompositeDataSupport(GROUP_MEMBER_ROW, nodeMap); - data.put(memberData); - } - return data; - } - - @Override - public void removeNodeFromGroup(String nodeName) throws JMException - { - if (getNodeName().equals(nodeName)) - { - _virtualHostNode.delete(); - } - else - { - @SuppressWarnings("rawtypes") - Collection<? extends RemoteReplicationNode> remoteNodes = _virtualHostNode.getRemoteReplicationNodes(); - for (RemoteReplicationNode<?> remoteNode : remoteNodes) - { - if (remoteNode.getName().equals(nodeName)) - { - try - { - remoteNode.delete(); - return; - } - catch(IllegalStateTransitionException e) - { - LOGGER.error("Cannot remove node '" + nodeName + "' from the group", e); - throw new JMException("Cannot remove node '" + nodeName + "' from the group:" + e.getMessage()); - } - } - } - - throw new JMException("Failed to find replication node with name '" + nodeName + "'."); - } - } - - @Override - public void setDesignatedPrimary(boolean primary) throws JMException - { - try - { - _virtualHostNode.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, primary)); - } - catch (RuntimeException e) - { - LOGGER.error("Failed to set node " + _virtualHostNode.getName() + " as designated primary", e); - throw new JMException(e.getMessage()); - } - } - - @Override - public void updateAddress(String nodeName, String newHostName, int newPort) throws JMException - { - throw new UnsupportedOperationException("Unsupported operation. Delete the node then add a new node in its place."); - } - - @Override - public ManagedObject getParentObject() - { - return null; - } - -} diff --git a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java b/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java deleted file mode 100644 index d23ca2a312..0000000000 --- a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * 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.qpid.server.store.berkeleydb.jmx; - -import javax.management.JMException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.server.jmx.MBeanProvider; -import org.apache.qpid.server.jmx.ManagedObject; -import org.apache.qpid.server.jmx.ManagedObjectRegistry; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode; - -/** - * This provide will create a {@link BDBHAMessageStoreManagerMBean} if the child is a BDBHAVirtualHostNode. - * - */ -public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider -{ - private static final Logger LOGGER = LoggerFactory.getLogger(BDBHAMessageStoreManagerMBeanProvider.class); - - public BDBHAMessageStoreManagerMBeanProvider() - { - super(); - } - - @Override - public boolean isChildManageableByMBean(ConfiguredObject child) - { - return child instanceof BDBHAVirtualHostNode && ((BDBHAVirtualHostNode)child).getState() != State.ERRORED; - } - - @Override - public ManagedObject createMBean(ConfiguredObject child, ManagedObjectRegistry registry) throws JMException - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("Creating mBean for child " + child); - } - - return new BDBHAMessageStoreManagerMBean((BDBHAVirtualHostNode<?>) child, registry); - } - - @Override - public String getType() - { - return "BDBHA"; - } -} diff --git a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ManagedBDBHAMessageStore.java b/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ManagedBDBHAMessageStore.java deleted file mode 100644 index fc1cd0801a..0000000000 --- a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ManagedBDBHAMessageStore.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.qpid.server.store.berkeleydb.jmx; - -import java.io.IOException; - -import javax.management.JMException; -import javax.management.openmbean.TabularData; - -import org.apache.qpid.management.common.mbeans.annotations.MBeanAttribute; -import org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParameter; -import org.apache.qpid.management.common.mbeans.annotations.MBeanOperation; - -public interface ManagedBDBHAMessageStore -{ - public static final String TYPE = "BDBHAMessageStore"; - - public static final String ATTR_GROUP_NAME = "GroupName"; - public static final String ATTR_NODE_NAME = "NodeName"; - public static final String ATTR_NODE_HOST_PORT = "NodeHostPort"; - public static final String ATTR_HELPER_HOST_PORT = "HelperHostPort"; - public static final String ATTR_DURABILITY = "Durability"; - public static final String ATTR_NODE_STATE = "NodeState"; - public static final String ATTR_DESIGNATED_PRIMARY = "DesignatedPrimary"; - public static final String ATTR_COALESCING_SYNC = "CoalescingSync"; - - public static final String GRP_MEM_COL_NODE_HOST_PORT = "NodeHostPort"; - public static final String GRP_MEM_COL_NODE_NAME = "NodeName"; - - @MBeanAttribute(name=ATTR_GROUP_NAME, description="Name identifying the group") - String getGroupName() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_NODE_NAME, description="Unique name identifying the node within the group") - String getNodeName() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_NODE_HOST_PORT, description="Host/port used to replicate data between this node and others in the group") - String getNodeHostPort() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_NODE_STATE, description="Current state of this node") - String getNodeState() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_HELPER_HOST_PORT, description="Host/port used to allow a new node to discover other group members") - String getHelperHostPort() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_DURABILITY, description="Durability") - String getDurability() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_DESIGNATED_PRIMARY, description="Designated primary flag. Applicable to the two node case.") - boolean getDesignatedPrimary() throws IOException, JMException; - - @MBeanAttribute(name=ATTR_COALESCING_SYNC, description="Coalescing sync flag. Applicable to the master sync policies NO_SYNC and WRITE_NO_SYNC only.") - boolean getCoalescingSync() throws IOException, JMException; - - @MBeanAttribute(name="getAllNodesInGroup", description="Get all nodes within the group, regardless of whether currently attached or not") - TabularData getAllNodesInGroup() throws IOException, JMException; - - @MBeanOperation(name="removeNodeFromGroup", description="Remove an existing node from the group") - void removeNodeFromGroup(@MBeanOperationParameter(name="nodeName", description="name of node")String nodeName) throws JMException; - - @MBeanOperation(name="setDesignatedPrimary", description="Set/unset this node as the designated primary for the group. Applicable to the two node case.") - void setDesignatedPrimary(@MBeanOperationParameter(name="primary", description="designated primary")boolean primary) throws JMException; - - @MBeanOperation(name="updateAddress", description="Update the address of another node. The node must be in a STOPPED state.") - void updateAddress(@MBeanOperationParameter(name="nodeName", description="name of node")String nodeName, - @MBeanOperationParameter(name="newHostName", description="new hostname")String newHostName, - @MBeanOperationParameter(name="newPort", description="new port number")int newPort) throws JMException; -} - diff --git a/qpid/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider b/qpid/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider deleted file mode 100644 index 8ece9627b0..0000000000 --- a/qpid/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider +++ /dev/null @@ -1,19 +0,0 @@ -# -# 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. -# -org.apache.qpid.server.store.berkeleydb.jmx.BDBHAMessageStoreManagerMBeanProvider diff --git a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java b/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java deleted file mode 100644 index 4a5f3e3650..0000000000 --- a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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.qpid.server.store.berkeleydb.jmx; - -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import javax.management.JMException; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.TabularData; - -import junit.framework.TestCase; - -import org.apache.qpid.server.jmx.ManagedObjectRegistry; -import org.apache.qpid.server.model.IllegalStateTransitionException; -import org.apache.qpid.server.model.RemoteReplicationNode; -import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost; -import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode; -import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode; -import org.apache.qpid.server.virtualhostnode.berkeleydb.NodeRole; - -public class BDBHAMessageStoreManagerMBeanTest extends TestCase -{ - private static final String TEST_VHOST_NAME = "test"; - private static final String TEST_GROUP_NAME = TEST_VHOST_NAME; - private static final String TEST_NODE_NAME = "testNodeName"; - private static final String TEST_NODE_HOST_PORT = "host:1234"; - private static final String TEST_HELPER_HOST_PORT = "host:5678"; - private static final String TEST_DURABILITY = "sync,sync,all"; - private static final NodeRole TEST_NODE_ROLE = NodeRole.MASTER; - private static final boolean TEST_DESIGNATED_PRIMARY_FLAG = false; - - private BDBHAVirtualHostNode<?> _virtualHostNode; - private BDBHAMessageStoreManagerMBean _mBean; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - _virtualHostNode = mock(BDBHAVirtualHostNode.class); - when(_virtualHostNode.getName()).thenReturn(TEST_NODE_NAME); - when(_virtualHostNode.getGroupName()).thenReturn(TEST_GROUP_NAME); - when(_virtualHostNode.getAddress()).thenReturn(TEST_NODE_HOST_PORT); - - ManagedObjectRegistry registry = mock(ManagedObjectRegistry.class); - _mBean = new BDBHAMessageStoreManagerMBean(_virtualHostNode, registry); - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - } - - public void testObjectName() throws Exception - { - String expectedObjectName = "org.apache.qpid:type=BDBHAMessageStore,name=" + ObjectName.quote(TEST_VHOST_NAME); - assertEquals(expectedObjectName, _mBean.getObjectName().toString()); - } - - public void testGroupName() throws Exception - { - when(_virtualHostNode.getGroupName()).thenReturn(TEST_GROUP_NAME); - - assertEquals(TEST_GROUP_NAME, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_GROUP_NAME)); - } - - public void testNodeName() throws Exception - { - when(_virtualHostNode.getName()).thenReturn(TEST_NODE_NAME); - - assertEquals(TEST_NODE_NAME, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_NODE_NAME)); - } - - public void testNodeHostPort() throws Exception - { - when(_virtualHostNode.getAddress()).thenReturn(TEST_NODE_HOST_PORT); - - assertEquals(TEST_NODE_HOST_PORT, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_NODE_HOST_PORT)); - } - - public void testHelperHostPort() throws Exception - { - when(_virtualHostNode.getHelperAddress()).thenReturn(TEST_HELPER_HOST_PORT); - - assertEquals(TEST_HELPER_HOST_PORT, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_HELPER_HOST_PORT)); - } - - public void testDurability() throws Exception - { - BDBHAVirtualHost virtualHost = mock(BDBHAVirtualHost.class); - when(_virtualHostNode.getVirtualHost()).thenReturn(virtualHost); - when(virtualHost.getDurability()).thenReturn(TEST_DURABILITY); - - assertEquals(TEST_DURABILITY, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_DURABILITY)); - } - - public void testIsCoalescingSync() throws Exception - { - BDBHAVirtualHost virtualHost = mock(BDBHAVirtualHost.class); - when(_virtualHostNode.getVirtualHost()).thenReturn(virtualHost); - when(virtualHost.isCoalescingSync()).thenReturn(true); - - assertEquals(true, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_COALESCING_SYNC)); - } - - public void testNodeState() throws Exception - { - when(_virtualHostNode.getRole()).thenReturn(TEST_NODE_ROLE); - - assertEquals(TEST_NODE_ROLE.name(), _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_NODE_STATE)); - } - - public void testDesignatedPrimaryFlag() throws Exception - { - when(_virtualHostNode.isDesignatedPrimary()).thenReturn(TEST_DESIGNATED_PRIMARY_FLAG); - - assertEquals(TEST_DESIGNATED_PRIMARY_FLAG, _mBean.getAttribute(ManagedBDBHAMessageStore.ATTR_DESIGNATED_PRIMARY)); - } - - public void testGroupMembersForGroupWithOneNode() throws Exception - { - BDBHARemoteReplicationNode<?> node = mockRemoteNode(); - - final TabularData resultsTable = _mBean.getAllNodesInGroup(); - - assertTableHasHeadingsNamed(resultsTable, BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_NAME, - BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_HOST_PORT); - - final int numberOfDataRows = resultsTable.size(); - assertEquals("Unexpected number of data rows", 2, numberOfDataRows); - Iterator<?> iterator = resultsTable.values().iterator(); - - final CompositeData firstRow = (CompositeData) iterator.next(); - assertEquals(TEST_NODE_NAME, firstRow.get(BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_NAME)); - assertEquals(TEST_NODE_HOST_PORT, firstRow.get(BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_HOST_PORT)); - - final CompositeData secondRow = (CompositeData) iterator.next(); - assertEquals(node.getName(), secondRow.get(BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_NAME)); - assertEquals(node.getAddress(), secondRow.get(BDBHAMessageStoreManagerMBean.GRP_MEM_COL_NODE_HOST_PORT)); - } - - public void testRemoveNodeFromReplicationGroup() throws Exception - { - BDBHARemoteReplicationNode<?> node = mockRemoteNode(); - - _mBean.removeNodeFromGroup(node.getName()); - - verify(node).delete(); - } - - public void testRemoveNodeFromReplicationGroupOnIllegalStateTransitionException() throws Exception - { - BDBHARemoteReplicationNode<?> node = mockRemoteNode(); - doThrow(new IllegalStateTransitionException("test")).when(node).delete(); - - try - { - _mBean.removeNodeFromGroup("remotenode"); - fail("Exception not thrown"); - } - catch (JMException je) - { - // PASS# - } - } - - public void testSetAsDesignatedPrimary() throws Exception - { - _mBean.setDesignatedPrimary(true); - - verify(_virtualHostNode).setAttributes( - eq(Collections.<String, Object> singletonMap(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true))); - } - - private void assertTableHasHeadingsNamed(final TabularData resultsTable, String... headingNames) - { - CompositeType headingsRow = resultsTable.getTabularType().getRowType(); - for (final String headingName : headingNames) - { - assertTrue("Table should have column with heading " + headingName, headingsRow.containsKey(headingName)); - } - } - - private BDBHARemoteReplicationNode<?> mockRemoteNode() - { - BDBHARemoteReplicationNode<?> remoteNode = mock(BDBHARemoteReplicationNode.class); - when(remoteNode.getName()).thenReturn("remotenode"); - when(remoteNode.getAddress()).thenReturn("remotehost:port"); - - @SuppressWarnings("rawtypes") - Collection<? extends RemoteReplicationNode> remoteNodes = Collections.singletonList(remoteNode); - doReturn(remoteNodes).when(_virtualHostNode).getRemoteReplicationNodes(); - - return remoteNode; - } -} |
