@Test public void testSessionsAreRecycledWhenEndpointsChange() throws Exception { final InetSocketAddress host11 = new InetSocketAddress(HOST1_IP1, 9003); final InetSocketAddress host21 = new InetSocketAddress(HOST2_IP1, 9003); final InetSocketAddress host31 = new InetSocketAddress(HOST3_IP1, 9003); final InetSocketAddress host12 = new InetSocketAddress(HOST1_IP2, 9003); final InetSocketAddress host22 = new InetSocketAddress(HOST2_IP2, 9003); final InetSocketAddress host32 = new InetSocketAddress(HOST3_IP2, 9003); final InetSocketAddress host13 = new InetSocketAddress(HOST1_IP3, 9003); final InetSocketAddress host23 = new InetSocketAddress(HOST2_IP3, 9003); final InetSocketAddress host33 = new InetSocketAddress(HOST3_IP3, 9003); NetworkAddressResolver resolver = mock(NetworkAddressResolver.class); when(resolver.resolve(HOST1)).thenReturn(asSet(HOST1_IP1, HOST1_IP2)).thenReturn(asSet(HOST1_IP1, HOST1_IP2, HOST1_IP3)); when(resolver.resolve(HOST2)).thenReturn(asSet(HOST2_IP1, HOST2_IP2)).thenReturn(asSet(HOST2_IP3)); when(resolver.resolve(HOST3)).thenReturn(asSet(HOST3_IP1, HOST3_IP2)).thenReturn(asSet(HOST3_IP3, HOST3_IP2, HOST3_IP1)); final SessionRecycler recycler = new SessionRecycler(sessionFactory, resolver, hosts, 5000); recycler.run(); verify(sessionFactory, times(6)).openSession(any(InetSocketAddress.class)); verify(sessionFactory).openSession(host11); verify(sessionFactory).openSession(host21); verify(sessionFactory).openSession(host31); verify(sessionFactory).openSession(host12); verify(sessionFactory).openSession(host22); verify(sessionFactory).openSession(host32); Set<SocketAddress> sessionAddresses = new HashSet<SocketAddress>(asList(host11, host21, host31, host12, host22, host32)); when(sessionFactory.getCurrentSessionAddresses()).thenReturn(sessionAddresses); recycler.run(); verify(sessionFactory, times(9)).openSession(any(InetSocketAddress.class)); verify(sessionFactory).openSession(host13); verify(sessionFactory).openSession(host23); verify(sessionFactory).openSession(host33); verify(sessionFactory, times(2)).closeSession(any(SocketAddress.class), eq(false)); verify(sessionFactory).closeSession(host21, false); verify(sessionFactory).closeSession(host22, false); }
@Override public void run() { recycleSessions(); }
SessionRecycler implements Runnable { @Override public void run() { recycleSessions(); } }
SessionRecycler implements Runnable { @Override public void run() { recycleSessions(); } SessionRecycler(IoSessionFactory sessionFactory, NetworkAddressResolver resolver, String hosts, long sessionRecycleInterval); }
SessionRecycler implements Runnable { @Override public void run() { recycleSessions(); } SessionRecycler(IoSessionFactory sessionFactory, NetworkAddressResolver resolver, String hosts, long sessionRecycleInterval); void initialise(); @Override void run(); @ManagedOperation void recycleSessions(); @ManagedAttribute String getHosts(); @ManagedAttribute String getLastResolvedHosts(); @ManagedAttribute String getLastOpenedSessions(); @ManagedAttribute String getLastClosedSessions(); @ManagedAttribute Date getLastErrorTimestamp(); @ManagedAttribute String getLastErrorMessage(); @ManagedAttribute long getSessionRecycleInterval(); @ManagedAttribute Date getLastRecycleTimestamp(); @ManagedAttribute Date getLastCheckTimestamp(); }
SessionRecycler implements Runnable { @Override public void run() { recycleSessions(); } SessionRecycler(IoSessionFactory sessionFactory, NetworkAddressResolver resolver, String hosts, long sessionRecycleInterval); void initialise(); @Override void run(); @ManagedOperation void recycleSessions(); @ManagedAttribute String getHosts(); @ManagedAttribute String getLastResolvedHosts(); @ManagedAttribute String getLastOpenedSessions(); @ManagedAttribute String getLastClosedSessions(); @ManagedAttribute Date getLastErrorTimestamp(); @ManagedAttribute String getLastErrorMessage(); @ManagedAttribute long getSessionRecycleInterval(); @ManagedAttribute Date getLastRecycleTimestamp(); @ManagedAttribute Date getLastCheckTimestamp();  }