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 public class TmfTraceTest
extends TestCase
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 private static final String DIRECTORY
= "testfiles";
50 private static final String TEST_STREAM
= "A-Test-10K";
51 private static final int BLOCK_SIZE
= 500;
52 private static final int NB_EVENTS
= 10000;
53 private static TmfTraceStub fTrace
= null;
55 private static byte SCALE
= (byte) -3;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 public TmfTraceTest(String name
) throws Exception
{
66 protected void setUp() throws Exception
{
68 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
69 // Dummy request to force the trace indexing
70 TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class) {
72 public void handleData(TmfEvent event
) {
73 super.handleData(event
);
76 fTrace
.sendRequest(request
);
77 request
.waitForCompletion();
81 protected void tearDown() throws Exception
{
87 // ------------------------------------------------------------------------
89 // ------------------------------------------------------------------------
91 private TmfTraceStub
setupTrace(String path
) {
94 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
95 File test
= new File(FileLocator
.toFileURL(location
).toURI());
96 fTrace
= new TmfTraceStub(test
.getPath(), BLOCK_SIZE
, false);
97 } catch (URISyntaxException e
) {
99 } catch (IOException e
) {
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
110 public void testTmfTraceDefault() throws Exception
{
111 TmfTraceStub trace
= null;
112 File testfile
= null;
114 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
115 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
116 trace
= new TmfTraceStub(testfile
.getPath());
117 } catch (URISyntaxException e
) {
118 fail("URISyntaxException");
119 } catch (IOException e
) {
122 assertTrue ("Open trace", trace
!= null);
123 assertEquals("getType", TmfEvent
.class, trace
.getType());
124 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
125 assertEquals("getName", TEST_STREAM
, trace
.getName());
126 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getCacheSize());
129 public void testTmfTraceDefaultCacheSize() throws Exception
{
130 TmfTraceStub trace
= null;
131 File testfile
= null;
133 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
134 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
135 trace
= new TmfTraceStub(testfile
.getPath(), 0);
136 } catch (URISyntaxException e
) {
137 fail("URISyntaxException");
138 } catch (IOException e
) {
141 assertTrue ("Open trace", trace
!= null);
142 assertEquals("getType", TmfEvent
.class, trace
.getType());
143 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
144 assertEquals("getName", TEST_STREAM
, trace
.getName());
145 assertEquals("getCacheSize", TmfTrace
.DEFAULT_INDEX_PAGE_SIZE
, trace
.getCacheSize());
148 public void testTmfTrace() throws Exception
{
149 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
150 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
151 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
154 public void testClone() throws Exception
{
155 TmfTraceStub trace
= fTrace
.clone();
156 assertEquals("getType", TmfEvent
.class, trace
.getType());
157 assertEquals("getPath", fTrace
.getPath(), trace
.getPath());
158 assertEquals("getName", TEST_STREAM
, trace
.getName());
159 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
160 assertEquals("getTimeRange", fTrace
.getTimeRange(), trace
.getTimeRange());
163 // ------------------------------------------------------------------------
164 // Get/Set time range
165 // ------------------------------------------------------------------------
167 public void testSetTimeRange() throws Exception
{
168 TmfTraceStub trace
= fTrace
.clone();
170 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
171 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
172 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
173 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
175 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
176 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
177 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
178 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
179 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
182 public void testSetStartTime() throws Exception
{
183 TmfTraceStub trace
= fTrace
.clone();
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());
190 trace
.setStartTime(new TmfTimestamp(100));
191 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
192 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
193 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
194 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
197 public void testSetEndTime() throws Exception
{
198 TmfTraceStub trace
= fTrace
.clone();
200 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
201 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
202 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
203 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
205 trace
.setEndTime(new TmfTimestamp(100));
206 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
207 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
208 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
209 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
212 // ------------------------------------------------------------------------
213 // Verify checkpoints
214 // ------------------------------------------------------------------------
216 public void testTmfTraceIndexing() throws Exception
{
217 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
218 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
219 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
220 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
221 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
222 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
224 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
225 int pageSize
= fTrace
.getCacheSize();
226 assertTrue("Checkpoints exist", checkpoints
!= null);
228 // Validate that each checkpoint points to the right event
229 for (int i
= 0; i
< checkpoints
.size(); i
++) {
230 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
231 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
232 TmfEvent event
= fTrace
.parseEvent(context
);
233 assertTrue(context
.getRank() == i
* pageSize
);
234 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
238 // ------------------------------------------------------------------------
239 // parseEvent - make sure parseEvent doesn't update the context
240 // ------------------------------------------------------------------------
242 public void testParseEvent() throws Exception
{
246 // On lower bound, returns the first event (ts = 0)
247 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
248 TmfContext svContext
= new TmfContext(context
);
250 TmfEvent event
= fTrace
.parseEvent(context
);
251 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
252 assertEquals("Event rank", 0, context
.getRank());
253 assertTrue("parseEvent", context
.equals(svContext
));
255 event
= fTrace
.parseEvent(context
);
256 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
257 assertEquals("Event rank", 0, context
.getRank());
258 assertTrue("parseEvent", context
.equals(svContext
));
260 event
= fTrace
.parseEvent(context
);
261 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
262 assertEquals("Event rank", 0, context
.getRank());
263 assertTrue("parseEvent", context
.equals(svContext
));
265 // Position the trace at event NB_READS
266 for (int i
= 1; i
< NB_READS
; i
++) {
267 event
= fTrace
.getNextEvent(context
);
268 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
271 svContext
= new TmfContext(context
);
272 event
= fTrace
.parseEvent(context
);
273 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
274 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
275 assertTrue("parseEvent", context
.equals(svContext
));
277 event
= fTrace
.parseEvent(context
);
278 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
279 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
280 assertTrue("parseEvent", context
.equals(svContext
));
283 // ------------------------------------------------------------------------
284 // getNextEvent - updates the context
285 // ------------------------------------------------------------------------
287 public void testGetNextEvent() throws Exception
{
291 // On lower bound, returns the first event (ts = 1)
292 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
296 for (int i
= 0; i
< NB_READS
; i
++) {
297 event
= fTrace
.getNextEvent(context
);
298 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
299 assertEquals("Event rank", i
+ 1, context
.getRank());
302 // Make sure we stay positioned
303 event
= fTrace
.parseEvent(context
);
304 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
305 assertEquals("Event rank", NB_READS
, context
.getRank());
308 // ------------------------------------------------------------------------
310 // Note: seekLocation() does not reliably set the rank
311 // ------------------------------------------------------------------------
313 public void testSeekLocationOnCacheBoundary() throws Exception
{
315 // Position trace at event rank 0
316 TmfContext context
= fTrace
.seekLocation(null);
317 TmfEvent event
= fTrace
.parseEvent(context
);
318 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
319 assertEquals("Event rank", 0, context
.getRank());
321 context
= fTrace
.seekLocation(context
.getLocation());
322 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
324 event
= fTrace
.parseEvent(context
);
325 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
326 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
328 event
= fTrace
.getNextEvent(context
);
329 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
330 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
332 // Position trace at event rank 1000
333 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
334 context
= fTrace
.seekLocation(tmpContext
.getLocation());
335 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
337 event
= fTrace
.parseEvent(context
);
338 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
339 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
341 event
= fTrace
.getNextEvent(context
);
342 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
343 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
345 // Position trace at event rank 4000
346 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
347 context
= fTrace
.seekLocation(tmpContext
.getLocation());
348 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
350 event
= fTrace
.parseEvent(context
);
351 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
352 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
354 event
= fTrace
.getNextEvent(context
);
355 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
356 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
359 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
361 // Position trace at event rank 9
362 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
363 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
364 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
366 TmfEvent event
= fTrace
.parseEvent(context
);
367 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
368 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
370 event
= fTrace
.getNextEvent(context
);
371 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
372 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
374 // Position trace at event rank 999
375 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
376 context
= fTrace
.seekLocation(tmpContext
.getLocation());
377 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
379 event
= fTrace
.parseEvent(context
);
380 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
381 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
383 event
= fTrace
.getNextEvent(context
);
384 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
385 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
387 // Position trace at event rank 1001
388 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
389 context
= fTrace
.seekLocation(tmpContext
.getLocation());
390 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
392 event
= fTrace
.parseEvent(context
);
393 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
394 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
396 event
= fTrace
.getNextEvent(context
);
397 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
398 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
400 // Position trace at event rank 4500
401 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
402 context
= fTrace
.seekLocation(tmpContext
.getLocation());
403 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
405 event
= fTrace
.parseEvent(context
);
406 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
407 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
409 event
= fTrace
.getNextEvent(context
);
410 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
411 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
414 public void testSeekLocationOutOfScope() throws Exception
{
416 // Position trace at beginning
417 TmfContext tmpContext
= fTrace
.seekLocation(null);
418 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
419 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
421 TmfEvent event
= fTrace
.parseEvent(context
);
422 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
423 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
425 event
= fTrace
.getNextEvent(context
);
426 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
427 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
429 // Position trace at event passed the end
430 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
431 context
= fTrace
.seekLocation(tmpContext
.getLocation());
432 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
434 event
= fTrace
.parseEvent(context
);
435 assertEquals("Event timestamp", null, event
);
436 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
438 event
= fTrace
.getNextEvent(context
);
439 assertEquals("Event timestamp", null, event
);
440 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
443 // ------------------------------------------------------------------------
444 // seekEvent on timestamp
445 // ------------------------------------------------------------------------
447 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
449 // Position trace at event rank 0
450 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
451 assertEquals("Event rank", 0, context
.getRank());
453 TmfEvent event
= fTrace
.parseEvent(context
);
454 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
455 assertEquals("Event rank", 0, context
.getRank());
457 event
= fTrace
.getNextEvent(context
);
458 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
459 assertEquals("Event rank", 1, context
.getRank());
461 // Position trace at event rank 1000
462 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
463 assertEquals("Event rank", 1000, context
.getRank());
465 event
= fTrace
.parseEvent(context
);
466 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
467 assertEquals("Event rank", 1000, context
.getRank());
469 event
= fTrace
.getNextEvent(context
);
470 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
471 assertEquals("Event rank", 1001, context
.getRank());
473 // Position trace at event rank 4000
474 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
475 assertEquals("Event rank", 4000, context
.getRank());
477 event
= fTrace
.parseEvent(context
);
478 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
479 assertEquals("Event rank", 4000, context
.getRank());
481 event
= fTrace
.getNextEvent(context
);
482 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
483 assertEquals("Event rank", 4001, context
.getRank());
486 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
488 // Position trace at event rank 1
489 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
490 assertEquals("Event rank", 1, context
.getRank());
492 TmfEvent event
= fTrace
.parseEvent(context
);
493 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
494 assertEquals("Event rank", 1, context
.getRank());
496 event
= fTrace
.getNextEvent(context
);
497 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
498 assertEquals("Event rank", 2, context
.getRank());
500 // Position trace at event rank 9
501 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
502 assertEquals("Event rank", 9, context
.getRank());
504 event
= fTrace
.parseEvent(context
);
505 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
506 assertEquals("Event rank", 9, context
.getRank());
508 event
= fTrace
.getNextEvent(context
);
509 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
510 assertEquals("Event rank", 10, context
.getRank());
512 // Position trace at event rank 999
513 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
514 assertEquals("Event rank", 999, context
.getRank());
516 event
= fTrace
.parseEvent(context
);
517 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
518 assertEquals("Event rank", 999, context
.getRank());
520 event
= fTrace
.getNextEvent(context
);
521 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
522 assertEquals("Event rank", 1000, context
.getRank());
524 // Position trace at event rank 1001
525 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
526 assertEquals("Event rank", 1001, context
.getRank());
528 event
= fTrace
.parseEvent(context
);
529 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
530 assertEquals("Event rank", 1001, context
.getRank());
532 event
= fTrace
.getNextEvent(context
);
533 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
534 assertEquals("Event rank", 1002, context
.getRank());
536 // Position trace at event rank 4500
537 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
538 assertEquals("Event rank", 4500, context
.getRank());
540 event
= fTrace
.parseEvent(context
);
541 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
542 assertEquals("Event rank", 4500, context
.getRank());
544 event
= fTrace
.getNextEvent(context
);
545 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
546 assertEquals("Event rank", 4501, context
.getRank());
549 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
551 // Position trace at beginning
552 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
553 assertEquals("Event rank", 0, context
.getRank());
555 TmfEvent event
= fTrace
.parseEvent(context
);
556 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
557 assertEquals("Event rank", 0, context
.getRank());
559 event
= fTrace
.getNextEvent(context
);
560 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
561 assertEquals("Event rank", 1, context
.getRank());
563 // Position trace at event passed the end
564 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
565 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
567 event
= fTrace
.parseEvent(context
);
568 assertEquals("Event timestamp", null, event
);
569 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
571 event
= fTrace
.getNextEvent(context
);
572 assertEquals("Event timestamp", null, event
);
573 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
576 // ------------------------------------------------------------------------
578 // ------------------------------------------------------------------------
580 public void testSeekOnRankOnCacheBoundary() throws Exception
{
582 // On lower bound, returns the first event (ts = 1)
583 TmfContext context
= fTrace
.seekEvent(0);
584 assertEquals("Event rank", 0, context
.getRank());
586 TmfEvent event
= fTrace
.parseEvent(context
);
587 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
588 assertEquals("Event rank", 0, context
.getRank());
590 event
= fTrace
.getNextEvent(context
);
591 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
592 assertEquals("Event rank", 1, context
.getRank());
594 // Position trace at event rank 1000
595 context
= fTrace
.seekEvent(1000);
596 assertEquals("Event rank", 1000, context
.getRank());
598 event
= fTrace
.parseEvent(context
);
599 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
600 assertEquals("Event rank", 1000, context
.getRank());
602 event
= fTrace
.getNextEvent(context
);
603 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
604 assertEquals("Event rank", 1001, context
.getRank());
606 // Position trace at event rank 4000
607 context
= fTrace
.seekEvent(4000);
608 assertEquals("Event rank", 4000, context
.getRank());
610 event
= fTrace
.parseEvent(context
);
611 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
612 assertEquals("Event rank", 4000, context
.getRank());
614 event
= fTrace
.getNextEvent(context
);
615 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
616 assertEquals("Event rank", 4001, context
.getRank());
619 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
621 // Position trace at event rank 9
622 TmfContext context
= fTrace
.seekEvent(9);
623 assertEquals("Event rank", 9, context
.getRank());
625 TmfEvent event
= fTrace
.parseEvent(context
);
626 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
627 assertEquals("Event rank", 9, context
.getRank());
629 event
= fTrace
.getNextEvent(context
);
630 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
631 assertEquals("Event rank", 10, context
.getRank());
633 // Position trace at event rank 999
634 context
= fTrace
.seekEvent(999);
635 assertEquals("Event rank", 999, context
.getRank());
637 event
= fTrace
.parseEvent(context
);
638 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
639 assertEquals("Event rank", 999, context
.getRank());
641 event
= fTrace
.getNextEvent(context
);
642 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
643 assertEquals("Event rank", 1000, context
.getRank());
645 // Position trace at event rank 1001
646 context
= fTrace
.seekEvent(1001);
647 assertEquals("Event rank", 1001, context
.getRank());
649 event
= fTrace
.parseEvent(context
);
650 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
651 assertEquals("Event rank", 1001, context
.getRank());
653 event
= fTrace
.getNextEvent(context
);
654 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
655 assertEquals("Event rank", 1002, context
.getRank());
657 // Position trace at event rank 4500
658 context
= fTrace
.seekEvent(4500);
659 assertEquals("Event rank", 4500, context
.getRank());
661 event
= fTrace
.parseEvent(context
);
662 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
663 assertEquals("Event rank", 4500, context
.getRank());
665 event
= fTrace
.getNextEvent(context
);
666 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
667 assertEquals("Event rank", 4501, context
.getRank());
670 public void testSeekEventOnRankOfScope() throws Exception
{
672 // Position trace at beginning
673 TmfContext context
= fTrace
.seekEvent(-1);
674 assertEquals("Event rank", 0, context
.getRank());
676 TmfEvent event
= fTrace
.parseEvent(context
);
677 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
678 assertEquals("Event rank", 0, context
.getRank());
680 event
= fTrace
.getNextEvent(context
);
681 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
682 assertEquals("Event rank", 1, context
.getRank());
684 // Position trace at event passed the end
685 context
= fTrace
.seekEvent(NB_EVENTS
);
686 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
688 event
= fTrace
.parseEvent(context
);
689 assertEquals("Event timestamp", null, event
);
690 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
692 event
= fTrace
.getNextEvent(context
);
693 assertEquals("Event timestamp", null, event
);
694 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
697 // ------------------------------------------------------------------------
699 // ------------------------------------------------------------------------
701 @SuppressWarnings("unchecked")
702 public void testProcessRequestForNbEvents() throws Exception
{
703 final int BLOCK_SIZE
= 100;
704 final int NB_EVENTS
= 1000;
705 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
707 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
708 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
710 public void handleData(TmfEvent event
) {
711 super.handleData(event
);
712 requestedEvents
.add(event
);
715 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
716 providers
[0].sendRequest(request
);
717 request
.waitForCompletion();
719 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
720 assertTrue("isCompleted", request
.isCompleted());
721 assertFalse("isCancelled", request
.isCancelled());
723 // Ensure that we have distinct events.
724 // Don't go overboard: we are not validating the stub!
725 for (int i
= 0; i
< NB_EVENTS
; i
++) {
726 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
730 @SuppressWarnings("unchecked")
731 public void testProcessRequestForAllEvents() throws Exception
{
732 final int BLOCK_SIZE
= 1;
733 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
735 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
736 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
738 public void handleData(TmfEvent event
) {
739 super.handleData(event
);
740 requestedEvents
.add(event
);
743 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
744 providers
[0].sendRequest(request
);
745 request
.waitForCompletion();
747 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
748 assertTrue("isCompleted", request
.isCompleted());
749 assertFalse("isCancelled", request
.isCancelled());
751 // Ensure that we have distinct events.
752 // Don't go overboard: we are not validating the stub!
753 for (int i
= 0; i
< NB_EVENTS
; i
++) {
754 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
758 // ------------------------------------------------------------------------
760 // ------------------------------------------------------------------------
762 @SuppressWarnings("unchecked")
763 public void testCancel() throws Exception
{
764 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
766 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
767 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
770 public void handleData(TmfEvent event
) {
771 super.handleData(event
);
772 requestedEvents
.add(event
);
773 if (++nbRead
== BLOCK_SIZE
)
777 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
778 providers
[0].sendRequest(request
);
779 request
.waitForCompletion();
781 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
782 assertTrue("isCompleted", request
.isCompleted());
783 assertTrue("isCancelled", request
.isCancelled());
This page took 0.049193 seconds and 6 git commands to generate.