/** * The default constructor which needs one parameter for initialization. * * @param platformManager * The Platform manager. * @param parameter * Additional parameters. */ public ExceptionSensorHook(IPlatformManager platformManager, Map<String, Object> parameter) { this.platformManager = platformManager; this.strConstraint = new StringConstraint(parameter); }
/** * The only constructor which needs the {@link Timer}. * * @param timer * The timer. * @param platformManager * The Platform manager. * @param parameter * Additional parameters. * @param connectionMetaDataStorage * the storage containing meta information on the connection. * @param statementReflectionCache * Caches the calls to getConnection() */ public StatementHook(Timer timer, IPlatformManager platformManager, ConnectionMetaDataStorage connectionMetaDataStorage, StatementReflectionCache statementReflectionCache, Map<String, Object> parameter) { this.timer = timer; this.platformManager = platformManager; this.connectionMetaDataStorage = connectionMetaDataStorage; this.strConstraint = new StringConstraint(parameter); this.statementReflectionCache = statementReflectionCache; }
/** * The only constructor which needs the {@link Timer}. * * @param timer * The timer. * @param platformManager * The Platform manager. * @param statementStorage * The statement storage. * @param parameter * Additional parameters. * @param connectionMetaDataStorage * the meta information storage for connections. * @param statementReflectionCache * Caches the calls to getConnection(). */ public PreparedStatementHook(Timer timer, IPlatformManager platformManager, StatementStorage statementStorage, ConnectionMetaDataStorage connectionMetaDataStorage, StatementReflectionCache statementReflectionCache, Map<String, Object> parameter) { this.timer = timer; this.platformManager = platformManager; this.statementStorage = statementStorage; this.connectionMetaDataStorage = connectionMetaDataStorage; this.strConstraint = new StringConstraint(parameter); this.statementReflectionCache = statementReflectionCache; }
/** * The default constructor is initialized with a reference to the original {@link ICoreService} * implementation to delegate all calls to if the data needs to be sent. * * @param timer * The timer. * @param platformManager * The Platform manager. * @param coreService * The real core service needed to delegate spans to. * @param tracer * Current tracer for the spans. * @param propertyAccessor * The property accessor. * @param param * Additional parameters. * @param enhancedExceptionSensor * If enhanced exception sensor is ON. */ public InvocationSequenceHook(Timer timer, IPlatformManager platformManager, ICoreService coreService, TracerImpl tracer, IPropertyAccessor propertyAccessor, Map<String, Object> param, boolean enhancedExceptionSensor) { this.timer = timer; this.platformManager = platformManager; this.realCoreService = coreService; this.tracer = tracer; this.propertyAccessor = propertyAccessor; this.strConstraint = new StringConstraint(param); this.enhancedExceptionSensor = enhancedExceptionSensor; }
@BeforeMethod public void initTestClass() { extractor = new HttpInformationExtractor(new StringConstraint(Collections.<String, Object> singletonMap("stringLength", "20"))); }
@BeforeMethod public void init() { stringLength = new Random().nextInt(1000) + 1; parameter = new HashMap<String, Object>(); parameter.put("stringLength", String.valueOf(stringLength)); constraint = new StringConstraint(parameter); }
this.platformManager = platformManager; this.threadMXBean = threadMXBean; this.extractor = new HttpInformationExtractor(new StringConstraint(parameters));
@Test public void stringLengthOf0WithFinalChar() { char finalChar = '\''; parameter.put("stringLength", String.valueOf(0)); StringConstraint constr = new StringConstraint(parameter); String testStr = finalChar + fillString('x', 50) + finalChar; String resultString = constr.cropKeepFinalCharacter(testStr, finalChar); assertThat(resultString, isEmptyString()); }
@Test public void stringLengthOf0() { parameter.put("stringLength", String.valueOf(0)); StringConstraint constr = new StringConstraint(parameter); String testStr = fillString('x', 100); String resultString = constr.crop(testStr); assertThat(resultString, isEmptyString()); }
@Test public void cropStringMapNoCropping() { constraint = new StringConstraint(Collections.<String, Object> singletonMap("stringLength", "20")); final String param1 = "p1"; final String param2 = "p2"; final String param3 = "p3"; final String param1VReal = "value"; final String param2VReal1 = "value5"; final String param2VReal2 = "value6"; final String param3VReal1 = "value7"; final String param3VReal2 = "value8"; final String[] param1V = new String[] { param1VReal }; final String[] param2V = new String[] { param2VReal1, param2VReal2 }; final String[] param3V = new String[] { param3VReal1, param3VReal2 }; final Map<String, String[]> parameterMap = new HashMap<String, String[]>(); MapUtils.putAll(parameterMap, new Object[][] { { param1, param1V }, { param2, param2V }, { param3, param3V } }); Map<String, String[]> result = constraint.crop(parameterMap); assertThat(result.size(), is(equalTo(parameterMap.size()))); assertThat("Same compared by ObjectUtils", ObjectUtils.equals(result, parameterMap)); assertThat(result.get(param1), is(param1V)); assertThat(result.get(param2), is(param2V)); assertThat(result.get(param3), is(param3V)); assertThat(result.get(param1)[0], is(param1VReal)); assertThat(result.get(param2)[0], is(param2VReal1)); assertThat(result.get(param2)[1], is(param2VReal2)); assertThat(result.get(param3)[0], is(param3VReal1)); assertThat(result.get(param3)[1], is(param3VReal2)); }
@Test /** Tests whether the first entry is correctly copied to new map */ public void cropStringMapCropSecondEntry() { constraint = new StringConstraint(Collections.<String, Object> singletonMap("stringLength", "20")); final String param1 = "p1"; final String param2 = "p2"; final String param3 = "p3"; final String param1VReal = "value"; final String param2VReal1 = "I am really very long and need to be cropped"; final String param2VReal2 = "value6"; final String param3VReal1 = "value7"; final String param3VReal2 = "value8"; final String[] param1V = new String[] { param1VReal }; final String[] param2V = new String[] { param2VReal1, param2VReal2 }; final String[] param3V = new String[] { param3VReal1, param3VReal2 }; final Map<String, String[]> parameterMap = new HashMap<String, String[]>(); MapUtils.putAll(parameterMap, new Object[][] { { param1, param1V }, { param2, param2V }, { param3, param3V } }); Map<String, String[]> result = constraint.crop(parameterMap); assertThat(result.size(), is(equalTo(parameterMap.size()))); assertThat("Not same by ObjectUtils, need to be cropped", !ObjectUtils.equals(result, parameterMap)); assertThat(result.get(param1), is(param1V)); assertThat(result.get(param2), is(not(param2V))); assertThat(result.get(param3), is(param3V)); assertThat(result.get(param1)[0], is(param1VReal)); assertThat(result.get(param2)[0], is(not(param2VReal1))); assertThat(result.get(param2)[1], is(param2VReal2)); assertThat(result.get(param3)[0], is(param3VReal1)); assertThat(result.get(param3)[1], is(param3VReal2)); }
this.strConstraint = new StringConstraint(param);
@Test public void valueTooLong() throws Exception { long constructorId = 5L; long sensorTypeId = 3L; long platformId = 1L; Object[] parameters = new Object[0]; StringConstraint strConstraint = new StringConstraint(parameter); // the actual error message is too long, so it should be cropped later on String exceptionMessage = fillString('x', stringLength + 1); MyTestException exceptionObject = new MyTestException(exceptionMessage); ExceptionSensorData exceptionSensorData = new ExceptionSensorData(new Timestamp(System.currentTimeMillis()), platformId, sensorTypeId, constructorId); exceptionSensorData.setExceptionEvent(ExceptionEvent.CREATED); exceptionSensorData.setThrowableIdentityHashCode(System.identityHashCode(exceptionObject)); // the actual error message to be verified against exceptionSensorData.setErrorMessage(strConstraint.crop(exceptionMessage)); when(platformManager.getPlatformId()).thenReturn(platformId); when(registeredSensorConfig.getTargetClassFqn()).thenReturn(MyTestException.class.getName()); exceptionHook.afterConstructor(coreService, constructorId, sensorTypeId, exceptionObject, parameters, registeredSensorConfig); verify(platformManager, times(1)).getPlatformId(); verify(coreService, times(1)).addDefaultData(argThat(new ExceptionSensorDataVerifier(exceptionSensorData))); verifyNoMoreInteractions(platformManager); }