@Test public void debugLog() { List<DefaultData> dataList = new ArrayList<>(); TimerData timerData = new TimerData(); timerData.setPlatformIdent(1L); dataList.add(timerData); when(log.isDebugEnabled()).thenReturn(true); agentStorageService.addDataObjects(dataList); verify(log, times(2)).isDebugEnabled(); verify(log).debug(anyString()); verifyNoMoreInteractions(log); }
@Test public void noHttpData() { doReturn(new TimerData()).when(invocationSequenceData).getTimerData(); String[] values = valueSource.getStringValues(invocationSequenceData, cachedDataService); assertThat(values, is(notNullValue())); assertThat(values.length, is(equalTo(0))); } }
@Test public void noHttpData() { doReturn(new TimerData()).when(invocationSequenceData).getTimerData(); String[] values = valueSource.getStringValues(invocationSequenceData, cachedDataService); assertThat(values, is(notNullValue())); assertThat(values.length, is(equalTo(0))); } }
@Test public void writeTaskWriteNotAllowedByStorageManager() { when(storageManager.canWriteMore()).thenReturn(false); storageWriter.new WriteTask(new TimerData(), Collections.emptyMap()).run(); verifyZeroInteractions(storageIndexingTreeHandler, extendedByteBufferOutputStream, streamProvider, serializer, serializerQueue, writingChannelManager); }
@Test public void writeTaskNoSerializerAvailable() throws InterruptedException { TimerData timerData = new TimerData(); WriteTask writeTask = storageWriter.new WriteTask(timerData, Collections.emptyMap()); when(serializerQueue.take()).thenReturn(null); writeTask.run(); verify(storageIndexingTreeHandler, times(1)).writeFailed(writeTask); verifyZeroInteractions(writingChannelManager, streamProvider, extendedByteBufferOutputStream); }
/** * Tests is in collection restrictions. */ @Test public void isInCollectionFalse() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.isInCollection("id", Collections.singletonList(2L))); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(false)); }
/** * Test equal restriction. */ @Test public void equalsTrue() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.equal("id", 1L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(true)); }
/** * Test equal restriction. */ @Test public void equalsFalse() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.equal("id", 0L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(false)); }
/** * Test is null restriction. */ @Test public void isNull() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.isNull("id")); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(false)); }
/** * Test greater than restriction. */ @Test public void greaterThanZero() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.greaterThan("id", 0L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(true)); }
/** * Test less or equal restriction. */ @Test public void lessEqualTwo() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.lessEqual("id", 2L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(true)); }
/** * Test greater than restriction. */ @Test public void greaterThanOne() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.greaterThan("id", 1L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(false)); }
/** * Test greater than restriction. */ @Test public void greaterThanTwo() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.greaterThan("id", 2L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(false)); }
/** * Test greater or equal restriction. */ @Test public void greaterEqualZero() { TimerData timerData = new TimerData(); timerData.setId(1L); List<IIndexQueryRestriction> restrictions = Collections.singletonList(IndexQueryRestrictionFactory.greaterEqual("id", 0L)); boolean result = processor.areAllRestrictionsFulfilled(timerData, restrictions); assertThat(result, is(true)); }
@Test public void getExclusiveDurationMustReturnZeroIfTheExclusiveTimeIsNotAvailable() { InvocationSequenceData invocationData = new InvocationSequenceData(); TimerData timerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); invocationData.setTimerData(timerData); double exclusiveDuration = DiagnosisHelper.getExclusiveDuration(invocationData); assertThat("Exclusive duration must be 0.", exclusiveDuration, is(timerData.getExclusiveDuration())); }
@Test public void writeTaskExceptionDuringWrite() throws IOException { TimerData timerData = new TimerData(); WriteTask writeTask = storageWriter.new WriteTask(timerData, Collections.emptyMap()); doThrow(IOException.class).when(writingChannelManager).write(Matchers.<ExtendedByteBufferOutputStream> anyObject(), Matchers.<Path> anyObject(), Matchers.<WriteReadCompletionRunnable> anyObject()); writeTask.run(); verify(storageIndexingTreeHandler, times(1)).writeFailed(writeTask); verify(extendedByteBufferOutputStream, times(1)).close(); verify(serializerQueue, times(1)).add(serializer); }
@Test public void writeTaskThrowableDuringWrite() throws IOException { TimerData timerData = new TimerData(); WriteTask writeTask = storageWriter.new WriteTask(timerData, Collections.emptyMap()); doThrow(Throwable.class).when(writingChannelManager).write(Matchers.<ExtendedByteBufferOutputStream> anyObject(), Matchers.<Path> anyObject(), Matchers.<WriteReadCompletionRunnable> anyObject()); writeTask.run(); verify(storageIndexingTreeHandler, times(1)).writeFailed(writeTask); verify(extendedByteBufferOutputStream, times(1)).close(); verify(serializerQueue, times(1)).add(serializer); }
@Test private void musteReturnAnObjectWithALongStringIfTheTimerDataHasNotHttpTimerDataOrSqlData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); TimerData timerData = new TimerData(); invocationSequenceData.setTimerData(timerData); long aggregationKey = (long) DiagnosisDataAggregator.getInstance().getAggregationKey(invocationSequenceData); assertThat("The returned object must be the method ident of the invocationsequencedata", aggregationKey, is(invocationSequenceData.getMethodIdent())); } }
@Test private void musteReturnAnInstanceWithTimerDataSourceTypeDataIfTheTimerDataIsTimerData() { InvocationSequenceData invocationSequenceData = new InvocationSequenceData(new Timestamp(10L), 10L, 20L, 108L); TimerData timerData = new TimerData(); invocationSequenceData.setTimerData(timerData); AggregatedDiagnosisData aggregatedDiagnosisData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(invocationSequenceData); assertThat("The object must have TIMERDATA as source type", aggregatedDiagnosisData.getSourceType(), is(SourceType.TIMERDATA)); }
@Test public void getExclusiveDurationMustReturnTheExclusiveDurationOfTheTimerDataWhenItIsARegularTimerData() { InvocationSequenceData invocationData = new InvocationSequenceData(); TimerData timerData = new TimerData(new Timestamp(System.currentTimeMillis()), 10L, 20L, 30L); timerData.calculateExclusiveMin(300d); timerData.setExclusiveDuration(300d); invocationData.setTimerData(timerData); double exclusiveDuration = DiagnosisHelper.getExclusiveDuration(invocationData); assertThat("Exclusive duration must be 300.", exclusiveDuration, is(timerData.getExclusiveDuration())); }