@Test public void mapSimpleLeafs() { Tag rootTag = Tags.tag(Tags.ROOT_TAG, "root"); Tag tagA = Tags.tag("A", "inputA", rootTag); Tag tagB = Tags.tag("B", "inputB", rootTag); Tag tagC = Tags.tag("C", "inputC", tagB); Tag tagD = Tags.tag("D", "inputD", tagA); RuleOutput outputA = new RuleOutput("RuleA", "A", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagA)); RuleOutput outputB = new RuleOutput("RuleB", "B", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagB)); RuleOutput outputC = new RuleOutput("RuleC", "C", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagC)); RuleOutput outputD = new RuleOutput("RuleD", "D", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagD)); storage.store(Arrays.asList(outputA, outputB, outputC, outputD)); Multimap<String, Tag> tags = storage.mapTags(TagState.LEAF); assertThat(tags.size(), equalTo(2)); assertThat(tags.keySet(), hasSize(2)); assertThat(tags.get("A"), empty()); assertThat(tags.get("B"), empty()); assertThat(tags.get("C"), containsInAnyOrder(tagC)); assertThat(tags.get("D"), containsInAnyOrder(tagD)); }
@Test public void mapWithConditionFailuresLeafs() { Tag rootTag = Tags.tag(Tags.ROOT_TAG, "root"); Tag tagA = Tags.tag("A", "inputA", rootTag); Tag tagB = Tags.tag("B", "inputB", rootTag); Tags.tag("C", "inputC", tagB); ConditionFailure failure = new ConditionFailure("ConditionX", "SomeHint"); Tag tagD = Tags.tag("D", "inputD", tagA); RuleOutput outputA = new RuleOutput("RuleA", "A", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagA)); RuleOutput outputB = new RuleOutput("RuleB", "B", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagB)); RuleOutput outputC = new RuleOutput("RuleC", "C", Collections.singleton(failure), Collections.<Tag> emptySet()); RuleOutput outputD = new RuleOutput("RuleD", "D", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagD)); storage.store(Arrays.asList(outputA, outputB, outputC, outputD)); Multimap<String, Tag> tags = storage.mapTags(TagState.LEAF); assertThat(tags.size(), equalTo(1)); assertThat(tags.get("A"), empty()); assertThat(tags.get("B"), empty()); assertThat(tags.get("C"), empty()); assertThat(tags.get("D"), containsInAnyOrder(tagD)); } }
@Test public void mapMultiTagLeafs() { Tag rootTag = Tags.tag(Tags.ROOT_TAG, "root"); Tag tagA = Tags.tag("A", "inputA", rootTag); Tag tagB = Tags.tag("B", "inputB", rootTag); Tag tagC1 = Tags.tag("C", "inputC1", tagB); Tag tagC2 = Tags.tag("C", "inputC2", tagB); Tag tagD1 = Tags.tag("D", "inputD1", tagA); Tag tagD2 = Tags.tag("D", "inputD2", tagA); RuleOutput outputA = new RuleOutput("RuleA", "A", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagA)); RuleOutput outputB = new RuleOutput("RuleB", "B", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagB)); RuleOutput outputC = new RuleOutput("RuleC", "C", Collections.<ConditionFailure> emptySet(), Arrays.asList(tagC1, tagC2)); RuleOutput outputD1 = new RuleOutput("RuleD", "D", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagD1)); RuleOutput outputD2 = new RuleOutput("RuleD", "D", Collections.<ConditionFailure> emptySet(), Collections.singleton(tagD2)); storage.store(Arrays.asList(outputA, outputB, outputC, outputD1, outputD2)); Multimap<String, Tag> tags = storage.mapTags(TagState.LEAF); assertThat(tags.size(), equalTo(4)); assertThat(tags.keySet(), hasSize(2)); assertThat(tags.get("A"), empty()); assertThat(tags.get("B"), empty()); assertThat(tags.get("C"), containsInAnyOrder(tagC1, tagC2)); assertThat(tags.get("D"), containsInAnyOrder(tagD1, tagD2)); }
when(sessionContext.getInput()).thenReturn(input); when(storage.getAllOutputsWithConditionFailures()).thenReturn(outputMap); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap);
@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(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionCauseStructure() { 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, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, "Test", 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 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(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(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)); }