@Test public void priorityReverse() { registeredSensorConfig.addSensorId(1, PriorityEnum.MIN); registeredSensorConfig.addSensorId(2, PriorityEnum.MAX); long[] sensorIds = registeredSensorConfig.getSensorIds(); assertThat(sensorIds.length, is(2)); // highest priority first assertThat(sensorIds[0], is(2L)); assertThat(sensorIds[1], is(1L)); } }
@Test public void priority() { registeredSensorConfig.addSensorId(1, PriorityEnum.MAX); registeredSensorConfig.addSensorId(2, PriorityEnum.MIN); long[] sensorIds = registeredSensorConfig.getSensorIds(); assertThat(sensorIds.length, is(2)); assertThat(sensorIds[0], is(1L)); assertThat(sensorIds[1], is(2L)); }
@Test public void noDoubleId() { registeredSensorConfig.addSensorId(1, PriorityEnum.MIN); registeredSensorConfig.addSensorId(2, PriorityEnum.MAX); registeredSensorConfig.addSensorId(1, PriorityEnum.MAX); registeredSensorConfig.addSensorId(2, PriorityEnum.MIN); long[] sensorIds = registeredSensorConfig.getSensorIds(); assertThat(sensorIds.length, is(2)); }
@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()); }
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
assertThat(instrumentationConfig.getAllInstrumentationPoints(), hasSize(1)); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(1)); assertThat(rsc.getSensorIds()[0], is(sensorId)); assertThat(rsc.getSettings(), is(settings)); assertThat(instrumentationConfig.getSpecialInstrumentationPoint(), is(nullValue()));
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
assertThat(rsc.getSensorIds().length, is(2)); assertThat(rsc.getSensorIds()[0], is(sensorId)); assertThat(rsc.getSensorIds()[1], is(invocationSensorId)); assertThat(rsc.isStartsInvocation(), is(true)); assertThat(rsc.isPropertyAccess(), is(true));
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(0)); assertThat(rsc.isConstructor(), is(true)); SpecialInstrumentationPoint ssc = instrumentationConfig.getSpecialInstrumentationPoint();
assertThat(instrumentationConfig.getAllInstrumentationPoints(), hasSize(1)); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(1)); assertThat(rsc.getSensorIds()[0], is(sensorId)); assertThat(rsc.getSettings(), is(settings)); assertThat(instrumentationConfig.getSpecialInstrumentationPoint(), is(nullValue()));
SensorInstrumentationPoint rsc = instrumentationConfig.getSensorInstrumentationPoint(); assertThat(rsc.getId(), is(methodId)); assertThat(rsc.getSensorIds().length, is(0)); assertThat(rsc.isConstructor(), is(false)); SpecialInstrumentationPoint ssc = instrumentationConfig.getSpecialInstrumentationPoint();
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
assertThat(rsc.getSensorIds().length, is(2)); assertThat(rsc.getSensorIds()[0], is(sensorId)); assertThat(rsc.getSensorIds()[1], is(invocationSensorId)); assertThat(rsc.isStartsInvocation(), is(true)); assertThat(rsc.isPropertyAccess(), is(false));
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
long[] sensorIds = { 17L }; when(sensorInstrumentationPoint.getId()).thenReturn(rscId); when(sensorInstrumentationPoint.getSensorIds()).thenReturn(sensorIds); when(sensorInstrumentationPoint.isStartsInvocation()).thenReturn(false); when(sensorInstrumentationPoint.getSettings()).thenReturn(Collections.<String, Object> singletonMap("key", "value"));
for (long sensorId : sensorInstrumentationPoint.getSensorIds()) { IMethodSensor sensor = methodSensorMap.get(sensorId); if (null != sensor) {
SensorInstrumentationPoint sensorInstrumentationPoint = config.getSensorInstrumentationPoint(); hookDispatcherMapper.addMapping(registeredSensorConfig.getId(), registeredSensorConfig); methodToSensorMap.put(Long.valueOf(registeredSensorConfig.getId()), sensorInstrumentationPoint.getSensorIds());