/** * Sets the parent to all nested sequences of the invocation to the correct one. * * @param parent * Parent to start from. */ private void connectChildren(InvocationSequenceData parent) { if (null != parent.getNestedSequences()) { for (InvocationSequenceData child : parent.getNestedSequences()) { child.setParentSequence(parent); connectChildren(child); } } }
nestedInvocationSequenceData.setParentSequence(invocationSequenceData);
@Test public void problemContextMustBeTheProperInvocationIfThereOneAndIsTheInvokerWithAParentSequence() { long methodIdent = 108L; Timestamp defDate = new Timestamp(new Date().getTime()); long platformIdent = RANDOM.nextLong(); long sensorTypeIdent = RANDOM.nextLong(); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); List<InvocationSequenceData> rawInvocations = new ArrayList<InvocationSequenceData>(); childSequence.setParentSequence(parentSequence); rawInvocations.add(childSequence); when(timeWastingOperation.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); CauseCluster problemContext = problemContextRule.action(); assertThat("The returned problemContext must be the invoker", problemContext.getCommonContext(), is(childSequence.getParentSequence())); }
@Test public void causeTypeIsRecursiveIfThereIsNotTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); } }
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasARegularTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); TimerData timerData = new TimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerData = new AggregatedDiagnosisTimerData(timerData); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerData); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerData); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerData); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerData); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerData); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
@Test public void causeTypeMustBeIterativeWhenTheChildInvocationsOfTheRootCauseAreIterativeAndHasAHttpTimerData() { Timestamp defDate = new Timestamp(new Date().getTime()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); HttpTimerData timerDataHttp = new HttpTimerData(currentTime, 10L, 20L, 30L); AggregatedDiagnosisTimerData aggregatedTimerDataHttp = new AggregatedDiagnosisTimerData(timerDataHttp); Random random = new Random(); long platformIdent = random.nextLong(); long sensorTypeIdent = random.nextLong(); long methodIdentEqual = new Long(108); long methodIdentDiff = random.nextLong(); InvocationSequenceData childSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); childSequence.setTimerData(timerDataHttp); InvocationSequenceData parentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); parentSequence.setTimerData(timerDataHttp); InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerDataHttp); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData()); rawInvocations.add(childSequence); when(problemContext.getCommonContext()).thenReturn(commonContext); when(commonContext.getParentSequence()).thenReturn(parentSequence); when(commonContext.getTimerData()).thenReturn(timerDataHttp); when(rootCause.getRawInvocationsSequenceElements()).thenReturn(rawInvocations); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.getAggregatedDiagnosisTimerData()).thenReturn(aggregatedTimerDataHttp); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE)); }
/** * Builds an invocation sequence data tree. * */ @BeforeMethod public void init() { List<InvocationSequenceData> nestedSequences1 = new ArrayList<>(); List<InvocationSequenceData> nestedSequences2 = new ArrayList<>(); rootInvocationSequence = new InvocationSequenceData(); rootInvocationSequence.setNestedSequences(nestedSequences1); firstChildSequence = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, 1L); firstChildSequence.setDuration(200d); firstChildSequence.setParentSequence(rootInvocationSequence); secondChildSequence = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, 2L); secondChildSequence.setDuration(4000d); secondChildSequence.setParentSequence(rootInvocationSequence); thirdChildSequence = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, 3L); thirdChildSequence.setDuration(500d); thirdChildSequence.setParentSequence(secondChildSequence); fourthChildSequence = new InvocationSequenceData(DEF_DATE, PLATFORM_IDENT, SENSOR_TYPE_IDENT, 4L); fourthChildSequence.setDuration(500d); fourthChildSequence.setParentSequence(rootInvocationSequence); nestedSequences1.add(firstChildSequence); nestedSequences1.add(secondChildSequence); nestedSequences1.add(fourthChildSequence); nestedSequences2.add(thirdChildSequence); rootInvocationSequence = new InvocationSequenceData(); rootInvocationSequence.setNestedSequences(nestedSequences1); secondChildSequence.setNestedSequences(nestedSequences2); }
@Test public void wrongGlobalContextResultsInWrongCommonContext() { long methodIdent = 108L; InvocationSequenceData root = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); InvocationSequenceData firstInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); firstInvocationSequenceData.setParentSequence(root); InvocationSequenceData secondInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); secondInvocationSequenceData.setParentSequence(root); root.getNestedSequences().add(firstInvocationSequenceData); root.getNestedSequences().add(secondInvocationSequenceData); CauseCluster one = new CauseCluster(root); CauseCluster two = new CauseCluster(secondInvocationSequenceData); one.setDistanceToNextCluster(1); one.setDepthOfCommonContext(1); two.setDistanceToNextCluster(1); two.setDepthOfCommonContext(1); List<CauseCluster> clustersToMerge = new ArrayList<CauseCluster>(); clustersToMerge.add(one); clustersToMerge.add(two); CauseCluster merged = new CauseCluster(clustersToMerge); assertThat("The returned problemContext must has size 2", merged.getCauseInvocations().size(), is(2)); assertThat("The returned root cause rule must not be null", merged.getCommonContext(), not(nullValue())); }
InvocationSequenceData grandParentSequence = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdentDiff); grandParentSequence.setTimerData(timerDataSql); parentSequence.setParentSequence(grandParentSequence); List<InvocationSequenceData> rawInvocations = new ArrayList<>(); rawInvocations.add(new InvocationSequenceData());
@Test public void isReturningTheProperValue() { long methodIdent = 108L; InvocationSequenceData root = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); InvocationSequenceData firstInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); firstInvocationSequenceData.setParentSequence(root); InvocationSequenceData secondInvocationSequenceData = new InvocationSequenceData(DEF_DATE, 10, 10, methodIdent); secondInvocationSequenceData.setParentSequence(root); root.getNestedSequences().add(firstInvocationSequenceData); root.getNestedSequences().add(secondInvocationSequenceData); CauseCluster one = new CauseCluster(firstInvocationSequenceData); CauseCluster two = new CauseCluster(secondInvocationSequenceData); one.setDistanceToNextCluster(1); one.setDepthOfCommonContext(1); two.setDistanceToNextCluster(1); two.setDepthOfCommonContext(1); List<CauseCluster> clustersToMerge = new ArrayList<CauseCluster>(); clustersToMerge.add(one); clustersToMerge.add(two); CauseCluster merged = new CauseCluster(clustersToMerge); assertThat("The returned problemContext must have size 2", merged.getCauseInvocations().size(), is(2)); assertThat("The returned problemContext must be the root one element", merged.getCommonContext(), is(root)); }
exceptionSensorData.setThrowableIdentityHashCode(1L); child.setExceptionSensorDataObjects(Collections.singletonList(exceptionSensorData)); child.setParentSequence(parent);
secondMethod.setTimerData(timerDataHttp); detectedProblemContext.getNestedSequences().add(firstMethod); firstMethod.setParentSequence(detectedProblemContext); firstMethod.getNestedSequences().add(secondMethod); secondMethod.setParentSequence(firstMethod); when(rootCause.getMethodIdent()).thenReturn(detectedProblemContext.getNestedSequences().get(0).getMethodIdent()); when(rootCause.size()).thenReturn(2);
secondMethod.setTimerData(timerData); detectedProblemContext.getNestedSequences().add(firstMethod); firstMethod.setParentSequence(detectedProblemContext); firstMethod.getNestedSequences().add(secondMethod); secondMethod.setParentSequence(firstMethod); when(rootCause.getMethodIdent()).thenReturn(detectedProblemContext.getNestedSequences().get(0).getMethodIdent()); when(rootCause.size()).thenReturn(2);
child.setParentSequence(invData); children.add(child); i += childCountForChild + 1;
exceptionSensorData.setThrowableIdentityHashCode(1L); child.setExceptionSensorDataObjects(Collections.singletonList(exceptionSensorData)); child.setParentSequence(parent);
secondMethod.setSqlStatementData(timerDataSql); detectedProblemContext.getNestedSequences().add(firstMethod); firstMethod.setParentSequence(detectedProblemContext); firstMethod.getNestedSequences().add(secondMethod); secondMethod.setParentSequence(firstMethod); when(rootCause.getMethodIdent()).thenReturn(detectedProblemContext.getNestedSequences().get(0).getMethodIdent()); when(rootCause.size()).thenReturn(2);
timerData.setExclusiveDuration(8000d); significantContext.setTimerData(timerData); significantContext.setParentSequence(globalContext); InvocationSequenceData significantContextChildWithParent = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); timerData.setExclusiveDuration(4000d); significantContextChildWithParent.setTimerData(timerData); significantContextChildWithParent.setParentSequence(significantContext); significantContext.getNestedSequences().add(significantContextChildWithParent); InvocationSequenceData secondSignificantContextChildWithParent = new InvocationSequenceData(defDate, platformIdent, sensorTypeIdent, methodIdent); secondSignificantContextChildWithParent.setTimerData(timerData); secondSignificantContextChildWithParent.setParentSequence(significantContext); significantContext.getNestedSequences().add(secondSignificantContextChildWithParent); List<InvocationSequenceData> rawInvocationsSignificant = new ArrayList<InvocationSequenceData>();
childTimer.setDuration(1L); child.setTimerData(childTimer); child.setParentSequence(parent);
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; }