}
public void testWithMock() throws Exception
{
SimpleConnectionManager cm = new SimpleConnectionManager();
SimpleConnectionEndpoint e1 = new SimpleConnectionEndpoint(cm, "jvm1", "sessionid1");
SimpleConnectionEndpoint e2 = new SimpleConnectionEndpoint(cm, "jvm1", "sessionid2");
SimpleConnectionEndpoint e3 = new SimpleConnectionEndpoint(cm, "jvm2", "sessionid3");
SimpleConnectionEndpoint e4 = new SimpleConnectionEndpoint(cm, "jvm2", "sessionid4");
SimpleConnectionEndpoint e5 = new SimpleConnectionEndpoint(cm, "jvm3", "sessionid5");
SimpleConnectionEndpoint e6 = new SimpleConnectionEndpoint(cm, "jvm3", "sessionid6");
assertFalse(e1.isClosed());
assertFalse(e2.isClosed());
assertFalse(e3.isClosed());
assertFalse(e4.isClosed());
assertFalse(e5.isClosed());
assertFalse(e6.isClosed());
cm.registerConnection("jvm1", "sessionid1", e1);
cm.registerConnection("jvm1", "sessionid2", e2);
cm.registerConnection("jvm2", "sessionid3", e3);
cm.registerConnection("jvm2", "sessionid4", e4);
cm.registerConnection("jvm3", "sessionid5", e5);
cm.registerConnection("jvm3", "sessionid6", e6);
assertTrue(cm.containsRemotingSession("sessionid1"));
assertTrue(cm.containsRemotingSession("sessionid2"));
assertTrue(cm.containsRemotingSession("sessionid3"));
assertTrue(cm.containsRemotingSession("sessionid4"));
assertTrue(cm.containsRemotingSession("sessionid5"));
assertTrue(cm.containsRemotingSession("sessionid6"));
ConnectionEndpoint r1 = cm.unregisterConnection("jvm3", "sessionid6");
assertEquals(e6, r1);
assertFalse(e6.isClosed());
assertNull(cm.unregisterConnection("blah", "blah"));
assertFalse(cm.containsRemotingSession("sessionid6"));
ConnectionEndpoint r2 = cm.unregisterConnection("jvm3", "sessionid5");
assertEquals(e5, r2);
assertFalse(e5.isClosed());
assertFalse(cm.containsRemotingSession("sessionid5"));
cm.handleClientFailure("sessionid4", true);
assertNull(cm.unregisterConnection("jvm2", "sessionid4"));
assertNull(cm.unregisterConnection("jvm2", "sessionid3"));
assertFalse(cm.containsRemotingSession("sessionid4"));
assertFalse(cm.containsRemotingSession("sessionid3"));
assertTrue(e3.isClosed());
assertTrue(e4.isClosed());
ConnectionEndpoint r3 = cm.unregisterConnection("jvm1", "sessionid1");
assertEquals(e1, r3);
assertFalse(e1.isClosed());
ConnectionEndpoint r4 = cm.unregisterConnection("jvm1", "sessionid2");
assertEquals(e2, r4);
assertFalse(e2.isClosed());
assertFalse(cm.containsRemotingSession("sessionid2"));
assertFalse(cm.containsRemotingSession("sessionid1"));
}