1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.trace
;
16 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
19 import java
.util
.Vector
;
21 import junit
.framework
.TestCase
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.linuxtools
.tmf
.component
.ITmfDataProvider
;
26 import org
.eclipse
.linuxtools
.tmf
.component
.TmfProviderManager
;
27 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
31 import org
.eclipse
.linuxtools
.tmf
.tests
.TmfCoreTestPlugin
;
32 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
35 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTrace
;
36 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
39 * <b><u>TmfTraceTest</u></b>
41 * Test suite for the TmfTrace class.
43 @SuppressWarnings("nls")
44 public class TmfTraceTest
extends TestCase
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 private static final String DIRECTORY
= "testfiles";
51 private static final String TEST_STREAM
= "A-Test-10K";
52 private static final int BLOCK_SIZE
= 500;
53 private static final int NB_EVENTS
= 10000;
54 private static TmfTraceStub fTrace
= null;
56 private static byte SCALE
= (byte) -3;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 public TmfTraceTest(String name
) throws Exception
{
67 protected void setUp() throws Exception
{
69 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
70 // Dummy request to force the trace indexing
71 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class) {
73 public void handleData(TmfEvent event
) {
74 super.handleData(event
);
77 fTrace
.sendRequest(request
);
78 request
.waitForCompletion();
82 protected void tearDown() throws Exception
{
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
92 private TmfTraceStub
setupTrace(String path
) {
95 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
96 File test
= new File(FileLocator
.toFileURL(location
).toURI());
97 fTrace
= new TmfTraceStub(test
.getPath(), BLOCK_SIZE
, false);
98 } catch (URISyntaxException e
) {
100 } catch (IOException e
) {
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
111 public void testTmfTraceDefault() throws Exception
{
112 TmfTraceStub trace
= null;
113 File testfile
= null;
115 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
116 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
117 trace
= new TmfTraceStub(testfile
.getPath());
118 } catch (URISyntaxException e
) {
119 fail("URISyntaxException");
120 } catch (IOException e
) {
123 assertTrue ("Open trace", trace
!= null);
124 assertEquals("getType", TmfEvent
.class, trace
.getType());
125 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
126 assertEquals("getName", TEST_STREAM
, trace
.getName());
127 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getCacheSize());
130 public void testTmfTraceDefaultCacheSize() throws Exception
{
131 TmfTraceStub trace
= null;
132 File testfile
= null;
134 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
135 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
136 trace
= new TmfTraceStub(testfile
.getPath(), 0);
137 } catch (URISyntaxException e
) {
138 fail("URISyntaxException");
139 } catch (IOException e
) {
142 assertTrue ("Open trace", trace
!= null);
143 assertEquals("getType", TmfEvent
.class, trace
.getType());
144 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
145 assertEquals("getName", TEST_STREAM
, trace
.getName());
146 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getCacheSize());
149 public void testTmfTrace() throws Exception
{
150 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
151 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
152 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
155 public void testClone() throws Exception
{
156 TmfTraceStub trace
= fTrace
.clone();
157 assertEquals("getType", TmfEvent
.class, trace
.getType());
158 assertEquals("getPath", fTrace
.getPath(), trace
.getPath());
159 assertEquals("getName", TEST_STREAM
, trace
.getName());
160 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
161 assertEquals("getTimeRange", fTrace
.getTimeRange(), trace
.getTimeRange());
164 // ------------------------------------------------------------------------
165 // Get/Set time range
166 // ------------------------------------------------------------------------
168 public void testSetTimeRange() throws Exception
{
169 TmfTraceStub trace
= fTrace
.clone();
171 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
172 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
173 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
174 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
176 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
177 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
178 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
179 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
180 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
183 public void testSetStartTime() throws Exception
{
184 TmfTraceStub trace
= fTrace
.clone();
186 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
187 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
188 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
189 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
191 trace
.setStartTime(new TmfTimestamp(100));
192 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
193 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
194 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
195 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
198 public void testSetEndTime() throws Exception
{
199 TmfTraceStub trace
= fTrace
.clone();
201 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
202 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
203 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
204 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
206 trace
.setEndTime(new TmfTimestamp(100));
207 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
208 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
209 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
210 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
213 // ------------------------------------------------------------------------
214 // Verify checkpoints
215 // ------------------------------------------------------------------------
217 public void testTmfTraceIndexing() throws Exception
{
218 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
219 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
220 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
221 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
222 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
223 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
225 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
226 int pageSize
= fTrace
.getCacheSize();
227 assertTrue("Checkpoints exist", checkpoints
!= null);
229 // Validate that each checkpoint points to the right event
230 for (int i
= 0; i
< checkpoints
.size(); i
++) {
231 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
232 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
233 TmfEvent event
= fTrace
.parseEvent(context
);
234 assertTrue(context
.getRank() == i
* pageSize
);
235 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
239 // ------------------------------------------------------------------------
240 // parseEvent - make sure parseEvent doesn't update the context
241 // ------------------------------------------------------------------------
243 public void testParseEvent() throws Exception
{
247 // On lower bound, returns the first event (ts = 0)
248 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
249 TmfContext svContext
= new TmfContext(context
);
251 TmfEvent event
= fTrace
.parseEvent(context
);
252 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
253 assertEquals("Event rank", 0, context
.getRank());
254 assertTrue("parseEvent", context
.equals(svContext
));
256 event
= fTrace
.parseEvent(context
);
257 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
258 assertEquals("Event rank", 0, context
.getRank());
259 assertTrue("parseEvent", context
.equals(svContext
));
261 event
= fTrace
.parseEvent(context
);
262 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
263 assertEquals("Event rank", 0, context
.getRank());
264 assertTrue("parseEvent", context
.equals(svContext
));
266 // Position the trace at event NB_READS
267 for (int i
= 1; i
< NB_READS
; i
++) {
268 event
= fTrace
.getNextEvent(context
);
269 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
272 svContext
= new TmfContext(context
);
273 event
= fTrace
.parseEvent(context
);
274 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
275 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
276 assertTrue("parseEvent", context
.equals(svContext
));
278 event
= fTrace
.parseEvent(context
);
279 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
280 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
281 assertTrue("parseEvent", context
.equals(svContext
));
284 // ------------------------------------------------------------------------
285 // getNextEvent - updates the context
286 // ------------------------------------------------------------------------
288 public void testGetNextEvent() throws Exception
{
292 // On lower bound, returns the first event (ts = 1)
293 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
297 for (int i
= 0; i
< NB_READS
; i
++) {
298 event
= fTrace
.getNextEvent(context
);
299 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
300 assertEquals("Event rank", i
+ 1, context
.getRank());
303 // Make sure we stay positioned
304 event
= fTrace
.parseEvent(context
);
305 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
306 assertEquals("Event rank", NB_READS
, context
.getRank());
309 // ------------------------------------------------------------------------
311 // Note: seekLocation() does not reliably set the rank
312 // ------------------------------------------------------------------------
314 public void testSeekLocationOnCacheBoundary() throws Exception
{
316 // Position trace at event rank 0
317 TmfContext context
= fTrace
.seekLocation(null);
318 TmfEvent event
= fTrace
.parseEvent(context
);
319 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
320 assertEquals("Event rank", 0, context
.getRank());
322 context
= fTrace
.seekLocation(context
.getLocation());
323 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
325 event
= fTrace
.parseEvent(context
);
326 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
327 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
329 event
= fTrace
.getNextEvent(context
);
330 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
331 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
333 // Position trace at event rank 1000
334 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
335 context
= fTrace
.seekLocation(tmpContext
.getLocation());
336 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
338 event
= fTrace
.parseEvent(context
);
339 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
340 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
342 event
= fTrace
.getNextEvent(context
);
343 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
344 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
346 // Position trace at event rank 4000
347 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
348 context
= fTrace
.seekLocation(tmpContext
.getLocation());
349 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
351 event
= fTrace
.parseEvent(context
);
352 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
353 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
355 event
= fTrace
.getNextEvent(context
);
356 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
357 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
360 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
362 // Position trace at event rank 9
363 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
364 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
365 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
367 TmfEvent event
= fTrace
.parseEvent(context
);
368 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
369 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
371 event
= fTrace
.getNextEvent(context
);
372 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
373 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
375 // Position trace at event rank 999
376 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
377 context
= fTrace
.seekLocation(tmpContext
.getLocation());
378 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
380 event
= fTrace
.parseEvent(context
);
381 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
382 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
384 event
= fTrace
.getNextEvent(context
);
385 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
386 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
388 // Position trace at event rank 1001
389 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
390 context
= fTrace
.seekLocation(tmpContext
.getLocation());
391 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
393 event
= fTrace
.parseEvent(context
);
394 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
395 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
397 event
= fTrace
.getNextEvent(context
);
398 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
399 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
401 // Position trace at event rank 4500
402 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
403 context
= fTrace
.seekLocation(tmpContext
.getLocation());
404 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
406 event
= fTrace
.parseEvent(context
);
407 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
408 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
410 event
= fTrace
.getNextEvent(context
);
411 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
412 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
415 public void testSeekLocationOutOfScope() throws Exception
{
417 // Position trace at beginning
418 TmfContext tmpContext
= fTrace
.seekLocation(null);
419 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
420 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
422 TmfEvent event
= fTrace
.parseEvent(context
);
423 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
424 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
426 event
= fTrace
.getNextEvent(context
);
427 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
428 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
430 // Position trace at event passed the end
431 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
432 context
= fTrace
.seekLocation(tmpContext
.getLocation());
433 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
435 event
= fTrace
.parseEvent(context
);
436 assertEquals("Event timestamp", null, event
);
437 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
439 event
= fTrace
.getNextEvent(context
);
440 assertEquals("Event timestamp", null, event
);
441 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
444 // ------------------------------------------------------------------------
445 // seekEvent on timestamp
446 // ------------------------------------------------------------------------
448 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
450 // Position trace at event rank 0
451 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
452 assertEquals("Event rank", 0, context
.getRank());
454 TmfEvent event
= fTrace
.parseEvent(context
);
455 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
456 assertEquals("Event rank", 0, context
.getRank());
458 event
= fTrace
.getNextEvent(context
);
459 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
460 assertEquals("Event rank", 1, context
.getRank());
462 // Position trace at event rank 1000
463 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
464 assertEquals("Event rank", 1000, context
.getRank());
466 event
= fTrace
.parseEvent(context
);
467 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
468 assertEquals("Event rank", 1000, context
.getRank());
470 event
= fTrace
.getNextEvent(context
);
471 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
472 assertEquals("Event rank", 1001, context
.getRank());
474 // Position trace at event rank 4000
475 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
476 assertEquals("Event rank", 4000, context
.getRank());
478 event
= fTrace
.parseEvent(context
);
479 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
480 assertEquals("Event rank", 4000, context
.getRank());
482 event
= fTrace
.getNextEvent(context
);
483 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
484 assertEquals("Event rank", 4001, context
.getRank());
487 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
489 // Position trace at event rank 1
490 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
491 assertEquals("Event rank", 1, context
.getRank());
493 TmfEvent event
= fTrace
.parseEvent(context
);
494 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
495 assertEquals("Event rank", 1, context
.getRank());
497 event
= fTrace
.getNextEvent(context
);
498 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
499 assertEquals("Event rank", 2, context
.getRank());
501 // Position trace at event rank 9
502 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
503 assertEquals("Event rank", 9, context
.getRank());
505 event
= fTrace
.parseEvent(context
);
506 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
507 assertEquals("Event rank", 9, context
.getRank());
509 event
= fTrace
.getNextEvent(context
);
510 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
511 assertEquals("Event rank", 10, context
.getRank());
513 // Position trace at event rank 999
514 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
515 assertEquals("Event rank", 999, context
.getRank());
517 event
= fTrace
.parseEvent(context
);
518 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
519 assertEquals("Event rank", 999, context
.getRank());
521 event
= fTrace
.getNextEvent(context
);
522 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
523 assertEquals("Event rank", 1000, context
.getRank());
525 // Position trace at event rank 1001
526 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
527 assertEquals("Event rank", 1001, context
.getRank());
529 event
= fTrace
.parseEvent(context
);
530 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
531 assertEquals("Event rank", 1001, context
.getRank());
533 event
= fTrace
.getNextEvent(context
);
534 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
535 assertEquals("Event rank", 1002, context
.getRank());
537 // Position trace at event rank 4500
538 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
539 assertEquals("Event rank", 4500, context
.getRank());
541 event
= fTrace
.parseEvent(context
);
542 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
543 assertEquals("Event rank", 4500, context
.getRank());
545 event
= fTrace
.getNextEvent(context
);
546 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
547 assertEquals("Event rank", 4501, context
.getRank());
550 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
552 // Position trace at beginning
553 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
554 assertEquals("Event rank", 0, context
.getRank());
556 TmfEvent event
= fTrace
.parseEvent(context
);
557 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
558 assertEquals("Event rank", 0, context
.getRank());
560 event
= fTrace
.getNextEvent(context
);
561 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
562 assertEquals("Event rank", 1, context
.getRank());
564 // Position trace at event passed the end
565 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
566 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
568 event
= fTrace
.parseEvent(context
);
569 assertEquals("Event timestamp", null, event
);
570 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
572 event
= fTrace
.getNextEvent(context
);
573 assertEquals("Event timestamp", null, event
);
574 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
577 // ------------------------------------------------------------------------
579 // ------------------------------------------------------------------------
581 public void testSeekOnRankOnCacheBoundary() throws Exception
{
583 // On lower bound, returns the first event (ts = 1)
584 TmfContext context
= fTrace
.seekEvent(0);
585 assertEquals("Event rank", 0, context
.getRank());
587 TmfEvent event
= fTrace
.parseEvent(context
);
588 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
589 assertEquals("Event rank", 0, context
.getRank());
591 event
= fTrace
.getNextEvent(context
);
592 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
593 assertEquals("Event rank", 1, context
.getRank());
595 // Position trace at event rank 1000
596 context
= fTrace
.seekEvent(1000);
597 assertEquals("Event rank", 1000, context
.getRank());
599 event
= fTrace
.parseEvent(context
);
600 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
601 assertEquals("Event rank", 1000, context
.getRank());
603 event
= fTrace
.getNextEvent(context
);
604 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
605 assertEquals("Event rank", 1001, context
.getRank());
607 // Position trace at event rank 4000
608 context
= fTrace
.seekEvent(4000);
609 assertEquals("Event rank", 4000, context
.getRank());
611 event
= fTrace
.parseEvent(context
);
612 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
613 assertEquals("Event rank", 4000, context
.getRank());
615 event
= fTrace
.getNextEvent(context
);
616 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
617 assertEquals("Event rank", 4001, context
.getRank());
620 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
622 // Position trace at event rank 9
623 TmfContext context
= fTrace
.seekEvent(9);
624 assertEquals("Event rank", 9, context
.getRank());
626 TmfEvent event
= fTrace
.parseEvent(context
);
627 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
628 assertEquals("Event rank", 9, context
.getRank());
630 event
= fTrace
.getNextEvent(context
);
631 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
632 assertEquals("Event rank", 10, context
.getRank());
634 // Position trace at event rank 999
635 context
= fTrace
.seekEvent(999);
636 assertEquals("Event rank", 999, context
.getRank());
638 event
= fTrace
.parseEvent(context
);
639 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
640 assertEquals("Event rank", 999, context
.getRank());
642 event
= fTrace
.getNextEvent(context
);
643 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
644 assertEquals("Event rank", 1000, context
.getRank());
646 // Position trace at event rank 1001
647 context
= fTrace
.seekEvent(1001);
648 assertEquals("Event rank", 1001, context
.getRank());
650 event
= fTrace
.parseEvent(context
);
651 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
652 assertEquals("Event rank", 1001, context
.getRank());
654 event
= fTrace
.getNextEvent(context
);
655 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
656 assertEquals("Event rank", 1002, context
.getRank());
658 // Position trace at event rank 4500
659 context
= fTrace
.seekEvent(4500);
660 assertEquals("Event rank", 4500, context
.getRank());
662 event
= fTrace
.parseEvent(context
);
663 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
664 assertEquals("Event rank", 4500, context
.getRank());
666 event
= fTrace
.getNextEvent(context
);
667 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
668 assertEquals("Event rank", 4501, context
.getRank());
671 public void testSeekEventOnRankOfScope() throws Exception
{
673 // Position trace at beginning
674 TmfContext context
= fTrace
.seekEvent(-1);
675 assertEquals("Event rank", 0, context
.getRank());
677 TmfEvent event
= fTrace
.parseEvent(context
);
678 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
679 assertEquals("Event rank", 0, context
.getRank());
681 event
= fTrace
.getNextEvent(context
);
682 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
683 assertEquals("Event rank", 1, context
.getRank());
685 // Position trace at event passed the end
686 context
= fTrace
.seekEvent(NB_EVENTS
);
687 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
689 event
= fTrace
.parseEvent(context
);
690 assertEquals("Event timestamp", null, event
);
691 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
693 event
= fTrace
.getNextEvent(context
);
694 assertEquals("Event timestamp", null, event
);
695 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
698 // ------------------------------------------------------------------------
700 // ------------------------------------------------------------------------
702 @SuppressWarnings("unchecked")
703 public void testProcessRequestForNbEvents() throws Exception
{
704 final int BLOCK_SIZE
= 100;
705 final int NB_EVENTS
= 1000;
706 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
708 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
709 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
711 public void handleData(TmfEvent event
) {
712 super.handleData(event
);
713 requestedEvents
.add(event
);
716 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
717 providers
[0].sendRequest(request
);
718 request
.waitForCompletion();
720 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
721 assertTrue("isCompleted", request
.isCompleted());
722 assertFalse("isCancelled", request
.isCancelled());
724 // Ensure that we have distinct events.
725 // Don't go overboard: we are not validating the stub!
726 for (int i
= 0; i
< NB_EVENTS
; i
++) {
727 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
731 @SuppressWarnings("unchecked")
732 public void testProcessRequestForAllEvents() throws Exception
{
733 final int BLOCK_SIZE
= 1;
734 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
736 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
737 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
739 public void handleData(TmfEvent event
) {
740 super.handleData(event
);
741 requestedEvents
.add(event
);
744 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
745 providers
[0].sendRequest(request
);
746 request
.waitForCompletion();
748 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
749 assertTrue("isCompleted", request
.isCompleted());
750 assertFalse("isCancelled", request
.isCancelled());
752 // Ensure that we have distinct events.
753 // Don't go overboard: we are not validating the stub!
754 for (int i
= 0; i
< NB_EVENTS
; i
++) {
755 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
759 // ------------------------------------------------------------------------
761 // ------------------------------------------------------------------------
763 @SuppressWarnings("unchecked")
764 public void testCancel() throws Exception
{
765 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
767 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
768 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
771 public void handleData(TmfEvent event
) {
772 super.handleData(event
);
773 requestedEvents
.add(event
);
774 if (++nbRead
== BLOCK_SIZE
)
778 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
779 providers
[0].sendRequest(request
);
780 request
.waitForCompletion();
782 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
783 assertTrue("isCompleted", request
.isCompleted());
784 assertTrue("isCancelled", request
.isCancelled());
This page took 0.049213 seconds and 6 git commands to generate.