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
.resources
.IFile
;
25 import org
.eclipse
.core
.runtime
.FileLocator
;
26 import org
.eclipse
.core
.runtime
.Path
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.TmfExperimentContext
;
28 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.TmfExperimentLocation
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLongLocation
;
42 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
43 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
46 * Test suite for the TmfExperiment class (single trace).
48 @SuppressWarnings({"nls","javadoc"})
49 public class TmfExperimentTest
extends TestCase
{
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 private static final String DIRECTORY
= "testfiles";
56 private static final String TEST_STREAM
= "A-Test-10K";
57 private static final String EXPERIMENT
= "MyExperiment";
58 private static int NB_EVENTS
= 10000;
59 private static int BLOCK_SIZE
= 1000;
61 private ITmfTrace
[] fTestTraces
;
62 private TmfExperimentStub fExperiment
;
64 private static byte SCALE
= (byte) -3;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 private synchronized ITmfTrace
[] setupTrace(final String path
) {
71 if (fTestTraces
== null) {
72 fTestTraces
= new ITmfTrace
[1];
74 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
75 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
76 final TmfTraceStub trace
= new TmfTraceStub(test
.getPath(), 0, true);
77 fTestTraces
[0] = trace
;
78 } catch (final TmfTraceException e
) {
80 } catch (final URISyntaxException e
) {
82 } catch (final IOException e
) {
89 private synchronized void setupExperiment() {
90 if (fExperiment
== null) {
91 fExperiment
= new TmfExperimentStub(EXPERIMENT
, fTestTraces
, BLOCK_SIZE
);
92 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
97 * @param name the test name
99 public TmfExperimentTest(final String name
) {
104 protected void setUp() throws Exception
{
106 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
111 protected void tearDown() throws Exception
{
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
119 public void testSimpleTmfExperimentConstructor() {
121 TmfExperiment experiment
= new TmfExperiment(TmfEvent
.class, EXPERIMENT
, fTestTraces
);
122 assertEquals("GetId", EXPERIMENT
, experiment
.getName());
123 assertEquals("GetCacheSize", TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, experiment
.getCacheSize());
124 experiment
.dispose();
126 experiment
= new TmfExperiment(TmfEvent
.class, EXPERIMENT
, null);
127 experiment
.dispose();
130 public void testNormalTmfExperimentConstructor() {
132 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
133 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
135 final long nbExperimentEvents
= fExperiment
.getNbEvents();
136 assertEquals("GetNbEvents", NB_EVENTS
, nbExperimentEvents
);
138 final long nbTraceEvents
= fExperiment
.getTraces()[0].getNbEvents();
139 assertEquals("GetNbEvents", NB_EVENTS
, nbTraceEvents
);
141 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
142 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
143 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
146 // ------------------------------------------------------------------------
148 // ------------------------------------------------------------------------
150 public void testGetTimestamp() {
151 assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment
.getTimestamp( 0));
152 assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment
.getTimestamp( 1));
153 assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment
.getTimestamp( 10));
154 assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment
.getTimestamp( 100));
155 assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment
.getTimestamp(1000));
156 assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment
.getTimestamp(2000));
157 assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment
.getTimestamp(2500));
158 assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment
.getTimestamp(9999));
159 assertNull("getTimestamp", fExperiment
.getTimestamp(10000));
162 // ------------------------------------------------------------------------
163 // Bookmarks file handling
164 // ------------------------------------------------------------------------
166 public void testBookmarks() {
167 assertNull("GetBookmarksFile", fExperiment
.getBookmarksFile());
168 IFile bookmarks
= (IFile
) fTestTraces
[0].getResource();
169 fExperiment
.setBookmarksFile(bookmarks
);
170 assertEquals("GetBookmarksFile", bookmarks
, fExperiment
.getBookmarksFile());
173 // ------------------------------------------------------------------------
174 // seekEvent by location
175 // ------------------------------------------------------------------------
177 public void testSeekBadLocation() {
178 ITmfContext context
= fExperiment
.seekEvent(new TmfLongLocation(0L));
179 assertNull("seekEvent", context
);
182 public void testSeekNoTrace() {
183 TmfExperiment experiment
= new TmfExperiment(TmfEvent
.class, EXPERIMENT
, null);
184 ITmfContext context
= experiment
.seekEvent((TmfExperimentLocation
) null);
185 assertNull("seekEvent", context
);
186 experiment
.dispose();
189 // ------------------------------------------------------------------------
190 // seekEvent on ratio
191 // ------------------------------------------------------------------------
193 public void testSeekEventOnRatio() {
196 ITmfContext context
= fExperiment
.seekEvent(0.0);
197 assertEquals("Context rank", 0, context
.getRank());
198 ITmfEvent event
= fExperiment
.parseEvent(context
);
199 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
200 assertEquals("Context rank", 0, context
.getRank());
203 int midTrace
= NB_EVENTS
/ 2;
204 context
= fExperiment
.seekEvent(0.5);
205 assertEquals("Context rank", midTrace
, context
.getRank());
206 event
= fExperiment
.parseEvent(context
);
207 assertEquals("Event timestamp", midTrace
+ 1, event
.getTimestamp().getValue());
208 assertEquals("Context rank", midTrace
, context
.getRank());
211 context
= fExperiment
.seekEvent(1.0);
212 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
213 event
= fExperiment
.parseEvent(context
);
214 assertNull("Event timestamp", event
);
215 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
218 context
= fExperiment
.seekEvent(1.1);
219 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
220 event
= fExperiment
.parseEvent(context
);
221 assertNull("Event timestamp", event
);
222 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
225 context
= fExperiment
.seekEvent(-0.5);
226 assertEquals("Context rank", 0, context
.getRank());
227 event
= fExperiment
.parseEvent(context
);
228 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
229 assertEquals("Context rank", 0, context
.getRank());
232 public void testGetLocationRatio() {
235 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
236 double ratio
= fExperiment
.getLocationRatio(context
.getLocation());
237 context
= fExperiment
.seekEvent(ratio
);
238 double ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
239 assertEquals("getLocationRatio", ratio
, ratio2
);
242 context
= fExperiment
.seekEvent(NB_EVENTS
/ 2);
243 ratio
= fExperiment
.getLocationRatio(context
.getLocation());
244 context
= fExperiment
.seekEvent(ratio
);
245 ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
246 assertEquals("getLocationRatio", ratio
, ratio2
);
249 context
= fExperiment
.seekEvent(NB_EVENTS
- 1);
250 ratio
= fExperiment
.getLocationRatio(context
.getLocation());
251 context
= fExperiment
.seekEvent(ratio
);
252 ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
253 assertEquals("getLocationRatio", ratio
, ratio2
);
256 // @SuppressWarnings("rawtypes")
257 // public void testGetCurrentLocation() {
258 // ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
259 // ITmfLocation location = fExperiment.getCurrentLocation();
260 // assertEquals("getCurrentLocation", location, context.getLocation());
263 // ------------------------------------------------------------------------
265 // ------------------------------------------------------------------------
267 public void testSeekRankOnCacheBoundary() {
269 long cacheSize
= fExperiment
.getCacheSize();
271 // On lower bound, returns the first event (TS = 1)
272 ITmfContext context
= fExperiment
.seekEvent(0);
273 assertEquals("Context rank", 0, context
.getRank());
275 ITmfEvent event
= fExperiment
.getNext(context
);
276 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
277 assertEquals("Context rank", 1, context
.getRank());
279 // Position trace at event rank [cacheSize]
280 context
= fExperiment
.seekEvent(cacheSize
);
281 assertEquals("Context rank", cacheSize
, context
.getRank());
283 event
= fExperiment
.getNext(context
);
284 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
285 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
287 // Position trace at event rank [4 * cacheSize]
288 context
= fExperiment
.seekEvent(4 * cacheSize
);
289 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
291 event
= fExperiment
.getNext(context
);
292 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
293 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
296 public void testSeekRankNotOnCacheBoundary() {
298 long cacheSize
= fExperiment
.getCacheSize();
300 // Position trace at event rank 9
301 ITmfContext context
= fExperiment
.seekEvent(9);
302 assertEquals("Context rank", 9, context
.getRank());
304 ITmfEvent event
= fExperiment
.getNext(context
);
305 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
306 assertEquals("Context rank", 10, context
.getRank());
308 // Position trace at event rank [cacheSize - 1]
309 context
= fExperiment
.seekEvent(cacheSize
- 1);
310 assertEquals("Context rank", cacheSize
- 1, context
.getRank());
312 event
= fExperiment
.getNext(context
);
313 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
314 assertEquals("Context rank", cacheSize
, context
.getRank());
316 // Position trace at event rank [cacheSize + 1]
317 context
= fExperiment
.seekEvent(cacheSize
+ 1);
318 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
320 event
= fExperiment
.getNext(context
);
321 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
322 assertEquals("Context rank", cacheSize
+ 2, context
.getRank());
324 // Position trace at event rank 4500
325 context
= fExperiment
.seekEvent(4500);
326 assertEquals("Context rank", 4500, context
.getRank());
328 event
= fExperiment
.getNext(context
);
329 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
330 assertEquals("Context rank", 4501, context
.getRank());
333 public void testSeekRankOutOfScope() {
335 // Position trace at beginning
336 ITmfContext context
= fExperiment
.seekEvent(-1);
337 assertEquals("Event rank", 0, context
.getRank());
339 ITmfEvent event
= fExperiment
.getNext(context
);
340 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
341 assertEquals("Context rank", 1, context
.getRank());
343 // Position trace at event passed the end
344 context
= fExperiment
.seekEvent(NB_EVENTS
);
345 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
347 event
= fExperiment
.getNext(context
);
348 assertNull("Event", event
);
349 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
352 // ------------------------------------------------------------------------
353 // seekEvent on timestamp
354 // ------------------------------------------------------------------------
356 public void testSeekTimestampOnCacheBoundary() {
358 long cacheSize
= fExperiment
.getCacheSize();
360 // Position trace at event rank 0
361 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
362 assertEquals("Context rank", 0, context
.getRank());
364 ITmfEvent event
= fExperiment
.getNext(context
);
365 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
366 assertEquals("Context rank", 1, context
.getRank());
368 // Position trace at event rank [cacheSize]
369 context
= fExperiment
.seekEvent(new TmfTimestamp(cacheSize
+ 1, SCALE
, 0));
370 assertEquals("Event rank", cacheSize
, context
.getRank());
372 event
= fExperiment
.getNext(context
);
373 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
374 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
376 // Position trace at event rank [4 * cacheSize]
377 context
= fExperiment
.seekEvent(new TmfTimestamp(4 * cacheSize
+ 1, SCALE
, 0));
378 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
380 event
= fExperiment
.getNext(context
);
381 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
382 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
385 public void testSeekTimestampNotOnCacheBoundary() {
387 // Position trace at event rank 1 (TS = 2)
388 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
389 assertEquals("Context rank", 1, context
.getRank());
391 ITmfEvent event
= fExperiment
.getNext(context
);
392 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
393 assertEquals("Context rank", 2, context
.getRank());
395 // Position trace at event rank 9 (TS = 10)
396 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
397 assertEquals("Context rank", 9, context
.getRank());
399 event
= fExperiment
.getNext(context
);
400 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
401 assertEquals("Context rank", 10, context
.getRank());
403 // Position trace at event rank 999 (TS = 1000)
404 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
405 assertEquals("Context rank", 999, context
.getRank());
407 event
= fExperiment
.getNext(context
);
408 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
409 assertEquals("Context rank", 1000, context
.getRank());
411 // Position trace at event rank 1001 (TS = 1002)
412 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
413 assertEquals("Context rank", 1001, context
.getRank());
415 event
= fExperiment
.getNext(context
);
416 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
417 assertEquals("Context rank", 1002, context
.getRank());
419 // Position trace at event rank 4500 (TS = 4501)
420 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
421 assertEquals("Context rank", 4500, context
.getRank());
423 event
= fExperiment
.getNext(context
);
424 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
425 assertEquals("Context rank", 4501, context
.getRank());
428 public void testSeekTimestampOutOfScope() {
430 // Position trace at beginning
431 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
432 assertEquals("Event rank", 0, context
.getRank());
434 ITmfEvent event
= fExperiment
.getNext(context
);
435 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
436 assertEquals("Event rank", 1, context
.getRank());
438 // Position trace at event passed the end
439 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
440 event
= fExperiment
.getNext(context
);
441 assertNull("Event location", event
);
442 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
445 // ------------------------------------------------------------------------
446 // seekEvent by location (context rank is undefined)
447 // ------------------------------------------------------------------------
449 public void testSeekLocationOnCacheBoundary() {
451 long cacheSize
= fExperiment
.getCacheSize();
453 // Position trace at event rank 0
454 ITmfContext tmpContext
= fExperiment
.seekEvent(0);
455 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
457 ITmfEvent event
= fExperiment
.getNext(context
);
458 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
460 event
= fExperiment
.getNext(context
);
461 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
463 // Position trace at event rank 'cacheSize'
464 tmpContext
= fExperiment
.seekEvent(cacheSize
);
465 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
467 event
= fExperiment
.getNext(context
);
468 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
470 event
= fExperiment
.getNext(context
);
471 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
473 // Position trace at event rank 4 * 'cacheSize'
474 tmpContext
= fExperiment
.seekEvent(4 * cacheSize
);
475 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
477 event
= fExperiment
.getNext(context
);
478 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
480 event
= fExperiment
.getNext(context
);
481 assertEquals("Event timestamp", 4 * cacheSize
+ 2, event
.getTimestamp().getValue());
484 public void testSeekLocationNotOnCacheBoundary() {
486 long cacheSize
= fExperiment
.getCacheSize();
488 // Position trace at event 'cacheSize' - 1
489 ITmfContext tmpContext
= fExperiment
.seekEvent(cacheSize
- 1);
490 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
492 ITmfEvent event
= fExperiment
.getNext(context
);
493 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
495 event
= fExperiment
.getNext(context
);
496 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
498 // Position trace at event rank 2 * 'cacheSize' - 1
499 tmpContext
= fExperiment
.seekEvent(2 * cacheSize
- 1);
500 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
501 context
= fExperiment
.seekEvent(2 * cacheSize
- 1);
503 event
= fExperiment
.getNext(context
);
504 assertEquals("Event timestamp", 2 * cacheSize
, event
.getTimestamp().getValue());
506 event
= fExperiment
.getNext(context
);
507 assertEquals("Event timestamp", 2 * cacheSize
+ 1, event
.getTimestamp().getValue());
509 // Position trace at event rank 4500
510 tmpContext
= fExperiment
.seekEvent(4500);
511 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
513 event
= fExperiment
.getNext(context
);
514 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
516 event
= fExperiment
.getNext(context
);
517 assertEquals("Event timestamp", 4502, event
.getTimestamp().getValue());
520 public void testSeekLocationOutOfScope() {
522 // Position trace at beginning
523 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
525 ITmfEvent event
= fExperiment
.getNext(context
);
526 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
529 // ------------------------------------------------------------------------
530 // getNext - updates the context
531 // ------------------------------------------------------------------------
533 private static void validateContextRanks(ITmfContext context
) {
534 assertTrue("Experiment context type", context
instanceof TmfExperimentContext
);
535 TmfExperimentContext ctx
= (TmfExperimentContext
) context
;
537 int nbTraces
= ctx
.getContexts().length
;
539 // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE)
540 long expRank
= -nbTraces
+ ((ctx
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) ?
1 : 0);
541 for (int i
= 0; i
< nbTraces
; i
++) {
542 long rank
= ctx
.getContexts()[i
].getRank();
549 assertEquals("Experiment context rank", expRank
, ctx
.getRank());
552 public void testGetNextAfteSeekingOnTS_1() {
554 final long INITIAL_TS
= 1;
555 final int NB_READS
= 20;
557 // On lower bound, returns the first event (ts = 1)
558 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
560 validateContextRanks(context
);
564 for (int i
= 0; i
< NB_READS
; i
++) {
565 event
= fExperiment
.getNext(context
);
566 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
567 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
570 // Make sure we stay positioned
571 event
= fExperiment
.parseEvent(context
);
572 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
573 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
575 validateContextRanks(context
);
578 public void testGetNextAfteSeekingOnTS_2() {
580 final long INITIAL_TS
= 2;
581 final int NB_READS
= 20;
583 // On lower bound, returns the first event (ts = 2)
584 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
586 validateContextRanks(context
);
590 for (int i
= 0; i
< NB_READS
; i
++) {
591 event
= fExperiment
.getNext(context
);
592 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
593 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
596 // Make sure we stay positioned
597 event
= fExperiment
.parseEvent(context
);
598 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
599 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
601 validateContextRanks(context
);
604 public void testGetNextAfteSeekingOnTS_3() {
606 final long INITIAL_TS
= 500;
607 final int NB_READS
= 20;
609 // On lower bound, returns the first event (ts = 500)
610 final ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(INITIAL_TS
, SCALE
, 0));
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());
619 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
622 // Make sure we stay positioned
623 event
= fExperiment
.parseEvent(context
);
624 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
625 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
627 validateContextRanks(context
);
630 public void testGetNextAfterSeekingOnRank_1() {
632 final long INITIAL_RANK
= 0L;
633 final int NB_READS
= 20;
635 // On lower bound, returns the first event (rank = 0)
636 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
638 validateContextRanks(context
);
642 for (int i
= 0; i
< NB_READS
; i
++) {
643 event
= fExperiment
.getNext(context
);
644 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
645 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
648 // Make sure we stay positioned
649 event
= fExperiment
.parseEvent(context
);
650 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
651 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
653 validateContextRanks(context
);
656 public void testGetNextAfterSeekingOnRank_2() {
658 final long INITIAL_RANK
= 1L;
659 final int NB_READS
= 20;
661 // On lower bound, returns the first event (rank = 0)
662 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
664 validateContextRanks(context
);
668 for (int i
= 0; i
< NB_READS
; i
++) {
669 event
= fExperiment
.getNext(context
);
670 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
671 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
674 // Make sure we stay positioned
675 event
= fExperiment
.parseEvent(context
);
676 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
677 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
679 validateContextRanks(context
);
682 public void testGetNextAfterSeekingOnRank_3() {
684 final long INITIAL_RANK
= 500L;
685 final int NB_READS
= 20;
687 // On lower bound, returns the first event (rank = 0)
688 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_RANK
);
690 validateContextRanks(context
);
694 for (int i
= 0; i
< NB_READS
; i
++) {
695 event
= fExperiment
.getNext(context
);
696 assertEquals("Event timestamp", INITIAL_RANK
+ i
+ 1, event
.getTimestamp().getValue());
697 assertEquals("Event rank", INITIAL_RANK
+ i
+ 1, context
.getRank());
700 // Make sure we stay positioned
701 event
= fExperiment
.parseEvent(context
);
702 assertEquals("Event timestamp", INITIAL_RANK
+ NB_READS
+ 1, event
.getTimestamp().getValue());
703 assertEquals("Event rank", INITIAL_RANK
+ NB_READS
, context
.getRank());
705 validateContextRanks(context
);
708 public void testGetNextAfterSeekingOnLocation_1() {
710 final ITmfLocation INITIAL_LOC
= null;
711 final long INITIAL_TS
= 1;
712 final int NB_READS
= 20;
714 // On lower bound, returns the first event (ts = 1)
715 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
717 validateContextRanks(context
);
721 for (int i
= 0; i
< NB_READS
; i
++) {
722 event
= fExperiment
.getNext(context
);
723 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
724 assertEquals("Event rank", INITIAL_TS
+ i
, context
.getRank());
727 // Make sure we stay positioned
728 event
= fExperiment
.parseEvent(context
);
729 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
730 assertEquals("Event rank", INITIAL_TS
+ NB_READS
- 1, context
.getRank());
732 validateContextRanks(context
);
735 public void testGetNextAfterSeekingOnLocation_2() {
737 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(1L).getLocation();
738 final long INITIAL_TS
= 2;
739 final int NB_READS
= 20;
741 // On lower bound, returns the first event (ts = 2)
742 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
744 validateContextRanks(context
);
748 for (int i
= 0; i
< NB_READS
; i
++) {
749 event
= fExperiment
.getNext(context
);
750 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
753 // Make sure we stay positioned
754 event
= fExperiment
.parseEvent(context
);
755 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
757 validateContextRanks(context
);
760 public void testGetNextAfterSeekingOnLocation_3() {
762 final ITmfLocation INITIAL_LOC
= fExperiment
.seekEvent(500L).getLocation();
763 final long INITIAL_TS
= 501;
764 final int NB_READS
= 20;
766 // On lower bound, returns the first event (ts = 501)
767 final ITmfContext context
= fExperiment
.seekEvent(INITIAL_LOC
);
769 validateContextRanks(context
);
773 for (int i
= 0; i
< NB_READS
; i
++) {
774 event
= fExperiment
.getNext(context
);
775 assertEquals("Event timestamp", INITIAL_TS
+ i
, event
.getTimestamp().getValue());
778 // Make sure we stay positioned
779 event
= fExperiment
.parseEvent(context
);
780 assertEquals("Event timestamp", INITIAL_TS
+ NB_READS
, event
.getTimestamp().getValue());
782 validateContextRanks(context
);
785 public void testGetNextLocation() {
786 ITmfContext context1
= fExperiment
.seekEvent(0);
787 fExperiment
.getNext(context1
);
788 ITmfLocation location
= context1
.getLocation();
789 ITmfEvent event1
= fExperiment
.getNext(context1
);
790 ITmfContext context2
= fExperiment
.seekEvent(location
);
791 ITmfEvent event2
= fExperiment
.getNext(context2
);
792 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
795 public void testGetNextEndLocation() {
796 ITmfContext context1
= fExperiment
.seekEvent(fExperiment
.getNbEvents() - 1);
797 fExperiment
.getNext(context1
);
798 ITmfLocation location
= context1
.getLocation();
799 ITmfContext context2
= fExperiment
.seekEvent(location
);
800 ITmfEvent event
= fExperiment
.getNext(context2
);
801 assertNull("Event", event
);
804 // ------------------------------------------------------------------------
806 // ------------------------------------------------------------------------
808 public void testProcessRequestForNbEvents() throws InterruptedException
{
810 final int blockSize
= 100;
811 final int nbEvents
= 1000;
812 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
814 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
815 final TmfEventRequest request
= new TmfEventRequest(TmfEvent
.class, range
, nbEvents
, blockSize
) {
817 public void handleData(final ITmfEvent event
) {
818 super.handleData(event
);
819 requestedEvents
.add(event
);
822 fExperiment
.sendRequest(request
);
823 request
.waitForCompletion();
825 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
826 assertTrue("isCompleted", request
.isCompleted());
827 assertFalse("isCancelled", request
.isCancelled());
829 // Ensure that we have distinct events.
830 // Don't go overboard: we are not validating the stub!
831 for (int i
= 0; i
< nbEvents
; i
++) {
832 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
836 public void testProcessRequestForNbEvents2() throws InterruptedException
{
838 final int blockSize
= 2 * NB_EVENTS
;
839 final int nbEvents
= 1000;
840 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
842 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
843 final TmfEventRequest request
= new TmfEventRequest(TmfEvent
.class, range
, nbEvents
, blockSize
) {
845 public void handleData(final ITmfEvent event
) {
846 super.handleData(event
);
847 requestedEvents
.add(event
);
850 fExperiment
.sendRequest(request
);
851 request
.waitForCompletion();
853 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
854 assertTrue("isCompleted", request
.isCompleted());
855 assertFalse("isCancelled", request
.isCancelled());
857 // Ensure that we have distinct events.
858 // Don't go overboard: we are not validating the stub!
859 for (int i
= 0; i
< nbEvents
; i
++) {
860 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
864 public void testProcessRequestForAllEvents() throws InterruptedException
{
866 final int nbEvents
= TmfDataRequest
.ALL_DATA
;
867 final int blockSize
= 1;
868 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
869 final long nbExpectedEvents
= NB_EVENTS
;
871 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
872 final TmfEventRequest request
= new TmfEventRequest(TmfEvent
.class, range
, nbEvents
, blockSize
) {
874 public void handleData(final ITmfEvent event
) {
875 super.handleData(event
);
876 requestedEvents
.add(event
);
879 fExperiment
.sendRequest(request
);
880 request
.waitForCompletion();
882 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
883 assertTrue("isCompleted", request
.isCompleted());
884 assertFalse("isCancelled", request
.isCancelled());
886 // Ensure that we have distinct events.
887 // Don't go overboard: we are not validating the stub!
888 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
889 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
893 // ------------------------------------------------------------------------
895 // ------------------------------------------------------------------------
897 public void testCancel() throws InterruptedException
{
899 final int nbEvents
= NB_EVENTS
;
900 final int blockSize
= BLOCK_SIZE
;
901 final Vector
<ITmfEvent
> requestedEvents
= new Vector
<ITmfEvent
>();
903 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
904 final TmfEventRequest request
= new TmfEventRequest(TmfEvent
.class, range
, nbEvents
, blockSize
) {
907 public void handleData(final ITmfEvent event
) {
908 super.handleData(event
);
909 requestedEvents
.add(event
);
910 if (++nbRead
== blockSize
) {
915 public void handleCancel() {
916 if (requestedEvents
.size() < blockSize
) {
917 System
.out
.println("aie");
921 fExperiment
.sendRequest(request
);
922 request
.waitForCompletion();
924 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
925 assertTrue("isCompleted", request
.isCompleted());
926 assertTrue("isCancelled", request
.isCancelled());