1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adjusted for new Trace Model
12 * Alexandre Montplaisir - Port to JUnit4
13 * Patrick Tasse - Fix for concurrency
14 *******************************************************************************/
16 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.trace
;
18 import static org
.junit
.Assert
.assertEquals
;
19 import static org
.junit
.Assert
.assertFalse
;
20 import static org
.junit
.Assert
.assertNotNull
;
21 import static org
.junit
.Assert
.assertNull
;
22 import static org
.junit
.Assert
.assertTrue
;
25 import java
.io
.IOException
;
26 import java
.net
.URISyntaxException
;
28 import java
.util
.Vector
;
30 import org
.eclipse
.core
.runtime
.FileLocator
;
31 import org
.eclipse
.core
.runtime
.Path
;
32 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.trace
.experiment
.TmfExperimentContext
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.TmfCoreTestPlugin
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestTrace
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
41 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
45 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
46 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
47 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
48 import org
.junit
.AfterClass
;
49 import org
.junit
.BeforeClass
;
50 import org
.junit
.Test
;
53 * Test suite for the TmfExperiment class (multiple traces).
55 @SuppressWarnings("javadoc")
56 public class TmfMultiTraceExperimentTest
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 private static final long DEFAULT_INITIAL_OFFSET_VALUE
= (1L * 100 * 1000 * 1000); // .1sec
63 private static final String EXPERIMENT
= "MyExperiment";
64 private static int NB_EVENTS
= 20000;
65 private static int BLOCK_SIZE
= 1000;
67 private static TmfExperimentStub fExperiment
;
69 private static byte SCALE
= (byte) -3;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 public static void setUp() {
77 ITmfTrace
[] traces
= setupTraces();
78 fExperiment
= new TmfExperimentStub(EXPERIMENT
, traces
, BLOCK_SIZE
);
79 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
83 public static void tearDown() {
84 fExperiment
.dispose();
87 private static ITmfTrace
[] setupTraces() {
89 ITmfTrace
[] traces
= new ITmfTrace
[2];
91 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(TmfTestTrace
.O_TEST_10K
.getFullPath()), null);
92 File test
= new File(FileLocator
.toFileURL(location
).toURI());
93 final TmfTraceStub trace1
= new TmfTraceStub(test
.getPath(), 0, true, null);
96 location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(TmfTestTrace
.E_TEST_10K
.getFullPath()), null);
97 test
= new File(FileLocator
.toFileURL(location
).toURI());
98 final TmfTraceStub trace2
= new TmfTraceStub(test
.getPath(), 0, true, null);
102 } catch (final TmfTraceException e
) {
104 } catch (final URISyntaxException e
) {
106 } catch (final IOException e
) {
109 return new ITmfTrace
[0];
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 public void testBasicTmfExperimentConstructor() {
118 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
119 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
121 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
122 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
123 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
125 TmfTimestamp initRange
= new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE
, ITmfTimestamp
.NANOSECOND_SCALE
);
126 assertEquals("getInitialRangeOffset", initRange
, fExperiment
.getInitialRangeOffset());
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 public void testSeekRankOnCacheBoundary() {
135 long cacheSize
= fExperiment
.getCacheSize();
137 // On lower bound, returns the first event (TS = 1)
138 ITmfContext context
= fExperiment
.seekEvent(0);
139 assertEquals("Context rank", 0, context
.getRank());
141 ITmfEvent event
= fExperiment
.getNext(context
);
142 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
143 assertEquals("Context rank", 1, context
.getRank());
145 // Position trace at event rank [cacheSize]
146 context
= fExperiment
.seekEvent(cacheSize
);
147 assertEquals("Context rank", cacheSize
, context
.getRank());
149 event
= fExperiment
.getNext(context
);
150 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
151 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
153 // Position trace at event rank [4 * cacheSize]
154 context
= fExperiment
.seekEvent(4 * cacheSize
);
155 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
157 event
= fExperiment
.getNext(context
);
158 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
159 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
163 public void testSeekRankNotOnCacheBoundary() {
164 long cacheSize
= fExperiment
.getCacheSize();
166 // Position trace at event rank 9
167 ITmfContext context
= fExperiment
.seekEvent(9);
168 assertEquals("Context rank", 9, context
.getRank());
170 ITmfEvent event
= fExperiment
.getNext(context
);
171 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
172 assertEquals("Context rank", 10, context
.getRank());
174 // Position trace at event rank [cacheSize - 1]
175 context
= fExperiment
.seekEvent(cacheSize
- 1);
176 assertEquals("Context rank", cacheSize
- 1, context
.getRank());
178 event
= fExperiment
.getNext(context
);
179 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
180 assertEquals("Context rank", cacheSize
, context
.getRank());
182 // Position trace at event rank [cacheSize + 1]
183 context
= fExperiment
.seekEvent(cacheSize
+ 1);
184 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
186 event
= fExperiment
.getNext(context
);
187 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
188 assertEquals("Context rank", cacheSize
+ 2, context
.getRank());
190 // Position trace at event rank 4500
191 context
= fExperiment
.seekEvent(4500);
192 assertEquals("Context rank", 4500, context
.getRank());
194 event
= fExperiment
.getNext(context
);
195 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
196 assertEquals("Context rank", 4501, context
.getRank());
200 public void testSeekRankOutOfScope() {
201 // Position trace at beginning
202 ITmfContext context
= fExperiment
.seekEvent(-1);
203 assertEquals("Event rank", 0, context
.getRank());
205 ITmfEvent event
= fExperiment
.getNext(context
);
206 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
207 assertEquals("Context rank", 1, context
.getRank());
209 // Position trace at event passed the end
210 context
= fExperiment
.seekEvent(NB_EVENTS
);
211 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
213 event
= fExperiment
.getNext(context
);
214 assertNull("Event", event
);
215 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
218 // ------------------------------------------------------------------------
219 // seekEvent on timestamp
220 // ------------------------------------------------------------------------
223 public void testSeekTimestampOnCacheBoundary() {
224 long cacheSize
= fExperiment
.getCacheSize();
226 // Position trace at event rank 0
227 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
));
228 assertEquals("Context rank", 0, context
.getRank());
230 ITmfEvent event
= fExperiment
.getNext(context
);
231 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
232 assertEquals("Context rank", 1, context
.getRank());
234 // Position trace at event rank [cacheSize]
235 context
= fExperiment
.seekEvent(new TmfTimestamp(cacheSize
+ 1, SCALE
));
236 assertEquals("Event rank", cacheSize
, context
.getRank());
238 event
= fExperiment
.getNext(context
);
239 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
240 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
242 // Position trace at event rank [4 * cacheSize]
243 context
= fExperiment
.seekEvent(new TmfTimestamp(4 * cacheSize
+ 1, SCALE
));
244 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
246 event
= fExperiment
.getNext(context
);
247 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
248 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
252 public void testSeekTimestampNotOnCacheBoundary() {
253 // Position trace at event rank 1 (TS = 2)
254 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
));
255 assertEquals("Context rank", 1, context
.getRank());
257 ITmfEvent event
= fExperiment
.getNext(context
);
258 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
259 assertEquals("Context rank", 2, context
.getRank());
261 // Position trace at event rank 9 (TS = 10)
262 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
));
263 assertEquals("Context rank", 9, context
.getRank());
265 event
= fExperiment
.getNext(context
);
266 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
267 assertEquals("Context rank", 10, context
.getRank());
269 // Position trace at event rank 999 (TS = 1000)
270 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
));
271 assertEquals("Context rank", 999, context
.getRank());
273 event
= fExperiment
.getNext(context
);
274 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
275 assertEquals("Context rank", 1000, context
.getRank());
277 // Position trace at event rank 1001 (TS = 1002)
278 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
));
279 assertEquals("Context rank", 1001, context
.getRank());
281 event
= fExperiment
.getNext(context
);
282 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
283 assertEquals("Context rank", 1002, context
.getRank());
285 // Position trace at event rank 4500 (TS = 4501)
286 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
));
287 assertEquals("Context rank", 4500, context
.getRank());
289 event
= fExperiment
.getNext(context
);
290 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
291 assertEquals("Context rank", 4501, context
.getRank());
295 public void testSeekTimestampOutOfScope() {
296 // Position trace at beginning
297 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
));
298 assertEquals("Event rank", 0, context
.getRank());
300 ITmfEvent event
= fExperiment
.getNext(context
);
301 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
302 assertEquals("Event rank", 1, context
.getRank());
304 // Position trace at event passed the end
305 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
));
306 event
= fExperiment
.getNext(context
);
307 assertNull("Event location", event
);
308 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
311 // ------------------------------------------------------------------------
312 // seekEvent by location (context rank is undefined)
313 // ------------------------------------------------------------------------
316 public void testSeekLocationOnCacheBoundary() {
317 long cacheSize
= fExperiment
.getCacheSize();
319 // Position trace at event rank 0
320 ITmfContext tmpContext
= fExperiment
.seekEvent(0);
321 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
323 ITmfEvent event
= fExperiment
.getNext(context
);
324 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
326 event
= fExperiment
.getNext(context
);
327 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
329 // Position trace at event rank 'cacheSize'
330 tmpContext
= fExperiment
.seekEvent(cacheSize
);
331 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
333 event
= fExperiment
.getNext(context
);
334 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
336 event
= fExperiment
.getNext(context
);
337 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
339 // Position trace at event rank 4 * 'cacheSize'
340 tmpContext
= fExperiment
.seekEvent(4 * cacheSize
);
341 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
343 event
= fExperiment
.getNext(context
);
344 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
346 event
= fExperiment
.getNext(context
);
347 assertEquals("Event timestamp", 4 * cacheSize
+ 2, event
.getTimestamp().getValue());
351 public void testSeekLocationNotOnCacheBoundary() {
352 long cacheSize
= fExperiment
.getCacheSize();
354 // Position trace at event 'cacheSize' - 1
355 ITmfContext tmpContext
= fExperiment
.seekEvent(cacheSize
- 1);
356 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
358 ITmfEvent event
= fExperiment
.getNext(context
);
359 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
361 event
= fExperiment
.getNext(context
);
362 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
364 // Position trace at event rank 2 * 'cacheSize' - 1
365 tmpContext
= fExperiment
.seekEvent(2 * cacheSize
- 1);
366 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
367 context
= fExperiment
.seekEvent(2 * cacheSize
- 1);
369 event
= fExperiment
.getNext(context
);
370 assertEquals("Event timestamp", 2 * cacheSize
, event
.getTimestamp().getValue());
372 event
= fExperiment
.getNext(context
);
373 assertEquals("Event timestamp", 2 * cacheSize
+ 1, event
.getTimestamp().getValue());
375 // Position trace at event rank 4500
376 tmpContext
= fExperiment
.seekEvent(4500);
377 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
379 event
= fExperiment
.getNext(context
);
380 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
382 event
= fExperiment
.getNext(context
);
383 assertEquals("Event timestamp", 4502, event
.getTimestamp().getValue());
387 public void testSeekLocationOutOfScope() {
388 // Position trace at beginning
389 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
391 ITmfEvent event
= fExperiment
.getNext(context
);
392 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
395 // ------------------------------------------------------------------------
396 // getNext - updates the context
397 // ------------------------------------------------------------------------
399 private static void validateContextRanks(ITmfContext context
) {
400 assertTrue("Experiment context type", context
instanceof TmfExperimentContext
);
401 TmfExperimentContext ctx
= (TmfExperimentContext
) context
;
403 int nbTraces
= ctx
.getNbTraces();
405 // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE)
406 long expRank
= -nbTraces
+ ((ctx
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) ?
1 : 0);
407 for (int i
= 0; i
< nbTraces
; i
++) {
408 ITmfContext subContext
= ctx
.getContext(i
);
409 assertNotNull(subContext
);
410 long rank
= subContext
.getRank();
417 assertEquals("Experiment context rank", expRank
, ctx
.getRank());
421 public void testGetNextAfteSeekingOnTS_1() {
422 final long INITIAL_TS
= 1;
423 final int NB_READS
= 20;
425 // On lower bound, returns the first event (ts = 1)
426 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
));
428 validateContextRanks(context
);
432 for (int i
= 0; i
< NB_READS
; i
++) {
433 event
= fExperiment
.getNext(context
);
434 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
435 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
438 // Make sure we stay positioned
439 event
= fExperiment
.parseEvent(context
);
440 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
441 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
443 validateContextRanks(context
);
447 public void testGetNextAfteSeekingOnTS_2() {
448 final long INITIAL_TS
= 2;
449 final int NB_READS
= 20;
451 // On lower bound, returns the first event (ts = 2)
452 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
));
454 validateContextRanks(context
);
458 for (int i
= 0; i
< NB_READS
; i
++) {
459 event
= fExperiment
.getNext(context
);
460 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
461 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
464 // Make sure we stay positioned
465 event
= fExperiment
.parseEvent(context
);
466 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
467 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
469 validateContextRanks(context
);
473 public void testGetNextAfteSeekingOnTS_3() {
474 final long INITIAL_TS
= 500;
475 final int NB_READS
= 20;
477 // On lower bound, returns the first event (ts = 500)
478 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
));
480 validateContextRanks(context
);
484 for (int i
= 0; i
< NB_READS
; i
++) {
485 event
= fExperiment
.getNext(context
);
486 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
487 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
490 // Make sure we stay positioned
491 event
= fExperiment
.parseEvent(context
);
492 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
493 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
495 validateContextRanks(context
);
499 public void testGetNextAfterSeekingOnRank_1() {
500 final long INITIAL_RANK
= 0L;
501 final int NB_READS
= 20;
503 // On lower bound, returns the first event (rank = 0)
504 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
506 validateContextRanks(context
);
510 for (int i
= 0; i
< NB_READS
; i
++) {
511 event
= fExperiment
.getNext(context
);
512 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
513 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
516 // Make sure we stay positioned
517 event
= fExperiment
.parseEvent(context
);
518 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
519 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
521 validateContextRanks(context
);
525 public void testGetNextAfterSeekingOnRank_2() {
526 final long INITIAL_RANK
= 1L;
527 final int NB_READS
= 20;
529 // On lower bound, returns the first event (rank = 0)
530 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
532 validateContextRanks(context
);
536 for (int i
= 0; i
< NB_READS
; i
++) {
537 event
= fExperiment
.getNext(context
);
538 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
539 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
542 // Make sure we stay positioned
543 event
= fExperiment
.parseEvent(context
);
544 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
545 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
547 validateContextRanks(context
);
551 public void testGetNextAfterSeekingOnRank_3() {
552 final long INITIAL_RANK
= 500L;
553 final int NB_READS
= 20;
555 // On lower bound, returns the first event (rank = 0)
556 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
558 validateContextRanks(context
);
562 for (int i
= 0; i
< NB_READS
; i
++) {
563 event
= fExperiment
.getNext(context
);
564 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
565 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
568 // Make sure we stay positioned
569 event
= fExperiment
.parseEvent(context
);
570 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
571 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
573 validateContextRanks(context
);
577 public void testGetNextAfterSeekingOnLocation_1() {
578 final ITmfLocation INITIAL_LOC
= null;
579 final long INITIAL_TS
= 1;
580 final int NB_READS
= 20;
582 // On lower bound, returns the first event (ts = 1)
583 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
585 validateContextRanks(context
);
589 for (int i
= 0; i
< NB_READS
; i
++) {
590 event
= fExperiment
.getNext(context
);
591 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
592 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
595 // Make sure we stay positioned
596 event
= fExperiment
.parseEvent(context
);
597 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
598 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
600 validateContextRanks(context
);
604 public void testGetNextAfterSeekingOnLocation_2() {
605 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(1L).getLocation();
606 final long INITIAL_TS
= 2;
607 final int NB_READS
= 20;
609 // On lower bound, returns the first event (ts = 2)
610 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
612 validateContextRanks(context
);
616 for (int i
= 0; i
< NB_READS
; i
++) {
617 event
= fExperiment
.getNext(context
);
618 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
621 // Make sure we stay positioned
622 event
= fExperiment
.parseEvent(context
);
623 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
625 validateContextRanks(context
);
629 public void testGetNextAfterSeekingOnLocation_3() {
630 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(500L).getLocation();
631 final long INITIAL_TS
= 501;
632 final int NB_READS
= 20;
634 // On lower bound, returns the first event (ts = 501)
635 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
637 validateContextRanks(context
);
641 for (int i
= 0; i
< NB_READS
; i
++) {
642 event
= fExperiment
.getNext(context
);
643 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
646 // Make sure we stay positioned
647 event
= fExperiment
.parseEvent(context
);
648 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
650 validateContextRanks(context
);
654 public void testGetNextLocation() {
655 ITmfContext context1
= fExperiment
.seekEvent(0);
656 fExperiment
.getNext(context1
);
657 ITmfLocation location
= context1
.getLocation();
658 ITmfEvent event1
= fExperiment
.getNext(context1
);
659 ITmfContext context2
= fExperiment
.seekEvent(location
);
660 ITmfEvent event2
= fExperiment
.getNext(context2
);
661 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
665 public void testGetNextEndLocation() {
666 ITmfContext context1
= fExperiment
.seekEvent(fExperiment
.getNbEvents() - 1);
667 fExperiment
.getNext(context1
);
668 ITmfLocation location
= context1
.getLocation();
669 ITmfContext context2
= fExperiment
.seekEvent(location
);
670 ITmfEvent event
= fExperiment
.getNext(context2
);
671 assertNull("Event", event
);
674 // ------------------------------------------------------------------------
676 // ------------------------------------------------------------------------
679 public void testProcessRequestForNbEvents() throws InterruptedException
{
680 final int nbEvents
= 1000;
681 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<>();
683 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
684 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class,
685 range
, 0, nbEvents
, ExecutionType
.FOREGROUND
) {
687 public void handleData(final ITmfEvent event
) {
688 super.handleData(event
);
689 requestedEvents
.add(event
);
692 fExperiment
.sendRequest(request
);
693 request
.waitForCompletion();
695 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
696 assertTrue("isCompleted", request
.isCompleted());
697 assertFalse("isCancelled", request
.isCancelled());
699 // Ensure that we have distinct events.
700 // Don't go overboard: we are not validating the stub!
701 for (int i
= 0; i
< nbEvents
; i
++) {
702 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
707 public void testProcessRequestForAllEvents() throws InterruptedException
{
708 final int nbEvents
= ITmfEventRequest
.ALL_DATA
;
709 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<>();
710 final long nbExpectedEvents
= NB_EVENTS
;
712 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
713 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class,
714 range
, 0, nbEvents
, ExecutionType
.FOREGROUND
) {
716 public void handleData(final ITmfEvent event
) {
717 super.handleData(event
);
718 requestedEvents
.add(event
);
721 fExperiment
.sendRequest(request
);
722 request
.waitForCompletion();
724 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
725 assertTrue("isCompleted", request
.isCompleted());
726 assertFalse("isCancelled", request
.isCancelled());
728 // Ensure that we have distinct events.
729 // Don't go overboard: we are not validating the stub!
730 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
731 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
735 // ------------------------------------------------------------------------
737 // ------------------------------------------------------------------------
740 public void testCancel() throws InterruptedException
{
741 final int nbEvents
= NB_EVENTS
;
742 final int limit
= BLOCK_SIZE
;
743 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<>();
745 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
746 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class,
747 range
, 0, nbEvents
, ExecutionType
.FOREGROUND
) {
751 public void handleData(final ITmfEvent event
) {
752 super.handleData(event
);
753 requestedEvents
.add(event
);
754 if (++nbRead
== limit
) {
759 fExperiment
.sendRequest(request
);
760 request
.waitForCompletion();
762 assertEquals("nbEvents", limit
, requestedEvents
.size());
763 assertTrue("isCompleted", request
.isCompleted());
764 assertTrue("isCancelled", request
.isCancelled());
767 // ------------------------------------------------------------------------
769 // ------------------------------------------------------------------------
772 public void testGetTimestamp() {
773 assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment
.getTimestamp( 0));
774 assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment
.getTimestamp( 1));
775 assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment
.getTimestamp( 10));
776 assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment
.getTimestamp( 100));
777 assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment
.getTimestamp( 1000));
778 assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment
.getTimestamp( 2000));
779 assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment
.getTimestamp( 2500));
780 assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment
.getTimestamp( 9999));
781 assertEquals("getTimestamp", new TmfTimestamp(20000, (byte) -3), fExperiment
.getTimestamp(19999));
782 assertNull("getTimestamp", fExperiment
.getTimestamp(20000));
785 // ------------------------------------------------------------------------
786 // getInitialRangeOffset, getCurrentRange, getCurrentTime
787 // ------------------------------------------------------------------------
790 public void testDefaultCurrentTimeValues() {
791 ITmfTrace
[] traces
= setupTraces();
792 TmfExperimentStub exp
= new TmfExperimentStub(EXPERIMENT
, traces
, BLOCK_SIZE
);
794 // verify initial values
795 TmfTimestamp initRange
= new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE
, ITmfTimestamp
.NANOSECOND_SCALE
);
796 assertEquals("getInitialRangeOffset", initRange
, exp
.getInitialRangeOffset());
802 public void testInitialRangeOffset() {
803 ITmfTrace
[] traces
= setupTraces();
804 ((TmfTraceStub
) traces
[0]).setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp
.MILLISECOND_SCALE
));
805 ((TmfTraceStub
) traces
[1]).setInitialRangeOffset(new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
));
806 TmfExperimentStub exp
= new TmfExperimentStub(EXPERIMENT
, traces
, BLOCK_SIZE
);
808 TmfTimestamp initRange
= new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
);
809 assertEquals("getInitialRangeOffset", initRange
, exp
.getInitialRangeOffset());