1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.trace
;
17 import java
.io
.IOException
;
18 import java
.net
.URISyntaxException
;
20 import java
.util
.Vector
;
22 import junit
.framework
.TestCase
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.component
.TmfProviderManager
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpointIndexer
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
42 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
45 * Test suite for the TmfTrace class.
47 @SuppressWarnings({"nls","javadoc"})
48 public class TmfTraceTest
extends TestCase
{
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 private static final String DIRECTORY
= "testfiles";
55 private static final String TEST_STREAM
= "A-Test-10K";
56 private static final int BLOCK_SIZE
= 500;
57 private static final int NB_EVENTS
= 10000;
58 private static TmfTraceStub fTrace
= null;
60 private static int SCALE
= -3;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
67 * @param name the test name
69 public TmfTraceTest(final String name
) {
74 protected void setUp() throws Exception
{
76 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
80 protected void tearDown() throws Exception
{
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
90 private static TmfTraceStub
setupTrace(final String path
) {
93 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
94 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
95 fTrace
= new TmfTraceStub(test
.toURI().getPath(), BLOCK_SIZE
);
97 } catch (final TmfTraceException e
) {
99 } catch (final URISyntaxException e
) {
101 } catch (final IOException e
) {
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
112 @SuppressWarnings("null")
113 public void testStandardConstructor() throws TmfTraceException
{
114 TmfTraceStub trace
= null;
115 File testfile
= null;
117 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
118 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
119 trace
= new TmfTraceStub(testfile
.toURI().getPath());
121 } catch (final URISyntaxException e
) {
122 fail("URISyntaxException");
123 } catch (final IOException e
) {
127 assertFalse ("Open trace", trace
== null);
128 assertEquals("getType", TmfEvent
.class, trace
.getType());
129 assertNull ("getResource", trace
.getResource());
130 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
131 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
132 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
133 assertEquals("getName", TEST_STREAM
, trace
.getName());
135 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
136 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
137 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
138 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
139 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
142 @SuppressWarnings("null")
143 public void testStandardConstructorCacheSize() throws TmfTraceException
{
144 TmfTraceStub trace
= null;
145 File testfile
= null;
147 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
148 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
149 trace
= new TmfTraceStub(testfile
.toURI().getPath(), 0);
151 } catch (final URISyntaxException e
) {
152 fail("URISyntaxException");
153 } catch (final IOException e
) {
157 assertFalse ("Open trace", trace
== null);
158 assertEquals("getType", TmfEvent
.class, trace
.getType());
159 assertNull ("getResource", trace
.getResource());
160 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
161 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
162 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
163 assertEquals("getName", TEST_STREAM
, trace
.getName());
165 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
166 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
167 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
168 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
169 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
172 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
173 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
174 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
);
176 } catch (final URISyntaxException e
) {
177 fail("URISyntaxException");
178 } catch (final IOException e
) {
182 assertEquals("getType", TmfEvent
.class, trace
.getType());
183 assertNull ("getResource", trace
.getResource());
184 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
185 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
186 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
187 assertEquals("getName", TEST_STREAM
, trace
.getName());
189 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
190 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
191 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
192 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
193 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
196 @SuppressWarnings("null")
197 public void testFullConstructor() throws TmfTraceException
{
198 TmfTraceStub trace
= null;
199 File testfile
= null;
201 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
202 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
203 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, null);
205 } catch (final URISyntaxException e
) {
206 fail("URISyntaxException");
207 } catch (final IOException e
) {
211 assertFalse ("Open trace", trace
== null);
212 assertEquals("getType", TmfEvent
.class, trace
.getType());
213 assertNull ("getResource", trace
.getResource());
214 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
215 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
216 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
217 assertEquals("getName", TEST_STREAM
, trace
.getName());
219 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
220 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
221 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
222 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
223 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
226 @SuppressWarnings("null")
227 public void testLiveTraceConstructor() throws TmfTraceException
{
228 TmfTraceStub trace
= null;
229 File testfile
= null;
230 final long interval
= 100;
232 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
233 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
234 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, interval
);
236 } catch (final URISyntaxException e
) {
237 fail("URISyntaxException");
238 } catch (final IOException e
) {
242 assertFalse ("Open trace", trace
== null);
243 assertEquals("getType", TmfEvent
.class, trace
.getType());
244 assertNull ("getResource", trace
.getResource());
245 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
246 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
247 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
248 assertEquals("getName", TEST_STREAM
, trace
.getName());
250 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
251 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
252 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
253 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
254 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
257 @SuppressWarnings({ "unchecked", "rawtypes", "null" })
258 public void testCopyConstructor() throws TmfTraceException
{
259 TmfTraceStub original
= null;
260 TmfTraceStub trace
= null;
261 File testfile
= null;
263 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
264 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
265 original
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, new TmfCheckpointIndexer(null));
266 trace
= new TmfTraceStub(original
);
268 } catch (final URISyntaxException e
) {
269 fail("URISyntaxException");
270 } catch (final IOException e
) {
274 assertFalse ("Open trace", trace
== null);
275 assertEquals("getType", TmfEvent
.class, trace
.getType());
276 assertNull ("getResource", trace
.getResource());
277 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
278 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
279 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
280 assertEquals("getName", TEST_STREAM
, trace
.getName());
282 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
283 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
284 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
285 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
286 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
288 // Test the copy of a null trace
290 new TmfTraceStub((TmfTraceStub
) null);
291 fail("Missing exception");
292 } catch (final IllegalArgumentException e
) {
294 } catch (final Exception e
) {
295 fail("Unexpected exception");
299 // ------------------------------------------------------------------------
300 // Trace initialization
301 // ------------------------------------------------------------------------
303 public void testInitializeNullPath() {
305 // Instantiate an "empty" trace
306 final TmfTraceStub trace
= new TmfTraceStub();
309 trace
.initialize(null, null, TmfEvent
.class);
310 fail("TmfTrace.initialize() - no exception thrown");
311 } catch (TmfTraceException e
) {
313 } catch (Exception e
) {
314 fail("TmfTrace.initialize() - wrong exception thrown");
318 public void testInitializeSimplePath() {
320 // Instantiate an "empty" trace
321 final TmfTraceStub trace
= new TmfTraceStub();
323 // Path == trace name
324 String path
= "TraceName";
326 trace
.initialize(null, path
, TmfEvent
.class);
327 } catch (Exception e
) {
328 fail("TmfTrace.initialize() - Exception thrown");
331 assertEquals("getType", TmfEvent
.class, trace
.getType());
332 assertNull ("getResource", trace
.getResource());
333 assertEquals("getPath", path
, trace
.getPath());
334 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
335 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
336 assertEquals("getName", path
, trace
.getName());
338 assertEquals("getNbEvents", 0, trace
.getNbEvents());
339 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
340 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
341 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
342 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
345 public void testInitializeNormalPath() {
347 // Instantiate an "empty" trace
348 final TmfTraceStub trace
= new TmfTraceStub();
350 // Path == trace name
351 String name
= "TraceName";
352 String path
= "/my/trace/path/" + name
;
354 trace
.initialize(null, path
, TmfEvent
.class);
355 } catch (Exception e
) {
356 fail("TmfTrace.initialize() - Exception thrown");
359 assertEquals("getType", TmfEvent
.class, trace
.getType());
360 assertNull ("getResource", trace
.getResource());
361 assertEquals("getPath", path
, trace
.getPath());
362 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
363 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
364 assertEquals("getName", name
, trace
.getName());
366 assertEquals("getNbEvents", 0, trace
.getNbEvents());
367 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
368 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
369 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
370 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
373 public void testInitTrace() throws URISyntaxException
, IOException
, TmfTraceException
, InterruptedException
{
375 // Instantiate an "empty" trace
376 final TmfTraceStub trace
= new TmfTraceStub();
378 assertNull ("getType", trace
.getType());
379 assertNull ("getResource", trace
.getResource());
380 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
381 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
382 assertEquals("getName", "", trace
.getName());
384 assertEquals("getNbEvents", 0, trace
.getNbEvents());
385 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
386 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
387 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
388 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
391 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
392 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
393 assertTrue("validate", trace
.validate(null, testfile
.getPath()));
395 // InitTrace and wait for indexing completion...
396 trace
.initTrace(null, testfile
.toURI().getPath(), TmfEvent
.class);
399 while (trace
.getNbEvents() < NB_EVENTS
&& nbSecs
< 10) {
403 if (trace
.getNbEvents() < NB_EVENTS
) {
407 assertEquals("getType", TmfEvent
.class, trace
.getType());
408 assertNull ("getResource", trace
.getResource());
409 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
410 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
411 assertEquals("getName", TEST_STREAM
, trace
.getName());
413 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
414 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
415 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
416 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
417 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
420 // ------------------------------------------------------------------------
421 // Set/Get streaming interval
422 // ------------------------------------------------------------------------
424 public void testSetStreamingInterval() throws TmfTraceException
{
425 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
428 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
431 trace
.setStreamingInterval(interval
);
432 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
435 trace
.setStreamingInterval(interval
);
436 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
439 trace
.setStreamingInterval(interval
);
440 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
445 // ------------------------------------------------------------------------
446 // Set/Get time range
447 // ------------------------------------------------------------------------
449 public void testSetTimeRange() throws TmfTraceException
{
450 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
453 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
454 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
455 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
456 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
458 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
459 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
460 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
461 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
462 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
467 public void testSetStartTime() throws TmfTraceException
{
468 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
471 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
472 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
473 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
474 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
476 trace
.setStartTime(new TmfTimestamp(100));
477 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
478 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
479 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
480 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
485 public void testSetEndTime() throws TmfTraceException
{
486 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
489 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
490 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
491 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
492 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
494 trace
.setEndTime(new TmfTimestamp(100));
495 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
496 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
497 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
498 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
503 public void testSetNbEvents() throws TmfTraceException
{
504 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
507 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
509 trace
.setNbEvents(0);
510 assertEquals("getNbEvents", 0, trace
.getNbEvents());
512 trace
.setNbEvents(-1);
513 assertEquals("getNbEvents", 0, trace
.getNbEvents());
515 trace
.setNbEvents(NB_EVENTS
+ 1);
516 assertEquals("getNbEvents", NB_EVENTS
+ 1, trace
.getNbEvents());
518 trace
.setNbEvents(NB_EVENTS
);
519 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
524 // ------------------------------------------------------------------------
525 // seekEvent on location (note: does not reliably set the rank)
526 // ------------------------------------------------------------------------
528 public void testSeekEventOnCacheBoundary() {
530 // Position trace at event rank 0
531 ITmfContext context
= fTrace
.seekEvent(0);
532 ITmfEvent event
= fTrace
.parseEvent(context
);
533 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
534 assertEquals("Event rank", 0, context
.getRank());
536 context
= fTrace
.seekEvent(context
.getLocation());
537 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
539 event
= fTrace
.parseEvent(context
);
540 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
541 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
543 event
= fTrace
.getNext(context
);
544 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
545 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
547 // Position trace at event rank 1000
548 ITmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
549 context
= fTrace
.seekEvent(tmpContext
.getLocation());
550 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
552 event
= fTrace
.parseEvent(context
);
553 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
554 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
556 event
= fTrace
.getNext(context
);
557 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
558 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
560 // Position trace at event rank 4000
561 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
562 context
= fTrace
.seekEvent(tmpContext
.getLocation());
563 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
565 event
= fTrace
.parseEvent(context
);
566 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
567 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
569 event
= fTrace
.getNext(context
);
570 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
571 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
574 public void testSeekEventNotOnCacheBoundary() {
576 // Position trace at event rank 9
577 ITmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
578 TmfContext context
= fTrace
.seekEvent(tmpContext
.getLocation());
579 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
581 ITmfEvent event
= fTrace
.parseEvent(context
);
582 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
583 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
585 event
= fTrace
.getNext(context
);
586 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
587 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
589 // Position trace at event rank 999
590 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
591 context
= fTrace
.seekEvent(tmpContext
.getLocation());
592 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
594 event
= fTrace
.parseEvent(context
);
595 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
596 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
598 event
= fTrace
.getNext(context
);
599 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
600 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
602 // Position trace at event rank 1001
603 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
604 context
= fTrace
.seekEvent(tmpContext
.getLocation());
605 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
607 event
= fTrace
.parseEvent(context
);
608 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
609 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
611 event
= fTrace
.getNext(context
);
612 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
613 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
615 // Position trace at event rank 4500
616 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
617 context
= fTrace
.seekEvent(tmpContext
.getLocation());
618 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
620 event
= fTrace
.parseEvent(context
);
621 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
622 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
624 event
= fTrace
.getNext(context
);
625 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
626 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
629 public void testSeekEventOutOfScope() {
631 // Position trace at beginning
632 ITmfContext tmpContext
= fTrace
.seekEvent(0);
633 ITmfContext context
= fTrace
.seekEvent(tmpContext
.getLocation());
634 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
636 ITmfEvent event
= fTrace
.parseEvent(context
);
637 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
638 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
640 event
= fTrace
.getNext(context
);
641 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
642 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
644 // Position trace at event passed the end
645 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
646 assertNull("Event timestamp", context
.getLocation());
647 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
649 event
= fTrace
.getNext(context
);
650 assertNull("Event", event
);
653 // ------------------------------------------------------------------------
654 // seekEvent on timestamp (note: does not reliably set the rank)
655 // ------------------------------------------------------------------------
657 public void testSeekEventOnNullTimestamp() {
659 // Position trace at event rank 0
660 ITmfContext context
= fTrace
.seekEvent((ITmfTimestamp
) null);
661 assertEquals("Event rank", 0, context
.getRank());
663 ITmfEvent event
= fTrace
.parseEvent(context
);
664 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
665 assertEquals("Event rank", 0, context
.getRank());
668 public void testSeekEventOnTimestampOnCacheBoundary() {
670 // Position trace at event rank 0
671 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
672 assertEquals("Event rank", 0, context
.getRank());
674 ITmfEvent event
= fTrace
.parseEvent(context
);
675 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
676 assertEquals("Event rank", 0, context
.getRank());
678 event
= fTrace
.getNext(context
);
679 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
680 assertEquals("Event rank", 1, context
.getRank());
682 // Position trace at event rank 1000
683 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
684 assertEquals("Event rank", 1000, context
.getRank());
686 event
= fTrace
.parseEvent(context
);
687 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
688 assertEquals("Event rank", 1000, context
.getRank());
690 event
= fTrace
.getNext(context
);
691 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
692 assertEquals("Event rank", 1001, context
.getRank());
694 // Position trace at event rank 4000
695 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
696 assertEquals("Event rank", 4000, context
.getRank());
698 event
= fTrace
.parseEvent(context
);
699 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
700 assertEquals("Event rank", 4000, context
.getRank());
702 event
= fTrace
.getNext(context
);
703 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
704 assertEquals("Event rank", 4001, context
.getRank());
707 public void testSeekEventOnTimestampNotOnCacheBoundary() {
709 // Position trace at event rank 1
710 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
711 assertEquals("Event rank", 1, context
.getRank());
713 ITmfEvent event
= fTrace
.parseEvent(context
);
714 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
715 assertEquals("Event rank", 1, context
.getRank());
717 event
= fTrace
.getNext(context
);
718 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
719 assertEquals("Event rank", 2, context
.getRank());
721 // Position trace at event rank 9
722 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
723 assertEquals("Event rank", 9, context
.getRank());
725 event
= fTrace
.parseEvent(context
);
726 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
727 assertEquals("Event rank", 9, context
.getRank());
729 event
= fTrace
.getNext(context
);
730 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
731 assertEquals("Event rank", 10, context
.getRank());
733 // Position trace at event rank 999
734 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
735 assertEquals("Event rank", 999, context
.getRank());
737 event
= fTrace
.parseEvent(context
);
738 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
739 assertEquals("Event rank", 999, context
.getRank());
741 event
= fTrace
.getNext(context
);
742 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
743 assertEquals("Event rank", 1000, context
.getRank());
745 // Position trace at event rank 1001
746 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
747 assertEquals("Event rank", 1001, context
.getRank());
749 event
= fTrace
.parseEvent(context
);
750 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
751 assertEquals("Event rank", 1001, context
.getRank());
753 event
= fTrace
.getNext(context
);
754 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
755 assertEquals("Event rank", 1002, context
.getRank());
757 // Position trace at event rank 4500
758 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
759 assertEquals("Event rank", 4500, context
.getRank());
761 event
= fTrace
.parseEvent(context
);
762 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
763 assertEquals("Event rank", 4500, context
.getRank());
765 event
= fTrace
.getNext(context
);
766 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
767 assertEquals("Event rank", 4501, context
.getRank());
770 public void testSeekEventOnTimestampOutOfScope() {
772 // Position trace at beginning
773 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
774 assertEquals("Event rank", 0, context
.getRank());
776 ITmfEvent event
= fTrace
.parseEvent(context
);
777 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
778 assertEquals("Event rank", 0, context
.getRank());
780 event
= fTrace
.getNext(context
);
781 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
782 assertEquals("Event rank", 1, context
.getRank());
784 // Position trace at event passed the end
785 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
786 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
788 event
= fTrace
.parseEvent(context
);
789 assertEquals("Event timestamp", null, event
);
790 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
792 event
= fTrace
.getNext(context
);
793 assertEquals("Event timestamp", null, event
);
794 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
797 // ------------------------------------------------------------------------
799 // ------------------------------------------------------------------------
801 public void testSeekEventOnNegativeRank() {
803 // Position trace at event rank 0
804 ITmfContext context
= fTrace
.seekEvent(-1);
805 assertEquals("Event rank", 0, context
.getRank());
807 ITmfEvent event
= fTrace
.parseEvent(context
);
808 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
809 assertEquals("Event rank", 0, context
.getRank());
812 public void testSeekOnRankOnCacheBoundary() {
814 // On lower bound, returns the first event (ts = 1)
815 ITmfContext context
= fTrace
.seekEvent(0);
816 assertEquals("Event rank", 0, context
.getRank());
818 ITmfEvent event
= fTrace
.parseEvent(context
);
819 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
820 assertEquals("Event rank", 0, context
.getRank());
822 event
= fTrace
.getNext(context
);
823 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
824 assertEquals("Event rank", 1, context
.getRank());
826 // Position trace at event rank 1000
827 context
= fTrace
.seekEvent(1000);
828 assertEquals("Event rank", 1000, context
.getRank());
830 event
= fTrace
.parseEvent(context
);
831 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
832 assertEquals("Event rank", 1000, context
.getRank());
834 event
= fTrace
.getNext(context
);
835 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
836 assertEquals("Event rank", 1001, context
.getRank());
838 // Position trace at event rank 4000
839 context
= fTrace
.seekEvent(4000);
840 assertEquals("Event rank", 4000, context
.getRank());
842 event
= fTrace
.parseEvent(context
);
843 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
844 assertEquals("Event rank", 4000, context
.getRank());
846 event
= fTrace
.getNext(context
);
847 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
848 assertEquals("Event rank", 4001, context
.getRank());
851 public void testSeekOnRankNotOnCacheBoundary() {
853 // Position trace at event rank 9
854 ITmfContext context
= fTrace
.seekEvent(9);
855 assertEquals("Event rank", 9, context
.getRank());
857 ITmfEvent event
= fTrace
.parseEvent(context
);
858 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
859 assertEquals("Event rank", 9, context
.getRank());
861 event
= fTrace
.getNext(context
);
862 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
863 assertEquals("Event rank", 10, context
.getRank());
865 // Position trace at event rank 999
866 context
= fTrace
.seekEvent(999);
867 assertEquals("Event rank", 999, context
.getRank());
869 event
= fTrace
.parseEvent(context
);
870 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
871 assertEquals("Event rank", 999, context
.getRank());
873 event
= fTrace
.getNext(context
);
874 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
875 assertEquals("Event rank", 1000, context
.getRank());
877 // Position trace at event rank 1001
878 context
= fTrace
.seekEvent(1001);
879 assertEquals("Event rank", 1001, context
.getRank());
881 event
= fTrace
.parseEvent(context
);
882 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
883 assertEquals("Event rank", 1001, context
.getRank());
885 event
= fTrace
.getNext(context
);
886 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
887 assertEquals("Event rank", 1002, context
.getRank());
889 // Position trace at event rank 4500
890 context
= fTrace
.seekEvent(4500);
891 assertEquals("Event rank", 4500, context
.getRank());
893 event
= fTrace
.parseEvent(context
);
894 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
895 assertEquals("Event rank", 4500, context
.getRank());
897 event
= fTrace
.getNext(context
);
898 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
899 assertEquals("Event rank", 4501, context
.getRank());
902 public void testSeekEventOnRankOutOfScope() {
904 // Position trace at beginning
905 ITmfContext context
= fTrace
.seekEvent(-1);
906 assertEquals("Event rank", 0, context
.getRank());
908 ITmfEvent event
= fTrace
.parseEvent(context
);
909 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
910 assertEquals("Event rank", 0, context
.getRank());
912 event
= fTrace
.getNext(context
);
913 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
914 assertEquals("Event rank", 1, context
.getRank());
916 // Position trace at event passed the end
917 context
= fTrace
.seekEvent(NB_EVENTS
);
918 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
920 event
= fTrace
.parseEvent(context
);
921 assertNull("Event", event
);
922 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
924 event
= fTrace
.getNext(context
);
925 assertNull("Event", event
);
926 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
929 // ------------------------------------------------------------------------
930 // parseEvent - make sure parseEvent doesn't update the context
931 // ------------------------------------------------------------------------
933 public void testParseEvent() {
935 final int NB_READS
= 20;
937 // On lower bound, returns the first event (ts = 0)
938 final TmfContext context
= (TmfContext
) fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
939 TmfContext svContext
= new TmfContext(context
);
941 ITmfEvent event
= fTrace
.parseEvent(context
);
942 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
943 assertEquals("Event rank", 0, context
.getRank());
944 assertTrue("parseEvent", context
.equals(svContext
));
946 event
= fTrace
.parseEvent(context
);
947 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
948 assertEquals("Event rank", 0, context
.getRank());
949 assertTrue("parseEvent", context
.equals(svContext
));
951 event
= fTrace
.parseEvent(context
);
952 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
953 assertEquals("Event rank", 0, context
.getRank());
954 assertTrue("parseEvent", context
.equals(svContext
));
956 // Position the trace at event NB_READS
957 for (int i
= 1; i
< NB_READS
; i
++) {
958 event
= fTrace
.getNext(context
);
959 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
962 svContext
= new TmfContext(context
);
963 event
= fTrace
.parseEvent(context
);
964 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
965 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
966 assertTrue("parseEvent", context
.equals(svContext
));
968 event
= fTrace
.parseEvent(context
);
969 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
970 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
971 assertTrue("parseEvent", context
.equals(svContext
));
974 // ------------------------------------------------------------------------
975 // getNext - updates the context
976 // ------------------------------------------------------------------------
978 public void testGetNextAfteSeekingOnTS_1() {
980 final long INITIAL_TS
= 1;
981 final int NB_READS
= 20;
983 // On lower bound, returns the first event (ts = 1)
984 final ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
988 for (int i
= 0; i
< NB_READS
; i
++) {
989 event
= fTrace
.getNext(context
);
990 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
991 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
994 // Make sure we stay positioned
995 event
= fTrace
.parseEvent(context
);
996 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
997 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
1000 public void testGetNextAfteSeekingOnTS_2() {
1002 final long INITIAL_TS
= 2;
1003 final int NB_READS
= 20;
1005 // On lower bound, returns the first event (ts = 500)
1006 final ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
1010 for (int i
= 0; i
< NB_READS
; i
++) {
1011 event
= fTrace
.getNext(context
);
1012 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
1013 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
1016 // Make sure we stay positioned
1017 event
= fTrace
.parseEvent(context
);
1018 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
1019 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
1022 public void testGetNextAfteSeekingOnTS_3() {
1024 final long INITIAL_TS
= 500;
1025 final int NB_READS
= 20;
1027 // On lower bound, returns the first event (ts = 500)
1028 final ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
1032 for (int i
= 0; i
< NB_READS
; i
++) {
1033 event
= fTrace
.getNext(context
);
1034 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
1035 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
1038 // Make sure we stay positioned
1039 event
= fTrace
.parseEvent(context
);
1040 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
1041 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
1044 public void testGetNextAfterSeekingOnRank_1() {
1046 final long INITIAL_RANK
= 0L;
1047 final int NB_READS
= 20;
1049 // On lower bound, returns the first event (rank = 0)
1050 final ITmfContext context
= fTrace
.seekEvent(INITIAL_RANK
);
1054 for (int i
= 0; i
< NB_READS
; i
++) {
1055 event
= fTrace
.getNext(context
);
1056 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
1057 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
1060 // Make sure we stay positioned
1061 event
= fTrace
.parseEvent(context
);
1062 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
1063 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
1066 public void testGetNextAfterSeekingOnRank_2() {
1068 final long INITIAL_RANK
= 1L;
1069 final int NB_READS
= 20;
1071 // On lower bound, returns the first event (rank = 0)
1072 final ITmfContext context
= fTrace
.seekEvent(INITIAL_RANK
);
1076 for (int i
= 0; i
< NB_READS
; i
++) {
1077 event
= fTrace
.getNext(context
);
1078 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
1079 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
1082 // Make sure we stay positioned
1083 event
= fTrace
.parseEvent(context
);
1084 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
1085 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
1088 public void testGetNextAfterSeekingOnRank_3() {
1090 final long INITIAL_RANK
= 500L;
1091 final int NB_READS
= 20;
1093 // On lower bound, returns the first event (rank = 0)
1094 final ITmfContext context
= fTrace
.seekEvent(INITIAL_RANK
);
1098 for (int i
= 0; i
< NB_READS
; i
++) {
1099 event
= fTrace
.getNext(context
);
1100 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
1101 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
1104 // Make sure we stay positioned
1105 event
= fTrace
.parseEvent(context
);
1106 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
1107 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
1110 public void testGetNextAfterSeekingOnLocation_1() {
1112 final ITmfLocation
<?
> INITIAL_LOC
= null;
1113 final long INITIAL_TS
= 1;
1114 final int NB_READS
= 20;
1116 // On lower bound, returns the first event (ts = 1)
1117 final ITmfContext context
= fTrace
.seekEvent(INITIAL_LOC
);
1121 for (int i
= 0; i
< NB_READS
; i
++) {
1122 event
= fTrace
.getNext(context
);
1123 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
1124 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
1127 // Make sure we stay positioned
1128 event
= fTrace
.parseEvent(context
);
1129 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
1130 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
1133 public void testGetNextAfterSeekingOnLocation_2() {
1135 final ITmfLocation
<?
> INITIAL_LOC
= fTrace
.seekEvent(1L).getLocation();
1136 final long INITIAL_TS
= 2;
1137 final int NB_READS
= 20;
1139 // On lower bound, returns the first event (ts = 501)
1140 final ITmfContext context
= fTrace
.seekEvent(INITIAL_LOC
);
1144 for (int i
= 0; i
< NB_READS
; i
++) {
1145 event
= fTrace
.getNext(context
);
1146 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
1149 // Make sure we stay positioned
1150 event
= fTrace
.parseEvent(context
);
1151 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
1154 public void testGetNextAfterSeekingOnLocation_3() {
1156 final ITmfLocation
<?
> INITIAL_LOC
= fTrace
.seekEvent(500L).getLocation();
1157 final long INITIAL_TS
= 501;
1158 final int NB_READS
= 20;
1160 // On lower bound, returns the first event (ts = 501)
1161 final ITmfContext context
= fTrace
.seekEvent(INITIAL_LOC
);
1165 for (int i
= 0; i
< NB_READS
; i
++) {
1166 event
= fTrace
.getNext(context
);
1167 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
1170 // Make sure we stay positioned
1171 event
= fTrace
.parseEvent(context
);
1172 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
1175 public void testGetNextLocation() {
1176 ITmfContext context1
= fTrace
.seekEvent(0);
1177 fTrace
.getNext(context1
);
1178 ITmfLocation
<?
> location
= context1
.getLocation().clone();
1179 ITmfEvent event1
= fTrace
.getNext(context1
);
1180 ITmfContext context2
= fTrace
.seekEvent(location
);
1181 ITmfEvent event2
= fTrace
.getNext(context2
);
1182 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
1185 public void testGetNextEndLocation() {
1186 ITmfContext context1
= fTrace
.seekEvent(fTrace
.getNbEvents() - 1);
1187 fTrace
.getNext(context1
);
1188 ITmfLocation
<?
> location
= context1
.getLocation().clone();
1189 ITmfContext context2
= fTrace
.seekEvent(location
);
1190 ITmfEvent event
= fTrace
.getNext(context2
);
1191 assertNull("Event", event
);
1194 // ------------------------------------------------------------------------
1196 // ------------------------------------------------------------------------
1198 @SuppressWarnings("hiding")
1199 public void testProcessEventRequestForAllEvents() throws InterruptedException
{
1200 final int BLOCK_SIZE
= 1;
1201 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1203 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
1204 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1206 public void handleData(final TmfEvent event
) {
1207 super.handleData(event
);
1208 requestedEvents
.add(event
);
1211 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1212 providers
[0].sendRequest(request
);
1213 request
.waitForCompletion();
1215 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1216 assertTrue("isCompleted", request
.isCompleted());
1217 assertFalse("isCancelled", request
.isCancelled());
1219 // Ensure that we have distinct events.
1220 // Don't go overboard: we are not validating the stub!
1221 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1222 assertEquals("Distinct events", i
+ 1, requestedEvents
.get(i
).getTimestamp().getValue());
1226 @SuppressWarnings("hiding")
1227 public void testProcessEventRequestForNbEvents() throws InterruptedException
{
1228 final int BLOCK_SIZE
= 100;
1229 final int NB_EVENTS
= 1000;
1230 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1232 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
1233 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1235 public void handleData(final TmfEvent event
) {
1236 super.handleData(event
);
1237 requestedEvents
.add(event
);
1240 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1241 providers
[0].sendRequest(request
);
1242 request
.waitForCompletion();
1244 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1245 assertTrue("isCompleted", request
.isCompleted());
1246 assertFalse("isCancelled", request
.isCancelled());
1248 // Ensure that we have distinct events.
1249 // Don't go overboard: we are not validating the stub!
1250 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1251 assertEquals("Distinct events", i
+ 1, requestedEvents
.get(i
).getTimestamp().getValue());
1255 @SuppressWarnings("hiding")
1256 public void testProcessEventRequestForSomeEvents() throws InterruptedException
{
1257 final int BLOCK_SIZE
= 1;
1258 final long startTime
= 100;
1259 final int NB_EVENTS
= 1000;
1260 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1262 final TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(startTime
, SCALE
), TmfTimestamp
.BIG_CRUNCH
);
1263 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1265 public void handleData(final TmfEvent event
) {
1266 super.handleData(event
);
1267 requestedEvents
.add(event
);
1270 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1271 providers
[0].sendRequest(request
);
1272 request
.waitForCompletion();
1274 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1275 assertTrue("isCompleted", request
.isCompleted());
1276 assertFalse("isCancelled", request
.isCancelled());
1278 // Ensure that we have distinct events.
1279 // Don't go overboard: we are not validating the stub!
1280 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1281 assertEquals("Distinct events", startTime
+ i
, requestedEvents
.get(i
).getTimestamp().getValue());
1285 @SuppressWarnings("hiding")
1286 public void testProcessEventRequestForOtherEvents() throws InterruptedException
{
1287 final int BLOCK_SIZE
= 1;
1288 final int startIndex
= 99;
1289 final long startTime
= 100;
1290 final int NB_EVENTS
= 1000;
1291 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1293 final TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(startTime
, SCALE
), TmfTimestamp
.BIG_CRUNCH
);
1294 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, startIndex
, NB_EVENTS
, BLOCK_SIZE
) {
1296 public void handleData(final TmfEvent event
) {
1297 super.handleData(event
);
1298 requestedEvents
.add(event
);
1301 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1302 providers
[0].sendRequest(request
);
1303 request
.waitForCompletion();
1305 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1306 assertTrue("isCompleted", request
.isCompleted());
1307 assertFalse("isCancelled", request
.isCancelled());
1309 // Ensure that we have distinct events.
1310 // Don't go overboard: we are not validating the stub!
1311 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1312 assertEquals("Distinct events", startTime
+ i
, requestedEvents
.get(i
).getTimestamp().getValue());
1316 @SuppressWarnings("hiding")
1317 public void testProcessDataRequestForSomeEvents() throws InterruptedException
{
1318 final int startIndex
= 100;
1319 final int NB_EVENTS
= 1000;
1320 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1322 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(TmfEvent
.class, startIndex
, NB_EVENTS
) {
1324 public void handleData(final TmfEvent event
) {
1325 super.handleData(event
);
1326 requestedEvents
.add(event
);
1329 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1330 providers
[0].sendRequest(request
);
1331 request
.waitForCompletion();
1333 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1334 assertTrue("isCompleted", request
.isCompleted());
1335 assertFalse("isCancelled", request
.isCancelled());
1337 // Ensure that we have distinct events.
1338 // Don't go overboard: we are not validating the stub!
1339 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1340 assertEquals("Distinct events", startIndex
+ 1 + i
, requestedEvents
.get(i
).getTimestamp().getValue());
1344 // ------------------------------------------------------------------------
1346 // ------------------------------------------------------------------------
1348 public void testCancel() throws InterruptedException
{
1349 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1351 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
1352 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1355 public void handleData(final TmfEvent event
) {
1356 super.handleData(event
);
1357 requestedEvents
.add(event
);
1358 if (++nbRead
== BLOCK_SIZE
) {
1363 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1364 providers
[0].sendRequest(request
);
1365 request
.waitForCompletion();
1367 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
1368 assertTrue("isCompleted", request
.isCompleted());
1369 assertTrue("isCancelled", request
.isCancelled());
1372 // ------------------------------------------------------------------------
1374 // ------------------------------------------------------------------------
1376 public void testDefaultTmfTraceStub() {
1377 assertFalse ("Open trace", fTrace
== null);
1378 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
1379 assertNull ("getResource", fTrace
.getResource());
1380 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
1381 assertEquals("getStreamingInterval", 0, fTrace
.getStreamingInterval());
1382 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
1384 assertEquals("getNbEvents", NB_EVENTS
, fTrace
.getNbEvents());
1385 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
1386 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
1387 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
1388 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
1390 String expected
= "TmfTrace [fPath=" + fTrace
.getPath() + ", fCacheSize=" + fTrace
.getCacheSize() +
1391 ", fNbEvents=" + fTrace
.getNbEvents() + ", fStartTime=" + fTrace
.getStartTime() +
1392 ", fEndTime=" + fTrace
.getEndTime() + ", fStreamingInterval=" + fTrace
.getStreamingInterval() +
1394 assertEquals("toString", expected
, fTrace
.toString());