/** * Registers method to the registration service. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return Id of the method. */ private long registerMethod(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // extract package and class name String fqn = methodInstrumentationConfig.getTargetClassFqn(); int index = fqn.lastIndexOf('.'); String packageName = index >= 0 ? fqn.substring(0, index) : ""; String className = fqn.substring(index + 1); return registrationService.registerMethodIdent(agentConfiguration.getPlatformId(), packageName, className, methodType.getName(), methodType.getParameters(), methodType.getReturnType(), methodType.getModifiers()); }
protected void prepareConfigurationMockConstructor(MethodInstrumentationConfig point, Class<?> clazz, boolean staticConstructor, Class<?>... parameterTypes) throws SecurityException, NoSuchMethodException { clazz.getDeclaredConstructor(parameterTypes); when(point.getTargetClassFqn()).thenReturn(clazz.getName()); when(point.getTargetMethodName()).thenReturn(staticConstructor ? "<clinit>" : "<init>"); when(point.getReturnType()).thenReturn("void"); if (ArrayUtils.isNotEmpty(parameterTypes)) { List<String> params = new ArrayList<String>(); for (Class<?> paramType : parameterTypes) { if (paramType.isArray()) { params.add(paramType.getComponentType().getName() + "[]"); } else { params.add(paramType.getName()); } } when(point.getParameterTypes()).thenReturn(params); } }
protected void prepareConfigurationMockMethod(MethodInstrumentationConfig point, Class<?> clazz, String methodName, Class<?>... parameterTypes) throws SecurityException, NoSuchMethodException { Method method = clazz.getDeclaredMethod(methodName, parameterTypes); when(point.getTargetClassFqn()).thenReturn(clazz.getName()); when(point.getTargetMethodName()).thenReturn(methodName); if (method.getReturnType().isArray()) { when(point.getReturnType()).thenReturn(method.getReturnType().getComponentType().getName() + "[]"); } else { when(point.getReturnType()).thenReturn(method.getReturnType().getName()); } if (ArrayUtils.isNotEmpty(parameterTypes)) { List<String> params = new ArrayList<String>(); for (Class<?> paramType : parameterTypes) { if (paramType.isArray()) { params.add(paramType.getComponentType().getName() + "[]"); } else { params.add(paramType.getName()); } } when(point.getParameterTypes()).thenReturn(params); } }
assertThat(sscCaptor.getValue().getId(), is(sscId)); assertThat(sscCaptor.getValue().getSensor(), is(methodSensor)); assertThat(sscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(sscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(sscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
ssc.setSensor(sensor); } else { String methodFull = config.getTargetClassFqn() + "#" + config.getTargetMethodName(); log.error("Sensor with the id " + sensorId + " does not exists on the agent, but it's defined for the method: " + methodFull);
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void");
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); assertThat(rscCaptor.getValue().getMethodSensors(), hasSize(1)); assertThat(rscCaptor.getValue().getMethodSensors(), hasItem(methodSensor)); assertThat(rscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(rscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(rscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); assertThat(rscCaptor.getValue().getMethodSensors(), hasSize(1)); assertThat(rscCaptor.getValue().getMethodSensors(), hasItem(methodSensor)); assertThat(rscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(rscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(rscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); assertThat(rscCaptor.getValue().getMethodSensors(), hasSize(1)); assertThat(rscCaptor.getValue().getMethodSensors(), hasItem(methodSensor)); assertThat(rscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(rscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(rscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); assertThat(rscCaptor.getValue().getMethodSensors(), hasSize(1)); assertThat(rscCaptor.getValue().getMethodSensors(), hasItem(methodSensor)); assertThat(rscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(rscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(rscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName)); assertThat(instrumentationConfig.getReturnType(), is(returnType));
assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName)); assertThat(instrumentationConfig.getReturnType(), is(returnType));
/** * Copies all the class/method information from the {@link MethodInstrumentationConfig} to the * {@link AbstractSensorConfig}. * * @param asc * {@link AbstractSensorConfig} * @param config * {@link MethodInstrumentationConfig} */ private void copyInfo(AbstractSensorConfig asc, MethodInstrumentationConfig config) { asc.setTargetClassFqn(config.getTargetClassFqn()); asc.setTargetMethodName(config.getTargetMethodName()); asc.setReturnType(config.getReturnType()); asc.setParameterTypes(config.getParameterTypes()); }
assertThat(instrumentationConfig.getTargetClassFqn(), is(className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName)); assertThat(instrumentationConfig.getReturnType(), is(returnType));
assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName)); assertThat(instrumentationConfig.getReturnType(), is(returnType));
assertThat(instrumentationConfig.getTargetClassFqn(), is(packageName + '.' + className)); assertThat(instrumentationConfig.getTargetMethodName(), is(methodName)); assertThat(instrumentationConfig.getReturnType(), is(returnType));
when(methodInstrumentationConfig.getTargetClassFqn()).thenReturn(className); when(methodInstrumentationConfig.getTargetMethodName()).thenReturn("<init>"); when(methodInstrumentationConfig.getReturnType()).thenReturn("void"); assertThat(rscCaptor.getValue().getMethodSensors(), hasSize(1)); assertThat(rscCaptor.getValue().getMethodSensors(), hasItem(methodSensor)); assertThat(rscCaptor.getValue().getTargetClassFqn(), is(methodInstrumentationConfig.getTargetClassFqn())); assertThat(rscCaptor.getValue().getTargetMethodName(), is(methodInstrumentationConfig.getTargetMethodName())); assertThat(rscCaptor.getValue().getReturnType(), is(methodInstrumentationConfig.getReturnType()));
rsc.addMethodSensor(sensor); } else { String methodFull = config.getTargetClassFqn() + "#" + config.getTargetMethodName(); log.error("Sensor with the id " + sensorId + " does not exists on the agent, but it's defined for the method: " + methodFull);