/** * {@inheritDoc} */ @Override public List<MethodSensorTypeConfig> getMethodSensorTypes() throws StorageException { ensureConfigurationExists(); List<MethodSensorTypeConfig> result = new ArrayList<MethodSensorTypeConfig>(); if (CollectionUtils.isNotEmpty(agentConfiguration.getMethodSensorTypeConfigs())) { result.addAll(agentConfiguration.getMethodSensorTypeConfigs()); } // exception sensor is also method sensor type if (null != agentConfiguration.getExceptionSensorTypeConfig()) { result.add(agentConfiguration.getExceptionSensorTypeConfig()); } // special sensors are also method sensor types if (CollectionUtils.isNotEmpty(agentConfiguration.getSpecialMethodSensorTypeConfigs())) { result.addAll(agentConfiguration.getSpecialMethodSensorTypeConfigs()); } return result; }
@Test public void includesSpecialSensors() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(agentConfiguration.getSpecialMethodSensorTypeConfigs()).thenReturn(Collections.singletonList(methodSensorTypeConfig)); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, hasSize(1)); assertThat(methodSensorTypes, hasItem(methodSensorTypeConfig)); } }
@Test public void noSpecialSensors() throws Exception { long agentId = 13L; when(environment.isClassLoadingDelegation()).thenReturn(false); when(environment.getJmxSensorConfig()).thenReturn(null); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 0).getClassName(), is(equalTo(eisc.getClassName()))); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 1).getClassName(), is(equalTo(closeableHttpAsyncCLient.getClassName()))); }
@Test public void mbeanServerInterceptorJmxNotActive() 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); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(2)); assertThat(sensorTypeConfigs.iterator().next().getClassName(), is(equalTo(eisc.getClassName()))); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); } }
@Test public void classLoadingDelegation() throws Exception { long agentId = 13L; long sensorId = 17L; when(environment.isClassLoadingDelegation()).thenReturn(true); ClassLoadingDelegationSensorConfig cldConfig = ClassLoadingDelegationSensorConfig.INSTANCE; when(registrationService.registerMethodSensorTypeIdent(agentId, cldConfig.getClassName(), cldConfig.getParameters())).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(3)); // first element will be class loading config MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(cldConfig.getName())); assertThat(sensorTypeConfig.getClassName(), is(cldConfig.getClassName())); assertThat(sensorTypeConfig.getParameters(), is(cldConfig.getParameters())); assertThat(sensorTypeConfig.getPriority(), is(cldConfig.getPriority())); verify(registrationService).registerMethodSensorTypeIdent(agentId, cldConfig.getClassName(), cldConfig.getParameters()); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
@Test public void mbeanServerInterceptor() throws Exception { long agentId = 13L; long sensorId = 17L; JmxSensorConfig jmxSensorConfig = mock(JmxSensorConfig.class); when(jmxSensorConfig.isActive()).thenReturn(true); when(environment.getJmxSensorConfig()).thenReturn(jmxSensorConfig); MBeanServerInterceptorSensorConfig msiConfig = MBeanServerInterceptorSensorConfig.INSTANCE; when(registrationService.registerMethodSensorTypeIdent(agentId, msiConfig.getClassName(), msiConfig.getParameters())).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(3)); // first element will be mbean server interceptor config MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(msiConfig.getName())); assertThat(sensorTypeConfig.getClassName(), is(msiConfig.getClassName())); assertThat(sensorTypeConfig.getParameters(), is(msiConfig.getParameters())); assertThat(sensorTypeConfig.getPriority(), is(msiConfig.getPriority())); verify(registrationService).registerMethodSensorTypeIdent(agentId, msiConfig.getClassName(), msiConfig.getParameters()); // needed because jmx sensor will be also registered verify(registrationService).registerJmxSensorTypeIdent(anyLong(), anyString()); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }