/** * {@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 notDefined() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, is(empty())); }
@Test public void defined() throws StorageException { MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(Collections.singletonList(methodSensorTypeConfig)); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, hasSize(1)); assertThat(methodSensorTypes, hasItem(methodSensorTypeConfig)); }
@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 includesExceptionSensor() throws StorageException { when(agentConfiguration.getMethodSensorTypeConfigs()).thenReturn(null); ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); List<MethodSensorTypeConfig> methodSensorTypes = configurationStorage.getMethodSensorTypes(); assertThat(methodSensorTypes, hasSize(1)); assertThat(methodSensorTypes, hasItem(exceptionSensorTypeConfig)); }
@Test public void configureMethodSensor() throws Exception { long agentId = 13L; long sensorId = 17L; String sensorName = "sensorName"; String className = "className"; Map<String, Object> parameters = Collections.<String, Object> singletonMap("key", "value"); IMethodSensorConfig methodSensorConfig = mock(IMethodSensorConfig.class); when(methodSensorConfig.getName()).thenReturn(sensorName); when(methodSensorConfig.getClassName()).thenReturn(className); when(methodSensorConfig.getParameters()).thenReturn(parameters); when(methodSensorConfig.getPriority()).thenReturn(PriorityEnum.MAX); when(environment.getMethodSensorConfigs()).thenReturn(Collections.singletonList(methodSensorConfig)); when(registrationService.registerMethodSensorTypeIdent(agentId, className, parameters)).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getMethodSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(1)); MethodSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getName(), is(sensorName)); assertThat(sensorTypeConfig.getClassName(), is(className)); assertThat(sensorTypeConfig.getParameters(), is(parameters)); assertThat(sensorTypeConfig.getPriority(), is(PriorityEnum.MAX)); verify(registrationService).registerMethodSensorTypeIdent(agentId, className, parameters); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }