{
Connection conn1 = cf.createConnection();
ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)conn1).getDelegate();
ConnectionState state1 = (ConnectionState)del1.getState();
ResourceManager rm1 = state1.getResourceManager();
Connection conn2 = cf.createConnection();
ClientConnectionDelegate del2 = (ClientConnectionDelegate)((JBossConnection)conn2).getDelegate();
ConnectionState state2 = (ConnectionState)del2.getState();
ResourceManager rm2 = state2.getResourceManager();
//Two connections for same server should share the same resource manager
assertTrue(rm1 == rm2);
assertTrue(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));
conn1.close();
//Check reference counting
assertTrue(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));
conn2.close();
assertFalse(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));
assertEquals(0, ResourceManagerFactory.instance.size());
}