/** * Return the {@link MethodSensorTypeConfig} for given sensor class name. * * @param sensorClassName * Sensor class name. * @return {@link MethodSensorTypeConfig} or <code>null</code> if such does not exists in the * configuration. */ public MethodSensorTypeConfig getMethodSensorTypeConfig(String sensorClassName) { if (StringUtils.isNotBlank(sensorClassName)) { for (MethodSensorTypeConfig methodSensorTypeConfig : methodSensorTypeConfigs) { if (sensorClassName.equals(methodSensorTypeConfig.getClassName())) { return methodSensorTypeConfig; } } } return null; }
/** * Return the {@link MethodSensorTypeConfig} for given special sensor class name. * * @param sensorClassName * Sensor class name. * @return {@link MethodSensorTypeConfig} or <code>null</code> if such does not exists in the * configuration. */ public MethodSensorTypeConfig getSpecialMethodSensorTypeConfig(String sensorClassName) { if (StringUtils.isNotBlank(sensorClassName)) { for (MethodSensorTypeConfig methodSensorTypeConfig : specialMethodSensorTypeConfigs) { if (sensorClassName.equals(methodSensorTypeConfig.getClassName())) { return methodSensorTypeConfig; } } } return null; }
/** * {@inheritDoc} */ @Override public void afterPropertiesSet() throws Exception { for (MethodSensorTypeConfig config : configurationStorage.getMethodSensorTypes()) { if (config.getClassName().equals(this.getClass().getName())) { this.init(config); break; } } }
for (IMethodSensor methodSensor : sensors) { MethodSensorTypeConfig methodSensorTypeConfig = methodSensor.getSensorTypeConfig(); if (PreparedStatementParameterSensor.class.getName().equals(methodSensorTypeConfig.getClassName())) { return true; if (ConnectionSensor.class.getName().equals(methodSensorTypeConfig.getClassName())) { return true;
/** * Returns if the given {@link InvocationSequenceData} should be removed due to the exception * constructor delegation. * * @param rsc * {@link RegisteredSensorConfig} * @param invocationSequenceData * {@link InvocationSequenceData} to check. * @return True if the invocation should be removed. */ private boolean removeDueToExceptionDelegation(RegisteredSensorConfig rsc, InvocationSequenceData invocationSequenceData) { List<IMethodSensor> sensors = rsc.getMethodSensors(); if (1 == sensors.size()) { MethodSensorTypeConfig methodSensorTypeConfig = sensors.get(0).getSensorTypeConfig(); if (ExceptionSensor.class.getName().equals(methodSensorTypeConfig.getClassName())) { return CollectionUtils.isEmpty(invocationSequenceData.getExceptionSensorDataObjects()); } } return false; }
@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()))); }
/** * Tests that skip is activated when certain sensor is only defined in the * {@link RegisteredSensorConfig}. * * @see #skippingSensors() */ @Test(dataProvider = "skippingSensors") public void skipSingleSensor(Class<? extends ISensor> sensorClass) { long methodId = 3L; long sensorTypeId = 11L; Object object = mock(Object.class); Object[] parameters = new Object[0]; Object result = mock(Object.class); MethodSensorTypeConfig sensorConfig = mock(MethodSensorTypeConfig.class); when(sensorConfig.getClassName()).thenReturn(sensorClass.getName()); when(rsc.getMethodSensors()).thenReturn(Collections.singletonList(methodSensor)); when(methodSensor.getSensorTypeConfig()).thenReturn(sensorConfig); invocationSequenceHook.beforeBody(methodId, sensorTypeId, object, parameters, rsc); invocationSequenceHook.firstAfterBody(methodId, sensorTypeId, object, parameters, result, false, rsc); invocationSequenceHook.secondAfterBody(coreService, methodId, sensorTypeId, object, parameters, result, false, rsc); verifyZeroInteractions(timer, coreService, realCoreService); }
@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); } }
when(sensorConfig.getClassName()).thenReturn(sensorClass.getName()); when(exceptionSensorConfig.getClassName()).thenReturn(ExceptionSensor.class.getName());
@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); }
@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); }
when(exceptionSensorConfig.getClassName()).thenReturn(ExceptionSensor.class.getName());
@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); }
when(exceptionSensorConfig.getClassName()).thenReturn(ExceptionSensor.class.getName());
when(exceptionSensorConfig.getClassName()).thenReturn(ExceptionSensor.class.getName());