1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 20112 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
.FileNotFoundException
;
18 import java
.io
.IOException
;
19 import java
.net
.URISyntaxException
;
21 import java
.util
.Vector
;
23 import junit
.framework
.TestCase
;
25 import org
.eclipse
.core
.runtime
.FileLocator
;
26 import org
.eclipse
.core
.runtime
.Path
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfProviderManager
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
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
.request
.TmfEventRequest
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceIndexer
;
39 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
42 * <b><u>TmfTraceTest</u></b>
44 * Test suite for the TmfTrace class.
46 @SuppressWarnings("nls")
47 public class TmfTraceTest
extends TestCase
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 private static final String DIRECTORY
= "testfiles";
54 private static final String TEST_STREAM
= "A-Test-10K";
55 private static final int BLOCK_SIZE
= 500;
56 private static final int NB_EVENTS
= 10000;
57 private static TmfTraceStub fTrace
= null;
59 private static int SCALE
= -3;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 public TmfTraceTest(final String name
) throws Exception
{
70 protected void setUp() throws Exception
{
72 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
76 protected void tearDown() throws Exception
{
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
86 private TmfTraceStub
setupTrace(final String path
) {
89 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
90 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
91 fTrace
= new TmfTraceStub(test
.toURI().getPath(), BLOCK_SIZE
);
93 } catch (final URISyntaxException e
) {
95 } catch (final IOException e
) {
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
106 public void testStandardConstructor() throws Exception
{
107 TmfTraceStub trace
= null;
108 File testfile
= null;
110 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
111 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
112 trace
= new TmfTraceStub(testfile
.toURI().getPath());
114 } catch (final URISyntaxException e
) {
115 fail("URISyntaxException");
116 } catch (final IOException e
) {
120 assertFalse ("Open trace", trace
== null);
121 assertEquals("getType", TmfEvent
.class, trace
.getType());
122 assertNull ("getResource", trace
.getResource());
123 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
124 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
125 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
126 assertEquals("getName", TEST_STREAM
, trace
.getName());
128 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
129 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
130 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
131 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
132 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
135 public void testStandardConstructorCacheSize() throws Exception
{
136 TmfTraceStub trace
= null;
137 File testfile
= null;
139 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
140 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
141 trace
= new TmfTraceStub(testfile
.toURI().getPath(), 0);
143 } catch (final URISyntaxException e
) {
144 fail("URISyntaxException");
145 } catch (final IOException e
) {
149 assertFalse ("Open trace", trace
== null);
150 assertEquals("getType", TmfEvent
.class, trace
.getType());
151 assertNull ("getResource", trace
.getResource());
152 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
153 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
154 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
155 assertEquals("getName", TEST_STREAM
, trace
.getName());
157 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
158 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
159 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
160 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
161 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
164 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
165 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
166 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
);
168 } catch (final URISyntaxException e
) {
169 fail("URISyntaxException");
170 } catch (final IOException e
) {
174 assertFalse ("Open trace", trace
== null);
175 assertEquals("getType", TmfEvent
.class, trace
.getType());
176 assertNull ("getResource", trace
.getResource());
177 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
178 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
179 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
180 assertEquals("getName", TEST_STREAM
, trace
.getName());
182 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
183 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
184 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
185 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
186 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
189 public void testFullConstructor() throws Exception
{
190 TmfTraceStub trace
= null;
191 File testfile
= null;
193 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
194 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
195 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, null);
197 } catch (final URISyntaxException e
) {
198 fail("URISyntaxException");
199 } catch (final IOException e
) {
203 assertFalse ("Open trace", trace
== null);
204 assertEquals("getType", TmfEvent
.class, trace
.getType());
205 assertNull ("getResource", trace
.getResource());
206 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
207 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
208 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
209 assertEquals("getName", TEST_STREAM
, trace
.getName());
211 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
212 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
213 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
214 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
215 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
218 public void testLiveTraceConstructor() throws Exception
{
219 TmfTraceStub trace
= null;
220 File testfile
= null;
221 final long interval
= 100;
223 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
224 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
225 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, interval
);
227 } catch (final URISyntaxException e
) {
228 fail("URISyntaxException");
229 } catch (final IOException e
) {
233 assertFalse ("Open trace", trace
== null);
234 assertEquals("getType", TmfEvent
.class, trace
.getType());
235 assertNull ("getResource", trace
.getResource());
236 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
237 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
238 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
239 assertEquals("getName", TEST_STREAM
, trace
.getName());
241 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
242 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
243 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
244 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
245 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
248 @SuppressWarnings({ "rawtypes", "unchecked" })
249 public void testCopyConstructor() throws Exception
{
250 TmfTraceStub original
= null;
251 TmfTraceStub trace
= null;
252 File testfile
= null;
254 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
255 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
256 original
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, new TmfTraceIndexer(null));
257 trace
= new TmfTraceStub(original
);
259 } catch (final URISyntaxException e
) {
260 fail("URISyntaxException");
261 } catch (final IOException e
) {
265 assertFalse ("Open trace", trace
== null);
266 assertEquals("getType", TmfEvent
.class, trace
.getType());
267 assertNull ("getResource", trace
.getResource());
268 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
269 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
270 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
271 assertEquals("getName", TEST_STREAM
, trace
.getName());
273 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
274 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
275 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
276 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
277 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
279 // Test the copy of a null trace
281 new TmfTraceStub((TmfTraceStub
) null);
282 fail("Missing exception");
283 } catch (final IllegalArgumentException e
) {
285 } catch (final Exception e
) {
286 fail("Unexpected exception");
290 // ------------------------------------------------------------------------
291 // Trace initialization
292 // ------------------------------------------------------------------------
294 public void testInitializeNullPath() throws Exception
{
296 // Instantiate an "empty" trace
297 final TmfTraceStub trace
= new TmfTraceStub();
300 trace
.initialize(null, null, TmfEvent
.class);
301 fail("TmfTrace.initialize() - no exception thrown");
302 } catch (FileNotFoundException e
) {
304 } catch (Exception e
) {
305 fail("TmfTrace.initialize() - wrong exception thrown");
309 public void testInitializeSimplePath() throws Exception
{
311 // Instantiate an "empty" trace
312 final TmfTraceStub trace
= new TmfTraceStub();
314 // Path == trace name
315 String path
= "TraceName";
317 trace
.initialize(null, path
, TmfEvent
.class);
318 } catch (Exception e
) {
319 fail("TmfTrace.initialize() - Exception thrown");
322 assertFalse ("Open trace", trace
== null);
323 assertEquals("getType", TmfEvent
.class, trace
.getType());
324 assertNull ("getResource", trace
.getResource());
325 assertEquals("getPath", path
, trace
.getPath());
326 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
327 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
328 assertEquals("getName", path
, trace
.getName());
330 assertEquals("getNbEvents", 0, trace
.getNbEvents());
331 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
332 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
333 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
334 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
337 public void testInitializeNormalPath() throws Exception
{
339 // Instantiate an "empty" trace
340 final TmfTraceStub trace
= new TmfTraceStub();
342 // Path == trace name
343 String name
= "TraceName";
344 String path
= "/my/trace/path/" + name
;
346 trace
.initialize(null, path
, TmfEvent
.class);
347 } catch (Exception e
) {
348 fail("TmfTrace.initialize() - Exception thrown");
351 assertFalse ("Open trace", trace
== null);
352 assertEquals("getType", TmfEvent
.class, trace
.getType());
353 assertNull ("getResource", trace
.getResource());
354 assertEquals("getPath", path
, trace
.getPath());
355 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
356 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
357 assertEquals("getName", name
, trace
.getName());
359 assertEquals("getNbEvents", 0, trace
.getNbEvents());
360 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
361 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
362 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
363 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
366 public void testInitTrace() throws Exception
{
368 // Instantiate an "empty" trace
369 final TmfTraceStub trace
= new TmfTraceStub();
371 assertFalse ("Open trace", trace
== null);
372 assertNull ("getType", trace
.getType());
373 assertNull ("getResource", trace
.getResource());
374 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
375 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
376 assertEquals("getName", "", trace
.getName());
378 assertEquals("getNbEvents", 0, trace
.getNbEvents());
379 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
380 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
381 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
382 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
385 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
386 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
387 assertTrue("validate", trace
.validate(null, testfile
.getPath()));
389 // InitTrace and wait for indexing completion...
390 trace
.initTrace(null, testfile
.getPath(), TmfEvent
.class);
392 while (trace
.getNbEvents() < NB_EVENTS
&& nbSecs
< 10) {
396 if (trace
.getNbEvents() < NB_EVENTS
) {
400 assertFalse ("Open trace", trace
== null);
401 assertEquals("getType", TmfEvent
.class, trace
.getType());
402 assertNull ("getResource", trace
.getResource());
403 assertEquals("getCacheSize", TmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
404 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
405 assertEquals("getName", TEST_STREAM
, trace
.getName());
407 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
408 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
409 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
410 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
411 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
414 // ------------------------------------------------------------------------
415 // Set/Get streaming interval
416 // ------------------------------------------------------------------------
418 public void testSetStreamingInterval() throws Exception
{
419 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
422 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
425 trace
.setStreamingInterval(interval
);
426 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
429 trace
.setStreamingInterval(interval
);
430 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
433 trace
.setStreamingInterval(interval
);
434 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
439 // ------------------------------------------------------------------------
440 // Set/Get time range
441 // ------------------------------------------------------------------------
443 public void testSetTimeRange() throws Exception
{
444 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
447 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
448 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
449 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
450 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
452 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
453 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
454 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
455 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
456 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
461 public void testSetStartTime() throws Exception
{
462 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
465 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
466 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
467 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
468 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
470 trace
.setStartTime(new TmfTimestamp(100));
471 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
472 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
473 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
474 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
479 public void testSetEndTime() throws Exception
{
480 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
483 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
484 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
485 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
486 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
488 trace
.setEndTime(new TmfTimestamp(100));
489 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
490 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
491 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
492 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
497 // ------------------------------------------------------------------------
498 // seekEvent on timestamp
499 // ------------------------------------------------------------------------
501 public void testSeekEventOnNullTimestamp() throws Exception
{
503 // Position trace at event rank 0
504 ITmfContext context
= fTrace
.seekEvent(null);
505 assertEquals("Event rank", 0, context
.getRank());
507 ITmfEvent event
= fTrace
.parseEvent(context
);
508 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
509 assertEquals("Event rank", 0, context
.getRank());
512 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
514 // Position trace at event rank 0
515 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
516 assertEquals("Event rank", 0, context
.getRank());
518 ITmfEvent event
= fTrace
.parseEvent(context
);
519 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
520 assertEquals("Event rank", 0, context
.getRank());
522 event
= fTrace
.getNextEvent(context
);
523 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
524 assertEquals("Event rank", 1, context
.getRank());
526 // Position trace at event rank 1000
527 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
528 assertEquals("Event rank", 1000, context
.getRank());
530 event
= fTrace
.parseEvent(context
);
531 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
532 assertEquals("Event rank", 1000, context
.getRank());
534 event
= fTrace
.getNextEvent(context
);
535 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
536 assertEquals("Event rank", 1001, context
.getRank());
538 // Position trace at event rank 4000
539 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
540 assertEquals("Event rank", 4000, context
.getRank());
542 event
= fTrace
.parseEvent(context
);
543 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
544 assertEquals("Event rank", 4000, context
.getRank());
546 event
= fTrace
.getNextEvent(context
);
547 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
548 assertEquals("Event rank", 4001, context
.getRank());
551 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
553 // Position trace at event rank 1
554 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
555 assertEquals("Event rank", 1, context
.getRank());
557 ITmfEvent event
= fTrace
.parseEvent(context
);
558 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
559 assertEquals("Event rank", 1, context
.getRank());
561 event
= fTrace
.getNextEvent(context
);
562 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
563 assertEquals("Event rank", 2, context
.getRank());
565 // Position trace at event rank 9
566 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
567 assertEquals("Event rank", 9, context
.getRank());
569 event
= fTrace
.parseEvent(context
);
570 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
571 assertEquals("Event rank", 9, context
.getRank());
573 event
= fTrace
.getNextEvent(context
);
574 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
575 assertEquals("Event rank", 10, context
.getRank());
577 // Position trace at event rank 999
578 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
579 assertEquals("Event rank", 999, context
.getRank());
581 event
= fTrace
.parseEvent(context
);
582 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
583 assertEquals("Event rank", 999, context
.getRank());
585 event
= fTrace
.getNextEvent(context
);
586 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
587 assertEquals("Event rank", 1000, context
.getRank());
589 // Position trace at event rank 1001
590 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
591 assertEquals("Event rank", 1001, context
.getRank());
593 event
= fTrace
.parseEvent(context
);
594 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
595 assertEquals("Event rank", 1001, context
.getRank());
597 event
= fTrace
.getNextEvent(context
);
598 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
599 assertEquals("Event rank", 1002, context
.getRank());
601 // Position trace at event rank 4500
602 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
603 assertEquals("Event rank", 4500, context
.getRank());
605 event
= fTrace
.parseEvent(context
);
606 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
607 assertEquals("Event rank", 4500, context
.getRank());
609 event
= fTrace
.getNextEvent(context
);
610 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
611 assertEquals("Event rank", 4501, context
.getRank());
614 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
616 // Position trace at beginning
617 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
618 assertEquals("Event rank", 0, context
.getRank());
620 ITmfEvent event
= fTrace
.parseEvent(context
);
621 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
622 assertEquals("Event rank", 0, context
.getRank());
624 event
= fTrace
.getNextEvent(context
);
625 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
626 assertEquals("Event rank", 1, context
.getRank());
628 // Position trace at event passed the end
629 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
630 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
632 event
= fTrace
.parseEvent(context
);
633 assertEquals("Event timestamp", null, event
);
634 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
636 event
= fTrace
.getNextEvent(context
);
637 assertEquals("Event timestamp", null, event
);
638 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
641 // ------------------------------------------------------------------------
643 // ------------------------------------------------------------------------
645 public void testSeekEventOnNegativeRank() throws Exception
{
647 // Position trace at event rank 0
648 ITmfContext context
= fTrace
.seekEvent(-1);
649 assertEquals("Event rank", 0, context
.getRank());
651 ITmfEvent event
= fTrace
.parseEvent(context
);
652 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
653 assertEquals("Event rank", 0, context
.getRank());
656 public void testSeekOnRankOnCacheBoundary() throws Exception
{
658 // On lower bound, returns the first event (ts = 1)
659 ITmfContext context
= fTrace
.seekEvent(0);
660 assertEquals("Event rank", 0, context
.getRank());
662 ITmfEvent event
= fTrace
.parseEvent(context
);
663 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
664 assertEquals("Event rank", 0, context
.getRank());
666 event
= fTrace
.getNextEvent(context
);
667 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
668 assertEquals("Event rank", 1, context
.getRank());
670 // Position trace at event rank 1000
671 context
= fTrace
.seekEvent(1000);
672 assertEquals("Event rank", 1000, context
.getRank());
674 event
= fTrace
.parseEvent(context
);
675 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
676 assertEquals("Event rank", 1000, context
.getRank());
678 event
= fTrace
.getNextEvent(context
);
679 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
680 assertEquals("Event rank", 1001, context
.getRank());
682 // Position trace at event rank 4000
683 context
= fTrace
.seekEvent(4000);
684 assertEquals("Event rank", 4000, context
.getRank());
686 event
= fTrace
.parseEvent(context
);
687 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
688 assertEquals("Event rank", 4000, context
.getRank());
690 event
= fTrace
.getNextEvent(context
);
691 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
692 assertEquals("Event rank", 4001, context
.getRank());
695 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
697 // Position trace at event rank 9
698 ITmfContext context
= fTrace
.seekEvent(9);
699 assertEquals("Event rank", 9, context
.getRank());
701 ITmfEvent event
= fTrace
.parseEvent(context
);
702 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
703 assertEquals("Event rank", 9, context
.getRank());
705 event
= fTrace
.getNextEvent(context
);
706 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
707 assertEquals("Event rank", 10, context
.getRank());
709 // Position trace at event rank 999
710 context
= fTrace
.seekEvent(999);
711 assertEquals("Event rank", 999, context
.getRank());
713 event
= fTrace
.parseEvent(context
);
714 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
715 assertEquals("Event rank", 999, context
.getRank());
717 event
= fTrace
.getNextEvent(context
);
718 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
719 assertEquals("Event rank", 1000, context
.getRank());
721 // Position trace at event rank 1001
722 context
= fTrace
.seekEvent(1001);
723 assertEquals("Event rank", 1001, context
.getRank());
725 event
= fTrace
.parseEvent(context
);
726 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
727 assertEquals("Event rank", 1001, context
.getRank());
729 event
= fTrace
.getNextEvent(context
);
730 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
731 assertEquals("Event rank", 1002, context
.getRank());
733 // Position trace at event rank 4500
734 context
= fTrace
.seekEvent(4500);
735 assertEquals("Event rank", 4500, context
.getRank());
737 event
= fTrace
.parseEvent(context
);
738 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
739 assertEquals("Event rank", 4500, context
.getRank());
741 event
= fTrace
.getNextEvent(context
);
742 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
743 assertEquals("Event rank", 4501, context
.getRank());
746 public void testSeekEventOnRankOfScope() throws Exception
{
748 // Position trace at beginning
749 ITmfContext context
= fTrace
.seekEvent(-1);
750 assertEquals("Event rank", 0, context
.getRank());
752 ITmfEvent event
= fTrace
.parseEvent(context
);
753 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
754 assertEquals("Event rank", 0, context
.getRank());
756 event
= fTrace
.getNextEvent(context
);
757 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
758 assertEquals("Event rank", 1, context
.getRank());
760 // Position trace at event passed the end
761 context
= fTrace
.seekEvent(NB_EVENTS
);
762 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
764 event
= fTrace
.parseEvent(context
);
765 assertEquals("Event timestamp", null, event
);
766 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
768 event
= fTrace
.getNextEvent(context
);
769 assertEquals("Event timestamp", null, event
);
770 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
773 // ------------------------------------------------------------------------
774 // parseEvent - make sure parseEvent doesn't update the context
775 // ------------------------------------------------------------------------
777 public void testParseEvent() throws Exception
{
779 final int NB_READS
= 20;
781 // On lower bound, returns the first event (ts = 0)
782 final TmfContext context
= (TmfContext
) fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
783 TmfContext svContext
= new TmfContext(context
);
785 ITmfEvent event
= fTrace
.parseEvent(context
);
786 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
787 assertEquals("Event rank", 0, context
.getRank());
788 assertTrue("parseEvent", context
.equals(svContext
));
790 event
= fTrace
.parseEvent(context
);
791 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
792 assertEquals("Event rank", 0, context
.getRank());
793 assertTrue("parseEvent", context
.equals(svContext
));
795 event
= fTrace
.parseEvent(context
);
796 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
797 assertEquals("Event rank", 0, context
.getRank());
798 assertTrue("parseEvent", context
.equals(svContext
));
800 // Position the trace at event NB_READS
801 for (int i
= 1; i
< NB_READS
; i
++) {
802 event
= fTrace
.getNextEvent(context
);
803 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
806 svContext
= new TmfContext(context
);
807 event
= fTrace
.parseEvent(context
);
808 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
809 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
810 assertTrue("parseEvent", context
.equals(svContext
));
812 event
= fTrace
.parseEvent(context
);
813 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
814 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
815 assertTrue("parseEvent", context
.equals(svContext
));
818 // ------------------------------------------------------------------------
819 // getNextEvent - updates the context
820 // ------------------------------------------------------------------------
822 public void testGetNextEvent() throws Exception
{
824 final int NB_READS
= 20;
826 // On lower bound, returns the first event (ts = 1)
827 final ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
831 for (int i
= 0; i
< NB_READS
; i
++) {
832 event
= fTrace
.getNextEvent(context
);
833 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
834 assertEquals("Event rank", i
+ 1, context
.getRank());
837 // Make sure we stay positioned
838 event
= fTrace
.parseEvent(context
);
839 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
840 assertEquals("Event rank", NB_READS
, context
.getRank());
843 // ------------------------------------------------------------------------
845 // ------------------------------------------------------------------------
847 @SuppressWarnings("unchecked")
848 public void testProcessRequestForNbEvents() throws Exception
{
849 final int BLOCK_SIZE
= 100;
850 final int NB_EVENTS
= 1000;
851 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
853 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
854 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
856 public void handleData(final TmfEvent event
) {
857 super.handleData(event
);
858 requestedEvents
.add(event
);
861 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
862 providers
[0].sendRequest(request
);
863 request
.waitForCompletion();
865 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
866 assertTrue("isCompleted", request
.isCompleted());
867 assertFalse("isCancelled", request
.isCancelled());
869 // Ensure that we have distinct events.
870 // Don't go overboard: we are not validating the stub!
871 for (int i
= 0; i
< NB_EVENTS
; i
++) {
872 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
876 @SuppressWarnings("unchecked")
877 public void testProcessRequestForAllEvents() throws Exception
{
878 final int BLOCK_SIZE
= 1;
879 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
881 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
882 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
884 public void handleData(final TmfEvent event
) {
885 super.handleData(event
);
886 requestedEvents
.add(event
);
889 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
890 providers
[0].sendRequest(request
);
891 request
.waitForCompletion();
893 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
894 assertTrue("isCompleted", request
.isCompleted());
895 assertFalse("isCancelled", request
.isCancelled());
897 // Ensure that we have distinct events.
898 // Don't go overboard: we are not validating the stub!
899 for (int i
= 0; i
< NB_EVENTS
; i
++) {
900 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
904 // ------------------------------------------------------------------------
906 // ------------------------------------------------------------------------
908 @SuppressWarnings("unchecked")
909 public void testCancel() throws Exception
{
910 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
912 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
913 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
916 public void handleData(final TmfEvent event
) {
917 super.handleData(event
);
918 requestedEvents
.add(event
);
919 if (++nbRead
== BLOCK_SIZE
) {
924 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
925 providers
[0].sendRequest(request
);
926 request
.waitForCompletion();
928 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
929 assertTrue("isCompleted", request
.isCompleted());
930 assertTrue("isCancelled", request
.isCancelled());
933 // ------------------------------------------------------------------------
935 // ------------------------------------------------------------------------
937 public void testDefaultTmfTraceStub() throws Exception
{
938 assertFalse ("Open trace", fTrace
== null);
939 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
940 assertNull ("getResource", fTrace
.getResource());
941 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
942 assertEquals("getStreamingInterval", 0, fTrace
.getStreamingInterval());
943 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
945 assertEquals("getNbEvents", NB_EVENTS
, fTrace
.getNbEvents());
946 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
947 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
948 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
949 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
951 String expected
= "TmfTrace [fPath=" + fTrace
.getPath() + ", fCacheSize=" + fTrace
.getCacheSize() +
952 ", fNbEvents=" + fTrace
.getNbEvents() + ", fStartTime=" + fTrace
.getStartTime() +
953 ", fEndTime=" + fTrace
.getEndTime() + ", fStreamingInterval=" + fTrace
.getStreamingInterval() +
955 assertEquals("toString", expected
, fTrace
.toString());
959 // // ------------------------------------------------------------------------
961 // // Note: seekLocation() does not reliably set the rank
962 // // ------------------------------------------------------------------------
964 // public void testSeekLocationOnCacheBoundary() throws Exception {
966 // // Position trace at event rank 0
967 // TmfContext context = fTrace.seekLocation(null);
968 // ITmfEvent event = fTrace.parseEvent(context);
969 // assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
970 // assertEquals("Event rank", 0, context.getRank());
972 // context = fTrace.seekLocation(context.getLocation());
973 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
975 // event = fTrace.parseEvent(context);
976 // assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
977 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
979 // event = fTrace.getNextEvent(context);
980 // assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
981 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
983 // // Position trace at event rank 1000
984 // ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
985 // context = fTrace.seekLocation(tmpContext.getLocation());
986 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
988 // event = fTrace.parseEvent(context);
989 // assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
990 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
992 // event = fTrace.getNextEvent(context);
993 // assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
994 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
996 // // Position trace at event rank 4000
997 // tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
998 // context = fTrace.seekLocation(tmpContext.getLocation());
999 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1001 // event = fTrace.parseEvent(context);
1002 // assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
1003 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1005 // event = fTrace.getNextEvent(context);
1006 // assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
1007 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1010 // public void testSeekLocationNotOnCacheBoundary() throws Exception {
1012 // // Position trace at event rank 9
1013 // ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0));
1014 // TmfContext context = fTrace.seekLocation(tmpContext.getLocation());
1015 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1017 // ITmfEvent event = fTrace.parseEvent(context);
1018 // assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
1019 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1021 // event = fTrace.getNextEvent(context);
1022 // assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
1023 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1025 // // Position trace at event rank 999
1026 // tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0));
1027 // context = fTrace.seekLocation(tmpContext.getLocation());
1028 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1030 // event = fTrace.parseEvent(context);
1031 // assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
1032 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1034 // event = fTrace.getNextEvent(context);
1035 // assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
1036 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1038 // // Position trace at event rank 1001
1039 // tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0));
1040 // context = fTrace.seekLocation(tmpContext.getLocation());
1041 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1043 // event = fTrace.parseEvent(context);
1044 // assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
1045 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1047 // event = fTrace.getNextEvent(context);
1048 // assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
1049 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1051 // // Position trace at event rank 4500
1052 // tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0));
1053 // context = fTrace.seekLocation(tmpContext.getLocation());
1054 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1056 // event = fTrace.parseEvent(context);
1057 // assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
1058 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1060 // event = fTrace.getNextEvent(context);
1061 // assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
1062 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1065 // public void testSeekLocationOutOfScope() throws Exception {
1067 // // Position trace at beginning
1068 // ITmfContext tmpContext = fTrace.seekLocation(null);
1069 // ITmfContext context = fTrace.seekLocation(tmpContext.getLocation());
1070 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1072 // ITmfEvent event = fTrace.parseEvent(context);
1073 // assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
1074 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1076 // event = fTrace.getNextEvent(context);
1077 // assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
1078 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1080 // // Position trace at event passed the end
1081 // tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
1082 // context = fTrace.seekLocation(tmpContext.getLocation());
1083 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1085 // event = fTrace.parseEvent(context);
1086 // assertEquals("Event timestamp", null, event);
1087 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1089 // event = fTrace.getNextEvent(context);
1090 // assertEquals("Event timestamp", null, event);
1091 // assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
1094 // ------------------------------------------------------------------------
1095 // Verify checkpoints
1096 // ------------------------------------------------------------------------
1098 // public void testTmfTraceIndexing() throws Exception {
1099 // assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize());
1100 // assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
1101 // assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
1102 // assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
1103 // assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
1104 // assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
1106 // final Vector<TmfCheckpoint> checkpoints = fTrace.getCheckpoints();
1107 // final int pageSize = fTrace.getIndexPageSize();
1108 // assertTrue("Checkpoints exist", checkpoints != null);
1110 // // Validate that each checkpoint points to the right event
1111 // for (int i = 0; i < checkpoints.size(); i++) {
1112 // final TmfCheckpoint checkpoint = checkpoints.get(i);
1113 // final TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
1114 // final ITmfEvent event = fTrace.parseEvent(context);
1115 // assertTrue(context.getRank() == i * pageSize);
1116 // assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));