Author: pferraro
Date: 2008-09-09 14:25:16 -0400 (Tue, 09 Sep 2008)
New Revision: 1788
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
Log:
Replace copy of the master flag with a formal view of singleton master status.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-08
16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -147,10 +147,10 @@
this.setHAPartition(partition);
- this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config,
config, this);
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config,
config, this, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
// this.localHandler.init();
- this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this);
+ this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this,
this);
this.loadManager = loadFactorProvider;
this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config,
this.clusteredHandler, loadFactorProvider);
this.domain = config.getDomain();
@@ -339,6 +339,7 @@
if (this.isMasterNode())
{
this.statusCount = (this.statusCount + 1) % this.processStatusFrequency;
+
if (this.statusCount == 0)
{
this.updateClusterStatus();
@@ -370,25 +371,11 @@
@Override
public void startSingleton()
{
- super.startSingleton();
-
- this.clusteredHandler.setMasterNode(true);
- this.resetRequestSource.setMasterNode(true);
-
// Ensure we do a full status on the next event
this.statusCount = this.processStatusFrequency - 1;
}
@Override
- public void stopSingleton()
- {
- super.stopSingleton();
-
- this.clusteredHandler.setMasterNode(false);
- this.resetRequestSource.setMasterNode(false);
- }
-
- @Override
@Inject(fromContext = FromContext.NAME)
public void setServiceHAName(String haName)
{
@@ -462,7 +449,7 @@
List<ClusterNode> narrowed = new
ArrayList<ClusterNode>(candidates.size());
ModClusterServiceDRMEntry champion = null;
- for (ModClusterServiceDRMEntry candidate : candidates)
+ for (ModClusterServiceDRMEntry candidate: candidates)
{
if (champion == null)
{
@@ -505,7 +492,7 @@
HAPartition partition = this.getHAPartition();
List<ModClusterServiceDRMEntry> replicants =
partition.getDistributedReplicantManager().lookupReplicants(this.getHAServiceKey());
Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new
HashMap<ClusterNode, ModClusterServiceDRMEntry>();
- for (ModClusterServiceDRMEntry replicant : replicants)
+ for (ModClusterServiceDRMEntry replicant: replicants)
{
nonresponsive.put(replicant.getPeer(), replicant);
}
@@ -525,7 +512,7 @@
Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new
HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
boolean resync = false;
- for (Object response : responses)
+ for (Object response: responses)
{
if (response instanceof ModClusterServiceStateGroupRpcResponse)
{
@@ -534,7 +521,7 @@
// Check for discovery events we haven't processed
MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
- for (MCMPServerDiscoveryEvent toCheck : mcssgrr.getUnacknowledgedEvents())
+ for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
{
if (latestEvent != null && latestEvent.getEventIndex() <=
toCheck.getEventIndex())
{
@@ -567,7 +554,7 @@
if (removed != null)
{
Integer lbf = new Integer(mcssgrr.getLoadBalanceFactor());
- for (String jvmRoute : removed.getJvmRoutes())
+ for (String jvmRoute: removed.getJvmRoutes())
{
loadBalanceFactors.put(jvmRoute, lbf);
}
@@ -603,12 +590,12 @@
// Add error-state objects for non-responsive peers
Integer lbf = new Integer(0);
- for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry :
nonresponsive.entrySet())
+ for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry:
nonresponsive.entrySet())
{
ClusterNode cn = entry.getKey();
statuses.put(entry.getKey(), new PeerMCMPDiscoveryStatus(cn, null,
latestEvents.get(cn)));
- for (String jvmRoute : entry.getValue().getJvmRoutes())
+ for (String jvmRoute: entry.getValue().getJvmRoutes())
{
loadBalanceFactors.put(jvmRoute, lbf);
}
@@ -621,7 +608,7 @@
// Pass along the LBF values
List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
- for (Map.Entry<String, Integer> entry : loadBalanceFactors.entrySet())
+ for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
{
statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(),
entry.getValue().intValue()));
}
@@ -631,8 +618,7 @@
this.notifyClusterStatusComplete(masterList, statuses);
}
- private void notifyClusterStatusComplete(Set<MCMPServerState> masterList,
- Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ private void notifyClusterStatusComplete(Set<MCMPServerState> masterList,
Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
{
HAPartition partition = this.getHAPartition();
@@ -641,10 +627,12 @@
ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry)
partition.getDistributedReplicantManager().lookupLocalReplicant(this.getHAServiceKey());
allStatuses.add(ourCurrentStatus);
- boolean othersFirst =
this.narrowCandidateList(allStatuses).contains(partition.getClusterNode());
- ModClusterServiceDRMEntry ourNewStatus = new
ModClusterServiceDRMEntry(partition.getClusterNode(), masterList);
- boolean updated = (ourNewStatus.equals(ourCurrentStatus) == false);
+ ClusterNode node = partition.getClusterNode();
+ boolean othersFirst = this.narrowCandidateList(allStatuses).contains(node);
+ ModClusterServiceDRMEntry ourNewStatus = new ModClusterServiceDRMEntry(node,
masterList);
+ boolean updated = !ourNewStatus.equals(ourCurrentStatus);
+
if (othersFirst)
{
this.clusterStatusComplete(statuses);
@@ -664,7 +652,7 @@
this.clusterStatusComplete(statuses);
}
}
-
+
/**
* @see
org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
*/
@@ -719,13 +707,9 @@
/*
public GroupRpcResponse getLocalAddress() throws IOException
{
- if (this.coord.isMasterNode())
- {
- return new
InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(),
-
this.coord.localHandler.getLocalAddress());
- }
+ if (!this.coord.isMasterNode()) return null;
- return null;
+ return new
InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(),
this.coord.localHandler.getLocalAddress());
}
*/
/**
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2008-09-08
16:23:59 UTC (rev 1787)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -46,9 +46,6 @@
void recordResetTransmission();
void recordResetSuccess();
- boolean isMasterNode();
- void setMasterNode(boolean master);
-
String getHAServiceName();
String getPartitionName();
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-08
16:23:59 UTC (rev 1787)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -34,6 +34,7 @@
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
@@ -64,11 +65,11 @@
final HAServiceKeyProvider serviceKeyProvider;
private final MCMPHandler localHandler;
+ private final HASingletonMBean singleton;
private final ClusteredMCMPHandlerRpcHandler rpcStub = new RpcStub();
// private AdvertiseListener advertiseListener;
private volatile String haServiceName;
- private volatile boolean masterNode = false;
@GuardedBy("errorState")
private final List<Boolean> errorState = new ArrayList<Boolean>();
@@ -83,24 +84,15 @@
*/
final StringManager sm = StringManager.getManager(Constants.Package);
- public ClusteredMCMPHandlerImpl(MCMPHandler localHandler, HAServiceKeyProvider
serviceKeyProvider)
+ public ClusteredMCMPHandlerImpl(MCMPHandler localHandler, HASingletonMBean singleton,
HAServiceKeyProvider serviceKeyProvider)
{
this.localHandler = localHandler;
+ this.singleton = singleton;
this.serviceKeyProvider = serviceKeyProvider;
}
// --------------------------------------------------- ClusteredMCMPHandler
-
- public boolean isMasterNode()
- {
- return this.masterNode;
- }
- public void setMasterNode(boolean masterNode)
- {
- this.masterNode = masterNode;
- }
-
/**
* @{inheritDoc}
* @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getHAServiceName()
@@ -243,7 +235,7 @@
*/
public synchronized void addProxy(InetAddress address, int port)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.addProxy(address, port);
}
@@ -268,7 +260,7 @@
*/
public synchronized void removeProxy(InetAddress address, int port)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.removeProxy(address, port);
}
@@ -298,7 +290,7 @@
public String getProxyConfiguration()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
return this.localHandler.getProxyConfiguration();
}
@@ -312,7 +304,7 @@
public void init(List<AddressPort> initialProxies)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.init(initialProxies);
}
@@ -332,7 +324,7 @@
public boolean isProxyHealthOK()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
return this.localHandler.isProxyHealthOK();
}
@@ -348,7 +340,7 @@
{
this.recordRequestFailure();
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.markProxiesInError();
}
@@ -362,7 +354,7 @@
public void reset()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.reset();
}
@@ -376,7 +368,7 @@
public void sendRequest(MCMPRequest request)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.sendRequest(request);
}
@@ -390,7 +382,7 @@
public void sendRequests(List<MCMPRequest> requests)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.sendRequests(requests);
}
@@ -574,36 +566,4 @@
throw new
IllegalStateException(ClusteredMCMPHandlerImpl.this.sm.getString("modcluster.error.rpc.noresp",
methodName));
}
}
-
- private enum State
- {
- OK(false), REQUIRES_RESET(true), RESET_PENDING(true);
-
- private boolean error;
-
- State(boolean error)
- {
- this.error = error;
- }
-
- public boolean isError()
- {
- return this.error;
- }
-
- public State error()
- {
- return REQUIRES_RESET;
- }
-
- public State resetStart()
- {
- return this == REQUIRES_RESET ? RESET_PENDING : this;
- }
-
- public State resetEnd()
- {
- return this == RESET_PENDING ? OK : this;
- }
- }
}
\ No newline at end of file
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-09-08
16:23:59 UTC (rev 1787)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -35,9 +35,5 @@
{
List<MCMPRequest> getLocalResetRequests();
- boolean isMasterNode();
-
- void setMasterNode(boolean master);
-
void setJbossWebServer(Server jbossWebServer);
}
\ No newline at end of file
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-08
16:23:59 UTC (rev 1787)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -29,6 +29,7 @@
import org.apache.catalina.Server;
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -63,20 +64,21 @@
private final NodeConfiguration nodeConfig;
private final BalancerConfiguration balancerConfig;
+ private final HASingletonMBean singleton;
private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
- private volatile boolean master;
private volatile Server jbossWebServer;
- public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig,
BalancerConfiguration balancerConfig, HAServiceKeyProvider serviceKeyProvider)
+ public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig,
BalancerConfiguration balancerConfig, HASingletonMBean singleton, HAServiceKeyProvider
serviceKeyProvider)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
+ this.singleton = singleton;
this.rpcStub = new RpcStub(serviceKeyProvider);
}
public List<MCMPRequest> getResetRequests()
{
- if (this.master)
+ if (this.singleton.isMasterNode())
{
List<MCMPRequest> resets = this.getLocalResetRequests();
this.addRemoteRequests(resets);
@@ -102,24 +104,6 @@
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#isMasterNode()
- */
- public boolean isMasterNode()
- {
- return this.master;
- }
-
- /**
- * @{inheritDoc}
- * @see
org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#setMasterNode(boolean)
- */
- public void setMasterNode(boolean master)
- {
- this.master = master;
- }
-
- /**
- * @{inheritDoc}
* @see
org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#setJbossWebServer(org.apache.catalina.Server)
*/
public void setJbossWebServer(Server jbossWebServer)
@@ -159,7 +143,7 @@
{
private final HAServiceKeyProvider serviceKeyProvider;
- public RpcStub(HAServiceKeyProvider serviceKeyProvider)
+ RpcStub(HAServiceKeyProvider serviceKeyProvider)
{
this.serviceKeyProvider = serviceKeyProvider;
}
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-09-08
16:23:59 UTC (rev 1787)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-09-09
18:25:16 UTC (rev 1788)
@@ -36,6 +36,7 @@
import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.ha.ClusteredMCMPHandler;
import org.jboss.modcluster.ha.ClusteredMCMPHandlerImpl;
@@ -60,8 +61,9 @@
private MCMPHandler localHandler = EasyMock.createStrictMock(MCMPHandler.class);
private HAServiceKeyProvider keyProvider =
EasyMock.createStrictMock(HAServiceKeyProvider.class);
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
+ private HASingletonMBean singleton =
EasyMock.createStrictMock(HASingletonMBean.class);
- private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler,
this.keyProvider);
+ private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler,
this.singleton, this.keyProvider);
public void testGetPartitionName()
{
@@ -91,23 +93,23 @@
List<AddressPort> list = Collections.singletonList(new AddressPort(address,
port));
// Test master case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.init(list);
- EasyMock.replay(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.replay(this.localHandler, this.singleton, this.keyProvider,
this.partition);
this.handler.init(list);
- EasyMock.verify(this.localHandler, this.keyProvider, this.partition);
- EasyMock.reset(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.verify(this.localHandler, this.singleton, this.keyProvider,
this.partition);
+ EasyMock.reset(this.localHandler, this.singleton, this.keyProvider,
this.partition);
// Test non-master case
- this.handler.setMasterNode(false);
-
Capture<List<AddressPort>> capturedList = new
Capture<List<AddressPort>>();
Capture<Object[]> capturedEvents = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
this.localHandler.init(EasyMock.capture(capturedList));
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
@@ -118,11 +120,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.replay(this.localHandler, this.singleton, this.keyProvider,
this.partition);
this.handler.init(list);
- EasyMock.verify(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.verify(this.localHandler, this.singleton, this.keyProvider,
this.partition);
assertNotNull(capturedList.getValue());
assertTrue(capturedList.getValue().isEmpty());
@@ -144,7 +146,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.reset(this.localHandler, this.singleton, this.keyProvider,
this.partition);
}
public void testUpdateServersFromMasterNode() throws Exception
@@ -175,15 +177,15 @@
EasyMock.expect(this.localHandler.getProxyStates()).andReturn(states);
- EasyMock.replay(this.localHandler, server, state);
+ EasyMock.replay(this.localHandler, this.singleton, server, state);
Set<MCMPServerState> result =
this.handler.updateServersFromMasterNode(Collections.singleton(server));
- EasyMock.verify(this.localHandler, server, state);
+ EasyMock.verify(this.localHandler, this.singleton, server, state);
assertSame(states, result);
- EasyMock.reset(this.localHandler, server, state);
+ EasyMock.reset(this.localHandler, this.singleton, server, state);
}
public void testGetConfiguration()
@@ -192,15 +194,15 @@
EasyMock.expect(this.localHandler.getConfiguration()).andReturn(configuration);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
MCMPHandlerConfiguration result = this.handler.getConfiguration();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
}
public void testAddProxy() throws Exception
@@ -209,39 +211,43 @@
int port = 0;
// Test master use case
- this.handler.setMasterNode(true);
+ // Test MCMPHandler.addProxy(String)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
- // Test MCMPHandler.addProxy(String)
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address.getHostName() + ":" + port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address.getHostName(), port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address, port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int, boolean)
@@ -256,13 +262,13 @@
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
Capture<Object[]> capturedEvents = new Capture<Object[]>();
ClusterNode node = EasyMock.createMock(ClusterNode.class);
// Test MCMPHandler.addProxy(String)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -271,11 +277,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address.getHostName() + ":" + port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
List<MCMPServerDiscoveryEvent> events =
this.handler.getPendingDiscoveryEvents();
@@ -294,10 +300,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -306,11 +314,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address.getHostName(), port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -329,10 +337,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -341,11 +351,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address, port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -364,7 +374,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int, boolean)
@@ -384,38 +394,40 @@
int port = 0;
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
// Test MCMPHandler.removeProxy(String, int)
this.localHandler.removeProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.removeProxy(address.getHostName(), port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.removeProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.removeProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.removeProxy(address, port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
Capture<Object[]> capturedEvents = new Capture<Object[]>();
ClusterNode node = EasyMock.createMock(ClusterNode.class);
// Test MCMPHandler.removeProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -424,11 +436,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.removeProxy(address.getHostName(), port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
List<MCMPServerDiscoveryEvent> events =
this.handler.getPendingDiscoveryEvents();
@@ -447,10 +459,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.removeProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -459,11 +473,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key),
EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents),
EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.removeProxy(address, port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -482,7 +496,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testGetProxyStates()
@@ -524,149 +538,149 @@
String configuration = "configuration";
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
EasyMock.expect(this.localHandler.getProxyConfiguration()).andReturn(configuration);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
String result = this.handler.getProxyConfiguration();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("getProxyConfiguration"), EasyMock.aryEq(new Object[0]),
EasyMock.aryEq(new Class[0]), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new StringGroupRpcResponse(node,
configuration))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
result = this.handler.getProxyConfiguration();
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testIsProxyHealthOK() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
EasyMock.expect(this.localHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
boolean result = this.handler.isProxyHealthOK();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertTrue(result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("isProxyHealthOk"), EasyMock.aryEq(new Object[0]),
EasyMock.aryEq(new Class[0]), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node,
true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
result = this.handler.isProxyHealthOK();
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertTrue(result);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testMarkProxiesInError() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.markProxiesInError();
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.markProxiesInError();
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("markProxiesInError"), EasyMock.aryEq(new Object[0]),
EasyMock.aryEq(new Class[0]), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node,
true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.markProxiesInError();
- EasyMock.verify(this.keyProvider, this.partition);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testReset() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.reset();
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.reset();
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("reset"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new
Class[0]), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node,
true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.reset();
- EasyMock.verify(this.keyProvider, this.partition);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testSendRequest() throws Exception
@@ -674,41 +688,42 @@
MCMPRequest request = new MCMPRequest(MCMPRequestType.INFO, false,
Collections.singletonMap("name", "value"));
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.sendRequest(EasyMock.same(request));
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.sendRequest(request);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
+ String key = "key";
- String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
Capture<Object[]> captured = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("sendRequest"), EasyMock.capture(captured), EasyMock.aryEq(new
Class[] { MCMPRequest.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.sendRequest(request);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertNotNull(captured.getValue());
assertEquals(1, captured.getValue().length);
assertSame(request, captured.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testSendRequests() throws Exception
@@ -716,41 +731,42 @@
List<MCMPRequest> requests = Collections.emptyList();
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.sendRequests(EasyMock.same(requests));
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.sendRequests(requests);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
+ String key = "key";
- String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
Capture<Object[]> captured = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key),
EasyMock.eq("sendRequests"), EasyMock.capture(captured), EasyMock.aryEq(new
Class[] { List.class }), EasyMock.eq(false),
EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new
ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.sendRequests(requests);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertNotNull(captured.getValue());
assertEquals(1, captured.getValue().length);
assertSame(requests, captured.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testShutdown()