getLog().debug("Looking up NestedBeanMonitorBean...");
NestedBeanMonitor monitor = (NestedBeanMonitor) ctx.lookup("NestedBeanMonitorBean/remote");
VMID monitorVM = monitor.getVMID();
runner.addRemovable(monitor);
ParentStatefulRemote parent = null;
boolean vmMatch = true;
for (int i = 0; i < 20 && vmMatch; i++)
{
env.put(NamingContext.PROVIDER_URL, namingURLS[i % 2]);
ctx = new InitialContext(env);
getLog().debug("Looking up testParentStateful... Attempt " + (i + 1));
parent = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
VMID parentVM = parent.getVMID();
vmMatch = monitorVM.equals(parentVM);
runner.addRemovable(parent);
if (vmMatch)
{
runner.removeBean(parent);
}
}
assertFalse("Monitor and SFSB in same VM", vmMatch);
// Reset the parent to initialize all the beans
parent.reset();
// Monitor the parent
monitor.monitor(parent);
// Reset the parent to clean things up
parent.reset();
parentInv++;
nestedInv++;
NestedStateful nested = (NestedStateful) parent.getNested();
parentInv++;
runner.addRemovable(nested);
NestedBeanSet beanSet = runner.getNestedBeanSet();
int attempts = 0;
while (beanSet.parent.getVMID().equals(beanSet.nested.getVMID()))
{
if (++attempts == 20)
{
System.err.println("Unable to obtain nested bean running on separate VM from parent");
log.warn("Unable to obtain nested bean running on separate VM from parent");
return;
}
beanSet = runner.getNestedBeanSet();
}
// Exercise the beans, trigger replication
assertEquals("Remote counter: ", 1, parent.increment());
parentInv++;
nestedInv++;
assertEquals("Remote counter: ", 2, parent.increment());
parentInv++;
nestedInv++;
assertEquals("Local counter: ", 1, parent.incrementLocal());
parentInv++;
assertEquals("Local counter: ", 2, parent.incrementLocal());
parentInv++;
// This call activates the nested bean without triggering the @PrePassivate
// callback at the end of the call because of the way the bean
// implements Optimized