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() {
75 fTrace
.sendRequest(request
);
76 request
.waitForCompletion();
80 protected void tearDown() throws Exception
{
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
90 private TmfTraceStub
setupTrace(String path
) {
93 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
94 File test
= new File(FileLocator
.toFileURL(location
).toURI());
95 fTrace
= new TmfTraceStub(test
.getPath(), BLOCK_SIZE
, false);
96 } catch (URISyntaxException e
) {
98 } catch (IOException e
) {
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
109 public void testTmfTraceDefault() throws Exception
{
110 TmfTraceStub trace
= null;
111 File testfile
= null;
113 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
114 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
115 trace
= new TmfTraceStub(testfile
.getPath());
116 } catch (URISyntaxException e
) {
117 fail("URISyntaxException");
118 } catch (IOException e
) {
121 assertTrue ("Open trace", trace
!= null);
122 assertEquals("getType", TmfEvent
.class, trace
.getType());
123 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
124 assertEquals("getName", TEST_STREAM
, trace
.getName());
125 assertEquals("getCacheSize", TmfTrace
.DEFAULT_CACHE_SIZE
, trace
.getCacheSize());
128 public void testTmfTraceDefaultCacheSize() throws Exception
{
129 TmfTraceStub trace
= null;
130 File testfile
= null;
132 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
133 testfile
= new File(FileLocator
.toFileURL(location
).toURI());
134 trace
= new TmfTraceStub(testfile
.getPath(), 0);
135 } catch (URISyntaxException e
) {
136 fail("URISyntaxException");
137 } catch (IOException e
) {
140 assertTrue ("Open trace", trace
!= null);
141 assertEquals("getType", TmfEvent
.class, trace
.getType());
142 assertEquals("getPath", testfile
.getPath(), trace
.getPath());
143 assertEquals("getName", TEST_STREAM
, trace
.getName());
144 assertEquals("getCacheSize", TmfTrace
.DEFAULT_CACHE_SIZE
, trace
.getCacheSize());
147 public void testTmfTrace() throws Exception
{
148 assertEquals("getType", TmfEvent
.class, fTrace
.getType());
149 assertEquals("getName", TEST_STREAM
, fTrace
.getName());
150 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
153 public void testClone() throws Exception
{
154 TmfTraceStub trace
= fTrace
.clone();
155 assertEquals("getType", TmfEvent
.class, trace
.getType());
156 assertEquals("getPath", fTrace
.getPath(), trace
.getPath());
157 assertEquals("getName", TEST_STREAM
, trace
.getName());
158 assertEquals("getCacheSize", BLOCK_SIZE
, trace
.getCacheSize());
159 assertEquals("getTimeRange", fTrace
.getTimeRange(), trace
.getTimeRange());
162 // ------------------------------------------------------------------------
163 // Get/Set time range
164 // ------------------------------------------------------------------------
166 public void testSetTimeRange() throws Exception
{
167 TmfTraceStub trace
= fTrace
.clone();
169 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
170 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
171 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
172 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
174 trace
.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200)));
175 assertEquals("setTimeRange", 100, trace
.getTimeRange().getStartTime().getValue());
176 assertEquals("setTimeRange", 200, trace
.getTimeRange().getEndTime().getValue());
177 assertEquals("setTimeRange", 100, trace
.getStartTime().getValue());
178 assertEquals("setTimeRange", 200, trace
.getEndTime().getValue());
181 public void testSetStartTime() throws Exception
{
182 TmfTraceStub trace
= fTrace
.clone();
184 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
185 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
186 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
187 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
189 trace
.setStartTime(new TmfTimestamp(100));
190 assertEquals("setStartTime", 100, trace
.getTimeRange().getStartTime().getValue());
191 assertEquals("setStartTime", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
192 assertEquals("setStartTime", 100, trace
.getStartTime().getValue());
193 assertEquals("setStartTime", NB_EVENTS
, trace
.getEndTime().getValue());
196 public void testSetEndTime() throws Exception
{
197 TmfTraceStub trace
= fTrace
.clone();
199 assertEquals("getRange-start", 1, trace
.getTimeRange().getStartTime().getValue());
200 assertEquals("getRange-end", NB_EVENTS
, trace
.getTimeRange().getEndTime().getValue());
201 assertEquals("getStartTime", 1, trace
.getStartTime().getValue());
202 assertEquals("getEndTime", NB_EVENTS
, trace
.getEndTime().getValue());
204 trace
.setEndTime(new TmfTimestamp(100));
205 assertEquals("setEndTime", 1, trace
.getTimeRange().getStartTime().getValue());
206 assertEquals("setEndTime", 100, trace
.getTimeRange().getEndTime().getValue());
207 assertEquals("setEndTime", 1, trace
.getStartTime().getValue());
208 assertEquals("setEndTime", 100, trace
.getEndTime().getValue());
211 // ------------------------------------------------------------------------
212 // Verify checkpoints
213 // ------------------------------------------------------------------------
215 public void testTmfTraceIndexing() throws Exception
{
216 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
217 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
218 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
219 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
220 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
221 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
223 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
224 int pageSize
= fTrace
.getCacheSize();
225 assertTrue("Checkpoints exist", checkpoints
!= null);
227 // Validate that each checkpoint points to the right event
228 for (int i
= 0; i
< checkpoints
.size(); i
++) {
229 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
230 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
231 TmfEvent event
= fTrace
.parseEvent(context
);
232 assertTrue(context
.getRank() == i
* pageSize
);
233 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
237 // ------------------------------------------------------------------------
238 // parseEvent - make sure parseEvent doesn't update the context
239 // ------------------------------------------------------------------------
241 public void testParseEvent() throws Exception
{
245 // On lower bound, returns the first event (ts = 0)
246 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
247 TmfContext svContext
= new TmfContext(context
);
249 TmfEvent event
= fTrace
.parseEvent(context
);
250 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
251 assertEquals("Event rank", 0, context
.getRank());
252 assertTrue("parseEvent", context
.equals(svContext
));
254 event
= fTrace
.parseEvent(context
);
255 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
256 assertEquals("Event rank", 0, context
.getRank());
257 assertTrue("parseEvent", context
.equals(svContext
));
259 event
= fTrace
.parseEvent(context
);
260 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
261 assertEquals("Event rank", 0, context
.getRank());
262 assertTrue("parseEvent", context
.equals(svContext
));
264 // Position the trace at event NB_READS
265 for (int i
= 1; i
< NB_READS
; i
++) {
266 event
= fTrace
.getNextEvent(context
);
267 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
270 svContext
= new TmfContext(context
);
271 event
= fTrace
.parseEvent(context
);
272 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
273 assertEquals("Event rank", NB_READS
-1 , context
.getRank());
274 assertTrue("parseEvent", context
.equals(svContext
));
276 event
= fTrace
.parseEvent(context
);
277 assertEquals("Event timestamp", NB_READS
, event
.getTimestamp().getValue());
278 assertEquals("Event rank", NB_READS
- 1, context
.getRank());
279 assertTrue("parseEvent", context
.equals(svContext
));
282 // ------------------------------------------------------------------------
283 // getNextEvent - updates the context
284 // ------------------------------------------------------------------------
286 public void testGetNextEvent() throws Exception
{
290 // On lower bound, returns the first event (ts = 1)
291 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
295 for (int i
= 0; i
< NB_READS
; i
++) {
296 event
= fTrace
.getNextEvent(context
);
297 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
298 assertEquals("Event rank", i
+ 1, context
.getRank());
301 // Make sure we stay positioned
302 event
= fTrace
.parseEvent(context
);
303 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
304 assertEquals("Event rank", NB_READS
, context
.getRank());
307 // ------------------------------------------------------------------------
309 // Note: seekLocation() does not reliably set the rank
310 // ------------------------------------------------------------------------
312 public void testSeekLocationOnCacheBoundary() throws Exception
{
314 // Position trace at event rank 0
315 TmfContext context
= fTrace
.seekLocation(null);
316 TmfEvent event
= fTrace
.parseEvent(context
);
317 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
318 assertEquals("Event rank", 0, context
.getRank());
320 context
= fTrace
.seekLocation(context
.getLocation());
321 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
323 event
= fTrace
.parseEvent(context
);
324 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
325 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
327 event
= fTrace
.getNextEvent(context
);
328 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
329 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
331 // Position trace at event rank 1000
332 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
333 context
= fTrace
.seekLocation(tmpContext
.getLocation());
334 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
336 event
= fTrace
.parseEvent(context
);
337 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
338 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
340 event
= fTrace
.getNextEvent(context
);
341 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
342 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
344 // Position trace at event rank 4000
345 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
346 context
= fTrace
.seekLocation(tmpContext
.getLocation());
347 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
349 event
= fTrace
.parseEvent(context
);
350 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
351 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
353 event
= fTrace
.getNextEvent(context
);
354 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
355 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
358 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
360 // Position trace at event rank 9
361 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
362 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
363 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
365 TmfEvent event
= fTrace
.parseEvent(context
);
366 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
367 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
369 event
= fTrace
.getNextEvent(context
);
370 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
371 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
373 // Position trace at event rank 999
374 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
375 context
= fTrace
.seekLocation(tmpContext
.getLocation());
376 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
378 event
= fTrace
.parseEvent(context
);
379 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
380 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
382 event
= fTrace
.getNextEvent(context
);
383 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
384 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
386 // Position trace at event rank 1001
387 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
388 context
= fTrace
.seekLocation(tmpContext
.getLocation());
389 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
391 event
= fTrace
.parseEvent(context
);
392 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
393 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
395 event
= fTrace
.getNextEvent(context
);
396 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
397 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
399 // Position trace at event rank 4500
400 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
401 context
= fTrace
.seekLocation(tmpContext
.getLocation());
402 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
404 event
= fTrace
.parseEvent(context
);
405 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
406 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
408 event
= fTrace
.getNextEvent(context
);
409 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
410 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
413 public void testSeekLocationOutOfScope() throws Exception
{
415 // Position trace at beginning
416 TmfContext tmpContext
= fTrace
.seekLocation(null);
417 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation());
418 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
420 TmfEvent event
= fTrace
.parseEvent(context
);
421 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
422 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
424 event
= fTrace
.getNextEvent(context
);
425 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
426 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
428 // Position trace at event passed the end
429 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
430 context
= fTrace
.seekLocation(tmpContext
.getLocation());
431 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
433 event
= fTrace
.parseEvent(context
);
434 assertEquals("Event timestamp", null, event
);
435 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
437 event
= fTrace
.getNextEvent(context
);
438 assertEquals("Event timestamp", null, event
);
439 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
442 // ------------------------------------------------------------------------
443 // seekEvent on timestamp
444 // ------------------------------------------------------------------------
446 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
448 // Position trace at event rank 0
449 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
450 assertEquals("Event rank", 0, context
.getRank());
452 TmfEvent event
= fTrace
.parseEvent(context
);
453 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
454 assertEquals("Event rank", 0, context
.getRank());
456 event
= fTrace
.getNextEvent(context
);
457 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
458 assertEquals("Event rank", 1, context
.getRank());
460 // Position trace at event rank 1000
461 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
462 assertEquals("Event rank", 1000, context
.getRank());
464 event
= fTrace
.parseEvent(context
);
465 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
466 assertEquals("Event rank", 1000, context
.getRank());
468 event
= fTrace
.getNextEvent(context
);
469 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
470 assertEquals("Event rank", 1001, context
.getRank());
472 // Position trace at event rank 4000
473 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
474 assertEquals("Event rank", 4000, context
.getRank());
476 event
= fTrace
.parseEvent(context
);
477 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
478 assertEquals("Event rank", 4000, context
.getRank());
480 event
= fTrace
.getNextEvent(context
);
481 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
482 assertEquals("Event rank", 4001, context
.getRank());
485 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
487 // Position trace at event rank 1
488 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
489 assertEquals("Event rank", 1, context
.getRank());
491 TmfEvent event
= fTrace
.parseEvent(context
);
492 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
493 assertEquals("Event rank", 1, context
.getRank());
495 event
= fTrace
.getNextEvent(context
);
496 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
497 assertEquals("Event rank", 2, context
.getRank());
499 // Position trace at event rank 9
500 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
501 assertEquals("Event rank", 9, context
.getRank());
503 event
= fTrace
.parseEvent(context
);
504 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
505 assertEquals("Event rank", 9, context
.getRank());
507 event
= fTrace
.getNextEvent(context
);
508 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
509 assertEquals("Event rank", 10, context
.getRank());
511 // Position trace at event rank 999
512 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
513 assertEquals("Event rank", 999, context
.getRank());
515 event
= fTrace
.parseEvent(context
);
516 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
517 assertEquals("Event rank", 999, context
.getRank());
519 event
= fTrace
.getNextEvent(context
);
520 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
521 assertEquals("Event rank", 1000, context
.getRank());
523 // Position trace at event rank 1001
524 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
525 assertEquals("Event rank", 1001, context
.getRank());
527 event
= fTrace
.parseEvent(context
);
528 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
529 assertEquals("Event rank", 1001, context
.getRank());
531 event
= fTrace
.getNextEvent(context
);
532 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
533 assertEquals("Event rank", 1002, context
.getRank());
535 // Position trace at event rank 4500
536 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
537 assertEquals("Event rank", 4500, context
.getRank());
539 event
= fTrace
.parseEvent(context
);
540 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
541 assertEquals("Event rank", 4500, context
.getRank());
543 event
= fTrace
.getNextEvent(context
);
544 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
545 assertEquals("Event rank", 4501, context
.getRank());
548 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
550 // Position trace at beginning
551 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
552 assertEquals("Event rank", 0, context
.getRank());
554 TmfEvent event
= fTrace
.parseEvent(context
);
555 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
556 assertEquals("Event rank", 0, context
.getRank());
558 event
= fTrace
.getNextEvent(context
);
559 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
560 assertEquals("Event rank", 1, context
.getRank());
562 // Position trace at event passed the end
563 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
564 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
566 event
= fTrace
.parseEvent(context
);
567 assertEquals("Event timestamp", null, event
);
568 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
570 event
= fTrace
.getNextEvent(context
);
571 assertEquals("Event timestamp", null, event
);
572 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
575 // ------------------------------------------------------------------------
577 // ------------------------------------------------------------------------
579 public void testSeekOnRankOnCacheBoundary() throws Exception
{
581 // On lower bound, returns the first event (ts = 1)
582 TmfContext context
= fTrace
.seekEvent(0);
583 assertEquals("Event rank", 0, context
.getRank());
585 TmfEvent event
= fTrace
.parseEvent(context
);
586 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
587 assertEquals("Event rank", 0, context
.getRank());
589 event
= fTrace
.getNextEvent(context
);
590 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
591 assertEquals("Event rank", 1, context
.getRank());
593 // Position trace at event rank 1000
594 context
= fTrace
.seekEvent(1000);
595 assertEquals("Event rank", 1000, context
.getRank());
597 event
= fTrace
.parseEvent(context
);
598 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
599 assertEquals("Event rank", 1000, context
.getRank());
601 event
= fTrace
.getNextEvent(context
);
602 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
603 assertEquals("Event rank", 1001, context
.getRank());
605 // Position trace at event rank 4000
606 context
= fTrace
.seekEvent(4000);
607 assertEquals("Event rank", 4000, context
.getRank());
609 event
= fTrace
.parseEvent(context
);
610 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
611 assertEquals("Event rank", 4000, context
.getRank());
613 event
= fTrace
.getNextEvent(context
);
614 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
615 assertEquals("Event rank", 4001, context
.getRank());
618 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
620 // Position trace at event rank 9
621 TmfContext context
= fTrace
.seekEvent(9);
622 assertEquals("Event rank", 9, context
.getRank());
624 TmfEvent event
= fTrace
.parseEvent(context
);
625 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
626 assertEquals("Event rank", 9, context
.getRank());
628 event
= fTrace
.getNextEvent(context
);
629 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
630 assertEquals("Event rank", 10, context
.getRank());
632 // Position trace at event rank 999
633 context
= fTrace
.seekEvent(999);
634 assertEquals("Event rank", 999, context
.getRank());
636 event
= fTrace
.parseEvent(context
);
637 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
638 assertEquals("Event rank", 999, context
.getRank());
640 event
= fTrace
.getNextEvent(context
);
641 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
642 assertEquals("Event rank", 1000, context
.getRank());
644 // Position trace at event rank 1001
645 context
= fTrace
.seekEvent(1001);
646 assertEquals("Event rank", 1001, context
.getRank());
648 event
= fTrace
.parseEvent(context
);
649 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
650 assertEquals("Event rank", 1001, context
.getRank());
652 event
= fTrace
.getNextEvent(context
);
653 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
654 assertEquals("Event rank", 1002, context
.getRank());
656 // Position trace at event rank 4500
657 context
= fTrace
.seekEvent(4500);
658 assertEquals("Event rank", 4500, context
.getRank());
660 event
= fTrace
.parseEvent(context
);
661 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
662 assertEquals("Event rank", 4500, context
.getRank());
664 event
= fTrace
.getNextEvent(context
);
665 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
666 assertEquals("Event rank", 4501, context
.getRank());
669 public void testSeekEventOnRankOfScope() throws Exception
{
671 // Position trace at beginning
672 TmfContext context
= fTrace
.seekEvent(-1);
673 assertEquals("Event rank", 0, context
.getRank());
675 TmfEvent event
= fTrace
.parseEvent(context
);
676 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
677 assertEquals("Event rank", 0, context
.getRank());
679 event
= fTrace
.getNextEvent(context
);
680 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
681 assertEquals("Event rank", 1, context
.getRank());
683 // Position trace at event passed the end
684 context
= fTrace
.seekEvent(NB_EVENTS
);
685 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
687 event
= fTrace
.parseEvent(context
);
688 assertEquals("Event timestamp", null, event
);
689 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
691 event
= fTrace
.getNextEvent(context
);
692 assertEquals("Event timestamp", null, event
);
693 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
696 // ------------------------------------------------------------------------
698 // ------------------------------------------------------------------------
700 @SuppressWarnings("unchecked")
701 public void testProcessRequestForNbEvents() throws Exception
{
702 final int BLOCK_SIZE
= 100;
703 final int NB_EVENTS
= 1000;
704 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
706 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
707 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
709 public void handleData() {
710 TmfEvent
[] events
= getData();
711 for (TmfEvent e
: events
) {
712 requestedEvents
.add(e
);
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() {
740 TmfEvent
[] events
= getData();
741 for (TmfEvent e
: events
) {
742 requestedEvents
.add(e
);
746 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
747 providers
[0].sendRequest(request
);
748 request
.waitForCompletion();
750 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
751 assertTrue("isCompleted", request
.isCompleted());
752 assertFalse("isCancelled", request
.isCancelled());
754 // Ensure that we have distinct events.
755 // Don't go overboard: we are not validating the stub!
756 for (int i
= 0; i
< NB_EVENTS
; i
++) {
757 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
761 // ------------------------------------------------------------------------
763 // ------------------------------------------------------------------------
765 @SuppressWarnings("unchecked")
766 public void testCancel() throws Exception
{
767 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
769 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
770 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
772 public void handleData() {
773 TmfEvent
[] events
= getData();
774 for (TmfEvent e
: events
) {
775 requestedEvents
.add(e
);
777 // Cancel request after the first chunk is received
781 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
782 providers
[0].sendRequest(request
);
783 request
.waitForCompletion();
785 assertEquals("nbEvents", BLOCK_SIZE
, requestedEvents
.size());
786 assertTrue("isCompleted", request
.isCompleted());
787 assertTrue("isCancelled", request
.isCancelled());
This page took 0.049147 seconds and 6 git commands to generate.