MBeanServerFactory.createMBeanServer("mockPartition");
try {
ClusterNode localAddress = new ClusterNodeImpl(new IpAddress("127.0.0.1", 12345));
MockHAPartition partition = new MockHAPartition(localAddress);
DistributedReplicantManagerImpl drm = new DistributedReplicantManagerImpl(partition);
drm.createService();
// Create a fake view for the MockHAPartition
Vector<ClusterNode> remoteAddresses = new Vector<ClusterNode>();
for (int i = 1; i < 5; i++)
remoteAddresses.add(new ClusterNodeImpl(new IpAddress("127.0.0.1", 12340 + i)));
Vector<ClusterNode> allNodes = new Vector<ClusterNode>(remoteAddresses);
allNodes.add(localAddress);
partition.setCurrentViewClusterNodes(allNodes);
drm.startService();
BlockingListenerThread blt =
new BlockingListenerThread(drm, true, null);
// Hold the lock monitor so the test thread can't acquire it
// This keeps the blocking thread alive.
synchronized(lock) {
// Spawn a thread that will change a key and then block on the
// notification back to itself
blt.start();
sleepThread(50);
assertTrue("Test thread is alive", blt.isAlive());
assertTrue("Test thread is blocking", blt.isBlocking());
RegistrationThread rt = new RegistrationThread(drm);
rt.start();
sleepThread(50);
assertTrue("No deadlock on listener registration", rt.isRegistered());
assertTrue("No deadlock on listener unregistration", rt.isUnregistered());
assertNull("No exception in deadlock tester", blt.getException());
assertTrue("Test thread is still blocking", blt.isBlocking());
assertTrue("Test thread is still alive", blt.isAlive());
}
drm.unregisterListener("TEST", blt);
sleepThread(50);
// Test going through remove
blt = new BlockingListenerThread(drm, false, null);