Properties env1 = new Properties();
env1.setProperty(Context.PROVIDER_URL, jndiURLs[0]);
env1.setProperty("jnp.disableDiscovery", "true");
InitialContext ctx1 = new InitialContext(env1);
VMTester tester1 = (VMTester) ctx1.lookup(TESTER_JNDI_NAME);
VMID create1 = tester1.getCreatorVMID();
// confirm that the bean didn't have to migrate
assertEquals("bean targeted where created", create1, tester1.getVMID());
// Get another bean from the same server; should target
// a different server from the first
VMTester tester2 = (VMTester) ctx1.lookup(TESTER_JNDI_NAME);
VMID create2 = tester2.getCreatorVMID();
assertEquals("2nd bean targeted where created", create2, tester2.getVMID());
assertFalse("creation of 2 beans load balanced", create1.equals(create2));
// A third bean should come from the same as the first
VMTester tester3 = (VMTester) ctx1.lookup(TESTER_JNDI_NAME);
VMID create3 = tester3.getCreatorVMID();
assertEquals("3rd bean targeted where created", create3, tester3.getVMID());
assertEquals("creation of 3 beans load balanced", create1, create3);
// Get the next proxy from the other server, but the overall
// bean creation should still be round robin
Properties env2 = new Properties();
env2.setProperty(Context.PROVIDER_URL, jndiURLs[1]);
env2.setProperty("jnp.disableDiscovery", "true");
InitialContext ctx2 = new InitialContext(env2);
VMTester tester4 = (VMTester) ctx2.lookup(TESTER_JNDI_NAME);
VMID create4 = tester4.getCreatorVMID();
assertEquals("4th bean targeted where created", create4, tester4.getVMID());
assertEquals("creation of 4 beans load balanced", create2, create4);
// One last time
VMTester tester5 = (VMTester) ctx2.lookup(TESTER_JNDI_NAME);
VMID create5 = tester5.getCreatorVMID();
assertEquals("5th bean targeted where created", create5, tester5.getVMID());
assertEquals("creation of 5 beans load balanced", create1, create5);
}