/** * {@inheritDoc} */ @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { InvocationTreeElement input = validateInput(newInput); if (input == null) { return; } lookupMap = InvocationTreeUtil.buildLookupMap(input); rootElement = InvocationTreeUtil.getRoot(input); }
@Test public void useNullValue() { Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(lookupMap, null); assertThat(treeElement, is(nullValue())); }
@Test public void successfulInTree() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span03); InvocationTreeElement root = InvocationTreeUtil.getRoot(treeElement); assertThat(root, is(tree)); }
@Test public void successful02() { Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(lookupMap, span01); assertThat(treeElement.getDataElement(), is(span01)); assertThat(treeElement, is(tree)); }
@Test public void successfulOfAsync() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span03); double duration = InvocationTreeUtil.calculateSpanExclusivePercentage(treeElement); assertThat(duration, is(0.2D)); }
@Test public void parentIsNotSpan() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), _invoc02); boolean result = InvocationTreeUtil.isChildOfSpan(treeElement); assertThat(result, is(false)); }
@Test public void successfulInTree() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span02); double duration = InvocationTreeUtil.calculateSpanExclusiveDuration(treeElement); assertThat(duration, is(100D)); }
@Test public void successful01() { Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(lookupMap, _invoc02); assertThat(treeElement.getDataElement(), is(_invoc02)); }
@Test public void successfulInTree() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span02); double duration = InvocationTreeUtil.calculateSpanExclusivePercentage(treeElement); assertThat(duration, is(closeTo(0.384D, 0.001))); }
@Test public void buildWithNestedExceptions() { Span span01 = createServerSpan(null); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(null); invoc01.getNestedSequences().add(_invoc02); invoc01.setNestedExceptions(true); doReturn(Arrays.asList(span01)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(3)); assertThat(tree.hasNestedExceptions(), is(true)); assertThat(tree.hasNestedSqls(), is(false)); }
@Test public void buildOneInvocationSequenceWithSpanWithoutSpanService() { Span span01 = createServerSpan(null); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(null); invoc01.getNestedSequences().add(_invoc02); builder.setMode(Mode.SINGLE).setInvocationSequence(invoc01); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(3)); assertThat(tree.getDataElement(), isA((Class) SpanIdent.class)); assertThat(tree.getChildren(), contains(hasProperty("dataElement", is(invoc01)))); verifyZeroInteractions(spanService, invocationService); }
@Test public void buildWithNestedSQLs() { Span span01 = createServerSpan(null); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(null); invoc01.getNestedSequences().add(_invoc02); invoc01.setNestedSqlStatements(true); doReturn(Arrays.asList(span01)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(3)); assertThat(tree.hasNestedExceptions(), is(false)); assertThat(tree.hasNestedSqls(), is(true)); } }
@Test public void buildTraceWithoutSdkSpans() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); Span span03 = createSdkSpan(span01); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(span02); invoc01.getNestedSequences().add(_invoc02); doReturn(Arrays.asList(span01, span02, span03)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(4)); assertThat(tree.getDataElement(), is(span01)); for (Object data : new Object[] { span01, span02, invoc01, _invoc02 }) { assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, data), is(not(nullValue()))); } assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, span03), is(nullValue())); verify(spanService).getSpans(1337L); verify(invocationService).getInvocationSequenceDetail(1337L); verifyNoMoreInteractions(spanService, invocationService); }
@Test public void buildOneInvocationSequenceWithSpan() { Span span01 = createServerSpan(null); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(null); invoc01.getNestedSequences().add(_invoc02); doReturn(span01).when(spanService).get(span01.getSpanIdent()); builder.setSpanService(spanService).setMode(Mode.SINGLE).setInvocationSequence(invoc01); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(3)); assertThat(tree.getDataElement(), is(span01)); assertThat(tree.getChildren(), contains(hasProperty("dataElement", is(invoc01)))); verify(spanService).get(span01.getSpanIdent()); verifyNoMoreInteractions(spanService); verifyZeroInteractions(invocationService); }
@Test public void buildOneInvocationSequence() { InvocationSequenceData invoc01 = createSequence(null); InvocationSequenceData _invoc02 = createSequence(null); InvocationSequenceData _invoc03 = createSequence(null); InvocationSequenceData _invoc04 = createSequence(null); invoc01.getNestedSequences().add(_invoc02); _invoc02.getNestedSequences().add(_invoc03); invoc01.getNestedSequences().add(_invoc04); builder.setMode(Mode.SINGLE).setInvocationSequence(invoc01); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(4)); assertThat(tree.getDataElement(), is(invoc01)); assertThat(tree.getChildren(), contains(hasProperty("dataElement", is(_invoc02)), hasProperty("dataElement", is(_invoc04)))); assertThat(tree.getChildren().get(0).getChildren(), contains(hasProperty("dataElement", is(_invoc03)))); assertThat(tree.getChildren().get(1).getChildren(), is(empty())); verifyZeroInteractions(spanService, invocationService); }
@Test public void buildTraceManyMissingSpans() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); Span span03 = createClientSpan(span01); Span span04 = createServerSpan(span01); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(span02); InvocationSequenceData _invoc03 = createSequence(span03); InvocationSequenceData _invoc04 = createSequence(span04); invoc01.getNestedSequences().addAll(Arrays.asList(_invoc02, _invoc03, _invoc04)); doReturn(Arrays.asList(span01)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(8)); assertThat(tree.getDataElement(), is(span01)); for (Object data : new Object[] { span01, span02, span03, span04, invoc01, _invoc02, _invoc03, _invoc04 }) { assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, data), is(not(nullValue()))); } verify(spanService).getSpans(1337L); verify(invocationService).getInvocationSequenceDetail(1337L); verifyNoMoreInteractions(spanService, invocationService); }
@Test public void buildTraceWithMissingInvocationSequence() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); Span span03 = createClientSpan(span02); Span span04 = createServerSpan(span03); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(span02); InvocationSequenceData invoc03 = createSequence(span02); InvocationSequenceData _invoc04 = createSequence(span03); invoc01.getNestedSequences().add(_invoc02); invoc03.getNestedSequences().add(_invoc04); doReturn(Arrays.asList(span01, span02, span03, span04)).when(spanService).getSpans(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(4)); assertThat(tree.getDataElement(), is(span01)); assertThat(tree.getChildren(), contains(hasProperty("dataElement", is(span02)))); assertThat(tree.getChildren().get(0).getChildren(), contains(hasProperty("dataElement", is(span03)))); assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren(), contains(hasProperty("dataElement", is(span04)))); assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren(), is(empty())); verify(spanService).getSpans(1337L); verify(invocationService).getInvocationSequenceDetail(1337L); verifyNoMoreInteractions(spanService, invocationService); }
@Test public void buildTrace() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); Span span03 = createClientSpan(span02); Span span04 = createServerSpan(span03); InvocationSequenceData invoc01 = createSequence(span01); InvocationSequenceData _invoc02 = createSequence(span02); InvocationSequenceData invoc03 = createSequence(span02); InvocationSequenceData _invoc04 = createSequence(span03); invoc01.getNestedSequences().add(_invoc02); invoc03.getNestedSequences().add(_invoc04); doReturn(Arrays.asList(span01, span02, span03, span04)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01, invoc03)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(8)); assertThat(tree.getDataElement(), is(span01)); for (Object data : new Object[] { span01, span02, span03, span04, invoc01, _invoc02, invoc03, _invoc04 }) { assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, data), is(not(nullValue()))); } verify(spanService).getSpans(1337L); verify(invocationService).getInvocationSequenceDetail(1337L); verifyNoMoreInteractions(spanService, invocationService); }
Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(4)); assertThat(tree.getDataElement(), is(span02));
@Test(invocationCount = 5) public void buildWideTreeShuffeledSpanProvision() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); InvocationSequenceData invoc03 = createSequence(span01); // between span02 and span03 Span span03 = createClientSpan(span01); Span span04 = createServerSpan(span03); InvocationSequenceData invoc01 = createSequence(span02); InvocationSequenceData invoc02 = createSequence(span04); List<Span> list = Arrays.asList(span01, span02, span03, span04); Collections.shuffle(list); doReturn(list).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01, invoc02, invoc03)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(7)); assertThat(tree.getDataElement(), is(span01)); assertThat(tree.getChildren(), contains(hasProperty("dataElement", is(span02)), hasProperty("dataElement", is(invoc03)), hasProperty("dataElement", is(span03)))); assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, span02).getChildren(), contains(hasProperty("dataElement", is(invoc01)))); assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, span03).getChildren(), contains(hasProperty("dataElement", is(span04)))); assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, span04).getChildren(), contains(hasProperty("dataElement", is(invoc02)))); verify(spanService).getSpans(1337L); verify(invocationService).getInvocationSequenceDetail(1337L); verifyNoMoreInteractions(spanService, invocationService); }