private void failoverTest(boolean passivate, boolean passivateAgain, boolean repeated)
throws Exception
{
BeanSet beanSet = runner.getBeanSet();
ShoppingCart parent = beanSet.cart;
NestedXPCMonitor monitor = beanSet.monitor;
// Confirm the nested beans are there
String deepId = monitor.getDeepNestedId();
Assert.assertNotNull("Got a deepId", deepId);
Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
String localDeepId = monitor.getLocalDeepNestedId();
Assert.assertNotNull("Got a localDeepId", localDeepId);
Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
VMID origId = parent.getVMID();
Assert.assertNotNull("Got a VMID", origId);
long id = parent.createCustomer();
Customer customer = parent.find(id);
Assert.assertNotNull("Customer created and found on parent", customer);
parent.setContainedCustomer();
Assert.assertTrue("Parent and contained share customer", parent.checkContainedCustomer());
Assert.assertTrue("Parent and remote nested do not share ref",
monitor.compareTopToNested(id));
Assert.assertTrue("Parent and local nested do share ref",
monitor.compareTopToLocalNested(id));
Assert.assertTrue("Remote nested and local nested do not share a ref",
monitor.compareNestedToLocalNested(id));
Assert.assertTrue("Remote nested and deepNested share a ref",
monitor.compareNestedToDeepNested(id));
Assert.assertTrue("Local nested and localDeepNested share a ref",
monitor.compareLocalNestedToLocalDeepNested(id));
VMID newId = parent.getVMID();
Assert.assertTrue("VMID remained the same", origId.equals(newId));
if (passivate)
{
runner.sleep();
}
parent.setUpFailover("once");
newId = parent.getVMID();
assertNotNull("Got a new VMID", newId);
assertFalse("Failover has occurred", origId.equals(newId));
InitialContext[] ctxs = new InitialContext[2];
ctxs[0] = getInitialContext(1);
ctxs[1] = getInitialContext(0);
monitor = runner.getXPCMonitor(ctxs, newId);
monitor.monitor(parent);
Assert.assertTrue("Parent and remote nested do not share ref",
monitor.compareTopToNested(id));
Assert.assertTrue("Parent and local nested do share ref",
monitor.compareTopToLocalNested(id));
Assert.assertTrue("Remote nested and local nested do not share a ref",
monitor.compareNestedToLocalNested(id));
Assert.assertTrue("Remote nested and deepNested share a ref",
monitor.compareNestedToDeepNested(id));
Assert.assertTrue("Local nested and localDeepNested share a ref",
monitor.compareLocalNestedToLocalDeepNested(id));
if (repeated)
{
if (passivateAgain)
{
runner.sleep();
}
origId = newId;
parent.setUpFailover("once");
newId = parent.getVMID();
assertNotNull("Got a new VMID", newId);
assertFalse("Failover has occurred", origId.equals(newId));
// Swap the contexts so we try node0 first
InitialContext ctx = ctxs[1];