@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(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
assertThat(instrumentationConfig.getParameterTypes(), is(parameters)); assertThat(instrumentationConfig.getAllInstrumentationPoints(), hasSize(2)); SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(0));
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName));
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint();
assertThat(instrumentationConfig.getParameterTypes(), is(parameters)); assertThat(instrumentationConfig.getAllInstrumentationPoints(), hasSize(2)); SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(0));
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName));
assertThat(ssc.getSensorId(), is(sensorId)); assertThat(ssc.getSubstitutionDescriptor(), is(substitutionDescriptor)); assertThat(instrumentationConfig.getSensorInstrumentationPoint(), is(nullValue()));
when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); when(methodInstrumentationConfig.getParameterTypes()).thenReturn(Collections.<String> emptyList()); when(methodInstrumentationConfig.getSensorInstrumentationPoint()).thenReturn(sensorInstrumentationPoint); when(methodInstrumentationConfig.getAllInstrumentationPoints()).thenReturn(Collections.<IMethodInstrumentationPoint> singleton(sensorInstrumentationPoint)); when(instrumenterFactory.getMethodVisitor(eq(sensorInstrumentationPoint), Matchers.<MethodVisitor> any(), anyInt(), anyString(), anyString(), anyBoolean())).thenReturn(methodVisitor);
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint();
SensorInstrumentationPoint sensorInstrumentationPoint = config.getSensorInstrumentationPoint(); if (null == sensorInstrumentationPoint) { return null;
/** * Checks if the {@link SensorInstrumentationPoint} exists in the * {@link MethodInstrumentationConfig}. If not new one is created, registered with registration * service and saved in the {@link MethodInstrumentationConfig}. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return {@link SensorInstrumentationPoint} for the {@link MethodInstrumentationConfig}. */ protected SensorInstrumentationPoint getOrCreateSensorInstrumentationPoint(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // check for existing SensorInstrumentationPoint sensorInstrumentationPoint = methodInstrumentationConfig.getSensorInstrumentationPoint(); // if not create new one if (null == sensorInstrumentationPoint) { // if not create new and register long id = registerMethod(agentConfiguration, methodType, methodInstrumentationConfig); sensorInstrumentationPoint = new SensorInstrumentationPoint(); sensorInstrumentationPoint.setId(id); if (Character.CONSTRUCTOR.equals(methodType.getMethodCharacter())) { sensorInstrumentationPoint.setConstructor(true); } // set to method instrumentation methodInstrumentationConfig.setSensorInstrumentationPoint(sensorInstrumentationPoint); } return sensorInstrumentationPoint; }
RegisteredSensorConfig registeredSensorConfig = createRegisteredSensorConfig(config); if (null != registeredSensorConfig) { SensorInstrumentationPoint sensorInstrumentationPoint = config.getSensorInstrumentationPoint(); hookDispatcherMapper.addMapping(registeredSensorConfig.getId(), registeredSensorConfig); methodToSensorMap.put(Long.valueOf(registeredSensorConfig.getId()), sensorInstrumentationPoint.getSensorIds());