use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class SegmentStoreFactoryTest method createPreloaded.
/**
* Create a pre-loaded fast segment store
*/
@Test
public void createPreloaded() {
ISegment[] data = new ISegment[1];
data[0] = new BasicSegment(0, 0);
ISegmentStore<@NonNull ISegment> segmentStore;
segmentStore = SegmentStoreFactory.createSegmentStore(data);
assertNotNull(segmentStore);
assertEquals(1, segmentStore.size());
segmentStore = SegmentStoreFactory.createSegmentStore(data, SegmentStoreType.Fast);
assertNotNull(segmentStore);
assertEquals(1, segmentStore.size());
segmentStore = SegmentStoreFactory.createSegmentStore(data, SegmentStoreType.Stable);
assertNotNull(segmentStore);
assertEquals(1, segmentStore.size());
segmentStore = SegmentStoreFactory.createSegmentStore(data, SegmentStoreType.Distinct);
assertNotNull(segmentStore);
assertEquals(1, segmentStore.size());
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class SegmentStoreFactoryTest method testDistinct.
private static void testDistinct(ISegmentStore<@NonNull ISegment> fixture) {
// test adding the same object
ISegment seg = new BasicSegment(0, 0);
fixture.add(seg);
fixture.add(seg);
assertEquals(1, fixture.size());
fixture.clear();
// test different equal objects
fixture.add(new BasicSegment(0, 0));
fixture.add(new BasicSegment(0, 0));
assertEquals(1, fixture.size());
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class INamedSegmentTest method testComparator.
/**
* Test the {@link SegmentTypeComparators#NAMED_SEGMENT_COMPARATOR}
* comparator
*/
@Test
public void testComparator() {
Comparator<ISegment> cmp = SegmentTypeComparators.NAMED_SEGMENT_COMPARATOR;
// Verify the comparator with the segments
assertEquals(cmp.compare(NAMED_SEGMENT2, NAMED_SEGMENT3), cmp.compare(NAMED_SEGMENT3, NAMED_SEGMENT2));
assertTrue(cmp.compare(NAMED_SEGMENT1, NAMED_SEGMENT2) > 0);
assertEquals(cmp.compare(NAMED_SEGMENT1, NAMED_SEGMENT2), -1 * cmp.compare(NAMED_SEGMENT2, NAMED_SEGMENT1));
assertTrue(cmp.compare(BASE_SEGMENT, NAMED_SEGMENT2) > 0);
assertTrue(cmp.compare(NAMED_SEGMENT2, BASE_SEGMENT) < 0);
assertTrue(cmp.compare(BASE_SEGMENT, NAMED_SEGMENT4) > 0);
assertTrue(cmp.compare(NAMED_SEGMENT4, BASE_SEGMENT) < 0);
// Add the segments to a segment store
ISegmentStore<BasicSegment> segStore = SegmentStoreFactory.createSegmentStore(SegmentStoreType.Fast);
segStore.add(BASE_SEGMENT);
segStore.add(NAMED_SEGMENT1);
segStore.add(NAMED_SEGMENT2);
segStore.add(NAMED_SEGMENT3);
segStore.add(NAMED_SEGMENT4);
// Iterate with this comparator on the segment store
Iterable<BasicSegment> iterable = segStore.iterator(cmp);
Iterator<BasicSegment> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
BasicSegment current = iterator.next();
BasicSegment prev = current;
int count = 1;
while (iterator.hasNext()) {
current = iterator.next();
assertTrue(cmp.compare(prev, current) <= 0);
prev = current;
count++;
}
assertEquals(5, count);
// Iterate with the reverse comparator
iterable = segStore.iterator(NonNullUtils.checkNotNull(cmp.reversed()));
iterator = iterable.iterator();
assertTrue(iterator.hasNext());
current = iterator.next();
prev = current;
count = 1;
while (iterator.hasNext()) {
current = iterator.next();
assertTrue(cmp.compare(prev, current) >= 0);
prev = current;
count++;
}
assertEquals(5, count);
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testTotalStats.
/**
* Test total statistics
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testTotalStats() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
IStatistics<@NonNull ISegment> totalStats = fixture.getStatsTotal();
assertNotNull(totalStats);
// no need to test the content much as it is tested in the other test.
assertEquals(StubSegmentStatisticsAnalysis.SIZE, totalStats.getNbElements());
trace.dispose();
fixture.dispose();
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testPartialPerTypeStats.
/**
* Test the partial per type statistic
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testPartialPerTypeStats() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
Map<@NonNull String, IStatistics<@NonNull ISegment>> perTypeStats = fixture.getStatsPerTypeForRange(100, 1100, new NullProgressMonitor());
assertNotNull(perTypeStats);
// no need to test the content much as it is tested in the other test.
assertEquals(2, perTypeStats.size());
assertEquals(ImmutableSet.<String>of("odd", "even"), perTypeStats.keySet());
IStatistics<@NonNull ISegment> segmentStoreStatistics = perTypeStats.get("even");
assertNotNull(segmentStoreStatistics);
// 526 = 1051/2+1 = see explanation of 1051 in #testPartialStats
assertEquals(526, segmentStoreStatistics.getNbElements());
trace.dispose();
fixture.dispose();
}
Aggregations