/** * Returns the timestamp of this element. The time stamp will be gathered from the data object. * * @return the {@link Timestamp} of this element */ private Timestamp getTimeStamp() { if (dataElement instanceof Span) { return ((Span) dataElement).getTimeStamp(); } else if (dataElement instanceof InvocationSequenceData) { return ((InvocationSequenceData) dataElement).getTimeStamp(); } return null; }
@Test public void descendingTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(20)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(1)); }
@Test public void equalTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(0)); }
@Test public void ascendingTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(20)); int result = e1.compareTo(e2); assertThat(result, is(-1)); }
@Test public void secondTimeIsNull() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(mock(InvocationSequenceData.class)); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(1)); }
@Test public void firstTimeIsNull() { InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(mock(InvocationSequenceData.class)); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(-1)); } }
Optional<InvocationSequenceData> rootSequence = invocationSequences.stream().min((i1, i2) -> i1.getTimeStamp().compareTo(i2.getTimeStamp()));
/** * Test that get will work even when branch can not generate key for the element if ID is * correctly set. * * @throws IndexingException */ @Test public void getWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); when(invocation.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); IStorageDescriptor storageDescriptor = rootBranch.put(invocation); when(invocation.getTimeStamp()).thenReturn(null); // test get assertThat(rootBranch.get(invocation), is(equalTo(storageDescriptor))); // then get and remove assertThat(rootBranch.getAndRemove(invocation), is(equalTo(storageDescriptor))); // confirm it is removed assertThat(rootBranch.get(invocation), is(nullValue())); }
@Test public void noBusinessContext() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getBusinessTransactionForId(APP_ID, BT_ID)).thenReturn(null); double duration = RandomUtils.nextDouble(); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getApplicationId()).thenReturn(APP_ID); when(data.getBusinessTransactionId()).thenReturn(BT_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(duration); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.BusinessTransaction.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_APPLICATION_NAME, String.valueOf(ApplicationDefinition.UNKNOWN_APP))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_BUSINESS_TRANSACTION_NAME, String.valueOf(BusinessTransactionDefinition.UNKNOWN_BUSINESS_TX))); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_DURATION, (Object) duration)); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); when(cachedDataService.getBusinessTransactionForId(APP_ID, BT_ID)).thenReturn(businessTransactionData); when(businessTransactionData.getApplication()).thenReturn(applicationData); double duration = RandomUtils.nextDouble(); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getApplicationId()).thenReturn(APP_ID); when(data.getBusinessTransactionId()).thenReturn(BT_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(duration); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.BusinessTransaction.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), not(hasKey(Series.TAG_AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_APPLICATION_NAME, String.valueOf(APP_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_BUSINESS_TRANSACTION_NAME, String.valueOf(BT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_DURATION, (Object) duration)); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getBusinessTransactionForId(APP_ID, BT_ID)).thenReturn(businessTransactionData); when(businessTransactionData.getApplication()).thenReturn(applicationData); double duration = RandomUtils.nextDouble(); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getApplicationId()).thenReturn(APP_ID); when(data.getBusinessTransactionId()).thenReturn(BT_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(duration); when(data.getId()).thenReturn(Long.MAX_VALUE); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.BusinessTransaction.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_APPLICATION_NAME, String.valueOf(APP_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_BUSINESS_TRANSACTION_NAME, String.valueOf(BT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_DURATION, (Object) duration)); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_TRACE_ID, (Object) Long.MAX_VALUE)); }
root = root.getParentSequence(); long delta = data.getTimeStamp().getTime() - root.getTimeStamp().getTime(); return new StyledString(NumberFormatter.formatLong(delta)); case DURATION:
/** * 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; }
return new StyledString(NumberFormatter.formatTimeWithMillis(data.getTimeStamp())); case METHOD: return TextFormatter.getStyledMethodString(methodIdent);