@Override public void run() { sendKeepAlive(); }
@Test public void reconnectExponential() throws Exception { when(connection.isConnected()).thenReturn(false); doThrow(ConnectException.class).when(connection).reconnect(); manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(1)).reconnect(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(2)).reconnect(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(3)).reconnect(); verify(connection, atLeast(1)).isConnected(); verifyNoMoreInteractions(connection); }
@Test public void connectedThenDisconnected() throws Exception { when(connection.isConnected()).thenReturn(true).thenReturn(false); when(platformManager.getPlatformId()).thenReturn(PLATFORM_ID); manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(2)).isConnected(); verify(connection).sendKeepAlive(PLATFORM_ID); // no reconnect at first disconnect verifyNoMoreInteractions(connection); }
@Test public void reconnect() throws Exception { when(connection.isConnected()).thenReturn(false); doThrow(ConnectException.class).when(connection).reconnect(); manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(2)).isConnected(); verify(connection).reconnect(); verifyNoMoreInteractions(connection); }
@Test public void connected() throws Exception { when(connection.isConnected()).thenReturn(true); when(platformManager.getPlatformId()).thenReturn(PLATFORM_ID); manager.sendKeepAlive(); verify(connection).isConnected(); verify(connection).sendKeepAlive(PLATFORM_ID); verifyNoMoreInteractions(connection); }
@Test public void reconnectKeepAliveReconnect() throws Exception { when(connection.isConnected()).thenReturn(false); when(platformManager.getPlatformId()).thenReturn(PLATFORM_ID); doThrow(ConnectException.class).when(connection).reconnect(); // first make sure we fire one reconnect manager.sendKeepAlive(); manager.sendKeepAlive(); verify(connection, times(1)).reconnect(); // then switch to connected when(connection.isConnected()).thenReturn(true); manager.sendKeepAlive(); verify(connection, times(1)).reconnect(); verify(connection, times(1)).sendKeepAlive(PLATFORM_ID); // then back to reconnect, but not called on first call when(connection.isConnected()).thenReturn(false); manager.sendKeepAlive(); verify(connection, times(1)).reconnect(); verify(connection, atLeast(1)).isConnected(); verifyNoMoreInteractions(connection); }