/** * Rule execution. * * @return DIAGNOSIS_TAG_CAUSE_STRUCTURE */ @Action(resultTag = RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE) public CauseStructure action() { // In case there is just one Root Cause method. if (rootCause.size() == 1) { return new CauseStructure(CauseType.SINGLE, rootCause.getSourceType()); } // The Root Causes are called either recursive if (calculateMaxRecursionDepth() > 1) { return new CauseStructure(CauseType.RECURSIVE, rootCause.getSourceType()); // or iterative. } else { return new CauseStructure(CauseType.ITERATIVE, rootCause.getSourceType()); } }
@Test public void causeTypeMustBeSingleWhenTheRootCauseHasJustOneElement() { when(rootCause.size()).thenReturn(1); CauseStructure causeStructure = causeStructureRule.action(); assertThat("The returned cause type must be single", causeStructure.getCauseType(), is(CauseType.SINGLE)); }
RootCause rootCause = new RootCause(rootCauseInvocations.get().getMethodIdent(), rootCauseInvocations.get().getAggregatedDiagnosisTimerData()); ProblemOccurrence problem = new ProblemOccurrence(inputInvocationSequence, globalContext.get(), problemContext.get().getCommonContext(), rootCause, causeStructure.get().getCauseType(), causeStructure.get().getSourceType()); problems.add(problem);
@Test(expectedExceptions = IllegalArgumentException.class) public void expectedExceptionsIfTheCauseHasNoElements() { long methodIdentEqual = new Long(108); when(rootCause.getMethodIdent()).thenReturn(methodIdentEqual); when(rootCause.size()).thenReturn(0); CauseStructure causeStructure = causeStructureRule.action(); assert (causeStructure.getCauseType() == CauseType.SINGLE); }
@Test public void collectProblemInstances() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("Test", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(1)); }
@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(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionProblemContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, "Test", tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@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)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionGlobalContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, "Test", Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@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(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionRootCause() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, "Test", tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
assertThat("The returned cause type must be iterative", causeStructure.getCauseType(), is(CauseType.ITERATIVE));
assertThat("The returned cause type must be recursive", causeStructure.getCauseType(), is(CauseType.RECURSIVE));
assertThat("The returned cause type must be recursive", causeStructure.getCauseType(), is(CauseType.RECURSIVE));
assertThat("The returned cause type must be recursive", causeStructure.getCauseType(), is(CauseType.RECURSIVE));