Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2009, 2014 Ericsson |
20658947 | 3 | * |
d18dd09b ASL |
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 | |
20658947 | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
20658947 | 11 | * Francois Chouinard - Adapted for TMF Trace Model 1.0 |
6e1886bc | 12 | * Alexandre Montplaisir - Port to JUnit4 |
d18dd09b ASL |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.core.tests.trace; |
d18dd09b | 16 | |
6e1886bc AM |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertFalse; | |
ff3f02c8 | 19 | import static org.junit.Assert.assertNotNull; |
6e1886bc AM |
20 | import static org.junit.Assert.assertNull; |
21 | import static org.junit.Assert.assertTrue; | |
22 | import static org.junit.Assert.fail; | |
23 | ||
d18dd09b | 24 | import java.io.File; |
e1ab8984 FC |
25 | import java.io.IOException; |
26 | import java.net.URISyntaxException; | |
27 | import java.net.URL; | |
d18dd09b ASL |
28 | import java.util.Vector; |
29 | ||
e1ab8984 FC |
30 | import org.eclipse.core.runtime.FileLocator; |
31 | import org.eclipse.core.runtime.Path; | |
2bdf0193 AM |
32 | import org.eclipse.tracecompass.internal.tmf.core.component.TmfProviderManager; |
33 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; | |
34 | import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider; | |
35 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
36 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
2bdf0193 | 37 | import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType; |
b8585c7c | 38 | import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest; |
2bdf0193 AM |
39 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; |
40 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
41 | import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin; | |
42 | import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace; | |
43 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
44 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
45 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
46 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
47 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
48 | import org.eclipse.tracecompass.tmf.core.trace.TmfContext; | |
49 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; | |
50 | import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis; | |
51 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; | |
6e1886bc AM |
52 | import org.junit.After; |
53 | import org.junit.Before; | |
8a6ff07f | 54 | import org.junit.Rule; |
6e1886bc | 55 | import org.junit.Test; |
8a6ff07f GB |
56 | import org.junit.rules.TestRule; |
57 | import org.junit.rules.Timeout; | |
d18dd09b ASL |
58 | |
59 | /** | |
ff4ed569 | 60 | * Test suite for the TmfTrace class. |
d18dd09b | 61 | */ |
cad06250 | 62 | @SuppressWarnings("javadoc") |
6e1886bc | 63 | public class TmfTraceTest { |
d18dd09b | 64 | |
8a6ff07f GB |
65 | /** Time-out tests after 20 seconds */ |
66 | @Rule | |
67 | public TestRule globalTimeout= new Timeout(20000); | |
68 | ||
f17b2f70 FC |
69 | // ------------------------------------------------------------------------ |
70 | // Variables | |
71 | // ------------------------------------------------------------------------ | |
6e1886bc | 72 | |
9c4d52ee | 73 | private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K; |
66262ad8 | 74 | private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec |
e31e01e8 | 75 | private static final int NB_EVENTS = 10000; |
8a6ff07f | 76 | private TmfTraceStub fTrace = null; |
d18dd09b | 77 | |
20658947 | 78 | private static int SCALE = -3; |
d18dd09b | 79 | |
e31e01e8 | 80 | // ------------------------------------------------------------------------ |
d18dd09b | 81 | // Housekeeping |
e31e01e8 | 82 | // ------------------------------------------------------------------------ |
d18dd09b | 83 | |
6e1886bc AM |
84 | @Before |
85 | public void setUp() { | |
8a6ff07f GB |
86 | try { |
87 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); | |
88 | final File test = new File(FileLocator.toFileURL(location).toURI()); | |
89 | fTrace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); | |
90 | TmfSignalManager.deregister(fTrace); | |
91 | fTrace.indexTrace(true); | |
92 | } catch (final TmfTraceException e) { | |
93 | e.printStackTrace(); | |
94 | } catch (final URISyntaxException e) { | |
95 | e.printStackTrace(); | |
96 | } catch (final IOException e) { | |
97 | e.printStackTrace(); | |
98 | } | |
f17b2f70 FC |
99 | } |
100 | ||
6e1886bc AM |
101 | @After |
102 | public void tearDown() { | |
f17b2f70 FC |
103 | fTrace.dispose(); |
104 | fTrace = null; | |
105 | } | |
ff4ed569 | 106 | |
e31e01e8 | 107 | // ------------------------------------------------------------------------ |
d18dd09b | 108 | // Constructors |
e31e01e8 | 109 | // ------------------------------------------------------------------------ |
d18dd09b | 110 | |
6e1886bc | 111 | @Test |
7886b91f | 112 | public void testFullConstructor() throws TmfTraceException { |
f17b2f70 | 113 | try { |
9c4d52ee | 114 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 | 115 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 116 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); |
51e75066 | 117 | trace.indexTrace(true); |
631d2ce9 AM |
118 | |
119 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
120 | assertNull("getResource", trace.getResource()); | |
121 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
122 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); | |
123 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 124 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
125 | |
126 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
127 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
128 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
129 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
130 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
131 | ||
f17b2f70 FC |
132 | } catch (final URISyntaxException e) { |
133 | fail("URISyntaxException"); | |
134 | } catch (final IOException e) { | |
135 | fail("IOException"); | |
136 | } | |
ff4ed569 FC |
137 | } |
138 | ||
6e1886bc | 139 | @Test |
54a7a54c | 140 | public void testLiveTraceConstructor() throws TmfTraceException { |
1703b536 FC |
141 | final long interval = 100; |
142 | try { | |
9c4d52ee | 143 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 | 144 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
7886b91f | 145 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, interval); |
51e75066 | 146 | trace.indexTrace(true); |
631d2ce9 AM |
147 | |
148 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
149 | assertNull("getResource", trace.getResource()); | |
150 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
7886b91f | 151 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
631d2ce9 | 152 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); |
9c4d52ee | 153 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
154 | |
155 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
156 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
157 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
158 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
159 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
160 | ||
1703b536 FC |
161 | } catch (final URISyntaxException e) { |
162 | fail("URISyntaxException"); | |
163 | } catch (final IOException e) { | |
164 | fail("IOException"); | |
165 | } | |
1703b536 FC |
166 | } |
167 | ||
6e1886bc | 168 | @Test |
54a7a54c | 169 | public void testCopyConstructor() throws TmfTraceException { |
20658947 | 170 | try { |
9c4d52ee | 171 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 | 172 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 173 | TmfTraceStub original = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); |
631d2ce9 | 174 | TmfTraceStub trace = new TmfTraceStub(original); |
51e75066 | 175 | trace.indexTrace(true); |
631d2ce9 AM |
176 | |
177 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
178 | assertNull("getResource", trace.getResource()); | |
179 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
7886b91f | 180 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
631d2ce9 | 181 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
9c4d52ee | 182 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
183 | |
184 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
185 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
186 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
187 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
188 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
189 | ||
f17b2f70 FC |
190 | } catch (final URISyntaxException e) { |
191 | fail("URISyntaxException"); | |
192 | } catch (final IOException e) { | |
193 | fail("IOException"); | |
194 | } | |
20658947 | 195 | |
20658947 FC |
196 | // Test the copy of a null trace |
197 | try { | |
198 | new TmfTraceStub((TmfTraceStub) null); | |
199 | fail("Missing exception"); | |
200 | } catch (final IllegalArgumentException e) { | |
201 | // test passed | |
202 | } catch (final Exception e) { | |
203 | fail("Unexpected exception"); | |
204 | } | |
d18dd09b ASL |
205 | } |
206 | ||
20658947 | 207 | // ------------------------------------------------------------------------ |
1703b536 | 208 | // Trace initialization |
20658947 FC |
209 | // ------------------------------------------------------------------------ |
210 | ||
6e1886bc | 211 | @Test |
54a7a54c | 212 | public void testInitializeNullPath() { |
1703b536 FC |
213 | // Instantiate an "empty" trace |
214 | final TmfTraceStub trace = new TmfTraceStub(); | |
20658947 | 215 | |
1703b536 | 216 | try { |
2771b032 | 217 | trace.initialize(null, null, ITmfEvent.class); |
1703b536 | 218 | fail("TmfTrace.initialize() - no exception thrown"); |
b4f71e4a | 219 | } catch (TmfTraceException e) { |
1703b536 FC |
220 | // Success |
221 | } catch (Exception e) { | |
222 | fail("TmfTrace.initialize() - wrong exception thrown"); | |
223 | } | |
ff4ed569 | 224 | } |
54a7a54c | 225 | |
6e1886bc | 226 | @Test |
54a7a54c | 227 | public void testInitializeSimplePath() { |
1703b536 FC |
228 | // Instantiate an "empty" trace |
229 | final TmfTraceStub trace = new TmfTraceStub(); | |
230 | ||
231 | // Path == trace name | |
232 | String path = "TraceName"; | |
233 | try { | |
2771b032 | 234 | trace.initialize(null, path, ITmfEvent.class); |
1703b536 FC |
235 | } catch (Exception e) { |
236 | fail("TmfTrace.initialize() - Exception thrown"); | |
237 | } | |
9b749023 | 238 | |
2771b032 | 239 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
1703b536 FC |
240 | assertNull ("getResource", trace.getResource()); |
241 | assertEquals("getPath", path, trace.getPath()); | |
0316808c | 242 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
1703b536 FC |
243 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
244 | assertEquals("getName", path, trace.getName()); | |
245 | ||
246 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 247 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
1703b536 | 248 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 249 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
1703b536 FC |
250 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
251 | } | |
252 | ||
6e1886bc | 253 | @Test |
54a7a54c | 254 | public void testInitializeNormalPath() { |
1703b536 FC |
255 | // Instantiate an "empty" trace |
256 | final TmfTraceStub trace = new TmfTraceStub(); | |
257 | ||
258 | // Path == trace name | |
259 | String name = "TraceName"; | |
260 | String path = "/my/trace/path/" + name; | |
261 | try { | |
2771b032 | 262 | trace.initialize(null, path, ITmfEvent.class); |
1703b536 FC |
263 | } catch (Exception e) { |
264 | fail("TmfTrace.initialize() - Exception thrown"); | |
265 | } | |
9b749023 | 266 | |
2771b032 | 267 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
1703b536 FC |
268 | assertNull ("getResource", trace.getResource()); |
269 | assertEquals("getPath", path, trace.getPath()); | |
0316808c | 270 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
1703b536 FC |
271 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
272 | assertEquals("getName", name, trace.getName()); | |
273 | ||
274 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 275 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
1703b536 | 276 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 277 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
1703b536 FC |
278 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
279 | } | |
20658947 | 280 | |
6e1886bc | 281 | @Test |
54a7a54c | 282 | public void testInitTrace() throws URISyntaxException, IOException, TmfTraceException, InterruptedException { |
20658947 FC |
283 | // Instantiate an "empty" trace |
284 | final TmfTraceStub trace = new TmfTraceStub(); | |
285 | ||
20658947 FC |
286 | assertNull ("getType", trace.getType()); |
287 | assertNull ("getResource", trace.getResource()); | |
0316808c | 288 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
20658947 FC |
289 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
290 | assertEquals("getName", "", trace.getName()); | |
291 | ||
292 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 293 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
20658947 | 294 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 295 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
20658947 FC |
296 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
297 | ||
298 | // Validate | |
9c4d52ee | 299 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
20658947 | 300 | final File testfile = new File(FileLocator.toFileURL(location).toURI()); |
a94410d9 | 301 | assertTrue("validate", trace.validate(null, testfile.getPath()).isOK()); |
20658947 FC |
302 | |
303 | // InitTrace and wait for indexing completion... | |
2771b032 | 304 | trace.initTrace(null, testfile.toURI().getPath(), ITmfEvent.class); |
51e75066 | 305 | trace.indexTrace(true); |
20658947 FC |
306 | int nbSecs = 0; |
307 | while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) { | |
308 | Thread.sleep(1000); | |
309 | nbSecs++; | |
310 | } | |
311 | if (trace.getNbEvents() < NB_EVENTS) { | |
312 | fail("indexing"); | |
313 | } | |
314 | ||
2771b032 | 315 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
20658947 | 316 | assertNull ("getResource", trace.getResource()); |
0316808c | 317 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
20658947 | 318 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
9c4d52ee | 319 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
20658947 FC |
320 | |
321 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
322 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
323 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
324 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
325 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
326 | } | |
d18dd09b | 327 | |
ff4ed569 | 328 | // ------------------------------------------------------------------------ |
1703b536 FC |
329 | // Set/Get streaming interval |
330 | // ------------------------------------------------------------------------ | |
331 | ||
6e1886bc | 332 | @Test |
54a7a54c | 333 | public void testSetStreamingInterval() throws TmfTraceException { |
1703b536 FC |
334 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
335 | ||
336 | long interval = 0; | |
337 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
338 | ||
339 | interval = 100; | |
340 | trace.setStreamingInterval(interval); | |
341 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
54a7a54c | 342 | |
1703b536 FC |
343 | interval = -1; |
344 | trace.setStreamingInterval(interval); | |
345 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
54a7a54c | 346 | |
1703b536 FC |
347 | interval = 0; |
348 | trace.setStreamingInterval(interval); | |
349 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
54a7a54c | 350 | |
1703b536 FC |
351 | trace.dispose(); |
352 | } | |
353 | ||
354 | // ------------------------------------------------------------------------ | |
355 | // Set/Get time range | |
ff4ed569 FC |
356 | // ------------------------------------------------------------------------ |
357 | ||
6e1886bc | 358 | @Test |
54a7a54c | 359 | public void testSetTimeRange() throws TmfTraceException { |
f17b2f70 | 360 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 361 | trace.indexTrace(true); |
f17b2f70 | 362 | |
ff4ed569 FC |
363 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
364 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
365 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
366 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
367 | ||
368 | trace.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200))); | |
369 | assertEquals("setTimeRange", 100, trace.getTimeRange().getStartTime().getValue()); | |
370 | assertEquals("setTimeRange", 200, trace.getTimeRange().getEndTime().getValue()); | |
371 | assertEquals("setTimeRange", 100, trace.getStartTime().getValue()); | |
372 | assertEquals("setTimeRange", 200, trace.getEndTime().getValue()); | |
f17b2f70 FC |
373 | |
374 | trace.dispose(); | |
ff4ed569 | 375 | } |
f17b2f70 | 376 | |
6e1886bc | 377 | @Test |
54a7a54c | 378 | public void testSetStartTime() throws TmfTraceException { |
f17b2f70 | 379 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 380 | trace.indexTrace(true); |
f17b2f70 | 381 | |
ff4ed569 FC |
382 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
383 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
384 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
385 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
386 | ||
387 | trace.setStartTime(new TmfTimestamp(100)); | |
388 | assertEquals("setStartTime", 100, trace.getTimeRange().getStartTime().getValue()); | |
389 | assertEquals("setStartTime", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
390 | assertEquals("setStartTime", 100, trace.getStartTime().getValue()); | |
391 | assertEquals("setStartTime", NB_EVENTS, trace.getEndTime().getValue()); | |
f17b2f70 FC |
392 | |
393 | trace.dispose(); | |
ff4ed569 | 394 | } |
f17b2f70 | 395 | |
6e1886bc | 396 | @Test |
54a7a54c | 397 | public void testSetEndTime() throws TmfTraceException { |
f17b2f70 | 398 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 399 | trace.indexTrace(true); |
f17b2f70 | 400 | |
ff4ed569 FC |
401 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
402 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
403 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
404 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
405 | ||
406 | trace.setEndTime(new TmfTimestamp(100)); | |
407 | assertEquals("setEndTime", 1, trace.getTimeRange().getStartTime().getValue()); | |
408 | assertEquals("setEndTime", 100, trace.getTimeRange().getEndTime().getValue()); | |
409 | assertEquals("setEndTime", 1, trace.getStartTime().getValue()); | |
410 | assertEquals("setEndTime", 100, trace.getEndTime().getValue()); | |
f17b2f70 FC |
411 | |
412 | trace.dispose(); | |
ff4ed569 | 413 | } |
f17b2f70 | 414 | |
6e1886bc | 415 | @Test |
54a7a54c | 416 | public void testSetNbEvents() throws TmfTraceException { |
b75d6b65 | 417 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 418 | trace.indexTrace(true); |
b75d6b65 FC |
419 | |
420 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
421 | ||
422 | trace.setNbEvents(0); | |
423 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
424 | ||
425 | trace.setNbEvents(-1); | |
426 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
427 | ||
428 | trace.setNbEvents(NB_EVENTS + 1); | |
429 | assertEquals("getNbEvents", NB_EVENTS + 1, trace.getNbEvents()); | |
430 | ||
431 | trace.setNbEvents(NB_EVENTS); | |
432 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
433 | ||
434 | trace.dispose(); | |
435 | } | |
436 | ||
a51b2b9f | 437 | // ------------------------------------------------------------------------ |
8a6ff07f | 438 | // State system, statistics and modules methods |
a51b2b9f AM |
439 | // ------------------------------------------------------------------------ |
440 | ||
6e1886bc | 441 | @Test |
b8585c7c | 442 | public void testGetModules() { |
8a6ff07f | 443 | /* There should not be any modules at this point */ |
ff3f02c8 AM |
444 | Iterable<IAnalysisModule> modules = fTrace.getAnalysisModules(); |
445 | assertFalse(modules.iterator().hasNext()); | |
8a6ff07f GB |
446 | |
447 | /* Open the trace, the modules should be populated */ | |
448 | fTrace.traceOpened(new TmfTraceOpenedSignal(this, fTrace, null)); | |
449 | ||
450 | modules = fTrace.getAnalysisModules(); | |
ff3f02c8 | 451 | assertTrue(modules.iterator().hasNext()); |
8a6ff07f | 452 | |
91e7f946 AM |
453 | /* |
454 | * Make sure all modules of type TestAnalysis are returned in the second | |
455 | * call | |
456 | */ | |
b8585c7c | 457 | int count = 0; |
ff3f02c8 AM |
458 | for (IAnalysisModule module : modules) { |
459 | if (module instanceof TestAnalysis) { | |
b8585c7c | 460 | count++; |
ff3f02c8 AM |
461 | IAnalysisModule otherModule = fTrace.getAnalysisModule(module.getId()); |
462 | assertNotNull(otherModule); | |
b8585c7c | 463 | assertEquals(otherModule, module); |
8a6ff07f GB |
464 | } |
465 | } | |
b8585c7c AM |
466 | /* |
467 | * FIXME: The exact count depends on the context the test is run (full | |
468 | * test suite or this file only), but there must be at least 2 modules | |
469 | */ | |
470 | assertTrue(count >= 2); | |
a51b2b9f AM |
471 | } |
472 | ||
e31e01e8 | 473 | // ------------------------------------------------------------------------ |
7e6347b0 FC |
474 | // seekEvent on location (note: does not reliably set the rank) |
475 | // ------------------------------------------------------------------------ | |
476 | ||
6e1886bc | 477 | @Test |
54a7a54c | 478 | public void testSeekEventOnCacheBoundary() { |
7e6347b0 FC |
479 | // Position trace at event rank 0 |
480 | ITmfContext context = fTrace.seekEvent(0); | |
481 | ITmfEvent event = fTrace.parseEvent(context); | |
482 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
483 | assertEquals("Event rank", 0, context.getRank()); | |
484 | ||
485 | context = fTrace.seekEvent(context.getLocation()); | |
486 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
487 | ||
488 | event = fTrace.parseEvent(context); | |
489 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
490 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
491 | ||
c32744d6 | 492 | event = fTrace.getNext(context); |
7e6347b0 FC |
493 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
494 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
495 | ||
496 | // Position trace at event rank 1000 | |
065cc19b | 497 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE)); |
7e6347b0 FC |
498 | context = fTrace.seekEvent(tmpContext.getLocation()); |
499 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
500 | ||
501 | event = fTrace.parseEvent(context); | |
502 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
503 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
504 | ||
c32744d6 | 505 | event = fTrace.getNext(context); |
7e6347b0 FC |
506 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
507 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
508 | ||
509 | // Position trace at event rank 4000 | |
065cc19b | 510 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE)); |
7e6347b0 FC |
511 | context = fTrace.seekEvent(tmpContext.getLocation()); |
512 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
513 | ||
514 | event = fTrace.parseEvent(context); | |
515 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
516 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
517 | ||
c32744d6 | 518 | event = fTrace.getNext(context); |
7e6347b0 FC |
519 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
520 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
521 | } | |
522 | ||
6e1886bc | 523 | @Test |
54a7a54c | 524 | public void testSeekEventNotOnCacheBoundary() { |
7e6347b0 | 525 | // Position trace at event rank 9 |
065cc19b | 526 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE)); |
7e6347b0 FC |
527 | TmfContext context = fTrace.seekEvent(tmpContext.getLocation()); |
528 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
529 | ||
530 | ITmfEvent event = fTrace.parseEvent(context); | |
531 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
532 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
533 | ||
c32744d6 | 534 | event = fTrace.getNext(context); |
7e6347b0 FC |
535 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
536 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
537 | ||
538 | // Position trace at event rank 999 | |
065cc19b | 539 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE)); |
7e6347b0 FC |
540 | context = fTrace.seekEvent(tmpContext.getLocation()); |
541 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
542 | ||
543 | event = fTrace.parseEvent(context); | |
544 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
545 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
546 | ||
c32744d6 | 547 | event = fTrace.getNext(context); |
7e6347b0 FC |
548 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
549 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
550 | ||
551 | // Position trace at event rank 1001 | |
065cc19b | 552 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE)); |
7e6347b0 FC |
553 | context = fTrace.seekEvent(tmpContext.getLocation()); |
554 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
555 | ||
556 | event = fTrace.parseEvent(context); | |
557 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
558 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
559 | ||
c32744d6 | 560 | event = fTrace.getNext(context); |
7e6347b0 FC |
561 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
562 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
563 | ||
564 | // Position trace at event rank 4500 | |
065cc19b | 565 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE)); |
7e6347b0 FC |
566 | context = fTrace.seekEvent(tmpContext.getLocation()); |
567 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
568 | ||
569 | event = fTrace.parseEvent(context); | |
570 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
571 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
572 | ||
c32744d6 | 573 | event = fTrace.getNext(context); |
7e6347b0 FC |
574 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
575 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
576 | } | |
577 | ||
6e1886bc | 578 | @Test |
54a7a54c | 579 | public void testSeekEventOutOfScope() { |
7e6347b0 FC |
580 | // Position trace at beginning |
581 | ITmfContext tmpContext = fTrace.seekEvent(0); | |
582 | ITmfContext context = fTrace.seekEvent(tmpContext.getLocation()); | |
583 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
584 | ||
585 | ITmfEvent event = fTrace.parseEvent(context); | |
586 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
587 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
588 | ||
c32744d6 | 589 | event = fTrace.getNext(context); |
7e6347b0 FC |
590 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
591 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
592 | ||
593 | // Position trace at event passed the end | |
065cc19b | 594 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE)); |
0316808c | 595 | assertNull("Event timestamp", context.getLocation()); |
7e6347b0 FC |
596 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
597 | ||
c32744d6 | 598 | event = fTrace.getNext(context); |
0316808c | 599 | assertNull("Event", event); |
7e6347b0 FC |
600 | } |
601 | ||
602 | // ------------------------------------------------------------------------ | |
603 | // seekEvent on timestamp (note: does not reliably set the rank) | |
54d55ced FC |
604 | // ------------------------------------------------------------------------ |
605 | ||
6e1886bc | 606 | @Test |
54a7a54c | 607 | public void testSeekEventOnNullTimestamp() { |
f17b2f70 | 608 | // Position trace at event rank 0 |
7e6347b0 | 609 | ITmfContext context = fTrace.seekEvent((ITmfTimestamp) null); |
ff4ed569 | 610 | assertEquals("Event rank", 0, context.getRank()); |
9b635e61 | 611 | |
72f1e62a | 612 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced | 613 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
20658947 | 614 | assertEquals("Event rank", 0, context.getRank()); |
54d55ced FC |
615 | } |
616 | ||
6e1886bc | 617 | @Test |
54a7a54c | 618 | public void testSeekEventOnTimestampOnCacheBoundary() { |
f17b2f70 | 619 | // Position trace at event rank 0 |
065cc19b | 620 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE)); |
54d55ced | 621 | assertEquals("Event rank", 0, context.getRank()); |
9b635e61 | 622 | |
72f1e62a | 623 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
624 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
625 | assertEquals("Event rank", 0, context.getRank()); | |
f17b2f70 | 626 | |
c32744d6 | 627 | event = fTrace.getNext(context); |
75828b1a | 628 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
e31e01e8 | 629 | assertEquals("Event rank", 1, context.getRank()); |
d18dd09b | 630 | |
f17b2f70 | 631 | // Position trace at event rank 1000 |
065cc19b | 632 | context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE)); |
54d55ced | 633 | assertEquals("Event rank", 1000, context.getRank()); |
f17b2f70 | 634 | |
9b635e61 | 635 | event = fTrace.parseEvent(context); |
54d55ced FC |
636 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
637 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 638 | |
c32744d6 | 639 | event = fTrace.getNext(context); |
e31e01e8 FC |
640 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
641 | assertEquals("Event rank", 1001, context.getRank()); | |
d18dd09b | 642 | |
f17b2f70 | 643 | // Position trace at event rank 4000 |
065cc19b | 644 | context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE)); |
54d55ced | 645 | assertEquals("Event rank", 4000, context.getRank()); |
f17b2f70 | 646 | |
9b635e61 | 647 | event = fTrace.parseEvent(context); |
54d55ced FC |
648 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
649 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 650 | |
c32744d6 | 651 | event = fTrace.getNext(context); |
e31e01e8 FC |
652 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
653 | assertEquals("Event rank", 4001, context.getRank()); | |
75828b1a | 654 | } |
d18dd09b | 655 | |
6e1886bc | 656 | @Test |
54a7a54c | 657 | public void testSeekEventOnTimestampNotOnCacheBoundary() { |
f17b2f70 | 658 | // Position trace at event rank 1 |
065cc19b | 659 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE)); |
54d55ced | 660 | assertEquals("Event rank", 1, context.getRank()); |
f17b2f70 | 661 | |
72f1e62a | 662 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
663 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
664 | assertEquals("Event rank", 1, context.getRank()); | |
f17b2f70 | 665 | |
c32744d6 | 666 | event = fTrace.getNext(context); |
54d55ced FC |
667 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
668 | assertEquals("Event rank", 2, context.getRank()); | |
d18dd09b | 669 | |
f17b2f70 | 670 | // Position trace at event rank 9 |
065cc19b | 671 | context = fTrace.seekEvent(new TmfTimestamp(10, SCALE)); |
54d55ced | 672 | assertEquals("Event rank", 9, context.getRank()); |
f17b2f70 | 673 | |
9b635e61 | 674 | event = fTrace.parseEvent(context); |
54d55ced FC |
675 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
676 | assertEquals("Event rank", 9, context.getRank()); | |
f17b2f70 | 677 | |
c32744d6 | 678 | event = fTrace.getNext(context); |
e31e01e8 FC |
679 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
680 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 681 | |
f17b2f70 | 682 | // Position trace at event rank 999 |
065cc19b | 683 | context = fTrace.seekEvent(new TmfTimestamp(1000, SCALE)); |
54d55ced | 684 | assertEquals("Event rank", 999, context.getRank()); |
f17b2f70 | 685 | |
9b635e61 | 686 | event = fTrace.parseEvent(context); |
54d55ced | 687 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
e31e01e8 | 688 | assertEquals("Event rank", 999, context.getRank()); |
f17b2f70 | 689 | |
c32744d6 | 690 | event = fTrace.getNext(context); |
54d55ced FC |
691 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
692 | assertEquals("Event rank", 1000, context.getRank()); | |
e31e01e8 | 693 | |
f17b2f70 | 694 | // Position trace at event rank 1001 |
065cc19b | 695 | context = fTrace.seekEvent(new TmfTimestamp(1002, SCALE)); |
e31e01e8 | 696 | assertEquals("Event rank", 1001, context.getRank()); |
f17b2f70 | 697 | |
9b635e61 | 698 | event = fTrace.parseEvent(context); |
54d55ced FC |
699 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
700 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 701 | |
c32744d6 | 702 | event = fTrace.getNext(context); |
54d55ced FC |
703 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
704 | assertEquals("Event rank", 1002, context.getRank()); | |
705 | ||
f17b2f70 | 706 | // Position trace at event rank 4500 |
065cc19b | 707 | context = fTrace.seekEvent(new TmfTimestamp(4501, SCALE)); |
54d55ced | 708 | assertEquals("Event rank", 4500, context.getRank()); |
f17b2f70 | 709 | |
9b635e61 | 710 | event = fTrace.parseEvent(context); |
54d55ced FC |
711 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
712 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 713 | |
c32744d6 | 714 | event = fTrace.getNext(context); |
54d55ced FC |
715 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
716 | assertEquals("Event rank", 4501, context.getRank()); | |
75828b1a | 717 | } |
d18dd09b | 718 | |
6e1886bc | 719 | @Test |
54a7a54c | 720 | public void testSeekEventOnTimestampOutOfScope() { |
f17b2f70 | 721 | // Position trace at beginning |
065cc19b | 722 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE)); |
54d55ced | 723 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 724 | |
72f1e62a | 725 | ITmfEvent event = fTrace.parseEvent(context); |
75828b1a | 726 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced | 727 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 728 | |
c32744d6 | 729 | event = fTrace.getNext(context); |
54d55ced FC |
730 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
731 | assertEquals("Event rank", 1, context.getRank()); | |
75828b1a | 732 | |
f17b2f70 | 733 | // Position trace at event passed the end |
065cc19b | 734 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE)); |
0316808c | 735 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
f17b2f70 | 736 | |
9b635e61 | 737 | event = fTrace.parseEvent(context); |
75828b1a | 738 | assertEquals("Event timestamp", null, event); |
0316808c | 739 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
f17b2f70 | 740 | |
c32744d6 | 741 | event = fTrace.getNext(context); |
54d55ced | 742 | assertEquals("Event timestamp", null, event); |
0316808c | 743 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
d18dd09b ASL |
744 | } |
745 | ||
54d55ced FC |
746 | // ------------------------------------------------------------------------ |
747 | // seekEvent on rank | |
748 | // ------------------------------------------------------------------------ | |
749 | ||
6e1886bc | 750 | @Test |
54a7a54c | 751 | public void testSeekEventOnNegativeRank() { |
20658947 FC |
752 | // Position trace at event rank 0 |
753 | ITmfContext context = fTrace.seekEvent(-1); | |
754 | assertEquals("Event rank", 0, context.getRank()); | |
755 | ||
756 | ITmfEvent event = fTrace.parseEvent(context); | |
757 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
758 | assertEquals("Event rank", 0, context.getRank()); | |
759 | } | |
760 | ||
6e1886bc | 761 | @Test |
54a7a54c | 762 | public void testSeekOnRankOnCacheBoundary() { |
f17b2f70 FC |
763 | // On lower bound, returns the first event (ts = 1) |
764 | ITmfContext context = fTrace.seekEvent(0); | |
54d55ced | 765 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 766 | |
72f1e62a | 767 | ITmfEvent event = fTrace.parseEvent(context); |
e31e01e8 | 768 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced | 769 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 770 | |
c32744d6 | 771 | event = fTrace.getNext(context); |
54d55ced FC |
772 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
773 | assertEquals("Event rank", 1, context.getRank()); | |
e31e01e8 | 774 | |
f17b2f70 | 775 | // Position trace at event rank 1000 |
54d55ced FC |
776 | context = fTrace.seekEvent(1000); |
777 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 778 | |
9b635e61 | 779 | event = fTrace.parseEvent(context); |
54d55ced FC |
780 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
781 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 782 | |
c32744d6 | 783 | event = fTrace.getNext(context); |
54d55ced FC |
784 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
785 | assertEquals("Event rank", 1001, context.getRank()); | |
e31e01e8 | 786 | |
f17b2f70 | 787 | // Position trace at event rank 4000 |
54d55ced FC |
788 | context = fTrace.seekEvent(4000); |
789 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 790 | |
9b635e61 | 791 | event = fTrace.parseEvent(context); |
54d55ced FC |
792 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
793 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 794 | |
c32744d6 | 795 | event = fTrace.getNext(context); |
54d55ced FC |
796 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
797 | assertEquals("Event rank", 4001, context.getRank()); | |
e31e01e8 FC |
798 | } |
799 | ||
6e1886bc | 800 | @Test |
54a7a54c | 801 | public void testSeekOnRankNotOnCacheBoundary() { |
f17b2f70 FC |
802 | // Position trace at event rank 9 |
803 | ITmfContext context = fTrace.seekEvent(9); | |
54d55ced | 804 | assertEquals("Event rank", 9, context.getRank()); |
f17b2f70 | 805 | |
72f1e62a | 806 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
807 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
808 | assertEquals("Event rank", 9, context.getRank()); | |
f17b2f70 | 809 | |
c32744d6 | 810 | event = fTrace.getNext(context); |
54d55ced FC |
811 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
812 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 813 | |
f17b2f70 | 814 | // Position trace at event rank 999 |
54d55ced FC |
815 | context = fTrace.seekEvent(999); |
816 | assertEquals("Event rank", 999, context.getRank()); | |
f17b2f70 | 817 | |
9b635e61 | 818 | event = fTrace.parseEvent(context); |
54d55ced FC |
819 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
820 | assertEquals("Event rank", 999, context.getRank()); | |
f17b2f70 | 821 | |
c32744d6 | 822 | event = fTrace.getNext(context); |
54d55ced FC |
823 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
824 | assertEquals("Event rank", 1000, context.getRank()); | |
d18dd09b | 825 | |
f17b2f70 | 826 | // Position trace at event rank 1001 |
54d55ced FC |
827 | context = fTrace.seekEvent(1001); |
828 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 829 | |
9b635e61 | 830 | event = fTrace.parseEvent(context); |
54d55ced FC |
831 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
832 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 833 | |
c32744d6 | 834 | event = fTrace.getNext(context); |
54d55ced FC |
835 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
836 | assertEquals("Event rank", 1002, context.getRank()); | |
837 | ||
f17b2f70 | 838 | // Position trace at event rank 4500 |
54d55ced FC |
839 | context = fTrace.seekEvent(4500); |
840 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 841 | |
9b635e61 | 842 | event = fTrace.parseEvent(context); |
54d55ced FC |
843 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
844 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 845 | |
c32744d6 | 846 | event = fTrace.getNext(context); |
54d55ced FC |
847 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
848 | assertEquals("Event rank", 4501, context.getRank()); | |
d18dd09b ASL |
849 | } |
850 | ||
6e1886bc | 851 | @Test |
54a7a54c | 852 | public void testSeekEventOnRankOutOfScope() { |
f17b2f70 FC |
853 | // Position trace at beginning |
854 | ITmfContext context = fTrace.seekEvent(-1); | |
54d55ced | 855 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 856 | |
72f1e62a | 857 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
858 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
859 | assertEquals("Event rank", 0, context.getRank()); | |
f17b2f70 | 860 | |
c32744d6 | 861 | event = fTrace.getNext(context); |
54d55ced FC |
862 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
863 | assertEquals("Event rank", 1, context.getRank()); | |
864 | ||
f17b2f70 | 865 | // Position trace at event passed the end |
54d55ced FC |
866 | context = fTrace.seekEvent(NB_EVENTS); |
867 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
f17b2f70 | 868 | |
9b635e61 | 869 | event = fTrace.parseEvent(context); |
0316808c | 870 | assertNull("Event", event); |
54d55ced | 871 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
f17b2f70 | 872 | |
c32744d6 | 873 | event = fTrace.getNext(context); |
0316808c | 874 | assertNull("Event", event); |
54d55ced FC |
875 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
876 | } | |
f17b2f70 | 877 | |
20658947 FC |
878 | // ------------------------------------------------------------------------ |
879 | // parseEvent - make sure parseEvent doesn't update the context | |
880 | // ------------------------------------------------------------------------ | |
881 | ||
6e1886bc | 882 | @Test |
54a7a54c | 883 | public void testParseEvent() { |
20658947 FC |
884 | final int NB_READS = 20; |
885 | ||
886 | // On lower bound, returns the first event (ts = 0) | |
065cc19b | 887 | final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE)); |
20658947 FC |
888 | TmfContext svContext = new TmfContext(context); |
889 | ||
890 | ITmfEvent event = fTrace.parseEvent(context); | |
891 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
892 | assertEquals("Event rank", 0, context.getRank()); | |
893 | assertTrue("parseEvent", context.equals(svContext)); | |
894 | ||
895 | event = fTrace.parseEvent(context); | |
896 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
897 | assertEquals("Event rank", 0, context.getRank()); | |
898 | assertTrue("parseEvent", context.equals(svContext)); | |
899 | ||
900 | event = fTrace.parseEvent(context); | |
901 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
902 | assertEquals("Event rank", 0, context.getRank()); | |
903 | assertTrue("parseEvent", context.equals(svContext)); | |
904 | ||
905 | // Position the trace at event NB_READS | |
906 | for (int i = 1; i < NB_READS; i++) { | |
c32744d6 | 907 | event = fTrace.getNext(context); |
20658947 FC |
908 | assertEquals("Event timestamp", i, event.getTimestamp().getValue()); |
909 | } | |
910 | ||
911 | svContext = new TmfContext(context); | |
912 | event = fTrace.parseEvent(context); | |
913 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); | |
914 | assertEquals("Event rank", NB_READS -1 , context.getRank()); | |
915 | assertTrue("parseEvent", context.equals(svContext)); | |
916 | ||
917 | event = fTrace.parseEvent(context); | |
918 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); | |
919 | assertEquals("Event rank", NB_READS - 1, context.getRank()); | |
920 | assertTrue("parseEvent", context.equals(svContext)); | |
921 | } | |
922 | ||
923 | // ------------------------------------------------------------------------ | |
17324c9a | 924 | // getNext - updates the context |
20658947 FC |
925 | // ------------------------------------------------------------------------ |
926 | ||
6e1886bc | 927 | @Test |
54a7a54c | 928 | public void testGetNextAfteSeekingOnTS_1() { |
17324c9a | 929 | final long INITIAL_TS = 1; |
20658947 FC |
930 | final int NB_READS = 20; |
931 | ||
932 | // On lower bound, returns the first event (ts = 1) | |
065cc19b | 933 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE)); |
20658947 FC |
934 | |
935 | // Read NB_EVENTS | |
936 | ITmfEvent event; | |
937 | for (int i = 0; i < NB_READS; i++) { | |
c32744d6 | 938 | event = fTrace.getNext(context); |
17324c9a FC |
939 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
940 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
20658947 FC |
941 | } |
942 | ||
943 | // Make sure we stay positioned | |
944 | event = fTrace.parseEvent(context); | |
17324c9a FC |
945 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
946 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
947 | } | |
948 | ||
6e1886bc | 949 | @Test |
54a7a54c | 950 | public void testGetNextAfteSeekingOnTS_2() { |
17324c9a FC |
951 | final long INITIAL_TS = 2; |
952 | final int NB_READS = 20; | |
953 | ||
954 | // On lower bound, returns the first event (ts = 500) | |
065cc19b | 955 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE)); |
17324c9a FC |
956 | |
957 | // Read NB_EVENTS | |
958 | ITmfEvent event; | |
959 | for (int i = 0; i < NB_READS; i++) { | |
960 | event = fTrace.getNext(context); | |
961 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
962 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
963 | } | |
964 | ||
965 | // Make sure we stay positioned | |
966 | event = fTrace.parseEvent(context); | |
967 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
968 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
969 | } | |
970 | ||
6e1886bc | 971 | @Test |
54a7a54c | 972 | public void testGetNextAfteSeekingOnTS_3() { |
17324c9a FC |
973 | final long INITIAL_TS = 500; |
974 | final int NB_READS = 20; | |
975 | ||
976 | // On lower bound, returns the first event (ts = 500) | |
065cc19b | 977 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE)); |
17324c9a FC |
978 | |
979 | // Read NB_EVENTS | |
980 | ITmfEvent event; | |
981 | for (int i = 0; i < NB_READS; i++) { | |
982 | event = fTrace.getNext(context); | |
983 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
984 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
985 | } | |
986 | ||
987 | // Make sure we stay positioned | |
988 | event = fTrace.parseEvent(context); | |
989 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
990 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
991 | } | |
992 | ||
6e1886bc | 993 | @Test |
54a7a54c | 994 | public void testGetNextAfterSeekingOnRank_1() { |
17324c9a FC |
995 | final long INITIAL_RANK = 0L; |
996 | final int NB_READS = 20; | |
997 | ||
998 | // On lower bound, returns the first event (rank = 0) | |
999 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1000 | ||
1001 | // Read NB_EVENTS | |
1002 | ITmfEvent event; | |
1003 | for (int i = 0; i < NB_READS; i++) { | |
1004 | event = fTrace.getNext(context); | |
1005 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1006 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1007 | } | |
1008 | ||
1009 | // Make sure we stay positioned | |
1010 | event = fTrace.parseEvent(context); | |
1011 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1012 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1013 | } | |
1014 | ||
6e1886bc | 1015 | @Test |
54a7a54c | 1016 | public void testGetNextAfterSeekingOnRank_2() { |
17324c9a FC |
1017 | final long INITIAL_RANK = 1L; |
1018 | final int NB_READS = 20; | |
1019 | ||
1020 | // On lower bound, returns the first event (rank = 0) | |
1021 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1022 | ||
1023 | // Read NB_EVENTS | |
1024 | ITmfEvent event; | |
1025 | for (int i = 0; i < NB_READS; i++) { | |
1026 | event = fTrace.getNext(context); | |
1027 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1028 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1029 | } | |
1030 | ||
1031 | // Make sure we stay positioned | |
1032 | event = fTrace.parseEvent(context); | |
1033 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1034 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1035 | } | |
1036 | ||
6e1886bc | 1037 | @Test |
54a7a54c | 1038 | public void testGetNextAfterSeekingOnRank_3() { |
17324c9a FC |
1039 | final long INITIAL_RANK = 500L; |
1040 | final int NB_READS = 20; | |
1041 | ||
1042 | // On lower bound, returns the first event (rank = 0) | |
1043 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1044 | ||
1045 | // Read NB_EVENTS | |
1046 | ITmfEvent event; | |
1047 | for (int i = 0; i < NB_READS; i++) { | |
1048 | event = fTrace.getNext(context); | |
1049 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1050 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1051 | } | |
1052 | ||
1053 | // Make sure we stay positioned | |
1054 | event = fTrace.parseEvent(context); | |
1055 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1056 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1057 | } | |
1058 | ||
6e1886bc | 1059 | @Test |
54a7a54c | 1060 | public void testGetNextAfterSeekingOnLocation_1() { |
1e1bef82 | 1061 | final ITmfLocation INITIAL_LOC = null; |
17324c9a FC |
1062 | final long INITIAL_TS = 1; |
1063 | final int NB_READS = 20; | |
1064 | ||
1065 | // On lower bound, returns the first event (ts = 1) | |
1066 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1067 | ||
1068 | // Read NB_EVENTS | |
1069 | ITmfEvent event; | |
1070 | for (int i = 0; i < NB_READS; i++) { | |
1071 | event = fTrace.getNext(context); | |
1072 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1073 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
1074 | } | |
1075 | ||
1076 | // Make sure we stay positioned | |
1077 | event = fTrace.parseEvent(context); | |
1078 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1079 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
1080 | } | |
1081 | ||
6e1886bc | 1082 | @Test |
54a7a54c | 1083 | public void testGetNextAfterSeekingOnLocation_2() { |
1e1bef82 | 1084 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(1L).getLocation(); |
17324c9a FC |
1085 | final long INITIAL_TS = 2; |
1086 | final int NB_READS = 20; | |
1087 | ||
1088 | // On lower bound, returns the first event (ts = 501) | |
1089 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1090 | ||
1091 | // Read NB_EVENTS | |
1092 | ITmfEvent event; | |
1093 | for (int i = 0; i < NB_READS; i++) { | |
1094 | event = fTrace.getNext(context); | |
1095 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1096 | } | |
1097 | ||
1098 | // Make sure we stay positioned | |
1099 | event = fTrace.parseEvent(context); | |
1100 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1101 | } | |
1102 | ||
6e1886bc | 1103 | @Test |
54a7a54c | 1104 | public void testGetNextAfterSeekingOnLocation_3() { |
1e1bef82 | 1105 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(500L).getLocation(); |
17324c9a FC |
1106 | final long INITIAL_TS = 501; |
1107 | final int NB_READS = 20; | |
1108 | ||
1109 | // On lower bound, returns the first event (ts = 501) | |
1110 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1111 | ||
1112 | // Read NB_EVENTS | |
1113 | ITmfEvent event; | |
1114 | for (int i = 0; i < NB_READS; i++) { | |
1115 | event = fTrace.getNext(context); | |
1116 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1117 | } | |
1118 | ||
1119 | // Make sure we stay positioned | |
1120 | event = fTrace.parseEvent(context); | |
1121 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1122 | } | |
1123 | ||
6e1886bc | 1124 | @Test |
54a7a54c | 1125 | public void testGetNextLocation() { |
17324c9a FC |
1126 | ITmfContext context1 = fTrace.seekEvent(0); |
1127 | fTrace.getNext(context1); | |
d62bb185 | 1128 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
1129 | ITmfEvent event1 = fTrace.getNext(context1); |
1130 | ITmfContext context2 = fTrace.seekEvent(location); | |
1131 | ITmfEvent event2 = fTrace.getNext(context2); | |
1132 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); | |
1133 | } | |
1134 | ||
6e1886bc | 1135 | @Test |
54a7a54c | 1136 | public void testGetNextEndLocation() { |
17324c9a FC |
1137 | ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); |
1138 | fTrace.getNext(context1); | |
d62bb185 | 1139 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
1140 | ITmfContext context2 = fTrace.seekEvent(location); |
1141 | ITmfEvent event = fTrace.getNext(context2); | |
1142 | assertNull("Event", event); | |
20658947 FC |
1143 | } |
1144 | ||
e31e01e8 | 1145 | // ------------------------------------------------------------------------ |
d18dd09b | 1146 | // processRequest |
e31e01e8 | 1147 | // ------------------------------------------------------------------------ |
d18dd09b | 1148 | |
6e1886bc | 1149 | @Test |
54a7a54c | 1150 | public void testProcessEventRequestForAllEvents() throws InterruptedException { |
ccf2bbb4 | 1151 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
7e6347b0 FC |
1152 | |
1153 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); | |
7184fc40 | 1154 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1155 | range, 0, NB_EVENTS, ExecutionType.FOREGROUND) { |
7e6347b0 | 1156 | @Override |
6256d8ad | 1157 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1158 | super.handleData(event); |
1159 | requestedEvents.add(event); | |
1160 | } | |
1161 | }; | |
fd3f1eff | 1162 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1163 | providers[0].sendRequest(request); |
1164 | request.waitForCompletion(); | |
1165 | ||
1166 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); | |
1167 | assertTrue("isCompleted", request.isCompleted()); | |
1168 | assertFalse("isCancelled", request.isCancelled()); | |
1169 | ||
1170 | // Ensure that we have distinct events. | |
1171 | // Don't go overboard: we are not validating the stub! | |
1172 | for (int i = 0; i < NB_EVENTS; i++) { | |
1173 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); | |
1174 | } | |
1175 | } | |
1176 | ||
6e1886bc | 1177 | @Test |
54a7a54c | 1178 | public void testProcessEventRequestForNbEvents() throws InterruptedException { |
6e1886bc | 1179 | final int nbEvents = 1000; |
ccf2bbb4 | 1180 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 1181 | |
f17b2f70 | 1182 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 1183 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1184 | range, 0, nbEvents, ExecutionType.FOREGROUND) { |
f17b2f70 | 1185 | @Override |
6256d8ad | 1186 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1187 | super.handleData(event); |
1188 | requestedEvents.add(event); | |
1189 | } | |
d18dd09b | 1190 | }; |
fd3f1eff | 1191 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1192 | providers[0].sendRequest(request); |
1193 | request.waitForCompletion(); | |
d18dd09b | 1194 | |
6e1886bc | 1195 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
d18dd09b ASL |
1196 | assertTrue("isCompleted", request.isCompleted()); |
1197 | assertFalse("isCancelled", request.isCancelled()); | |
1198 | ||
1199 | // Ensure that we have distinct events. | |
f17b2f70 | 1200 | // Don't go overboard: we are not validating the stub! |
6e1886bc | 1201 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 | 1202 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 1203 | } |
d18dd09b | 1204 | } |
f17b2f70 | 1205 | |
6e1886bc | 1206 | @Test |
54a7a54c | 1207 | public void testProcessEventRequestForSomeEvents() throws InterruptedException { |
7e6347b0 | 1208 | final long startTime = 100; |
6e1886bc | 1209 | final int nbEvents = 1000; |
ccf2bbb4 | 1210 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 1211 | |
7e6347b0 | 1212 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 1213 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1214 | range, 0, nbEvents, ExecutionType.FOREGROUND) { |
f17b2f70 | 1215 | @Override |
6256d8ad | 1216 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1217 | super.handleData(event); |
1218 | requestedEvents.add(event); | |
1219 | } | |
d18dd09b | 1220 | }; |
fd3f1eff | 1221 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1222 | providers[0].sendRequest(request); |
1223 | request.waitForCompletion(); | |
d18dd09b | 1224 | |
6e1886bc | 1225 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
d18dd09b ASL |
1226 | assertTrue("isCompleted", request.isCompleted()); |
1227 | assertFalse("isCancelled", request.isCancelled()); | |
1228 | ||
1229 | // Ensure that we have distinct events. | |
f17b2f70 | 1230 | // Don't go overboard: we are not validating the stub! |
6e1886bc | 1231 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 FC |
1232 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
1233 | } | |
1234 | } | |
1235 | ||
6e1886bc | 1236 | @Test |
54a7a54c | 1237 | public void testProcessEventRequestForOtherEvents() throws InterruptedException { |
7e6347b0 FC |
1238 | final int startIndex = 99; |
1239 | final long startTime = 100; | |
6e1886bc | 1240 | final int nbEvents = 1000; |
ccf2bbb4 | 1241 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
7e6347b0 FC |
1242 | |
1243 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); | |
7184fc40 | 1244 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1245 | range, startIndex, nbEvents, ExecutionType.FOREGROUND) { |
7e6347b0 | 1246 | @Override |
6256d8ad | 1247 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1248 | super.handleData(event); |
1249 | requestedEvents.add(event); | |
1250 | } | |
1251 | }; | |
fd3f1eff | 1252 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1253 | providers[0].sendRequest(request); |
1254 | request.waitForCompletion(); | |
1255 | ||
6e1886bc | 1256 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
7e6347b0 FC |
1257 | assertTrue("isCompleted", request.isCompleted()); |
1258 | assertFalse("isCancelled", request.isCancelled()); | |
1259 | ||
1260 | // Ensure that we have distinct events. | |
1261 | // Don't go overboard: we are not validating the stub! | |
6e1886bc | 1262 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 FC |
1263 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
1264 | } | |
1265 | } | |
1266 | ||
6e1886bc | 1267 | @Test |
54a7a54c | 1268 | public void testProcessDataRequestForSomeEvents() throws InterruptedException { |
7e6347b0 | 1269 | final int startIndex = 100; |
6e1886bc | 1270 | final int nbEvents = 1000; |
ccf2bbb4 | 1271 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
7e6347b0 | 1272 | |
fd3f1eff AM |
1273 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
1274 | TmfTimeRange.ETERNITY, | |
9765b9f1 AM |
1275 | startIndex, |
1276 | nbEvents, | |
fd3f1eff | 1277 | TmfEventRequest.ExecutionType.FOREGROUND) { |
7e6347b0 | 1278 | @Override |
6256d8ad | 1279 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1280 | super.handleData(event); |
1281 | requestedEvents.add(event); | |
1282 | } | |
1283 | }; | |
fd3f1eff | 1284 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1285 | providers[0].sendRequest(request); |
1286 | request.waitForCompletion(); | |
1287 | ||
6e1886bc | 1288 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
7e6347b0 FC |
1289 | assertTrue("isCompleted", request.isCompleted()); |
1290 | assertFalse("isCancelled", request.isCancelled()); | |
1291 | ||
1292 | // Ensure that we have distinct events. | |
1293 | // Don't go overboard: we are not validating the stub! | |
6e1886bc | 1294 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 | 1295 | assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 1296 | } |
d18dd09b | 1297 | } |
f17b2f70 | 1298 | |
e31e01e8 | 1299 | // ------------------------------------------------------------------------ |
d18dd09b | 1300 | // cancel |
e31e01e8 | 1301 | // ------------------------------------------------------------------------ |
d18dd09b | 1302 | |
6e1886bc | 1303 | @Test |
54a7a54c | 1304 | public void testCancel() throws InterruptedException { |
7886b91f | 1305 | final int limit = 500; |
ccf2bbb4 | 1306 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 1307 | |
f17b2f70 | 1308 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 1309 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1310 | range, 0, NB_EVENTS, ExecutionType.FOREGROUND) { |
f17b2f70 | 1311 | int nbRead = 0; |
672a642a | 1312 | |
f17b2f70 | 1313 | @Override |
6256d8ad | 1314 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1315 | super.handleData(event); |
1316 | requestedEvents.add(event); | |
672a642a | 1317 | if (++nbRead == limit) { |
f17b2f70 | 1318 | cancel(); |
20658947 | 1319 | } |
f17b2f70 | 1320 | } |
d18dd09b | 1321 | }; |
fd3f1eff | 1322 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1323 | providers[0].sendRequest(request); |
1324 | request.waitForCompletion(); | |
d18dd09b | 1325 | |
672a642a | 1326 | assertEquals("nbEvents", limit, requestedEvents.size()); |
d18dd09b ASL |
1327 | assertTrue("isCompleted", request.isCompleted()); |
1328 | assertTrue("isCancelled", request.isCancelled()); | |
1329 | } | |
e31e01e8 | 1330 | |
1703b536 FC |
1331 | // ------------------------------------------------------------------------ |
1332 | // toString | |
1333 | // ------------------------------------------------------------------------ | |
1334 | ||
6e1886bc | 1335 | @Test |
54a7a54c | 1336 | public void testDefaultTmfTraceStub() { |
1703b536 | 1337 | assertFalse ("Open trace", fTrace == null); |
2771b032 | 1338 | assertEquals("getType", ITmfEvent.class, fTrace.getType()); |
1703b536 | 1339 | assertNull ("getResource", fTrace.getResource()); |
1703b536 | 1340 | assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval()); |
9c4d52ee | 1341 | assertEquals("getName", TEST_TRACE.getPath(), fTrace.getName()); |
1703b536 FC |
1342 | |
1343 | assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents()); | |
1344 | assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); | |
1345 | assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); | |
1346 | assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); | |
1347 | assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); | |
1348 | ||
1349 | String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() + | |
1350 | ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() + | |
1351 | ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() + | |
1352 | "]"; | |
1353 | assertEquals("toString", expected, fTrace.toString()); | |
1354 | } | |
1355 | ||
66262ad8 BH |
1356 | // ------------------------------------------------------------------------ |
1357 | // getInitialRangeOffset, getCurrentRange, getCurrentTime | |
1358 | // ------------------------------------------------------------------------ | |
6e1886bc AM |
1359 | |
1360 | @Test | |
66262ad8 BH |
1361 | public void testCurrentTimeValues() throws TmfTraceException { |
1362 | ||
1363 | TmfTraceStub trace = null; | |
1364 | File testfile = null; | |
1365 | try { | |
9c4d52ee | 1366 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
66262ad8 | 1367 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 1368 | trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); |
66262ad8 BH |
1369 | // verify initial values |
1370 | TmfTimestamp defaultInitRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE); | |
1371 | assertEquals("getInitialRangeOffset", defaultInitRange, trace.getInitialRangeOffset()); | |
66262ad8 | 1372 | trace.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE)); |
51e75066 | 1373 | trace.indexTrace(true); |
e73a4ba5 GB |
1374 | |
1375 | TmfTimestamp initRange = new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE); | |
1376 | assertEquals("getInitialRangeOffset", initRange, trace.getInitialRangeOffset()); | |
1377 | ||
66262ad8 BH |
1378 | } catch (final URISyntaxException e) { |
1379 | fail("URISyntaxException"); | |
1380 | } catch (final IOException e) { | |
1381 | fail("IOException"); | |
1382 | } | |
66262ad8 | 1383 | } |
bb52f9bc GB |
1384 | |
1385 | /** | |
1386 | * Run the String getHostId() method test | |
1387 | */ | |
1388 | @Test | |
1389 | public void testTraceHostId() { | |
1390 | String a = fTrace.getHostId(); | |
1391 | assertEquals("A-Test-10K", a); | |
1392 | } | |
9b749023 | 1393 | } |