/** * {@inheritDoc} */ @Override public List<JmxSensorTypeConfig> getJmxSensorTypes() throws StorageException { ensureConfigurationExists(); List<JmxSensorTypeConfig> result = new ArrayList<JmxSensorTypeConfig>(1); if (null != agentConfiguration.getJmxSensorTypeConfig()) { result.add(agentConfiguration.getJmxSensorTypeConfig()); } return result; }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getJmxSensorTypeConfig()).thenReturn(null); List<JmxSensorTypeConfig> jmxSensorTypes = configurationStorage.getJmxSensorTypes(); assertThat(jmxSensorTypes, is(empty())); } }
@Test public void defined() throws StorageException { JmxSensorTypeConfig jmxSensorTypeConfig = mock(JmxSensorTypeConfig.class); when(agentConfiguration.getJmxSensorTypeConfig()).thenReturn(jmxSensorTypeConfig); List<JmxSensorTypeConfig> jmxSensorTypes = configurationStorage.getJmxSensorTypes(); assertThat(jmxSensorTypes, hasSize(1)); assertThat(jmxSensorTypes, hasItem(jmxSensorTypeConfig)); }
@Test public void configureJmxSensorNotActive() throws Exception { long agentId = 13L; JmxSensorConfig jmxSensorConfig = mock(JmxSensorConfig.class); when(jmxSensorConfig.isActive()).thenReturn(false); when(environment.getJmxSensorConfig()).thenReturn(jmxSensorConfig); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); JmxSensorTypeConfig sensorTypeConfig = agentConfiguration.getJmxSensorTypeConfig(); assertThat(sensorTypeConfig, is(nullValue())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
@SuppressWarnings("unchecked") @Test public void configureJmxSensor() throws Exception { long agentId = 13L; long sensorId = 17L; String className = "className"; Map<String, Object> parameters = Collections.<String, Object> singletonMap("key", "value"); JmxSensorConfig jmxSensorConfig = mock(JmxSensorConfig.class); when(jmxSensorConfig.getClassName()).thenReturn(className); when(jmxSensorConfig.getParameters()).thenReturn(parameters); when(jmxSensorConfig.isActive()).thenReturn(true); when(environment.getJmxSensorConfig()).thenReturn(jmxSensorConfig); when(registrationService.registerJmxSensorTypeIdent(agentId, className)).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); JmxSensorTypeConfig sensorTypeConfig = agentConfiguration.getJmxSensorTypeConfig(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getClassName(), is(className)); assertThat(sensorTypeConfig.getParameters(), is(parameters)); verify(registrationService).registerJmxSensorTypeIdent(agentId, className); // needed because of the intercepting server sensor verify(registrationService, times(3)).registerMethodSensorTypeIdent(anyLong(), anyString(), anyMap()); verifyNoMoreInteractions(registrationService); }