1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.tests
.segmentstore
.statistics
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import java
.util
.Collections
;
20 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
.AbstractSegmentStatisticsAnalysis
;
23 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
.SegmentStoreStatistics
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
25 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.xml
.TmfXmlTraceStub
;
26 import org
.junit
.Test
;
28 import com
.google
.common
.collect
.ImmutableSet
;
31 * Test class to test the {@link AbstractSegmentStatisticsAnalysis} class
33 * @author Matthew Khouzam
35 public class AbstractStatsAnalysisTest
{
38 * Test execution with no trace
40 * @throws TmfAnalysisException
44 public void testExecuteNoTrace() throws TmfAnalysisException
{
45 StubSegmentStatisticsAnalysis fixture
= new StubSegmentStatisticsAnalysis();
46 assertFalse(fixture
.executeAnalysis(new NullProgressMonitor()));
50 * Test execution with no dependent analyses
52 * @throws TmfAnalysisException
56 public void testExecuteNoDepend() throws TmfAnalysisException
{
57 StubSegmentStatisticsAnalysis fixture
= new StubSegmentStatisticsAnalysis();
58 fixture
.setTrace(new TmfXmlTraceStub());
59 assertFalse(fixture
.executeAnalysis(new NullProgressMonitor()));
65 * @throws TmfAnalysisException
69 public void testExecute() throws TmfAnalysisException
{
70 StubSegmentStatisticsAnalysis fixture
= new StubSegmentStatisticsAnalysis();
71 TmfXmlTraceStub trace
= new TmfXmlTraceStub();
72 fixture
.setTrace(trace
);
73 fixture
.getDependentAnalyses();
74 assertTrue(fixture
.executeAnalysis(new NullProgressMonitor()));
78 * Test total statistics
80 * @throws TmfAnalysisException
85 public void testTotalStats() throws TmfAnalysisException
{
86 StubSegmentStatisticsAnalysis fixture
= getValidSegmentStats();
87 SegmentStoreStatistics totalStats
= fixture
.getTotalStats();
88 assertNotNull(totalStats
);
89 // no need to test the content much as it is tested in the other test.
90 assertEquals(StubSegmentStatisticsAnalysis
.SIZE
, totalStats
.getNbSegments());
94 * Test per-type statistics
96 * @throws TmfAnalysisException
101 public void testPerTypeStats() throws TmfAnalysisException
{
102 StubSegmentStatisticsAnalysis fixture
= getValidSegmentStats();
103 Map
<@NonNull String
, @NonNull SegmentStoreStatistics
> perTypeStats
= fixture
.getPerSegmentTypeStats();
104 assertNotNull(perTypeStats
);
105 // no need to test the content much as it is tested in the other test.
106 assertEquals(2, perTypeStats
.size());
107 assertEquals(ImmutableSet
.<String
> of("odd", "even"), perTypeStats
.keySet());
108 SegmentStoreStatistics segmentStoreStatistics
= perTypeStats
.get("even");
109 assertNotNull(segmentStoreStatistics
);
110 // starts with 0 so size + 1
111 assertEquals(StubSegmentStatisticsAnalysis
.SIZE
/ 2 + 1, segmentStoreStatistics
.getNbSegments());
115 * Test the partial statistics
117 * @throws TmfAnalysisException
122 public void testPartialStats() throws TmfAnalysisException
{
123 StubSegmentStatisticsAnalysis fixture
= getValidSegmentStats();
124 SegmentStoreStatistics totalStats
= fixture
.getTotalStatsForRange(100, 1100, new NullProgressMonitor());
125 assertNotNull(totalStats
);
126 // no need to test the content much as it is tested in the other test.
128 // 1051 = 1001 where start is between start and end + 50 overlapping
130 assertEquals(1051, totalStats
.getNbSegments());
134 * Test the partial per type statistic
136 * @throws TmfAnalysisException
141 public void testPartialPerTypeStats() throws TmfAnalysisException
{
142 StubSegmentStatisticsAnalysis fixture
= getValidSegmentStats();
143 Map
<@NonNull String
, @NonNull SegmentStoreStatistics
> perTypeStats
= fixture
.getPerSegmentTypeStatsForRange(100, 1100, new NullProgressMonitor());
144 assertNotNull(perTypeStats
);
145 // no need to test the content much as it is tested in the other test.
146 assertEquals(2, perTypeStats
.size());
147 assertEquals(ImmutableSet
.<String
> of("odd", "even"), perTypeStats
.keySet());
148 SegmentStoreStatistics segmentStoreStatistics
= perTypeStats
.get("even");
149 assertNotNull(segmentStoreStatistics
);
150 // 526 = 1051/2+1 = see explanation of 1051 in #testPartialStats
151 assertEquals(526, segmentStoreStatistics
.getNbSegments());
155 * Test the cancel operation
157 * @throws TmfAnalysisException
161 public void testPartialPerTypeStatsCancel() throws TmfAnalysisException
{
162 StubSegmentStatisticsAnalysis fixture
= getValidSegmentStats();
163 NullProgressMonitor monitor
= new NullProgressMonitor();
164 monitor
.setCanceled(true);
165 Map
<@NonNull String
, @NonNull SegmentStoreStatistics
> perTypeStats
= fixture
.getPerSegmentTypeStatsForRange(100, 1100, monitor
);
166 assertEquals(Collections
.emptyMap(), perTypeStats
);
169 private static StubSegmentStatisticsAnalysis
getValidSegmentStats() throws TmfAnalysisException
{
170 StubSegmentStatisticsAnalysis fixture
= new StubSegmentStatisticsAnalysis();
171 TmfXmlTraceStub trace
= new TmfXmlTraceStub();
172 fixture
.setTrace(trace
);
173 fixture
.getDependentAnalyses();
174 fixture
.executeAnalysis(new NullProgressMonitor());