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 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.trace
;
17 import java
.io
.IOException
;
18 import java
.net
.URISyntaxException
;
20 import java
.util
.Vector
;
22 import junit
.framework
.TestCase
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.TmfExperimentContext
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
38 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
39 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
42 * Test suite for the TmfExperiment class (multiple traces).
44 @SuppressWarnings({"nls","javadoc"})
45 public class TmfMultiTraceExperimentTest
extends TestCase
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
50 private static final long DEFAULT_INITIAL_OFFSET_VALUE
= (1L * 100 * 1000 * 1000); // .1sec
51 private static final String DIRECTORY
= "testfiles";
52 private static final String TEST_STREAM1
= "O-Test-10K";
53 private static final String TEST_STREAM2
= "E-Test-10K";
54 private static final String EXPERIMENT
= "MyExperiment";
55 private static int NB_EVENTS
= 20000;
56 private static int BLOCK_SIZE
= 1000;
58 private static ITmfTrace
[] fTraces
;
59 private static TmfExperimentStub fExperiment
;
61 private static byte SCALE
= (byte) -3;
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 private synchronized static ITmfTrace
[] setupTrace(final String path1
, final String path2
) {
68 if (fTraces
== null) {
69 fTraces
= new ITmfTrace
[2];
71 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path1
), null);
72 File test
= new File(FileLocator
.toFileURL(location
).toURI());
73 final TmfTraceStub trace1
= new TmfTraceStub(test
.getPath(), 0, true);
74 trace1
.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp
.MILLISECOND_SCALE
));
77 location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path2
), null);
78 test
= new File(FileLocator
.toFileURL(location
).toURI());
79 final TmfTraceStub trace2
= new TmfTraceStub(test
.getPath(), 0, true);
80 trace2
.setInitialRangeOffset(new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
));
82 } catch (final TmfTraceException e
) {
84 } catch (final URISyntaxException e
) {
86 } catch (final IOException e
) {
94 * @param name the test name
96 public TmfMultiTraceExperimentTest(final String name
) {
101 protected synchronized void setUp() throws Exception
{
103 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM1
, DIRECTORY
+ File
.separator
+ TEST_STREAM2
);
104 if (fExperiment
== null) {
105 fExperiment
= new TmfExperimentStub(EXPERIMENT
, fTraces
, BLOCK_SIZE
);
106 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
111 protected void tearDown() throws Exception
{
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
119 public void testBasicTmfExperimentConstructor() {
121 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
122 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
124 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
125 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
126 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
128 TmfTimestamp initRange
= new TmfTimestamp(2, ITmfTimestamp
.MILLISECOND_SCALE
);
129 assertEquals("getInitialRangeOffset", initRange
, fExperiment
.getInitialRangeOffset());
130 assertEquals("getCurrentTime", fExperiment
.getTimeRange().getStartTime(), fExperiment
.getCurrentTime());
132 ITmfTimestamp startTimestamp
= fExperiment
.getTimeRange().getStartTime();
133 long endValue
= startTimestamp
.getValue() + initRange
.normalize(0, startTimestamp
.getScale()).getValue();
134 ITmfTimestamp endTimestamp
= new TmfTimestamp(endValue
, startTimestamp
.getScale());
135 TmfTimeRange expectedRange
= new TmfTimeRange(startTimestamp
, endTimestamp
);
136 assertEquals("getCurrentRange", expectedRange
, fExperiment
.getCurrentRange());
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
143 public void testSeekRankOnCacheBoundary() {
145 long cacheSize
= fExperiment
.getCacheSize();
147 // On lower bound, returns the first event (TS = 1)
148 ITmfContext context
= fExperiment
.seekEvent(0);
149 assertEquals("Context rank", 0, context
.getRank());
151 ITmfEvent event
= fExperiment
.getNext(context
);
152 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
153 assertEquals("Context rank", 1, context
.getRank());
155 // Position trace at event rank [cacheSize]
156 context
= fExperiment
.seekEvent(cacheSize
);
157 assertEquals("Context rank", cacheSize
, context
.getRank());
159 event
= fExperiment
.getNext(context
);
160 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
161 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
163 // Position trace at event rank [4 * cacheSize]
164 context
= fExperiment
.seekEvent(4 * cacheSize
);
165 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
167 event
= fExperiment
.getNext(context
);
168 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
169 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
172 public void testSeekRankNotOnCacheBoundary() {
174 long cacheSize
= fExperiment
.getCacheSize();
176 // Position trace at event rank 9
177 ITmfContext context
= fExperiment
.seekEvent(9);
178 assertEquals("Context rank", 9, context
.getRank());
180 ITmfEvent event
= fExperiment
.getNext(context
);
181 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
182 assertEquals("Context rank", 10, context
.getRank());
184 // Position trace at event rank [cacheSize - 1]
185 context
= fExperiment
.seekEvent(cacheSize
- 1);
186 assertEquals("Context rank", cacheSize
- 1, context
.getRank());
188 event
= fExperiment
.getNext(context
);
189 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
190 assertEquals("Context rank", cacheSize
, context
.getRank());
192 // Position trace at event rank [cacheSize + 1]
193 context
= fExperiment
.seekEvent(cacheSize
+ 1);
194 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
196 event
= fExperiment
.getNext(context
);
197 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
198 assertEquals("Context rank", cacheSize
+ 2, context
.getRank());
200 // Position trace at event rank 4500
201 context
= fExperiment
.seekEvent(4500);
202 assertEquals("Context rank", 4500, context
.getRank());
204 event
= fExperiment
.getNext(context
);
205 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
206 assertEquals("Context rank", 4501, context
.getRank());
209 public void testSeekRankOutOfScope() {
211 // Position trace at beginning
212 ITmfContext context
= fExperiment
.seekEvent(-1);
213 assertEquals("Event rank", 0, context
.getRank());
215 ITmfEvent event
= fExperiment
.getNext(context
);
216 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
217 assertEquals("Context rank", 1, context
.getRank());
219 // Position trace at event passed the end
220 context
= fExperiment
.seekEvent(NB_EVENTS
);
221 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
223 event
= fExperiment
.getNext(context
);
224 assertNull("Event", event
);
225 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
228 // ------------------------------------------------------------------------
229 // seekEvent on timestamp
230 // ------------------------------------------------------------------------
232 public void testSeekTimestampOnCacheBoundary() {
234 long cacheSize
= fExperiment
.getCacheSize();
236 // Position trace at event rank 0
237 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
238 assertEquals("Context rank", 0, context
.getRank());
240 ITmfEvent event
= fExperiment
.getNext(context
);
241 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
242 assertEquals("Context rank", 1, context
.getRank());
244 // Position trace at event rank [cacheSize]
245 context
= fExperiment
.seekEvent(new TmfTimestamp(cacheSize
+ 1, SCALE
, 0));
246 assertEquals("Event rank", cacheSize
, context
.getRank());
248 event
= fExperiment
.getNext(context
);
249 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
250 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
252 // Position trace at event rank [4 * cacheSize]
253 context
= fExperiment
.seekEvent(new TmfTimestamp(4 * cacheSize
+ 1, SCALE
, 0));
254 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
256 event
= fExperiment
.getNext(context
);
257 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
258 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
261 public void testSeekTimestampNotOnCacheBoundary() {
263 // Position trace at event rank 1 (TS = 2)
264 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
265 assertEquals("Context rank", 1, context
.getRank());
267 ITmfEvent event
= fExperiment
.getNext(context
);
268 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
269 assertEquals("Context rank", 2, context
.getRank());
271 // Position trace at event rank 9 (TS = 10)
272 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
273 assertEquals("Context rank", 9, context
.getRank());
275 event
= fExperiment
.getNext(context
);
276 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
277 assertEquals("Context rank", 10, context
.getRank());
279 // Position trace at event rank 999 (TS = 1000)
280 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
281 assertEquals("Context rank", 999, context
.getRank());
283 event
= fExperiment
.getNext(context
);
284 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
285 assertEquals("Context rank", 1000, context
.getRank());
287 // Position trace at event rank 1001 (TS = 1002)
288 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
289 assertEquals("Context rank", 1001, context
.getRank());
291 event
= fExperiment
.getNext(context
);
292 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
293 assertEquals("Context rank", 1002, context
.getRank());
295 // Position trace at event rank 4500 (TS = 4501)
296 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
297 assertEquals("Context rank", 4500, context
.getRank());
299 event
= fExperiment
.getNext(context
);
300 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
301 assertEquals("Context rank", 4501, context
.getRank());
304 public void testSeekTimestampOutOfScope() {
306 // Position trace at beginning
307 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
308 assertEquals("Event rank", 0, context
.getRank());
310 ITmfEvent event
= fExperiment
.getNext(context
);
311 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
312 assertEquals("Event rank", 1, context
.getRank());
314 // Position trace at event passed the end
315 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
316 event
= fExperiment
.getNext(context
);
317 assertNull("Event location", event
);
318 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
321 // ------------------------------------------------------------------------
322 // seekEvent by location (context rank is undefined)
323 // ------------------------------------------------------------------------
325 public void testSeekLocationOnCacheBoundary() {
327 long cacheSize
= fExperiment
.getCacheSize();
329 // Position trace at event rank 0
330 ITmfContext tmpContext
= fExperiment
.seekEvent(0);
331 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
333 ITmfEvent event
= fExperiment
.getNext(context
);
334 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
336 event
= fExperiment
.getNext(context
);
337 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
339 // Position trace at event rank 'cacheSize'
340 tmpContext
= fExperiment
.seekEvent(cacheSize
);
341 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
343 event
= fExperiment
.getNext(context
);
344 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
346 event
= fExperiment
.getNext(context
);
347 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
349 // Position trace at event rank 4 * 'cacheSize'
350 tmpContext
= fExperiment
.seekEvent(4 * cacheSize
);
351 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
353 event
= fExperiment
.getNext(context
);
354 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
356 event
= fExperiment
.getNext(context
);
357 assertEquals("Event timestamp", 4 * cacheSize
+ 2, event
.getTimestamp().getValue());
360 public void testSeekLocationNotOnCacheBoundary() {
362 long cacheSize
= fExperiment
.getCacheSize();
364 // Position trace at event 'cacheSize' - 1
365 ITmfContext tmpContext
= fExperiment
.seekEvent(cacheSize
- 1);
366 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
368 ITmfEvent event
= fExperiment
.getNext(context
);
369 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
371 event
= fExperiment
.getNext(context
);
372 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
374 // Position trace at event rank 2 * 'cacheSize' - 1
375 tmpContext
= fExperiment
.seekEvent(2 * cacheSize
- 1);
376 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
377 context
= fExperiment
.seekEvent(2 * cacheSize
- 1);
379 event
= fExperiment
.getNext(context
);
380 assertEquals("Event timestamp", 2 * cacheSize
, event
.getTimestamp().getValue());
382 event
= fExperiment
.getNext(context
);
383 assertEquals("Event timestamp", 2 * cacheSize
+ 1, event
.getTimestamp().getValue());
385 // Position trace at event rank 4500
386 tmpContext
= fExperiment
.seekEvent(4500);
387 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
389 event
= fExperiment
.getNext(context
);
390 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
392 event
= fExperiment
.getNext(context
);
393 assertEquals("Event timestamp", 4502, event
.getTimestamp().getValue());
396 public void testSeekLocationOutOfScope() {
398 // Position trace at beginning
399 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
401 ITmfEvent event
= fExperiment
.getNext(context
);
402 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
405 // ------------------------------------------------------------------------
406 // getNext - updates the context
407 // ------------------------------------------------------------------------
409 private static void validateContextRanks(ITmfContext context
) {
410 assertTrue("Experiment context type", context
instanceof TmfExperimentContext
);
411 TmfExperimentContext ctx
= (TmfExperimentContext
) context
;
413 int nbTraces
= ctx
.getContexts().length
;
415 // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE)
416 long expRank
= -nbTraces
+ ((ctx
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) ?
1 : 0);
417 for (int i
= 0; i
< nbTraces
; i
++) {
418 long rank
= ctx
.getContexts()[i
].getRank();
425 assertEquals("Experiment context rank", expRank
, ctx
.getRank());
428 public void testGetNextAfteSeekingOnTS_1() {
430 final long INITIAL_TS
= 1;
431 final int NB_READS
= 20;
433 // On lower bound, returns the first event (ts = 1)
434 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
436 validateContextRanks(context
);
440 for (int i
= 0; i
< NB_READS
; i
++) {
441 event
= fExperiment
.getNext(context
);
442 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
443 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
446 // Make sure we stay positioned
447 event
= fExperiment
.parseEvent(context
);
448 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
449 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
451 validateContextRanks(context
);
454 public void testGetNextAfteSeekingOnTS_2() {
456 final long INITIAL_TS
= 2;
457 final int NB_READS
= 20;
459 // On lower bound, returns the first event (ts = 2)
460 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
462 validateContextRanks(context
);
466 for (int i
= 0; i
< NB_READS
; i
++) {
467 event
= fExperiment
.getNext(context
);
468 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
469 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
472 // Make sure we stay positioned
473 event
= fExperiment
.parseEvent(context
);
474 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
475 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
477 validateContextRanks(context
);
480 public void testGetNextAfteSeekingOnTS_3() {
482 final long INITIAL_TS
= 500;
483 final int NB_READS
= 20;
485 // On lower bound, returns the first event (ts = 500)
486 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
488 validateContextRanks(context
);
492 for (int i
= 0; i
< NB_READS
; i
++) {
493 event
= fExperiment
.getNext(context
);
494 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
495 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
498 // Make sure we stay positioned
499 event
= fExperiment
.parseEvent(context
);
500 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
501 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
503 validateContextRanks(context
);
506 public void testGetNextAfterSeekingOnRank_1() {
508 final long INITIAL_RANK
= 0L;
509 final int NB_READS
= 20;
511 // On lower bound, returns the first event (rank = 0)
512 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
514 validateContextRanks(context
);
518 for (int i
= 0; i
< NB_READS
; i
++) {
519 event
= fExperiment
.getNext(context
);
520 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
521 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
524 // Make sure we stay positioned
525 event
= fExperiment
.parseEvent(context
);
526 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
527 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
529 validateContextRanks(context
);
532 public void testGetNextAfterSeekingOnRank_2() {
534 final long INITIAL_RANK
= 1L;
535 final int NB_READS
= 20;
537 // On lower bound, returns the first event (rank = 0)
538 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
540 validateContextRanks(context
);
544 for (int i
= 0; i
< NB_READS
; i
++) {
545 event
= fExperiment
.getNext(context
);
546 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
547 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
550 // Make sure we stay positioned
551 event
= fExperiment
.parseEvent(context
);
552 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
553 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
555 validateContextRanks(context
);
558 public void testGetNextAfterSeekingOnRank_3() {
560 final long INITIAL_RANK
= 500L;
561 final int NB_READS
= 20;
563 // On lower bound, returns the first event (rank = 0)
564 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
566 validateContextRanks(context
);
570 for (int i
= 0; i
< NB_READS
; i
++) {
571 event
= fExperiment
.getNext(context
);
572 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
573 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
576 // Make sure we stay positioned
577 event
= fExperiment
.parseEvent(context
);
578 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
579 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
581 validateContextRanks(context
);
584 public void testGetNextAfterSeekingOnLocation_1() {
586 final ITmfLocation INITIAL_LOC
= null;
587 final long INITIAL_TS
= 1;
588 final int NB_READS
= 20;
590 // On lower bound, returns the first event (ts = 1)
591 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
593 validateContextRanks(context
);
597 for (int i
= 0; i
< NB_READS
; i
++) {
598 event
= fExperiment
.getNext(context
);
599 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
600 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
603 // Make sure we stay positioned
604 event
= fExperiment
.parseEvent(context
);
605 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
606 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
608 validateContextRanks(context
);
611 public void testGetNextAfterSeekingOnLocation_2() {
613 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(1L).getLocation();
614 final long INITIAL_TS
= 2;
615 final int NB_READS
= 20;
617 // On lower bound, returns the first event (ts = 2)
618 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
620 validateContextRanks(context
);
624 for (int i
= 0; i
< NB_READS
; i
++) {
625 event
= fExperiment
.getNext(context
);
626 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
629 // Make sure we stay positioned
630 event
= fExperiment
.parseEvent(context
);
631 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
633 validateContextRanks(context
);
636 public void testGetNextAfterSeekingOnLocation_3() {
638 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(500L).getLocation();
639 final long INITIAL_TS
= 501;
640 final int NB_READS
= 20;
642 // On lower bound, returns the first event (ts = 501)
643 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
645 validateContextRanks(context
);
649 for (int i
= 0; i
< NB_READS
; i
++) {
650 event
= fExperiment
.getNext(context
);
651 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
654 // Make sure we stay positioned
655 event
= fExperiment
.parseEvent(context
);
656 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
658 validateContextRanks(context
);
661 public void testGetNextLocation() {
662 ITmfContext context1
= fExperiment
.seekEvent(0);
663 fExperiment
.getNext(context1
);
664 ITmfLocation location
= context1
.getLocation();
665 ITmfEvent event1
= fExperiment
.getNext(context1
);
666 ITmfContext context2
= fExperiment
.seekEvent(location
);
667 ITmfEvent event2
= fExperiment
.getNext(context2
);
668 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
671 public void testGetNextEndLocation() {
672 ITmfContext context1
= fExperiment
.seekEvent(fExperiment
.getNbEvents() - 1);
673 fExperiment
.getNext(context1
);
674 ITmfLocation location
= context1
.getLocation();
675 ITmfContext context2
= fExperiment
.seekEvent(location
);
676 ITmfEvent event
= fExperiment
.getNext(context2
);
677 assertNull("Event", event
);
680 // ------------------------------------------------------------------------
682 // ------------------------------------------------------------------------
684 public void testProcessRequestForNbEvents() throws InterruptedException
{
686 final int blockSize
= 100;
687 final int nbEvents
= 1000;
688 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
690 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
691 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
693 public void handleData(final ITmfEvent event
) {
694 super.handleData(event
);
695 requestedEvents
.add(event
);
698 fExperiment
.sendRequest(request
);
699 request
.waitForCompletion();
701 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
702 assertTrue("isCompleted", request
.isCompleted());
703 assertFalse("isCancelled", request
.isCancelled());
705 // Ensure that we have distinct events.
706 // Don't go overboard: we are not validating the stub!
707 for (int i
= 0; i
< nbEvents
; i
++) {
708 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
712 public void testProcessRequestForNbEvents2() throws InterruptedException
{
714 final int blockSize
= 2 * NB_EVENTS
;
715 final int nbEvents
= 1000;
716 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
718 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
719 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
721 public void handleData(final ITmfEvent event
) {
722 super.handleData(event
);
723 requestedEvents
.add(event
);
726 fExperiment
.sendRequest(request
);
727 request
.waitForCompletion();
729 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
730 assertTrue("isCompleted", request
.isCompleted());
731 assertFalse("isCancelled", request
.isCancelled());
733 // Ensure that we have distinct events.
734 // Don't go overboard: we are not validating the stub!
735 for (int i
= 0; i
< nbEvents
; i
++) {
736 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
740 public void testProcessRequestForAllEvents() throws InterruptedException
{
742 final int nbEvents
= TmfDataRequest
.ALL_DATA
;
743 final int blockSize
= 1;
744 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
745 final long nbExpectedEvents
= NB_EVENTS
;
747 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
748 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
750 public void handleData(final ITmfEvent event
) {
751 super.handleData(event
);
752 requestedEvents
.add(event
);
755 fExperiment
.sendRequest(request
);
756 request
.waitForCompletion();
758 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
759 assertTrue("isCompleted", request
.isCompleted());
760 assertFalse("isCancelled", request
.isCancelled());
762 // Ensure that we have distinct events.
763 // Don't go overboard: we are not validating the stub!
764 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
765 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
769 // ------------------------------------------------------------------------
771 // ------------------------------------------------------------------------
773 public void testCancel() throws InterruptedException
{
775 final int nbEvents
= NB_EVENTS
;
776 final int blockSize
= BLOCK_SIZE
;
777 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
779 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
780 final TmfEventRequest request
= new TmfEventRequest(ITmfEvent
.class, range
, nbEvents
, blockSize
) {
783 public void handleData(final ITmfEvent event
) {
784 super.handleData(event
);
785 requestedEvents
.add(event
);
786 if (++nbRead
== blockSize
) {
791 public void handleCancel() {
792 if (requestedEvents
.size() < blockSize
) {
793 System
.out
.println("aie");
797 fExperiment
.sendRequest(request
);
798 request
.waitForCompletion();
800 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
801 assertTrue("isCompleted", request
.isCompleted());
802 assertTrue("isCancelled", request
.isCancelled());
805 // ------------------------------------------------------------------------
807 // ------------------------------------------------------------------------
809 public void testGetTimestamp() {
810 assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment
.getTimestamp( 0));
811 assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment
.getTimestamp( 1));
812 assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment
.getTimestamp( 10));
813 assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment
.getTimestamp( 100));
814 assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment
.getTimestamp( 1000));
815 assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment
.getTimestamp( 2000));
816 assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment
.getTimestamp( 2500));
817 assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment
.getTimestamp( 9999));
818 assertEquals("getTimestamp", new TmfTimestamp(20000, (byte) -3), fExperiment
.getTimestamp(19999));
819 assertNull("getTimestamp", fExperiment
.getTimestamp(20000));
822 // ------------------------------------------------------------------------
823 // getInitialRangeOffset, getCurrentRange, getCurrentTime
824 // ------------------------------------------------------------------------
826 public void testDefaultCurrentTimeValues() {
827 // reset to default initial range offset
828 ((TmfTraceStub
)fTraces
[0]).setInitialRangeOffset(null);
829 ((TmfTraceStub
)fTraces
[1]).setInitialRangeOffset(null);
831 TmfExperimentStub exp
= new TmfExperimentStub(EXPERIMENT
, fTraces
, BLOCK_SIZE
);
833 // verify initial values
834 TmfTimestamp initRange
= new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE
, ITmfTimestamp
.NANOSECOND_SCALE
);
835 assertEquals("getInitialRangeOffset", initRange
, exp
.getInitialRangeOffset());
836 assertEquals("getCurrentTime", TmfTimestamp
.ZERO
, exp
.getCurrentTime());
837 assertEquals("getCurrentRange", TmfTimeRange
.NULL_RANGE
, exp
.getCurrentRange());