/** * {@inheritDoc} */ @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { // NOCHK:8-params double endTime = timeStack.pop().doubleValue(); double startTime = timeStack.pop().doubleValue(); if (threadLast.get().booleanValue()) { threadLast.set(Boolean.FALSE); double duration = endTime - startTime; String sql = parameters[0].toString(); Timestamp timestamp = new Timestamp(System.currentTimeMillis() - Math.round(duration)); long platformId = platformManager.getPlatformId(); SqlStatementData sqlData = new SqlStatementData(timestamp, platformId, sensorTypeId, methodId); sqlData.setPreparedStatement(false); sqlData.setSql(strConstraint.crop(sql)); sqlData.setDuration(duration); sqlData.calculateMin(duration); sqlData.calculateMax(duration); sqlData.setCount(1L); // populate the connection meta data. connectionMetaDataStorage.populate(sqlData, statementReflectionCache.getConnection(object.getClass(), object)); coreService.addDefaultData(sqlData); } }
sqlData.setSql(strConstraint.crop(sql)); sqlData.setDuration(duration); sqlData.calculateMin(duration);
@Test private void musteReturnAnInstanceWithDataBaseSourceTypeDataIfHasSqlData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); SqlStatementData sqlStatementData = new SqlStatementData(new Timestamp(10), 10, 10, 108L); sqlStatementData.setCount(1); sqlStatementData.setSql("blahblahblah"); invocationSequenceData.setSqlStatementData(sqlStatementData); AggregatedDiagnosisData aggregatedDiagnosisData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(invocationSequenceData); assertThat("The object must have DATABASE as source type", aggregatedDiagnosisData.getSourceType(), is(SourceType.DATABASE)); }
@Test private void mustReturnAnInstanceWithDataBaseSourceTypeDataIfHasSqlDataAndTimerData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); SqlStatementData sqlStatementData = new SqlStatementData(new Timestamp(10), 10, 10, 108L); sqlStatementData.setCount(1); sqlStatementData.setSql("blahblahblah"); invocationSequenceData.setSqlStatementData(sqlStatementData); TimerData timerData = new TimerData(new Timestamp(10), 10L, 20, 108L); invocationSequenceData.setTimerData(timerData); AggregatedDiagnosisData aggregatedDiagnosisData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(invocationSequenceData); assertThat("The object must have DATABASE as source type", aggregatedDiagnosisData.getSourceType(), is(SourceType.DATABASE)); } }
@Test private void musteReturnAnObjectWithAPairLongStringIfTheTimerDataHasSqlData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); SqlStatementData sqlStatementData = new SqlStatementData(new Timestamp(10), 10, 10, 108L); sqlStatementData.setCount(1); sqlStatementData.setSql("blahblahblah"); invocationSequenceData.setSqlStatementData(sqlStatementData); TimerData timerData = new TimerData(); invocationSequenceData.setTimerData(timerData); Pair<Long, String> aggregationKey = (Pair<Long, String>) DiagnosisDataAggregator.getInstance().getAggregationKey(invocationSequenceData); assertThat("The string of the pair must be the sql data", aggregationKey.getSecond(), is(sqlStatementData.getSql())); }
/** * Tests that the {@link SqlStatementData} is searched correctly. */ @Test public void sqlStatementDataSearch() { SqlStatementData sqlData = new SqlStatementData(); sqlData.setMethodIdent(1L); sqlData.setSql("Select blah from table where condition"); SearchCriteria searchCriteria = new SearchCriteria("Blah"); SearchCriteria wrong = new SearchCriteria("halB"); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(sqlData, searchCriteria, repositoryDefinition), is(equalTo(true))); searchCriteria.setCaseSensitive(true); assertThat(SearchFactory.isSearchCompatible(sqlData, searchCriteria, repositoryDefinition), is(equalTo(false))); assertThat(SearchFactory.isSearchCompatible(sqlData, wrong, repositoryDefinition), is(equalTo(false))); List<String> parameters = new ArrayList<>(); parameters.add("blah"); sqlData.setSql("Select somthing from table where condition=?"); sqlData.setParameterValues(parameters); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(sqlData, searchCriteria, repositoryDefinition), is(equalTo(true))); searchCriteria.setCaseSensitive(true); assertThat(SearchFactory.isSearchCompatible(sqlData, searchCriteria, repositoryDefinition), is(equalTo(false))); assertThat(SearchFactory.isSearchCompatible(sqlData, wrong, repositoryDefinition), is(equalTo(false))); }
@Test private void ifTheAggregatedObjectHasSQLDataAndIsDefinedInTheMapItMustBeAggregatedToTheDiagnosisAggregator() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 2L); diagnosisDataAggregationPerformer = new DiagnosisDataAggregationPerformer(); SqlStatementData sqlStatementData = new SqlStatementData(new Timestamp(10), 10, 10, 108L); sqlStatementData.setCount(1); sqlStatementData.setSql("blahblahblah"); invocationSequenceData.setSqlStatementData(sqlStatementData); HttpTimerData timerData = new HttpTimerData(new Timestamp(10), 10, 10, 108L); invocationSequenceData.setTimerData(timerData); Object key = new Pair<Long, String>(invocationSequenceData.getMethodIdent(), invocationSequenceData.getSqlStatementData().getSql()); diagnosisDataAggregationPerformer.diagnosisDataAggregationMap.put(key, alreadyAggregatedObject); diagnosisDataAggregationPerformer.aggregateInvocationSequenceData(invocationSequenceData); verify(alreadyAggregatedObject, times(1)).aggregate(invocationSequenceData); }
InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); timerDataSql.setCount(1); timerDataSql.setSql("somethingsomething"); childSequence.setTimerData(timerDataSql); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff);
@Test private void ifTheAggregatedObjectIsNotDefineInTheMapItMustBeAggregated() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 2L); diagnosisDataAggregationPerformer = new DiagnosisDataAggregationPerformer(); SqlStatementData sqlStatementData = new SqlStatementData(new Timestamp(10), 10, 10, 108L); sqlStatementData.setCount(1); sqlStatementData.setSql("blahblahblah"); invocationSequenceData.setSqlStatementData(sqlStatementData); TimerData timerData = new TimerData(new Timestamp(10), 10, 10, 108L); invocationSequenceData.setTimerData(timerData); Object key = new Pair<Long, String>(invocationSequenceData.getMethodIdent(), invocationSequenceData.getSqlStatementData().getSql()); AggregatedDiagnosisData alreadyAggregatedObject = new AggregatedDiagnosisData(SourceType.TIMERDATA, invocationSequenceData, key); diagnosisDataAggregationPerformer.diagnosisDataAggregationMap.put(key, alreadyAggregatedObject); InvocationSequenceData secondInvocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 2L); secondInvocationSequenceData.setTimerData(timerData); List<InvocationSequenceData> invocationSequenceDataList = new ArrayList<>(); invocationSequenceDataList.add(invocationSequenceData); invocationSequenceDataList.add(secondInvocationSequenceData); diagnosisDataAggregationPerformer.aggregateInvocationSequenceDataList(invocationSequenceDataList); List<AggregatedDiagnosisData> resultList = diagnosisDataAggregationPerformer.getAggregationResultList(); assertThat("The list must have 2 aggregated objects", resultList.size(), is(2)); assertThat("The first aggregated object must have the same method ident that the invocationSequenceData", resultList.get(0).getMethodIdent(), equalTo(invocationSequenceData.getMethodIdent())); assertThat("The second aggregated object must have the same method ident that the secondInvocationSequenceData", resultList.get(1).getMethodIdent(), equalTo(secondInvocationSequenceData.getMethodIdent())); } }
InvocationSequenceData detectedProblemContext = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); timerDataSql.setCount(1); timerDataSql.setSql("somethingsomething"); detectedProblemContext.setSqlStatementData(timerDataSql); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentEqual);
SqlStatementData sqlData = new SqlStatementData(); sqlData.setMethodIdent(1L); sqlData.setSql("Select blah from table where condition"); invocationData.setSqlStatementData(sqlData); searchCriteria.setCaseSensitive(false);
/** * Returns template for {@link SqlStatementData}. * * @param sqlStatementData * Source object. * @param id * Should id be inserted into template. * @param sql * Should SQL query be inserted into template. * @param parameters * Should parameters be inserted into template. * @return Template object. */ protected SqlStatementData getTemplate(SqlStatementData sqlStatementData, boolean id, boolean sql, boolean parameters) { SqlStatementData template = OccurrenceFinderFactory.getEmptyTemplate(sqlStatementData); if (id && (0 != sqlStatementData.getId())) { template.setId(sqlStatementData.getId()); } if (sql && (null != sqlStatementData.getSql())) { template.setSql(sqlStatementData.getSql()); } if (parameters && (null != sqlStatementData.getParameterValues())) { template.setParameterValues(sqlStatementData.getParameterValues()); } return template; }
/** * {@inheritDoc} */ @Override public void setInputDefinition(InputDefinition inputDefinition) { super.setInputDefinition(inputDefinition); template = new SqlStatementData(); template.setPlatformIdent(inputDefinition.getIdDefinition().getPlatformId()); template.setId(-1); if (inputDefinition.hasInputDefinitionExtra(InputDefinitionExtrasMarkerFactory.SQL_STATEMENT_EXTRAS_MARKER)) { SqlStatementInputDefinitionExtra inputDefinitionExtra = inputDefinition.getInputDefinitionExtra(InputDefinitionExtrasMarkerFactory.SQL_STATEMENT_EXTRAS_MARKER); template.setSql(inputDefinitionExtra.getSql()); } dataAccessService = inputDefinition.getRepositoryDefinition().getSqlDataAccessService(); cachedDataService = inputDefinition.getRepositoryDefinition().getCachedDataService(); }