Field field = ServerPeer.class.getDeclaredField("connectionManager");
field.setAccessible(true);
field.set(mockPeer, cm);
ServerConnectionFactoryEndpoint cfEnd1 = new ServerConnectionFactoryEndpoint("UName","UName",mockPeer,
null,
null,
0,
false,
0,
0,
0,
0,
true);
cm.registerConnectionFactory(cfEnd1);
ServerConnectionFactoryEndpoint cfEnd2 = new ServerConnectionFactoryEndpoint("UName2","UName2",mockPeer,
null,
null,
0,
false,
0,
0,
0,
0,
true);
cm.registerConnectionFactory(cfEnd2);
MockRemotingCallbackHandler session1Handler = new MockRemotingCallbackHandler();
MockRemotingCallbackHandler session2Handler = new MockRemotingCallbackHandler();
MockRemotingCallbackHandler session3Handler = new MockRemotingCallbackHandler();
MockRemotingCallbackHandler session4Handler = new MockRemotingCallbackHandler();
cm.registerConnectionFactoryCallback("VM1", "Session1", session1Handler);
cm.registerConnectionFactoryCallback("VM1", "Session2", session2Handler);
cm.registerConnectionFactoryCallback("VM2", "Session3", session3Handler);
cm.registerConnectionFactoryCallback("VM4", "Session3", session3Handler);
cfEnd1.addCallback("VM1", "Session1", session1Handler);
cfEnd1.addCallback("VM1", "Session2", session2Handler);
cfEnd2.addCallback("VM2", "Session3", session3Handler);
cfEnd2.addCallback("VM2", "Session4", session4Handler);
assertEquals(2, cfEnd1.getCallbackHandlers().size());
assertEquals(2, cfEnd2.getCallbackHandlers().size());
cm.handleClientFailure("Session1");
assertEquals(1, cfEnd1.getCallbackHandlers().size());
assertEquals(2, cfEnd2.getCallbackHandlers().size());
cm.handleClientFailure("Session3");
assertEquals(1, cfEnd1.getCallbackHandlers().size());
assertEquals(1, cfEnd2.getCallbackHandlers().size());
cm.handleClientFailure("Session2");
assertEquals(0, cfEnd1.getCallbackHandlers().size());
assertEquals(1, cfEnd2.getCallbackHandlers().size());
cm.handleClientFailure("Session4");
assertEquals(0, cfEnd1.getCallbackHandlers().size());
assertEquals(0, cfEnd2.getCallbackHandlers().size());
}