@Override protected Collection<JmxAttributeDescriptor> performRemoteCall(IAgentService service) throws Exception { return agentService.analyzeJmxAttributes(platformIdent, descriptors); } };
@Test public void analyzeJmxAttributes() throws Exception { Collection<JmxAttributeDescriptor> result = mock(Collection.class); when(client.isConnected()).thenReturn(true); doReturn(result).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); Collection<JmxAttributeDescriptor> receivedResult = connection.analyzeJmxAttributes(id, descriptors); assertThat(receivedResult, is(result)); verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); }
@Test(expectedExceptions = { BusinessException.class }) public void businessException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(BusinessException.class).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); try { connection.analyzeJmxAttributes(id, descriptors); } finally { verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(TimeoutException.class).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); try { connection.analyzeJmxAttributes(id, descriptors); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void remoteException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(RuntimeException.class).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); try { connection.analyzeJmxAttributes(id, descriptors); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(false)); throw e; } finally { // fail fast call, only one attempt verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); verify(client).close(); } }