invocationSequenceData.setSqlStatementData((SqlStatementData) dataObject);
@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 public void getExclusiveDurationMustReturnTheExclusiveDurationOfTheTimerDataWhenItIsASqlData() { InvocationSequenceData invocationData = new InvocationSequenceData(); SqlStatementData timerData = new SqlStatementData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); timerData.calculateExclusiveMin(300d); timerData.setExclusiveDuration(300d); timerData.setCount(1); invocationData.setSqlStatementData(timerData); double exclusiveDuration = DiagnosisHelper.getExclusiveDuration(invocationData); assertThat("Exclusive duration must be 300.", exclusiveDuration, is(timerData.getExclusiveDuration())); } }
@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 public void sqlStatementDataMustReturnAEmptyListOfAggregatedDiagnosisDataWhenTheDurationIsZero() { long platformIdent = 108; long sensorTypeIdent = 1; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); nestedSequences.add(firstMethod); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); nestedSequences.add(secondMethod); when(globalContext.getDuration()).thenReturn(new Double(0)); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Action method must return an array of AggregatedDiagnosisData not empty", timeWastingOperationsResults, hasSize(0)); }
@Test public void sqlStatementDataMustReturnANotEmptyListOfAggregatedDiagnosisDataWhenTheDurationIsTooLong() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Action method must return a group of AggregatedDiagnosisData not empty", timeWastingOperationsResults, not(hasSize(0))); }
@Test public void sqlStatementDataMustReturnANotNullListOfAggregatedDiagnosisData() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("The returned list of AggregatedDiagnosisData must not be null", timeWastingOperationsResults, notNullValue()); }
@Test public void sqlStatementDataMustReturnAListOfAggregatedDiagnosisDataWithOneElement() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Action method must return a list with one AggregatedDiagnosisData", timeWastingOperationsResults, hasSize(1)); }
@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())); }
@Test public void sqlStatementDataMustReturnAValidListOfAggregatedDiagnosisData() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Action method must return a list of AggregatedDiagnosisData not empty", timeWastingOperationsResults, not(hasSize(0))); for (AggregatedDiagnosisData AggregatedDiagnosisInvocationData : timeWastingOperationsResults) { isAValidAggregatedDiagnosisData(AggregatedDiagnosisInvocationData); } }
/** * Test that {@link InvocationExtractorDataProcessor} will extract all children of an * invocation. */ @Test public void testInvocationExtractor() { AbstractDataProcessor chainedProcessor = mock(AbstractDataProcessor.class); List<AbstractDataProcessor> chainedList = new ArrayList<>(); chainedList.add(chainedProcessor); InvocationExtractorDataProcessor invocationExtractorDataProcessor = new InvocationExtractorDataProcessor(chainedList); invocationExtractorDataProcessor.setStorageWriter(storageWriter); InvocationSequenceData invocationSequenceData = new InvocationSequenceData(); List<InvocationSequenceData> children = new ArrayList<>(); InvocationSequenceData child1 = new InvocationSequenceData(new Timestamp(new Date().getTime()), 10, 10, 10); TimerData timerData = new TimerData(); child1.setTimerData(timerData); InvocationSequenceData child2 = new InvocationSequenceData(new Timestamp(new Date().getTime()), 20, 20, 20); SqlStatementData sqlStatementData = new SqlStatementData(); child2.setSqlStatementData(sqlStatementData); children.add(child1); children.add(child2); invocationSequenceData.setNestedSequences(children); assertThat(invocationExtractorDataProcessor.canBeProcessed(invocationSequenceData), is(true)); invocationExtractorDataProcessor.process(invocationSequenceData); verify(chainedProcessor, times(1)).process(timerData); verify(chainedProcessor, times(1)).process(timerData); verify(chainedProcessor, times(0)).process(child1); verify(chainedProcessor, times(0)).process(child2); }
invData.setId(random.nextLong()); invData.setEnd(random.nextDouble()); invData.setSqlStatementData(getSqlStatementInstance()); if (childCount == 0) { return invData; child.setSqlStatementData(getSqlStatementInstance()); child.setParentSequence(invData); children.add(child);
@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); }
@Test public void sqlStatementDataMustReturnAListOfAggregatedDiagnosisDataWithTwoElements() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); InvocationSequenceData thirdMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 3L); SqlStatementData thirdSqlStatementData = new SqlStatementData(); thirdSqlStatementData.calculateExclusiveMin(200d); thirdSqlStatementData.setExclusiveDuration(200d); thirdSqlStatementData.setCount(1); secondMethod.setSqlStatementData(thirdSqlStatementData); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); nestedSequences.add(thirdMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Action method must return a list with two AggregatedDiagnosisData", timeWastingOperationsResults, hasSize(2)); }
@Test public void sqlStatementDataMustReturnTheExpectedAggregatedDiagnosisData() { long platformIdent = 108; long sensorTypeIdent = 1; double highDuration = 2000; Timestamp defDate = new Timestamp(new Date().getTime()); List<InvocationSequenceData> nestedSequences = new ArrayList<>(); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 1L); SqlStatementData firstSqlStatementData = new SqlStatementData(); firstSqlStatementData.calculateExclusiveMin(200d); firstSqlStatementData.setExclusiveDuration(200d); firstSqlStatementData.setCount(1); firstMethod.setSqlStatementData(firstSqlStatementData); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 2L); InvocationSequenceData thirdMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, 3L); SqlStatementData thirdSqlStatementData = new SqlStatementData(); thirdSqlStatementData.calculateExclusiveMin(300d); thirdSqlStatementData.setExclusiveDuration(300d); thirdSqlStatementData.setCount(1); thirdMethod.setSqlStatementData(thirdSqlStatementData); nestedSequences.add(firstMethod); nestedSequences.add(secondMethod); nestedSequences.add(thirdMethod); when(globalContext.getDuration()).thenReturn(highDuration); when(globalContext.getNestedSequences()).thenReturn(nestedSequences); List<AggregatedDiagnosisData> timeWastingOperationsResults = timeWastingOperationsRule.action(); assertThat("Identifier is not the expected one, the first result must have 3 as method identifier", timeWastingOperationsResults.get(0).getMethodIdent(), is(3L)); assertThat("Identifier is not the expected one, the first result must have 1 as method identifier", timeWastingOperationsResults.get(1).getMethodIdent(), is(1L)); }
@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())); } }
timerDataSql.setCount(1); timerDataSql.setSql("somethingsomething"); detectedProblemContext.setSqlStatementData(timerDataSql); InvocationSequenceData firstMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentEqual); firstMethod.setSqlStatementData(timerDataSql); InvocationSequenceData secondMethod = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentEqual); secondMethod.setSqlStatementData(timerDataSql); detectedProblemContext.getNestedSequences().add(firstMethod); firstMethod.setParentSequence(detectedProblemContext);
sqlData.setMethodIdent(1L); sqlData.setSql("Select blah from table where condition"); invocationData.setSqlStatementData(sqlData); searchCriteria.setCaseSensitive(false); assertThat(SearchFactory.isSearchCompatible(invocationData, searchCriteria, repositoryDefinition), is(equalTo(true))); assertThat(SearchFactory.isSearchCompatible(invocationData, wrong, repositoryDefinition), is(equalTo(false))); invocationData.setSqlStatementData(null); ExceptionSensorData exceptionData = new ExceptionSensorData(); exceptionData.setMethodIdent(1L);
sql.setCount(1L); sql.setDuration(1L); child.setSqlStatementData(sql); child.setParentSequence(parent);
/** * Clones invocation sequence. This method returns new object exactly same as the original * object, but with out nested sequences set. * * @return Cloned invocation sequence. */ public InvocationSequenceData getClonedInvocationSequence() { InvocationSequenceData clone = new InvocationSequenceData(this.getTimeStamp(), this.getPlatformIdent(), this.getSensorTypeIdent(), this.getMethodIdent()); clone.setId(this.getId()); clone.setSpanIdent(this.getSpanIdent()); clone.setChildCount(this.getChildCount()); clone.setDuration(this.getDuration()); clone.setEnd(this.getEnd()); clone.setNestedSequences(Collections.<InvocationSequenceData> emptyList()); clone.setParameterContentData(this.getParameterContentData()); clone.setParentSequence(this.getParentSequence()); clone.setPosition(this.getPosition()); clone.setSqlStatementData(this.getSqlStatementData()); clone.setTimerData(this.getTimerData()); clone.setExceptionSensorDataObjects(this.getExceptionSensorDataObjects()); clone.setStart(this.getStart()); clone.setNestedSqlStatements(this.isNestedSqlStatements()); clone.setNestedExceptions(this.isNestedExceptions()); clone.setLoggingData(this.getLoggingData()); clone.setApplicationId(this.getApplicationId()); clone.setBusinessTransactionId(this.getBusinessTransactionId()); return clone; }