/** * {@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()); }
/** * {@inheritDoc} */ @Override public boolean isEnhancedExceptionSensorActivated() throws StorageException { ensureConfigurationExists(); if (isExceptionSensorActivated()) { return agentConfiguration.getExceptionSensorTypeConfig().isEnhanced(); } return false; }
/** * Creates the agent based {@link ExceptionSensorTypeConfig} with correctly registered ID. * * @param platformId * ID of the agent. * @param exceptionSensorConfig * {@link IExceptionSensorConfig} defined in the {@link Environment}. * @return {@link ExceptionSensorTypeConfig}. */ private ExceptionSensorTypeConfig getExceptionSensorTypeConfig(long platformId, IExceptionSensorConfig exceptionSensorConfig) { long id = registrationService.registerMethodSensorTypeIdent(platformId, exceptionSensorConfig.getClassName(), exceptionSensorConfig.getParameters()); ExceptionSensorTypeConfig exceptionSensorTypeConfig = new ExceptionSensorTypeConfig(); exceptionSensorTypeConfig.setId(id); exceptionSensorTypeConfig.setClassName(exceptionSensorConfig.getClassName()); exceptionSensorTypeConfig.setParameters(exceptionSensorConfig.getParameters()); exceptionSensorTypeConfig.setName(exceptionSensorConfig.getName()); exceptionSensorTypeConfig.setEnhanced(exceptionSensorConfig.isEnhanced()); return exceptionSensorTypeConfig; }
@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(exceptionSensorTypeConfig.getId()).thenReturn(sensorId); when(exceptionSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL);
@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)); } }