001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cluster.drm;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026: import java.util.Vector;
027:
028: import org.jboss.ha.framework.interfaces.ClusterNode;
029: import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
030: import org.jboss.ha.framework.interfaces.DistributedState;
031: import org.jboss.ha.framework.interfaces.HAPartition;
032: import org.jgroups.stack.IpAddress;
033:
034: /**
035: * Mock implementation of HAPartition intended to support unit testing
036: * of DistributedReplicantManagerImpl without the need for an underlying
037: * JChannel.
038: *
039: * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
040: * @version $Id: MockHAPartition.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
041: */
042: public class MockHAPartition implements HAPartition {
043: public static final String PARTITION_NAME = "MockPartition";
044:
045: private DistributedReplicantManager drm;
046: private Vector currentNodes;
047: private ClusterNode localAddress;
048: private ArrayList remoteReplicants;
049:
050: public MockHAPartition(ClusterNode localAddress) {
051: this .localAddress = localAddress;
052: }
053:
054: // ------------------------------------------------------------ HAPartition
055:
056: public String getNodeName() {
057: return localAddress.getName();
058: }
059:
060: public String getPartitionName() {
061: return PARTITION_NAME;
062: }
063:
064: public DistributedReplicantManager getDistributedReplicantManager() {
065: return drm;
066: }
067:
068: public DistributedState getDistributedStateService() {
069:
070: throw new UnsupportedOperationException("not implemented");
071: }
072:
073: public void registerRPCHandler(String serviceName, Object handler) {
074: if (handler instanceof DistributedReplicantManager)
075: drm = (DistributedReplicantManager) handler;
076: else
077: throw new UnsupportedOperationException("not implemented");
078: }
079:
080: public void unregisterRPCHandler(String serviceName,
081: Object subscriber) {
082: if (subscriber == drm)
083: drm = null;
084: else
085: throw new UnsupportedOperationException("not implemented");
086: }
087:
088: public ArrayList callMethodOnCluster(String serviceName,
089: String methodName, Object[] args, Class[] types,
090: boolean excludeSelf) throws Exception {
091: if (excludeSelf) {
092: if ("_add".equals(methodName)) {
093: // no-op -- there is no cluster
094: return null;
095: } else if ("lookupLocalReplicants".equals(methodName)
096: && args.length == 0) {
097: return remoteReplicants;
098: }
099: }
100: // TODO Implement lookupLocalReplicants for DRM SERVICE_NAME
101:
102: throw new UnsupportedOperationException("not implemented");
103: }
104:
105: public ArrayList callMethodOnCluster(String serviceName,
106: String methodName, Object[] args, boolean excludeSelf)
107: throws Exception {
108:
109: throw new UnsupportedOperationException("not implemented");
110: }
111:
112: public void callAsynchMethodOnCluster(String serviceName,
113: String methodName, Object[] args, Class[] types,
114: boolean excludeSelf) throws Exception {
115: if (excludeSelf && "_remove".equals(methodName)) {
116: // no-op -- there is no cluster
117: return;
118: }
119:
120: throw new UnsupportedOperationException("not implemented");
121: }
122:
123: public void callAsynchMethodOnCluster(String serviceName,
124: String methodName, Object[] args, boolean excludeSelf)
125: throws Exception {
126: throw new UnsupportedOperationException("not implemented");
127: }
128:
129: public ArrayList callMethodOnCoordinatorNode(String serviceName,
130: String methodName, Object[] args, Class[] types,
131: boolean excludeSelf) throws Exception {
132: throw new UnsupportedOperationException("not implemented");
133: }
134:
135: public void subscribeToStateTransferEvents(String serviceName,
136: HAPartitionStateTransfer subscriber) {
137: // no-op. at this point the test fixture directly passes state
138: // to the target DRM
139: }
140:
141: public void unsubscribeFromStateTransferEvents(String serviceName,
142: HAPartitionStateTransfer subscriber) {
143: // no-op. at this point the test fixture directly passes state
144: // to the target DRM
145: }
146:
147: public void registerMembershipListener(HAMembershipListener listener) {
148: // no-op. at this point the test fixture directly passes membership
149: // changes to the target DRM
150: }
151:
152: public void unregisterMembershipListener(
153: HAMembershipListener listener) {
154: // no-op. at this point the test fixture directly passes membership
155: // changes to the target DRM
156: }
157:
158: public boolean getAllowSynchronousMembershipNotifications() {
159: return false;
160: }
161:
162: public void setAllowSynchronousMembershipNotifications(
163: boolean allowSync) {
164: // no-op
165: }
166:
167: public long getCurrentViewId() {
168:
169: throw new UnsupportedOperationException("not implemented");
170: }
171:
172: public Vector getCurrentView() {
173: Vector result = new Vector();
174: for (int i = 0; i < currentNodes.size(); i++)
175: result.add(((ClusterNode) currentNodes.elementAt(i))
176: .getName());
177:
178: return result;
179: }
180:
181: public ClusterNode[] getClusterNodes() {
182: ClusterNode[] result = new ClusterNode[currentNodes.size()];
183: return (ClusterNode[]) currentNodes.toArray(result);
184: }
185:
186: public ClusterNode getClusterNode() {
187: return localAddress;
188: }
189:
190: // --------------------------------------------------------- Public Methods
191:
192: public void setCurrentViewClusterNodes(Vector nodes) {
193: this .currentNodes = nodes;
194: }
195:
196: public void setRemoteReplicants(ArrayList remoteReplicants) {
197: this.remoteReplicants = remoteReplicants;
198: }
199:
200: }
|