/** * {@inheritDoc} */ @Override public boolean hasChildren(Object element) { InvocationTreeElement ite = InvocationTreeUtil.lookupTreeElement(lookupMap, element); if (ite == null) { return false; } return ite.hasChildren(); }
/** * {@inheritDoc} */ @Override public Object[] getChildren(Object inputElement) { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(lookupMap, inputElement); List<Object> objects = new ArrayList<>(); for (InvocationTreeElement its : treeElement.getChildren()) { objects.add(its.getDataElement()); } return objects.toArray(); }
@Test public void nullLookupMap() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(null, span01); assertThat(treeElement, is(nullValue())); } }
@Test public void useNullValue() { Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(lookupMap, null); assertThat(treeElement, is(nullValue())); }
/** * {@inheritDoc} */ @Override public Object getParent(Object element) { InvocationTreeElement ite = InvocationTreeUtil.lookupTreeElement(lookupMap, element); if ((ite == null) || (ite.getParent() == null)) { return null; } else { return ite.getParent().getDataElement(); } }
@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 successfulInTree() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span03); InvocationTreeElement root = InvocationTreeUtil.getRoot(treeElement); assertThat(root, 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 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(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); }
@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 buildTraceOnlySpans() { Span span01 = createServerSpan(null); Span span02 = createServerSpan(span01); Span span03 = createClientSpan(span02); Span span04 = createServerSpan(span03); Span span05 = createSdkSpan(span02); 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, span05)).when(spanService).getSpans(1337L); doReturn(Arrays.asList(invoc01, invoc03)).when(invocationService).getInvocationSequenceDetail(1337L); builder.setSpanService(spanService).setInvocationService(invocationService).setTraceId(1337L).setMode(Mode.ONLY_SPANS_WITH_SDK); InvocationTreeElement tree = builder.build(); Map<Object, InvocationTreeElement> lookupMap = InvocationTreeUtil.buildLookupMap(tree); assertThat(lookupMap.size(), is(5)); assertThat(tree.getDataElement(), is(span01)); for (Object data : new Object[] { span01, span02, span03, span04, span05 }) { assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, data), is(not(nullValue()))); } for (Object data : new Object[] { invoc01, _invoc02, invoc03, _invoc04 }) { assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, data), is(nullValue())); } 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); }
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren(), contains(hasProperty("dataElement", is(span03)))); assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren(), is(empty())); assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, _invoc02), is(nullValue())); assertThat(InvocationTreeUtil.lookupTreeElement(lookupMap, span04), is(nullValue())); verify(spanService).get(span02.getSpanIdent()); verify(spanService).get(span03.getSpanIdent());
InvocationTreeElement ite = InvocationTreeUtil.lookupTreeElement(contentProvider.getLookupMap(), span);