/** * {@inheritDoc} */ @Override public ExceptionSensorTypeConfig getExceptionSensorType() throws StorageException { ensureConfigurationExists(); return agentConfiguration.getExceptionSensorTypeConfig(); }
/** * {@inheritDoc} */ @Override public boolean isExceptionSensorActivated() throws StorageException { ensureConfigurationExists(); return null != agentConfiguration.getExceptionSensorTypeConfig(); }
/** * {@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.getExceptionSensorTypeConfig()).thenReturn(null); boolean exceptionSensorActivated = configurationStorage.isExceptionSensorActivated(); assertThat(exceptionSensorActivated, is(false)); }
@Test public void defined() throws StorageException { ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); boolean exceptionSensorActivated = configurationStorage.isExceptionSensorActivated(); assertThat(exceptionSensorActivated, is(true)); }
/** * {@inheritDoc} */ @Override public boolean isEnhancedExceptionSensorActivated() throws StorageException { ensureConfigurationExists(); if (isExceptionSensorActivated()) { return agentConfiguration.getExceptionSensorTypeConfig().isEnhanced(); } return false; }
@Test public void defined() throws StorageException { ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); ExceptionSensorTypeConfig config = configurationStorage.getExceptionSensorType(); assertThat(config, is(exceptionSensorTypeConfig)); }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(null); ExceptionSensorTypeConfig config = configurationStorage.getExceptionSensorType(); assertThat(config, is(nullValue())); } }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(null); boolean enhancedExceptionSensorActivated = configurationStorage.isEnhancedExceptionSensorActivated(); assertThat(enhancedExceptionSensorActivated, is(false)); }
@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 notEnchanced() throws StorageException { ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); when(exceptionSensorTypeConfig.isEnhanced()).thenReturn(false); boolean enhancedExceptionSensorActivated = configurationStorage.isEnhancedExceptionSensorActivated(); assertThat(enhancedExceptionSensorActivated, is(false)); }
@Test public void enchanced() throws StorageException { ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); when(exceptionSensorTypeConfig.isEnhanced()).thenReturn(true); boolean enhancedExceptionSensorActivated = configurationStorage.isEnhancedExceptionSensorActivated(); assertThat(enhancedExceptionSensorActivated, is(true)); } }
/** * {@inheritDoc} */ protected void applyAssignment(AgentConfig agentConfiguration, SensorInstrumentationPoint sensorInstrumentationPoint) { // there can be only one exception sensor so I just take the id ExceptionSensorTypeConfig exceptionSensorTypeConfig = agentConfiguration.getExceptionSensorTypeConfig(); long sensorId = exceptionSensorTypeConfig.getId(); // set to rsc sensorInstrumentationPoint.addSensorId(sensorId, exceptionSensorTypeConfig.getPriority()); // add all settings sensorInstrumentationPoint.addSettings(exceptionSensorAssignment.getSettings()); }
@Test public void configureExceptionSensor() throws Exception { long agentId = 13L; long sensorId = 17L; String sensorName = "sensorName"; String className = "className"; Map<String, Object> parameters = Collections.<String, Object> singletonMap("key", "value"); IExceptionSensorConfig exceptionSensorConfig = mock(IExceptionSensorConfig.class); when(exceptionSensorConfig.getName()).thenReturn(sensorName); when(exceptionSensorConfig.getClassName()).thenReturn(className); when(exceptionSensorConfig.getParameters()).thenReturn(parameters); when(environment.getExceptionSensorConfig()).thenReturn(exceptionSensorConfig); when(registrationService.registerMethodSensorTypeIdent(agentId, className, parameters)).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); ExceptionSensorTypeConfig sensorTypeConfig = agentConfiguration.getExceptionSensorTypeConfig(); 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.NORMAL)); // default priority 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); }
when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);
when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig);