c7c7903d924535df3e3eeaeedadd96de586500fd
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
.core
.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
.core
.component
.ITmfDataProvider
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfProviderManager
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpoint
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
37 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
40 * <b><u>TmfTraceTest</u></b>
42 * Test suite for the TmfTrace class.
44 @SuppressWarnings("nls")
45 public class TmfTraceTest
extends TestCase
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 private static final String DIRECTORY
= "testfiles";
52 private static final String TEST_STREAM
= "A-Test-10K";
53 private static final int BLOCK_SIZE
= 500;
54 private static final int NB_EVENTS
= 10000;
55 private static TmfTraceStub fTrace
= null;
57 private static byte SCALE
= (byte) -3;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 public TmfTraceTest(String name
) throws Exception
{
68 protected void setUp() throws Exception
{
70 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
71 // Dummy request to force the trace indexing
72 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class) {
74 public void handleData(TmfEvent event
) {
75 super.handleData(event
);
78 fTrace
.sendRequest(request
);
79 request
.waitForCompletion();
83 protected void tearDown() throws Exception
{
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
93 private TmfTraceStub
setupTrace(String path
) {
96 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
97 File test
= new File(FileLocator
.toFileURL(location
).toURI());
98 fTrace
= new TmfTraceStub(test
.toURI().getPath(), BLOCK_SIZE
, false);
99 } catch (URISyntaxException e
) {
101 } catch (IOException e
) {
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
112 public void testTmfTraceDefault() throws Exception
{
113 TmfTraceStub trace
= null;
114 File testfile
= null;
116 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
117 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
118 trace
= new TmfTraceStub(testfile
.toURI().getPath());
119 } catch (URISyntaxException e
) {
120 fail("URISyntaxException");
121 } catch (IOException e
) {
124 assertTrue ("Open trace", trace
!= null);
125 assertEquals("getType", TmfEvent
.class, trace
.getType());
126 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
127 assertEquals("getName", TEST_STREAM
, trace
.getName());
128 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getIndexPageSize());
131 public void testTmfTraceDefaultCacheSize() throws Exception
{
132 TmfTraceStub trace
= null;
133 File testfile
= null;
135 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
136 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
137 trace
= new TmfTraceStub(testfile
.toURI().getPath(), 0);
138 } catch (URISyntaxException e
) {
139 fail("URISyntaxException");
140 } catch (IOException e
) {
143 assertTrue ("Open trace", trace
!= null);
144 assertEquals("getType", TmfEvent
.class, trace
.getType());
145 assertEquals("getPath", testfile
.toURI().getPath(), trace
.getPath());
146 assertEquals("getName", TEST_STREAM
, trace
.getName());
147 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getIndexPageSize());
150 public void testTmfTrace() throws Exception
{
151 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
152 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
153 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getIndexPageSize());
156 public void testClone() throws Exception
{
157 TmfTraceStub trace
= fTrace
.clone();
158 assertEquals("getType", TmfEvent
.class, trace
.getType());
159 assertEquals("getPath", fTrace
.getPath(), trace
.getPath());
160 assertEquals("getName", TEST_STREAM
, trace
.getName());
161 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getIndexPageSize());
162 assertEquals("getTimeRange", fTrace
.getTimeRange(), trace
.getTimeRange());
165 // ------------------------------------------------------------------------
166 // Get/Set time range
167 // ------------------------------------------------------------------------
169 public void testSetTimeRange() throws Exception
{
170 TmfTraceStub trace
= fTrace
.clone();
172 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
173 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
174 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
175 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
177 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
178 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
179 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
180 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
181 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
184 public void testSetStartTime() throws Exception
{
185 TmfTraceStub trace
= fTrace
.clone();
187 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
188 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
189 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
190 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
192 trace
.setStartTime(new TmfTimestamp(100));
193 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
194 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
195 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
196 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
199 public void testSetEndTime() throws Exception
{
200 TmfTraceStub trace
= fTrace
.clone();
202 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
203 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
204 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
205 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
207 trace
.setEndTime(new TmfTimestamp(100));
208 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
209 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
210 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
211 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
214 // ------------------------------------------------------------------------
215 // Verify checkpoints
216 // ------------------------------------------------------------------------
218 public void testTmfTraceIndexing() throws Exception
{
219 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getIndexPageSize());
220 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
221 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
222 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
223 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
224 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
226 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
227 int pageSize
= fTrace
.getIndexPageSize();
228 assertTrue("Checkpoints exist", checkpoints
!= null);
230 // Validate that each checkpoint points to the right event
231 for (int i
= 0; i
< checkpoints
.size(); i
++) {
232 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
233 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
234 ITmfEvent event
= fTrace
.parseEvent(context
);
235 assertTrue(context
.getRank() == i
* pageSize
);
236 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
240 // ------------------------------------------------------------------------
241 // parseEvent - make sure parseEvent doesn't update the context
242 // ------------------------------------------------------------------------
244 public void testParseEvent() throws Exception
{
248 // On lower bound, returns the first event (ts = 0)
249 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
250 TmfContext svContext
= new TmfContext(context
);
252 ITmfEvent event
= fTrace
.parseEvent(context
);
253 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
254 assertEquals("Event rank", 0, context
.getRank());
255 assertTrue("parseEvent", context
.equals(svContext
));
257 event
= fTrace
.parseEvent(context
);
258 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
259 assertEquals("Event rank", 0, context
.getRank());
260 assertTrue("parseEvent", context
.equals(svContext
));
262 event
= fTrace
.parseEvent(context
);
263 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
264 assertEquals("Event rank", 0, context
.getRank());
265 assertTrue("parseEvent", context
.equals(svContext
));
267 // Position the trace at event NB_READS
268 for (int i
= 1; i
< NB_READS
; i
++) {
269 event
= fTrace
.getNextEvent(context
);
270 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
273 svContext
= new TmfContext(context
);
274 event
= fTrace
.parseEvent(context
);
275 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
276 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
277 assertTrue("parseEvent", context
.equals(svContext
));
279 event
= fTrace
.parseEvent(context
);
280 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
281 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
282 assertTrue("parseEvent", context
.equals(svContext
));
285 // ------------------------------------------------------------------------
286 // getNextEvent - updates the context
287 // ------------------------------------------------------------------------
289 public void testGetNextEvent() throws Exception
{
293 // On lower bound, returns the first event (ts = 1)
294 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
298 for (int i
= 0; i
< NB_READS
; i
++) {
299 event
= fTrace
.getNextEvent(context
);
300 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
301 assertEquals("Event rank", i
+ 1, context
.getRank());
304 // Make sure we stay positioned
305 event
= fTrace
.parseEvent(context
);
306 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
307 assertEquals("Event rank", NB_READS
, context
.getRank());
310 // ------------------------------------------------------------------------
312 // Note: seekLocation() does not reliably set the rank
313 // ------------------------------------------------------------------------
315 public void testSeekLocationOnCacheBoundary() throws Exception
{
317 // Position trace at event rank 0
318 TmfContext context
= fTrace
.seekLocation(null);
319 ITmfEvent event
= fTrace
.parseEvent(context
);
320 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
321 assertEquals("Event rank", 0, context
.getRank());
323 context
= fTrace
.seekLocation(context
.getLocation());
324 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
326 event
= fTrace
.parseEvent(context
);
327 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
328 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
330 event
= fTrace
.getNextEvent(context
);
331 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
332 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
334 // Position trace at event rank 1000
335 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
336 context
= fTrace
.seekLocation(tmpContext
.getLocation());
337 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
339 event
= fTrace
.parseEvent(context
);
340 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
341 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
343 event
= fTrace
.getNextEvent(context
);
344 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
345 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
347 // Position trace at event rank 4000
348 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
349 context
= fTrace
.seekLocation(tmpContext
.getLocation());
350 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
352 event
= fTrace
.parseEvent(context
);
353 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
354 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
356 event
= fTrace
.getNextEvent(context
);
357 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
358 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
361 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
363 // Position trace at event rank 9
364 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
365 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
366 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
368 ITmfEvent event
= fTrace
.parseEvent(context
);
369 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
370 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
372 event
= fTrace
.getNextEvent(context
);
373 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
374 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
376 // Position trace at event rank 999
377 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
378 context
= fTrace
.seekLocation(tmpContext
.getLocation());
379 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
381 event
= fTrace
.parseEvent(context
);
382 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
383 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
385 event
= fTrace
.getNextEvent(context
);
386 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
387 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
389 // Position trace at event rank 1001
390 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
391 context
= fTrace
.seekLocation(tmpContext
.getLocation());
392 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
394 event
= fTrace
.parseEvent(context
);
395 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
396 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
398 event
= fTrace
.getNextEvent(context
);
399 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
400 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
402 // Position trace at event rank 4500
403 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
404 context
= fTrace
.seekLocation(tmpContext
.getLocation());
405 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
407 event
= fTrace
.parseEvent(context
);
408 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
409 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
411 event
= fTrace
.getNextEvent(context
);
412 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
413 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
416 public void testSeekLocationOutOfScope() throws Exception
{
418 // Position trace at beginning
419 TmfContext tmpContext
= fTrace
.seekLocation(null);
420 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
421 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
423 ITmfEvent event
= fTrace
.parseEvent(context
);
424 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
425 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
427 event
= fTrace
.getNextEvent(context
);
428 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
429 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
431 // Position trace at event passed the end
432 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
433 context
= fTrace
.seekLocation(tmpContext
.getLocation());
434 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
436 event
= fTrace
.parseEvent(context
);
437 assertEquals("Event timestamp", null, event
);
438 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
440 event
= fTrace
.getNextEvent(context
);
441 assertEquals("Event timestamp", null, event
);
442 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
445 // ------------------------------------------------------------------------
446 // seekEvent on timestamp
447 // ------------------------------------------------------------------------
449 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
451 // Position trace at event rank 0
452 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
453 assertEquals("Event rank", 0, context
.getRank());
455 ITmfEvent event
= fTrace
.parseEvent(context
);
456 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
457 assertEquals("Event rank", 0, context
.getRank());
459 event
= fTrace
.getNextEvent(context
);
460 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
461 assertEquals("Event rank", 1, context
.getRank());
463 // Position trace at event rank 1000
464 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
465 assertEquals("Event rank", 1000, context
.getRank());
467 event
= fTrace
.parseEvent(context
);
468 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
469 assertEquals("Event rank", 1000, context
.getRank());
471 event
= fTrace
.getNextEvent(context
);
472 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
473 assertEquals("Event rank", 1001, context
.getRank());
475 // Position trace at event rank 4000
476 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
477 assertEquals("Event rank", 4000, context
.getRank());
479 event
= fTrace
.parseEvent(context
);
480 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
481 assertEquals("Event rank", 4000, context
.getRank());
483 event
= fTrace
.getNextEvent(context
);
484 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
485 assertEquals("Event rank", 4001, context
.getRank());
488 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
490 // Position trace at event rank 1
491 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
492 assertEquals("Event rank", 1, context
.getRank());
494 ITmfEvent event
= fTrace
.parseEvent(context
);
495 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
496 assertEquals("Event rank", 1, context
.getRank());
498 event
= fTrace
.getNextEvent(context
);
499 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
500 assertEquals("Event rank", 2, context
.getRank());
502 // Position trace at event rank 9
503 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
504 assertEquals("Event rank", 9, context
.getRank());
506 event
= fTrace
.parseEvent(context
);
507 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
508 assertEquals("Event rank", 9, context
.getRank());
510 event
= fTrace
.getNextEvent(context
);
511 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
512 assertEquals("Event rank", 10, context
.getRank());
514 // Position trace at event rank 999
515 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
516 assertEquals("Event rank", 999, context
.getRank());
518 event
= fTrace
.parseEvent(context
);
519 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
520 assertEquals("Event rank", 999, context
.getRank());
522 event
= fTrace
.getNextEvent(context
);
523 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
524 assertEquals("Event rank", 1000, context
.getRank());
526 // Position trace at event rank 1001
527 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
528 assertEquals("Event rank", 1001, context
.getRank());
530 event
= fTrace
.parseEvent(context
);
531 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
532 assertEquals("Event rank", 1001, context
.getRank());
534 event
= fTrace
.getNextEvent(context
);
535 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
536 assertEquals("Event rank", 1002, context
.getRank());
538 // Position trace at event rank 4500
539 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
540 assertEquals("Event rank", 4500, context
.getRank());
542 event
= fTrace
.parseEvent(context
);
543 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
544 assertEquals("Event rank", 4500, context
.getRank());
546 event
= fTrace
.getNextEvent(context
);
547 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
548 assertEquals("Event rank", 4501, context
.getRank());
551 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
553 // Position trace at beginning
554 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
555 assertEquals("Event rank", 0, context
.getRank());
557 ITmfEvent event
= fTrace
.parseEvent(context
);
558 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
559 assertEquals("Event rank", 0, context
.getRank());
561 event
= fTrace
.getNextEvent(context
);
562 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
563 assertEquals("Event rank", 1, context
.getRank());
565 // Position trace at event passed the end
566 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
567 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
569 event
= fTrace
.parseEvent(context
);
570 assertEquals("Event timestamp", null, event
);
571 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
573 event
= fTrace
.getNextEvent(context
);
574 assertEquals("Event timestamp", null, event
);
575 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
578 // ------------------------------------------------------------------------
580 // ------------------------------------------------------------------------
582 public void testSeekOnRankOnCacheBoundary() throws Exception
{
584 // On lower bound, returns the first event (ts = 1)
585 TmfContext context
= fTrace
.seekEvent(0);
586 assertEquals("Event rank", 0, context
.getRank());
588 ITmfEvent event
= fTrace
.parseEvent(context
);
589 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
590 assertEquals("Event rank", 0, context
.getRank());
592 event
= fTrace
.getNextEvent(context
);
593 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
594 assertEquals("Event rank", 1, context
.getRank());
596 // Position trace at event rank 1000
597 context
= fTrace
.seekEvent(1000);
598 assertEquals("Event rank", 1000, context
.getRank());
600 event
= fTrace
.parseEvent(context
);
601 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
602 assertEquals("Event rank", 1000, context
.getRank());
604 event
= fTrace
.getNextEvent(context
);
605 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
606 assertEquals("Event rank", 1001, context
.getRank());
608 // Position trace at event rank 4000
609 context
= fTrace
.seekEvent(4000);
610 assertEquals("Event rank", 4000, context
.getRank());
612 event
= fTrace
.parseEvent(context
);
613 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
614 assertEquals("Event rank", 4000, context
.getRank());
616 event
= fTrace
.getNextEvent(context
);
617 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
618 assertEquals("Event rank", 4001, context
.getRank());
621 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
623 // Position trace at event rank 9
624 TmfContext context
= fTrace
.seekEvent(9);
625 assertEquals("Event rank", 9, context
.getRank());
627 ITmfEvent event
= fTrace
.parseEvent(context
);
628 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
629 assertEquals("Event rank", 9, context
.getRank());
631 event
= fTrace
.getNextEvent(context
);
632 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
633 assertEquals("Event rank", 10, context
.getRank());
635 // Position trace at event rank 999
636 context
= fTrace
.seekEvent(999);
637 assertEquals("Event rank", 999, context
.getRank());
639 event
= fTrace
.parseEvent(context
);
640 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
641 assertEquals("Event rank", 999, context
.getRank());
643 event
= fTrace
.getNextEvent(context
);
644 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
645 assertEquals("Event rank", 1000, context
.getRank());
647 // Position trace at event rank 1001
648 context
= fTrace
.seekEvent(1001);
649 assertEquals("Event rank", 1001, context
.getRank());
651 event
= fTrace
.parseEvent(context
);
652 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
653 assertEquals("Event rank", 1001, context
.getRank());
655 event
= fTrace
.getNextEvent(context
);
656 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
657 assertEquals("Event rank", 1002, context
.getRank());
659 // Position trace at event rank 4500
660 context
= fTrace
.seekEvent(4500);
661 assertEquals("Event rank", 4500, context
.getRank());
663 event
= fTrace
.parseEvent(context
);
664 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
665 assertEquals("Event rank", 4500, context
.getRank());
667 event
= fTrace
.getNextEvent(context
);
668 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
669 assertEquals("Event rank", 4501, context
.getRank());
672 public void testSeekEventOnRankOfScope() throws Exception
{
674 // Position trace at beginning
675 TmfContext context
= fTrace
.seekEvent(-1);
676 assertEquals("Event rank", 0, context
.getRank());
678 ITmfEvent event
= fTrace
.parseEvent(context
);
679 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
680 assertEquals("Event rank", 0, context
.getRank());
682 event
= fTrace
.getNextEvent(context
);
683 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
684 assertEquals("Event rank", 1, context
.getRank());
686 // Position trace at event passed the end
687 context
= fTrace
.seekEvent(NB_EVENTS
);
688 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
690 event
= fTrace
.parseEvent(context
);
691 assertEquals("Event timestamp", null, event
);
692 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
694 event
= fTrace
.getNextEvent(context
);
695 assertEquals("Event timestamp", null, event
);
696 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
699 // ------------------------------------------------------------------------
701 // ------------------------------------------------------------------------
703 @SuppressWarnings("unchecked")
704 public void testProcessRequestForNbEvents() throws Exception
{
705 final int BLOCK_SIZE
= 100;
706 final int NB_EVENTS
= 1000;
707 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
709 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
710 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
712 public void handleData(TmfEvent event
) {
713 super.handleData(event
);
714 requestedEvents
.add(event
);
717 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
718 providers
[0].sendRequest(request
);
719 request
.waitForCompletion();
721 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
722 assertTrue("isCompleted", request
.isCompleted());
723 assertFalse("isCancelled", request
.isCancelled());
725 // Ensure that we have distinct events.
726 // Don't go overboard: we are not validating the stub!
727 for (int i
= 0; i
< NB_EVENTS
; i
++) {
728 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
732 @SuppressWarnings("unchecked")
733 public void testProcessRequestForAllEvents() throws Exception
{
734 final int BLOCK_SIZE
= 1;
735 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
737 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
738 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
740 public void handleData(TmfEvent event
) {
741 super.handleData(event
);
742 requestedEvents
.add(event
);
745 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
746 providers
[0].sendRequest(request
);
747 request
.waitForCompletion();
749 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
750 assertTrue("isCompleted", request
.isCompleted());
751 assertFalse("isCancelled", request
.isCancelled());
753 // Ensure that we have distinct events.
754 // Don't go overboard: we are not validating the stub!
755 for (int i
= 0; i
< NB_EVENTS
; i
++) {
756 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
760 // ------------------------------------------------------------------------
762 // ------------------------------------------------------------------------
764 @SuppressWarnings("unchecked")
765 public void testCancel() throws Exception
{
766 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
768 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
769 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
772 public void handleData(TmfEvent event
) {
773 super.handleData(event
);
774 requestedEvents
.add(event
);
775 if (++nbRead
== BLOCK_SIZE
)
779 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
780 providers
[0].sendRequest(request
);
781 request
.waitForCompletion();
783 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
784 assertTrue("isCompleted", request
.isCompleted());
785 assertTrue("isCancelled", request
.isCancelled());
This page took 0.050271 seconds and 5 git commands to generate.