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
.tmf
.core
.component
.ITmfDataProvider
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfProviderManager
;
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
.ITmfTrace
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpointIndexer
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
41 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
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 TmfTraceException e
) {
95 } catch (final URISyntaxException e
) {
97 } catch (final IOException e
) {
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
108 public void testStandardConstructor() throws Exception
{
109 TmfTraceStub trace
= null;
110 File testfile
= null;
112 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
113 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
114 trace
= new TmfTraceStub(testfile
.toURI().getPath());
116 } catch (final URISyntaxException e
) {
117 fail("URISyntaxException");
118 } catch (final IOException e
) {
122 assertFalse ("Open trace", trace
== null);
123 assertEquals("getType", TmfEvent
.class, trace
.getType());
124 assertNull ("getResource", trace
.getResource());
125 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
126 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
127 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
128 assertEquals("getName", TEST_STREAM
, trace
.getName());
130 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
131 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
132 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
133 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
134 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
137 public void testStandardConstructorCacheSize() throws Exception
{
138 TmfTraceStub trace
= null;
139 File testfile
= null;
141 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
142 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
143 trace
= new TmfTraceStub(testfile
.toURI().getPath(), 0);
145 } catch (final URISyntaxException e
) {
146 fail("URISyntaxException");
147 } catch (final IOException e
) {
151 assertFalse ("Open trace", trace
== null);
152 assertEquals("getType", TmfEvent
.class, trace
.getType());
153 assertNull ("getResource", trace
.getResource());
154 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
155 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
156 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
157 assertEquals("getName", TEST_STREAM
, trace
.getName());
159 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
160 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
161 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
162 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
163 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
166 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
167 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
168 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
);
170 } catch (final URISyntaxException e
) {
171 fail("URISyntaxException");
172 } catch (final IOException e
) {
176 assertFalse ("Open trace", trace
== null);
177 assertEquals("getType", TmfEvent
.class, trace
.getType());
178 assertNull ("getResource", trace
.getResource());
179 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
180 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
181 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
182 assertEquals("getName", TEST_STREAM
, trace
.getName());
184 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
185 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
186 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
187 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
188 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
191 public void testFullConstructor() throws Exception
{
192 TmfTraceStub trace
= null;
193 File testfile
= null;
195 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
196 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
197 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, null);
199 } catch (final URISyntaxException e
) {
200 fail("URISyntaxException");
201 } catch (final IOException e
) {
205 assertFalse ("Open trace", trace
== null);
206 assertEquals("getType", TmfEvent
.class, trace
.getType());
207 assertNull ("getResource", trace
.getResource());
208 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
209 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
210 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
211 assertEquals("getName", TEST_STREAM
, trace
.getName());
213 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
214 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
215 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
216 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
217 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
220 public void testLiveTraceConstructor() throws Exception
{
221 TmfTraceStub trace
= null;
222 File testfile
= null;
223 final long interval
= 100;
225 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
226 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
227 trace
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, interval
);
229 } catch (final URISyntaxException e
) {
230 fail("URISyntaxException");
231 } catch (final IOException e
) {
235 assertFalse ("Open trace", trace
== null);
236 assertEquals("getType", TmfEvent
.class, trace
.getType());
237 assertNull ("getResource", trace
.getResource());
238 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
239 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
240 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
241 assertEquals("getName", TEST_STREAM
, trace
.getName());
243 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
244 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
245 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
246 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
247 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
250 @SuppressWarnings({ "rawtypes", "unchecked" })
251 public void testCopyConstructor() throws Exception
{
252 TmfTraceStub original
= null;
253 TmfTraceStub trace
= null;
254 File testfile
= null;
256 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
257 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
258 original
= new TmfTraceStub(testfile
.toURI().getPath(), BLOCK_SIZE
, new TmfCheckpointIndexer(null));
259 trace
= new TmfTraceStub(original
);
261 } catch (final URISyntaxException e
) {
262 fail("URISyntaxException");
263 } catch (final IOException e
) {
267 assertFalse ("Open trace", trace
== null);
268 assertEquals("getType", TmfEvent
.class, trace
.getType());
269 assertNull ("getResource", trace
.getResource());
270 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
271 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
272 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
273 assertEquals("getName", TEST_STREAM
, trace
.getName());
275 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
276 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
277 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
278 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
279 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
281 // Test the copy of a null trace
283 new TmfTraceStub((TmfTraceStub
) null);
284 fail("Missing exception");
285 } catch (final IllegalArgumentException e
) {
287 } catch (final Exception e
) {
288 fail("Unexpected exception");
292 // ------------------------------------------------------------------------
293 // Trace initialization
294 // ------------------------------------------------------------------------
296 public void testInitializeNullPath() throws Exception
{
298 // Instantiate an "empty" trace
299 final TmfTraceStub trace
= new TmfTraceStub();
302 trace
.initialize(null, null, TmfEvent
.class);
303 fail("TmfTrace.initialize() - no exception thrown");
304 } catch (TmfTraceException e
) {
306 } catch (Exception e
) {
307 fail("TmfTrace.initialize() - wrong exception thrown");
311 public void testInitializeSimplePath() throws Exception
{
313 // Instantiate an "empty" trace
314 final TmfTraceStub trace
= new TmfTraceStub();
316 // Path == trace name
317 String path
= "TraceName";
319 trace
.initialize(null, path
, TmfEvent
.class);
320 } catch (Exception e
) {
321 fail("TmfTrace.initialize() - Exception thrown");
324 assertFalse ("Open trace", trace
== null);
325 assertEquals("getType", TmfEvent
.class, trace
.getType());
326 assertNull ("getResource", trace
.getResource());
327 assertEquals("getPath", path
, trace
.getPath());
328 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
329 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
330 assertEquals("getName", path
, trace
.getName());
332 assertEquals("getNbEvents", 0, trace
.getNbEvents());
333 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
334 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
335 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
336 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
339 public void testInitializeNormalPath() throws Exception
{
341 // Instantiate an "empty" trace
342 final TmfTraceStub trace
= new TmfTraceStub();
344 // Path == trace name
345 String name
= "TraceName";
346 String path
= "/my/trace/path/" + name
;
348 trace
.initialize(null, path
, TmfEvent
.class);
349 } catch (Exception e
) {
350 fail("TmfTrace.initialize() - Exception thrown");
353 assertFalse ("Open trace", trace
== null);
354 assertEquals("getType", TmfEvent
.class, trace
.getType());
355 assertNull ("getResource", trace
.getResource());
356 assertEquals("getPath", path
, trace
.getPath());
357 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
358 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
359 assertEquals("getName", name
, trace
.getName());
361 assertEquals("getNbEvents", 0, trace
.getNbEvents());
362 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
363 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
364 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
365 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
368 public void testInitTrace() throws Exception
{
370 // Instantiate an "empty" trace
371 final TmfTraceStub trace
= new TmfTraceStub();
373 assertFalse ("Open trace", trace
== null);
374 assertNull ("getType", trace
.getType());
375 assertNull ("getResource", trace
.getResource());
376 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
377 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
378 assertEquals("getName", "", trace
.getName());
380 assertEquals("getNbEvents", 0, trace
.getNbEvents());
381 assertEquals("getRange-start", Long
.MAX_VALUE
, trace
.getTimeRange().getStartTime().getValue());
382 assertEquals("getRange-end", Long
.MIN_VALUE
, trace
.getTimeRange().getEndTime().getValue());
383 assertEquals("getStartTime", Long
.MAX_VALUE
, trace
.getStartTime().getValue());
384 assertEquals("getEndTime", Long
.MIN_VALUE
, trace
.getEndTime().getValue());
387 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
388 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
389 assertTrue("validate", trace
.validate(null, testfile
.getPath()));
391 // InitTrace and wait for indexing completion...
392 trace
.initTrace(null, testfile
.getPath(), TmfEvent
.class);
395 while (trace
.getNbEvents() < NB_EVENTS
&& nbSecs
< 10) {
399 if (trace
.getNbEvents() < NB_EVENTS
) {
403 assertFalse ("Open trace", trace
== null);
404 assertEquals("getType", TmfEvent
.class, trace
.getType());
405 assertNull ("getResource", trace
.getResource());
406 assertEquals("getCacheSize", ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, trace
.getCacheSize());
407 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
408 assertEquals("getName", TEST_STREAM
, trace
.getName());
410 assertEquals("getNbEvents", NB_EVENTS
, trace
.getNbEvents());
411 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
412 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
413 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
414 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
417 // ------------------------------------------------------------------------
418 // Set/Get streaming interval
419 // ------------------------------------------------------------------------
421 public void testSetStreamingInterval() throws Exception
{
422 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
425 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
428 trace
.setStreamingInterval(interval
);
429 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
432 trace
.setStreamingInterval(interval
);
433 assertEquals("getStreamingInterval", 0, trace
.getStreamingInterval());
436 trace
.setStreamingInterval(interval
);
437 assertEquals("getStreamingInterval", interval
, trace
.getStreamingInterval());
442 // ------------------------------------------------------------------------
443 // Set/Get time range
444 // ------------------------------------------------------------------------
446 public void testSetTimeRange() throws Exception
{
447 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
450 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
451 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
452 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
453 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
455 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
456 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
457 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
458 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
459 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
464 public void testSetStartTime() throws Exception
{
465 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
468 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
469 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
470 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
471 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
473 trace
.setStartTime(new TmfTimestamp(100));
474 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
475 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
476 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
477 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
482 public void testSetEndTime() throws Exception
{
483 final TmfTraceStub trace
= new TmfTraceStub(fTrace
);
486 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
487 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
488 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
489 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
491 trace
.setEndTime(new TmfTimestamp(100));
492 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
493 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
494 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
495 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
500 // ------------------------------------------------------------------------
501 // seekEvent on location (note: does not reliably set the rank)
502 // ------------------------------------------------------------------------
504 public void testSeekEventOnCacheBoundary() throws Exception
{
506 // Position trace at event rank 0
507 ITmfContext context
= fTrace
.seekEvent(0);
508 ITmfEvent event
= fTrace
.parseEvent(context
);
509 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
510 assertEquals("Event rank", 0, context
.getRank());
512 context
= fTrace
.seekEvent(context
.getLocation());
513 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
515 event
= fTrace
.parseEvent(context
);
516 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
517 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
519 event
= fTrace
.getNext(context
);
520 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
521 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
523 // Position trace at event rank 1000
524 ITmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
525 context
= fTrace
.seekEvent(tmpContext
.getLocation());
526 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
528 event
= fTrace
.parseEvent(context
);
529 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
530 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
532 event
= fTrace
.getNext(context
);
533 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
534 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
536 // Position trace at event rank 4000
537 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
538 context
= fTrace
.seekEvent(tmpContext
.getLocation());
539 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
541 event
= fTrace
.parseEvent(context
);
542 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
543 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
545 event
= fTrace
.getNext(context
);
546 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
547 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
550 public void testSeekEventNotOnCacheBoundary() throws Exception
{
552 // Position trace at event rank 9
553 ITmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
554 TmfContext context
= fTrace
.seekEvent(tmpContext
.getLocation());
555 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
557 ITmfEvent event
= fTrace
.parseEvent(context
);
558 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
559 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
561 event
= fTrace
.getNext(context
);
562 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
563 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
565 // Position trace at event rank 999
566 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
567 context
= fTrace
.seekEvent(tmpContext
.getLocation());
568 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
570 event
= fTrace
.parseEvent(context
);
571 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
572 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
574 event
= fTrace
.getNext(context
);
575 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
576 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
578 // Position trace at event rank 1001
579 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
580 context
= fTrace
.seekEvent(tmpContext
.getLocation());
581 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
583 event
= fTrace
.parseEvent(context
);
584 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
585 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
587 event
= fTrace
.getNext(context
);
588 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
589 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
591 // Position trace at event rank 4500
592 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
593 context
= fTrace
.seekEvent(tmpContext
.getLocation());
594 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
596 event
= fTrace
.parseEvent(context
);
597 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
598 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
600 event
= fTrace
.getNext(context
);
601 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
602 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
605 public void testSeekEventOutOfScope() throws Exception
{
607 // Position trace at beginning
608 ITmfContext tmpContext
= fTrace
.seekEvent(0);
609 ITmfContext context
= fTrace
.seekEvent(tmpContext
.getLocation());
610 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
612 ITmfEvent event
= fTrace
.parseEvent(context
);
613 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
614 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
616 event
= fTrace
.getNext(context
);
617 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
618 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
620 // Position trace at event passed the end
621 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
622 assertNull("Event timestamp", context
.getLocation());
623 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
625 event
= fTrace
.getNext(context
);
626 assertNull("Event", event
);
629 // ------------------------------------------------------------------------
630 // seekEvent on timestamp (note: does not reliably set the rank)
631 // ------------------------------------------------------------------------
633 public void testSeekEventOnNullTimestamp() throws Exception
{
635 // Position trace at event rank 0
636 ITmfContext context
= fTrace
.seekEvent((ITmfTimestamp
) null);
637 assertEquals("Event rank", 0, context
.getRank());
639 ITmfEvent event
= fTrace
.parseEvent(context
);
640 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
641 assertEquals("Event rank", 0, context
.getRank());
644 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
646 // Position trace at event rank 0
647 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
648 assertEquals("Event rank", 0, context
.getRank());
650 ITmfEvent event
= fTrace
.parseEvent(context
);
651 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
652 assertEquals("Event rank", 0, context
.getRank());
654 event
= fTrace
.getNext(context
);
655 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
656 assertEquals("Event rank", 1, context
.getRank());
658 // Position trace at event rank 1000
659 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
660 assertEquals("Event rank", 1000, context
.getRank());
662 event
= fTrace
.parseEvent(context
);
663 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
664 assertEquals("Event rank", 1000, context
.getRank());
666 event
= fTrace
.getNext(context
);
667 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
668 assertEquals("Event rank", 1001, context
.getRank());
670 // Position trace at event rank 4000
671 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
672 assertEquals("Event rank", 4000, context
.getRank());
674 event
= fTrace
.parseEvent(context
);
675 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
676 assertEquals("Event rank", 4000, context
.getRank());
678 event
= fTrace
.getNext(context
);
679 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
680 assertEquals("Event rank", 4001, context
.getRank());
683 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
685 // Position trace at event rank 1
686 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
687 assertEquals("Event rank", 1, context
.getRank());
689 ITmfEvent event
= fTrace
.parseEvent(context
);
690 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
691 assertEquals("Event rank", 1, context
.getRank());
693 event
= fTrace
.getNext(context
);
694 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
695 assertEquals("Event rank", 2, context
.getRank());
697 // Position trace at event rank 9
698 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
699 assertEquals("Event rank", 9, context
.getRank());
701 event
= fTrace
.parseEvent(context
);
702 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
703 assertEquals("Event rank", 9, context
.getRank());
705 event
= fTrace
.getNext(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(new TmfTimestamp(1000, SCALE
, 0));
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
.getNext(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(new TmfTimestamp(1002, SCALE
, 0));
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
.getNext(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(new TmfTimestamp(4501, SCALE
, 0));
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
.getNext(context
);
742 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
743 assertEquals("Event rank", 4501, context
.getRank());
746 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
748 // Position trace at beginning
749 ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
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
.getNext(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(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
762 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
764 event
= fTrace
.parseEvent(context
);
765 assertEquals("Event timestamp", null, event
);
766 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
768 event
= fTrace
.getNext(context
);
769 assertEquals("Event timestamp", null, event
);
770 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
773 // ------------------------------------------------------------------------
775 // ------------------------------------------------------------------------
777 public void testSeekEventOnNegativeRank() throws Exception
{
779 // Position trace at event rank 0
780 ITmfContext context
= fTrace
.seekEvent(-1);
781 assertEquals("Event rank", 0, context
.getRank());
783 ITmfEvent event
= fTrace
.parseEvent(context
);
784 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
785 assertEquals("Event rank", 0, context
.getRank());
788 public void testSeekOnRankOnCacheBoundary() throws Exception
{
790 // On lower bound, returns the first event (ts = 1)
791 ITmfContext context
= fTrace
.seekEvent(0);
792 assertEquals("Event rank", 0, context
.getRank());
794 ITmfEvent event
= fTrace
.parseEvent(context
);
795 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
796 assertEquals("Event rank", 0, context
.getRank());
798 event
= fTrace
.getNext(context
);
799 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
800 assertEquals("Event rank", 1, context
.getRank());
802 // Position trace at event rank 1000
803 context
= fTrace
.seekEvent(1000);
804 assertEquals("Event rank", 1000, context
.getRank());
806 event
= fTrace
.parseEvent(context
);
807 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
808 assertEquals("Event rank", 1000, context
.getRank());
810 event
= fTrace
.getNext(context
);
811 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
812 assertEquals("Event rank", 1001, context
.getRank());
814 // Position trace at event rank 4000
815 context
= fTrace
.seekEvent(4000);
816 assertEquals("Event rank", 4000, context
.getRank());
818 event
= fTrace
.parseEvent(context
);
819 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
820 assertEquals("Event rank", 4000, context
.getRank());
822 event
= fTrace
.getNext(context
);
823 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
824 assertEquals("Event rank", 4001, context
.getRank());
827 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
829 // Position trace at event rank 9
830 ITmfContext context
= fTrace
.seekEvent(9);
831 assertEquals("Event rank", 9, context
.getRank());
833 ITmfEvent event
= fTrace
.parseEvent(context
);
834 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
835 assertEquals("Event rank", 9, context
.getRank());
837 event
= fTrace
.getNext(context
);
838 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
839 assertEquals("Event rank", 10, context
.getRank());
841 // Position trace at event rank 999
842 context
= fTrace
.seekEvent(999);
843 assertEquals("Event rank", 999, context
.getRank());
845 event
= fTrace
.parseEvent(context
);
846 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
847 assertEquals("Event rank", 999, context
.getRank());
849 event
= fTrace
.getNext(context
);
850 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
851 assertEquals("Event rank", 1000, context
.getRank());
853 // Position trace at event rank 1001
854 context
= fTrace
.seekEvent(1001);
855 assertEquals("Event rank", 1001, context
.getRank());
857 event
= fTrace
.parseEvent(context
);
858 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
859 assertEquals("Event rank", 1001, context
.getRank());
861 event
= fTrace
.getNext(context
);
862 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
863 assertEquals("Event rank", 1002, context
.getRank());
865 // Position trace at event rank 4500
866 context
= fTrace
.seekEvent(4500);
867 assertEquals("Event rank", 4500, context
.getRank());
869 event
= fTrace
.parseEvent(context
);
870 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
871 assertEquals("Event rank", 4500, context
.getRank());
873 event
= fTrace
.getNext(context
);
874 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
875 assertEquals("Event rank", 4501, context
.getRank());
878 public void testSeekEventOnRankOutOfScope() throws Exception
{
880 // Position trace at beginning
881 ITmfContext context
= fTrace
.seekEvent(-1);
882 assertEquals("Event rank", 0, context
.getRank());
884 ITmfEvent event
= fTrace
.parseEvent(context
);
885 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
886 assertEquals("Event rank", 0, context
.getRank());
888 event
= fTrace
.getNext(context
);
889 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
890 assertEquals("Event rank", 1, context
.getRank());
892 // Position trace at event passed the end
893 context
= fTrace
.seekEvent(NB_EVENTS
);
894 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
896 event
= fTrace
.parseEvent(context
);
897 assertNull("Event", event
);
898 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
900 event
= fTrace
.getNext(context
);
901 assertNull("Event", event
);
902 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
905 // ------------------------------------------------------------------------
906 // parseEvent - make sure parseEvent doesn't update the context
907 // ------------------------------------------------------------------------
909 public void testParseEvent() throws Exception
{
911 final int NB_READS
= 20;
913 // On lower bound, returns the first event (ts = 0)
914 final TmfContext context
= (TmfContext
) fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
915 TmfContext svContext
= new TmfContext(context
);
917 ITmfEvent event
= fTrace
.parseEvent(context
);
918 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
919 assertEquals("Event rank", 0, context
.getRank());
920 assertTrue("parseEvent", context
.equals(svContext
));
922 event
= fTrace
.parseEvent(context
);
923 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
924 assertEquals("Event rank", 0, context
.getRank());
925 assertTrue("parseEvent", context
.equals(svContext
));
927 event
= fTrace
.parseEvent(context
);
928 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
929 assertEquals("Event rank", 0, context
.getRank());
930 assertTrue("parseEvent", context
.equals(svContext
));
932 // Position the trace at event NB_READS
933 for (int i
= 1; i
< NB_READS
; i
++) {
934 event
= fTrace
.getNext(context
);
935 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
938 svContext
= new TmfContext(context
);
939 event
= fTrace
.parseEvent(context
);
940 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
941 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
942 assertTrue("parseEvent", context
.equals(svContext
));
944 event
= fTrace
.parseEvent(context
);
945 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
946 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
947 assertTrue("parseEvent", context
.equals(svContext
));
950 // ------------------------------------------------------------------------
951 // readNextEvent - updates the context
952 // ------------------------------------------------------------------------
954 public void testReadNextEvent() throws Exception
{
956 final int NB_READS
= 20;
958 // On lower bound, returns the first event (ts = 1)
959 final ITmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
963 for (int i
= 0; i
< NB_READS
; i
++) {
964 event
= fTrace
.getNext(context
);
965 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
966 assertEquals("Event rank", i
+ 1, context
.getRank());
969 // Make sure we stay positioned
970 event
= fTrace
.parseEvent(context
);
971 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
972 assertEquals("Event rank", NB_READS
, context
.getRank());
975 // ------------------------------------------------------------------------
977 // ------------------------------------------------------------------------
979 @SuppressWarnings("unchecked")
980 public void testProcessEventRequestForAllEvents() throws Exception
{
981 final int BLOCK_SIZE
= 1;
982 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
984 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
985 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
987 public void handleData(final TmfEvent event
) {
988 super.handleData(event
);
989 requestedEvents
.add(event
);
992 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
993 providers
[0].sendRequest(request
);
994 request
.waitForCompletion();
996 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
997 assertTrue("isCompleted", request
.isCompleted());
998 assertFalse("isCancelled", request
.isCancelled());
1000 // Ensure that we have distinct events.
1001 // Don't go overboard: we are not validating the stub!
1002 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1003 assertEquals("Distinct events", i
+ 1, requestedEvents
.get(i
).getTimestamp().getValue());
1007 @SuppressWarnings("unchecked")
1008 public void testProcessEventRequestForNbEvents() throws Exception
{
1009 final int BLOCK_SIZE
= 100;
1010 final int NB_EVENTS
= 1000;
1011 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1013 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
1014 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1016 public void handleData(final TmfEvent event
) {
1017 super.handleData(event
);
1018 requestedEvents
.add(event
);
1021 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1022 providers
[0].sendRequest(request
);
1023 request
.waitForCompletion();
1025 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1026 assertTrue("isCompleted", request
.isCompleted());
1027 assertFalse("isCancelled", request
.isCancelled());
1029 // Ensure that we have distinct events.
1030 // Don't go overboard: we are not validating the stub!
1031 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1032 assertEquals("Distinct events", i
+ 1, requestedEvents
.get(i
).getTimestamp().getValue());
1036 @SuppressWarnings("unchecked")
1037 public void testProcessEventRequestForSomeEvents() throws Exception
{
1038 final int BLOCK_SIZE
= 1;
1039 final long startTime
= 100;
1040 final int NB_EVENTS
= 1000;
1041 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1043 final TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(startTime
, SCALE
), TmfTimestamp
.BIG_CRUNCH
);
1044 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1046 public void handleData(final TmfEvent event
) {
1047 super.handleData(event
);
1048 requestedEvents
.add(event
);
1051 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1052 providers
[0].sendRequest(request
);
1053 request
.waitForCompletion();
1055 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1056 assertTrue("isCompleted", request
.isCompleted());
1057 assertFalse("isCancelled", request
.isCancelled());
1059 // Ensure that we have distinct events.
1060 // Don't go overboard: we are not validating the stub!
1061 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1062 assertEquals("Distinct events", startTime
+ i
, requestedEvents
.get(i
).getTimestamp().getValue());
1066 @SuppressWarnings("unchecked")
1067 public void testProcessEventRequestForOtherEvents() throws Exception
{
1068 final int BLOCK_SIZE
= 1;
1069 final int startIndex
= 99;
1070 final long startTime
= 100;
1071 final int NB_EVENTS
= 1000;
1072 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1074 final TmfTimeRange range
= new TmfTimeRange(new TmfTimestamp(startTime
, SCALE
), TmfTimestamp
.BIG_CRUNCH
);
1075 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, startIndex
, NB_EVENTS
, BLOCK_SIZE
) {
1077 public void handleData(final TmfEvent event
) {
1078 super.handleData(event
);
1079 requestedEvents
.add(event
);
1082 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1083 providers
[0].sendRequest(request
);
1084 request
.waitForCompletion();
1086 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1087 assertTrue("isCompleted", request
.isCompleted());
1088 assertFalse("isCancelled", request
.isCancelled());
1090 // Ensure that we have distinct events.
1091 // Don't go overboard: we are not validating the stub!
1092 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1093 assertEquals("Distinct events", startTime
+ i
, requestedEvents
.get(i
).getTimestamp().getValue());
1097 @SuppressWarnings("unchecked")
1098 public void testProcessDataRequestForSomeEvents() throws Exception
{
1099 final int startIndex
= 100;
1100 final int NB_EVENTS
= 1000;
1101 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1103 final TmfDataRequest
<TmfEvent
> request
= new TmfDataRequest
<TmfEvent
>(TmfEvent
.class, startIndex
, NB_EVENTS
) {
1105 public void handleData(final TmfEvent event
) {
1106 super.handleData(event
);
1107 requestedEvents
.add(event
);
1110 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1111 providers
[0].sendRequest(request
);
1112 request
.waitForCompletion();
1114 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
1115 assertTrue("isCompleted", request
.isCompleted());
1116 assertFalse("isCancelled", request
.isCancelled());
1118 // Ensure that we have distinct events.
1119 // Don't go overboard: we are not validating the stub!
1120 for (int i
= 0; i
< NB_EVENTS
; i
++) {
1121 assertEquals("Distinct events", startIndex
+ 1 + i
, requestedEvents
.get(i
).getTimestamp().getValue());
1125 // ------------------------------------------------------------------------
1127 // ------------------------------------------------------------------------
1129 @SuppressWarnings("unchecked")
1130 public void testCancel() throws Exception
{
1131 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
1133 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
1134 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
1137 public void handleData(final TmfEvent event
) {
1138 super.handleData(event
);
1139 requestedEvents
.add(event
);
1140 if (++nbRead
== BLOCK_SIZE
) {
1145 final ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
1146 providers
[0].sendRequest(request
);
1147 request
.waitForCompletion();
1149 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
1150 assertTrue("isCompleted", request
.isCompleted());
1151 assertTrue("isCancelled", request
.isCancelled());
1154 // ------------------------------------------------------------------------
1156 // ------------------------------------------------------------------------
1158 public void testDefaultTmfTraceStub() throws Exception
{
1159 assertFalse ("Open trace", fTrace
== null);
1160 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
1161 assertNull ("getResource", fTrace
.getResource());
1162 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
1163 assertEquals("getStreamingInterval", 0, fTrace
.getStreamingInterval());
1164 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
1166 assertEquals("getNbEvents", NB_EVENTS
, fTrace
.getNbEvents());
1167 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
1168 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
1169 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
1170 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
1172 String expected
= "TmfTrace [fPath=" + fTrace
.getPath() + ", fCacheSize=" + fTrace
.getCacheSize() +
1173 ", fNbEvents=" + fTrace
.getNbEvents() + ", fStartTime=" + fTrace
.getStartTime() +
1174 ", fEndTime=" + fTrace
.getEndTime() + ", fStreamingInterval=" + fTrace
.getStreamingInterval() +
1176 assertEquals("toString", expected
, fTrace
.toString());