1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.trace
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertFalse
;
19 import static org
.junit
.Assert
.assertNull
;
20 import static org
.junit
.Assert
.assertTrue
;
23 import java
.io
.IOException
;
24 import java
.net
.URISyntaxException
;
26 import java
.util
.Vector
;
28 import org
.eclipse
.core
.runtime
.FileLocator
;
29 import org
.eclipse
.core
.runtime
.Path
;
30 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.TmfExperimentContext
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
42 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
43 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
44 import org
.junit
.Before
;
45 import org
.junit
.Test
;
48 * Test suite for the TmfExperiment class (multiple traces).
50 @SuppressWarnings({"nls","javadoc"})
51 public class TmfMultiTraceExperimentTest
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 private static final long DEFAULT_INITIAL_OFFSET_VALUE
= (1L * 100 * 1000 * 1000); // .1sec
58 private static final String DIRECTORY
= "testfiles";
59 private static final String TEST_STREAM1
= "O-Test-10K";
60 private static final String TEST_STREAM2
= "E-Test-10K";
61 private static final String EXPERIMENT
= "MyExperiment";
62 private static int NB_EVENTS
= 20000;
63 private static int BLOCK_SIZE
= 1000;
65 private static ITmfTrace
[] fTraces
;
66 private static TmfExperimentStub fExperiment
;
68 private static byte SCALE
= (byte) -3;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
76 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM1
, DIRECTORY
+ File
.separator
+ TEST_STREAM2
);
77 if (fExperiment
== null) {
78 fExperiment
= new TmfExperimentStub(EXPERIMENT
, fTraces
, BLOCK_SIZE
);
79 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
83 private synchronized static ITmfTrace
[] setupTrace(final String path1
, final String path2
) {
84 if (fTraces
== null) {
85 fTraces
= new ITmfTrace
[2];
87 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path1
), null);
88 File test
= new File(FileLocator
.toFileURL(location
).toURI());
89 final TmfTraceStub trace1
= new TmfTraceStub(test
.getPath(), 0, true);
90 trace1
.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp
.MILLISECOND_SCALE
));
93 location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path2
), null);
94 test
= new File(FileLocator
.toFileURL(location
).toURI());
95 final TmfTraceStub trace2
= new TmfTraceStub(test
.getPath(), 0, true);
96 trace2
.setInitialRangeOffset(new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
));
98 } catch (final TmfTraceException e
) {
100 } catch (final URISyntaxException e
) {
102 } catch (final IOException e
) {
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
114 public void testBasicTmfExperimentConstructor() {
115 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
116 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
118 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
119 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
120 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
122 TmfTimestamp initRange
= new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
);
123 assertEquals("getInitialRangeOffset", initRange
, fExperiment
.getInitialRangeOffset());
124 assertEquals("getCurrentTime", fExperiment
.getTimeRange().getStartTime(), fExperiment
.getCurrentTime());
126 ITmfTimestamp startTimestamp
= fExperiment
.getTimeRange().getStartTime();
127 long endValue
= startTimestamp
.getValue() + initRange
.normalize(0, startTimestamp
.getScale()).getValue();
128 ITmfTimestamp endTimestamp
= new TmfTimestamp(endValue
, startTimestamp
.getScale());
129 TmfTimeRange expectedRange
= new TmfTimeRange(startTimestamp
, endTimestamp
);
130 assertEquals("getCurrentRange", expectedRange
, fExperiment
.getCurrentRange());
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 public void testSeekRankOnCacheBoundary() {
139 long cacheSize
= fExperiment
.getCacheSize();
141 // On lower bound, returns the first event (TS = 1)
142 ITmfContext context
= fExperiment
.seekEvent(0);
143 assertEquals("Context rank", 0, context
.getRank());
145 ITmfEvent event
= fExperiment
.getNext(context
);
146 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
147 assertEquals("Context rank", 1, context
.getRank());
149 // Position trace at event rank [cacheSize]
150 context
= fExperiment
.seekEvent(cacheSize
);
151 assertEquals("Context rank", cacheSize
, context
.getRank());
153 event
= fExperiment
.getNext(context
);
154 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
155 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
157 // Position trace at event rank [4 * cacheSize]
158 context
= fExperiment
.seekEvent(4 * cacheSize
);
159 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
161 event
= fExperiment
.getNext(context
);
162 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
163 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
167 public void testSeekRankNotOnCacheBoundary() {
168 long cacheSize
= fExperiment
.getCacheSize();
170 // Position trace at event rank 9
171 ITmfContext context
= fExperiment
.seekEvent(9);
172 assertEquals("Context rank", 9, context
.getRank());
174 ITmfEvent event
= fExperiment
.getNext(context
);
175 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
176 assertEquals("Context rank", 10, context
.getRank());
178 // Position trace at event rank [cacheSize - 1]
179 context
= fExperiment
.seekEvent(cacheSize
- 1);
180 assertEquals("Context rank", cacheSize
- 1, context
.getRank());
182 event
= fExperiment
.getNext(context
);
183 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
184 assertEquals("Context rank", cacheSize
, context
.getRank());
186 // Position trace at event rank [cacheSize + 1]
187 context
= fExperiment
.seekEvent(cacheSize
+ 1);
188 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
190 event
= fExperiment
.getNext(context
);
191 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
192 assertEquals("Context rank", cacheSize
+ 2, context
.getRank());
194 // Position trace at event rank 4500
195 context
= fExperiment
.seekEvent(4500);
196 assertEquals("Context rank", 4500, context
.getRank());
198 event
= fExperiment
.getNext(context
);
199 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
200 assertEquals("Context rank", 4501, context
.getRank());
204 public void testSeekRankOutOfScope() {
205 // Position trace at beginning
206 ITmfContext context
= fExperiment
.seekEvent(-1);
207 assertEquals("Event rank", 0, context
.getRank());
209 ITmfEvent event
= fExperiment
.getNext(context
);
210 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
211 assertEquals("Context rank", 1, context
.getRank());
213 // Position trace at event passed the end
214 context
= fExperiment
.seekEvent(NB_EVENTS
);
215 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
217 event
= fExperiment
.getNext(context
);
218 assertNull("Event", event
);
219 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
222 // ------------------------------------------------------------------------
223 // seekEvent on timestamp
224 // ------------------------------------------------------------------------
227 public void testSeekTimestampOnCacheBoundary() {
228 long cacheSize
= fExperiment
.getCacheSize();
230 // Position trace at event rank 0
231 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
232 assertEquals("Context rank", 0, context
.getRank());
234 ITmfEvent event
= fExperiment
.getNext(context
);
235 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
236 assertEquals("Context rank", 1, context
.getRank());
238 // Position trace at event rank [cacheSize]
239 context
= fExperiment
.seekEvent(new TmfTimestamp(cacheSize
+ 1, SCALE
, 0));
240 assertEquals("Event rank", cacheSize
, context
.getRank());
242 event
= fExperiment
.getNext(context
);
243 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
244 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
246 // Position trace at event rank [4 * cacheSize]
247 context
= fExperiment
.seekEvent(new TmfTimestamp(4 * cacheSize
+ 1, SCALE
, 0));
248 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
250 event
= fExperiment
.getNext(context
);
251 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
252 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
256 public void testSeekTimestampNotOnCacheBoundary() {
257 // Position trace at event rank 1 (TS = 2)
258 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
259 assertEquals("Context rank", 1, context
.getRank());
261 ITmfEvent event
= fExperiment
.getNext(context
);
262 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
263 assertEquals("Context rank", 2, context
.getRank());
265 // Position trace at event rank 9 (TS = 10)
266 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
267 assertEquals("Context rank", 9, context
.getRank());
269 event
= fExperiment
.getNext(context
);
270 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
271 assertEquals("Context rank", 10, context
.getRank());
273 // Position trace at event rank 999 (TS = 1000)
274 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
275 assertEquals("Context rank", 999, context
.getRank());
277 event
= fExperiment
.getNext(context
);
278 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
279 assertEquals("Context rank", 1000, context
.getRank());
281 // Position trace at event rank 1001 (TS = 1002)
282 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
283 assertEquals("Context rank", 1001, context
.getRank());
285 event
= fExperiment
.getNext(context
);
286 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
287 assertEquals("Context rank", 1002, context
.getRank());
289 // Position trace at event rank 4500 (TS = 4501)
290 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
291 assertEquals("Context rank", 4500, context
.getRank());
293 event
= fExperiment
.getNext(context
);
294 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
295 assertEquals("Context rank", 4501, context
.getRank());
299 public void testSeekTimestampOutOfScope() {
300 // Position trace at beginning
301 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
302 assertEquals("Event rank", 0, context
.getRank());
304 ITmfEvent event
= fExperiment
.getNext(context
);
305 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
306 assertEquals("Event rank", 1, context
.getRank());
308 // Position trace at event passed the end
309 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
310 event
= fExperiment
.getNext(context
);
311 assertNull("Event location", event
);
312 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
315 // ------------------------------------------------------------------------
316 // seekEvent by location (context rank is undefined)
317 // ------------------------------------------------------------------------
320 public void testSeekLocationOnCacheBoundary() {
321 long cacheSize
= fExperiment
.getCacheSize();
323 // Position trace at event rank 0
324 ITmfContext tmpContext
= fExperiment
.seekEvent(0);
325 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
327 ITmfEvent event
= fExperiment
.getNext(context
);
328 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
330 event
= fExperiment
.getNext(context
);
331 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
333 // Position trace at event rank 'cacheSize'
334 tmpContext
= fExperiment
.seekEvent(cacheSize
);
335 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
337 event
= fExperiment
.getNext(context
);
338 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
340 event
= fExperiment
.getNext(context
);
341 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
343 // Position trace at event rank 4 * 'cacheSize'
344 tmpContext
= fExperiment
.seekEvent(4 * cacheSize
);
345 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
347 event
= fExperiment
.getNext(context
);
348 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
350 event
= fExperiment
.getNext(context
);
351 assertEquals("Event timestamp", 4 * cacheSize
+ 2, event
.getTimestamp().getValue());
355 public void testSeekLocationNotOnCacheBoundary() {
356 long cacheSize
= fExperiment
.getCacheSize();
358 // Position trace at event 'cacheSize' - 1
359 ITmfContext tmpContext
= fExperiment
.seekEvent(cacheSize
- 1);
360 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
362 ITmfEvent event
= fExperiment
.getNext(context
);
363 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
365 event
= fExperiment
.getNext(context
);
366 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
368 // Position trace at event rank 2 * 'cacheSize' - 1
369 tmpContext
= fExperiment
.seekEvent(2 * cacheSize
- 1);
370 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
371 context
= fExperiment
.seekEvent(2 * cacheSize
- 1);
373 event
= fExperiment
.getNext(context
);
374 assertEquals("Event timestamp", 2 * cacheSize
, event
.getTimestamp().getValue());
376 event
= fExperiment
.getNext(context
);
377 assertEquals("Event timestamp", 2 * cacheSize
+ 1, event
.getTimestamp().getValue());
379 // Position trace at event rank 4500
380 tmpContext
= fExperiment
.seekEvent(4500);
381 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
383 event
= fExperiment
.getNext(context
);
384 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
386 event
= fExperiment
.getNext(context
);
387 assertEquals("Event timestamp", 4502, event
.getTimestamp().getValue());
391 public void testSeekLocationOutOfScope() {
392 // Position trace at beginning
393 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
395 ITmfEvent event
= fExperiment
.getNext(context
);
396 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
399 // ------------------------------------------------------------------------
400 // getNext - updates the context
401 // ------------------------------------------------------------------------
403 private static void validateContextRanks(ITmfContext context
) {
404 assertTrue("Experiment context type", context
instanceof TmfExperimentContext
);
405 TmfExperimentContext ctx
= (TmfExperimentContext
) context
;
407 int nbTraces
= ctx
.getContexts().length
;
409 // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE)
410 long expRank
= -nbTraces
+ ((ctx
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) ?
1 : 0);
411 for (int i
= 0; i
< nbTraces
; i
++) {
412 long rank
= ctx
.getContexts()[i
].getRank();
419 assertEquals("Experiment context rank", expRank
, ctx
.getRank());
423 public void testGetNextAfteSeekingOnTS_1() {
424 final long INITIAL_TS
= 1;
425 final int NB_READS
= 20;
427 // On lower bound, returns the first event (ts = 1)
428 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
430 validateContextRanks(context
);
434 for (int i
= 0; i
< NB_READS
; i
++) {
435 event
= fExperiment
.getNext(context
);
436 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
437 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
440 // Make sure we stay positioned
441 event
= fExperiment
.parseEvent(context
);
442 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
443 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
445 validateContextRanks(context
);
449 public void testGetNextAfteSeekingOnTS_2() {
450 final long INITIAL_TS
= 2;
451 final int NB_READS
= 20;
453 // On lower bound, returns the first event (ts = 2)
454 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
456 validateContextRanks(context
);
460 for (int i
= 0; i
< NB_READS
; i
++) {
461 event
= fExperiment
.getNext(context
);
462 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
463 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
466 // Make sure we stay positioned
467 event
= fExperiment
.parseEvent(context
);
468 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
469 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
471 validateContextRanks(context
);
475 public void testGetNextAfteSeekingOnTS_3() {
476 final long INITIAL_TS
= 500;
477 final int NB_READS
= 20;
479 // On lower bound, returns the first event (ts = 500)
480 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
482 validateContextRanks(context
);
486 for (int i
= 0; i
< NB_READS
; i
++) {
487 event
= fExperiment
.getNext(context
);
488 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
489 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
492 // Make sure we stay positioned
493 event
= fExperiment
.parseEvent(context
);
494 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
495 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
497 validateContextRanks(context
);
501 public void testGetNextAfterSeekingOnRank_1() {
502 final long INITIAL_RANK
= 0L;
503 final int NB_READS
= 20;
505 // On lower bound, returns the first event (rank = 0)
506 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
508 validateContextRanks(context
);
512 for (int i
= 0; i
< NB_READS
; i
++) {
513 event
= fExperiment
.getNext(context
);
514 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
515 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
518 // Make sure we stay positioned
519 event
= fExperiment
.parseEvent(context
);
520 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
521 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
523 validateContextRanks(context
);
527 public void testGetNextAfterSeekingOnRank_2() {
528 final long INITIAL_RANK
= 1L;
529 final int NB_READS
= 20;
531 // On lower bound, returns the first event (rank = 0)
532 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
534 validateContextRanks(context
);
538 for (int i
= 0; i
< NB_READS
; i
++) {
539 event
= fExperiment
.getNext(context
);
540 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
541 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
544 // Make sure we stay positioned
545 event
= fExperiment
.parseEvent(context
);
546 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
547 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
549 validateContextRanks(context
);
553 public void testGetNextAfterSeekingOnRank_3() {
554 final long INITIAL_RANK
= 500L;
555 final int NB_READS
= 20;
557 // On lower bound, returns the first event (rank = 0)
558 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
560 validateContextRanks(context
);
564 for (int i
= 0; i
< NB_READS
; i
++) {
565 event
= fExperiment
.getNext(context
);
566 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
567 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
570 // Make sure we stay positioned
571 event
= fExperiment
.parseEvent(context
);
572 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
573 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
575 validateContextRanks(context
);
579 public void testGetNextAfterSeekingOnLocation_1() {
580 final ITmfLocation INITIAL_LOC
= null;
581 final long INITIAL_TS
= 1;
582 final int NB_READS
= 20;
584 // On lower bound, returns the first event (ts = 1)
585 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
587 validateContextRanks(context
);
591 for (int i
= 0; i
< NB_READS
; i
++) {
592 event
= fExperiment
.getNext(context
);
593 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
594 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
597 // Make sure we stay positioned
598 event
= fExperiment
.parseEvent(context
);
599 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
600 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
602 validateContextRanks(context
);
606 public void testGetNextAfterSeekingOnLocation_2() {
607 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(1L).getLocation();
608 final long INITIAL_TS
= 2;
609 final int NB_READS
= 20;
611 // On lower bound, returns the first event (ts = 2)
612 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
614 validateContextRanks(context
);
618 for (int i
= 0; i
< NB_READS
; i
++) {
619 event
= fExperiment
.getNext(context
);
620 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
623 // Make sure we stay positioned
624 event
= fExperiment
.parseEvent(context
);
625 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
627 validateContextRanks(context
);
631 public void testGetNextAfterSeekingOnLocation_3() {
632 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(500L).getLocation();
633 final long INITIAL_TS
= 501;
634 final int NB_READS
= 20;
636 // On lower bound, returns the first event (ts = 501)
637 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
639 validateContextRanks(context
);
643 for (int i
= 0; i
< NB_READS
; i
++) {
644 event
= fExperiment
.getNext(context
);
645 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
648 // Make sure we stay positioned
649 event
= fExperiment
.parseEvent(context
);
650 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
652 validateContextRanks(context
);
656 public void testGetNextLocation() {
657 ITmfContext context1
= fExperiment
.seekEvent(0);
658 fExperiment
.getNext(context1
);
659 ITmfLocation location
= context1
.getLocation();
660 ITmfEvent event1
= fExperiment
.getNext(context1
);
661 ITmfContext context2
= fExperiment
.seekEvent(location
);
662 ITmfEvent event2
= fExperiment
.getNext(context2
);
663 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
667 public void testGetNextEndLocation() {
668 ITmfContext context1
= fExperiment
.seekEvent(fExperiment
.getNbEvents() - 1);
669 fExperiment
.getNext(context1
);
670 ITmfLocation location
= context1
.getLocation();
671 ITmfContext context2
= fExperiment
.seekEvent(location
);
672 ITmfEvent event
= fExperiment
.getNext(context2
);
673 assertNull("Event", event
);
676 // ------------------------------------------------------------------------
678 // ------------------------------------------------------------------------
681 public void testProcessRequestForNbEvents() throws InterruptedException
{
682 final int blockSize
= 100;
683 final int nbEvents
= 1000;
684 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
686 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
687 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
689 public void handleData(final ITmfEvent event
) {
690 super.handleData(event
);
691 requestedEvents
.add(event
);
694 fExperiment
.sendRequest(request
);
695 request
.waitForCompletion();
697 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
698 assertTrue("isCompleted", request
.isCompleted());
699 assertFalse("isCancelled", request
.isCancelled());
701 // Ensure that we have distinct events.
702 // Don't go overboard: we are not validating the stub!
703 for (int i
= 0; i
< nbEvents
; i
++) {
704 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
709 public void testProcessRequestForNbEvents2() throws InterruptedException
{
710 final int blockSize
= 2 * NB_EVENTS
;
711 final int nbEvents
= 1000;
712 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
714 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
715 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
717 public void handleData(final ITmfEvent event
) {
718 super.handleData(event
);
719 requestedEvents
.add(event
);
722 fExperiment
.sendRequest(request
);
723 request
.waitForCompletion();
725 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
726 assertTrue("isCompleted", request
.isCompleted());
727 assertFalse("isCancelled", request
.isCancelled());
729 // Ensure that we have distinct events.
730 // Don't go overboard: we are not validating the stub!
731 for (int i
= 0; i
< nbEvents
; i
++) {
732 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
737 public void testProcessRequestForAllEvents() throws InterruptedException
{
738 final int nbEvents
= TmfDataRequest
.ALL_DATA
;
739 final int blockSize
= 1;
740 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
741 final long nbExpectedEvents
= NB_EVENTS
;
743 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
744 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
746 public void handleData(final ITmfEvent event
) {
747 super.handleData(event
);
748 requestedEvents
.add(event
);
751 fExperiment
.sendRequest(request
);
752 request
.waitForCompletion();
754 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
755 assertTrue("isCompleted", request
.isCompleted());
756 assertFalse("isCancelled", request
.isCancelled());
758 // Ensure that we have distinct events.
759 // Don't go overboard: we are not validating the stub!
760 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
761 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
765 // ------------------------------------------------------------------------
767 // ------------------------------------------------------------------------
770 public void testCancel() throws InterruptedException
{
771 final int nbEvents
= NB_EVENTS
;
772 final int blockSize
= BLOCK_SIZE
;
773 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
775 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
776 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
779 public void handleData(final ITmfEvent event
) {
780 super.handleData(event
);
781 requestedEvents
.add(event
);
782 if (++nbRead
== blockSize
) {
787 public void handleCancel() {
788 if (requestedEvents
.size() < blockSize
) {
789 System
.out
.println("aie");
793 fExperiment
.sendRequest(request
);
794 request
.waitForCompletion();
796 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
797 assertTrue("isCompleted", request
.isCompleted());
798 assertTrue("isCancelled", request
.isCancelled());
801 // ------------------------------------------------------------------------
803 // ------------------------------------------------------------------------
806 public void testGetTimestamp() {
807 assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment
.getTimestamp( 0));
808 assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment
.getTimestamp( 1));
809 assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment
.getTimestamp( 10));
810 assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment
.getTimestamp( 100));
811 assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment
.getTimestamp( 1000));
812 assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment
.getTimestamp( 2000));
813 assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment
.getTimestamp( 2500));
814 assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment
.getTimestamp( 9999));
815 assertEquals("getTimestamp", new TmfTimestamp(20000, (byte) -3), fExperiment
.getTimestamp(19999));
816 assertNull("getTimestamp", fExperiment
.getTimestamp(20000));
819 // ------------------------------------------------------------------------
820 // getInitialRangeOffset, getCurrentRange, getCurrentTime
821 // ------------------------------------------------------------------------
824 public void testDefaultCurrentTimeValues() {
825 // reset to default initial range offset
826 ((TmfTraceStub
)fTraces
[0]).setInitialRangeOffset(null);
827 ((TmfTraceStub
)fTraces
[1]).setInitialRangeOffset(null);
829 TmfExperimentStub exp
= new TmfExperimentStub(EXPERIMENT
, fTraces
, BLOCK_SIZE
);
831 // verify initial values
832 TmfTimestamp initRange
= new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE
, ITmfTimestamp
.NANOSECOND_SCALE
);
833 assertEquals("getInitialRangeOffset", initRange
, exp
.getInitialRangeOffset());
834 assertEquals("getCurrentTime", TmfTimestamp
.ZERO
, exp
.getCurrentTime());
835 assertEquals("getCurrentRange", TmfTimeRange
.NULL_RANGE
, exp
.getCurrentRange());