/** * Finds the proper sensor id from the agent configuration and the environment used for the * {@link MethodSensorAssignment}. * * @param agentConfiguration * {@link AgentConfig} * @param environment * {@link Environment} * @param assignment * {@link MethodSensorAssignment} * @return {@link MethodSensorTypeConfig} for the given assignment. */ private MethodSensorTypeConfig getSensorTypeConfigFromConfiguration(AgentConfig agentConfiguration, Environment environment, MethodSensorAssignment assignment) { IMethodSensorConfig methodSensorConfig = environment.getMethodSensorTypeConfig(assignment.getSensorConfigClass()); return agentConfiguration.getMethodSensorTypeConfig(methodSensorConfig.getClassName()); }
@Test public void instrumentationExist() throws Exception { long agentId = 13L; long sensorId = 15L; String sensorClassName = "sensorClassName"; MethodSensorTypeConfig methodSensorTypeConfig = mock(MethodSensorTypeConfig.class); when(methodSensorTypeConfig.getId()).thenReturn(sensorId); when(methodSensorTypeConfig.getPriority()).thenReturn(PriorityEnum.NORMAL); AgentConfig agentConfiguration = mock(AgentConfig.class); when(agentConfiguration.getPlatformId()).thenReturn(agentId); when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); Map<String, Object> settings = Collections.<String, Object> singletonMap("key", "value"); when(assignment.getSettings()).thenReturn(settings); IMethodSensorConfig methodSensorConfig = mock(IMethodSensorConfig.class); when(methodSensorConfig.getClassName()).thenReturn(sensorClassName); when(environment.getMethodSensorTypeConfig(Matchers.<Class<? extends IMethodSensorConfig>> any())).thenReturn(methodSensorConfig); SensorInstrumentationPoint rsc = mock(SensorInstrumentationPoint.class); when(rsc.getSensorIds()).thenReturn(new long[] { sensorId }); MethodInstrumentationConfig instrumentationConfig = mock(MethodInstrumentationConfig.class); when(instrumentationConfig.getSensorInstrumentationPoint()).thenReturn(rsc); when(methodType.getMethodInstrumentationConfig()).thenReturn(instrumentationConfig); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(true)); // verify no interaction verifyZeroInteractions(registrationService); verify(instrumentationConfig, times(0)).setSensorInstrumentationPoint(Matchers.<SensorInstrumentationPoint> any()); verify(methodType, times(0)).setMethodInstrumentationConfig(Matchers.<MethodInstrumentationConfig> any()); }
when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig);
when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); when(agentConfiguration.getMethodSensorTypeConfig(invocClassName)).thenReturn(invocSensorTypeConfig);
when(agentConfiguration.getMethodSensorTypeConfig(sensorClassName)).thenReturn(methodSensorTypeConfig); when(agentConfiguration.getMethodSensorTypeConfig(invocClassName)).thenReturn(invocSensorTypeConfig);
/** * {@inheritDoc} */ @Override protected void applyAssignment(AgentConfig agentConfiguration, SensorInstrumentationPoint registeredSensorConfig) { // call super first super.applyAssignment(agentConfiguration, registeredSensorConfig); // check for invocation starts if (assignment.isStartsInvocation()) { // find the id of invocation sensor and only mark if one is found IMethodSensorConfig invocationSensorConfig = environment.getMethodSensorTypeConfig(InvocationSequenceSensorConfig.class); if (null != invocationSensorConfig) { MethodSensorTypeConfig invocationSensorTypeConfig = agentConfiguration.getMethodSensorTypeConfig(invocationSensorConfig.getClassName()); registeredSensorConfig.addSensorId(invocationSensorTypeConfig.getId(), invocationSensorTypeConfig.getPriority()); registeredSensorConfig.setStartsInvocation(true); } } } }