@Override protected Void performRemoteCall(IKeepAliveService service) { service.sendKeepAlive(platformId); return null; } };
@Test public void keepAlive() throws Exception { when(client.isConnected()).thenReturn(true); long id = 3L; connection.sendKeepAlive(id); verify(keepAliveService, times(1)).sendKeepAlive(id); verifyNoMoreInteractions(keepAliveService); }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(TimeoutException.class).when(keepAliveService).sendKeepAlive(anyLong()); long id = 3L; try { connection.sendKeepAlive(id); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(keepAliveService, times(1)).sendKeepAlive(id); verifyNoMoreInteractions(keepAliveService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void remoteException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(RuntimeException.class).when(keepAliveService).sendKeepAlive(anyLong()); long id = 3L; try { connection.sendKeepAlive(id); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(false)); throw e; } finally { // fail fast call, only one attempt verify(keepAliveService, times(1)).sendKeepAlive(id); verifyNoMoreInteractions(keepAliveService); verify(client).close(); } }