b2b4a595acbac717efe74cc543370d77b7dc38ed
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
.TmfExperimentLocation
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
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
.core
.trace
.TmfExperiment
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
40 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
41 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
44 * Test suite for the TmfExperiment class (single trace).
46 @SuppressWarnings({ "nls" })
47 public class TmfExperimentTest
extends TestCase
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 private static final String DIRECTORY
= "testfiles";
54 private static final String TEST_STREAM
= "A-Test-10K";
55 private static final String EXPERIMENT
= "MyExperiment";
56 private static int NB_EVENTS
= 10000;
57 private static int BLOCK_SIZE
= 1000;
59 private ITmfTrace
<TmfEvent
>[] fTestTraces
;
60 private TmfExperimentStub
<ITmfEvent
> fExperiment
;
62 private static byte SCALE
= (byte) -3;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 @SuppressWarnings("unchecked")
69 private synchronized ITmfTrace
<?
>[] setupTrace(final String path
) {
70 if (fTestTraces
== null) {
71 fTestTraces
= new ITmfTrace
[1];
73 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
74 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
75 final TmfTraceStub trace
= new TmfTraceStub(test
.getPath(), 0, true);
76 fTestTraces
[0] = trace
;
77 } catch (final TmfTraceException e
) {
79 } catch (final URISyntaxException e
) {
81 } catch (final IOException e
) {
88 private synchronized void setupExperiment() {
89 if (fExperiment
== null) {
90 fExperiment
= new TmfExperimentStub
<ITmfEvent
>(EXPERIMENT
, fTestTraces
, BLOCK_SIZE
);
91 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
95 public TmfExperimentTest(final String name
) throws Exception
{
100 protected void setUp() throws Exception
{
102 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
107 protected void tearDown() throws Exception
{
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
115 public void testSimpleTmfExperimentConstructor() {
117 TmfExperiment
<TmfEvent
> experiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, fTestTraces
);
118 assertEquals("GetId", EXPERIMENT
, experiment
.getName());
119 assertEquals("GetCacheSize", TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, experiment
.getCacheSize());
120 experiment
.dispose();
122 experiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, null);
123 experiment
.dispose();
126 public void testNormalTmfExperimentConstructor() {
128 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
129 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
131 final long nbExperimentEvents
= fExperiment
.getNbEvents();
132 assertEquals("GetNbEvents", NB_EVENTS
, nbExperimentEvents
);
134 final long nbTraceEvents
= fExperiment
.getTraces()[0].getNbEvents();
135 assertEquals("GetNbEvents", NB_EVENTS
, nbTraceEvents
);
137 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
138 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
139 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
142 @SuppressWarnings("static-access")
143 public void testSetCurrentExperiment() {
145 TmfExperiment
<TmfEvent
> experiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, fTestTraces
);
146 experiment
.setCurrentExperiment(experiment
);
147 assertEquals("getCurrentExperiment", experiment
, experiment
.getCurrentExperiment());
149 TmfExperiment
<TmfEvent
> experiment2
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, null);
150 experiment
.setCurrentExperiment(experiment2
);
151 assertEquals("getCurrentExperiment", experiment2
, experiment
.getCurrentExperiment());
153 experiment
.dispose();
154 experiment2
.dispose();
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
161 public void testGetTimestamp() throws Exception
{
162 assertTrue("getTimestamp", fExperiment
.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
163 assertTrue("getTimestamp", fExperiment
.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
164 assertTrue("getTimestamp", fExperiment
.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
165 assertTrue("getTimestamp", fExperiment
.getTimestamp( 1000).equals(new TmfTimestamp(1001, (byte) -3)));
166 assertTrue("getTimestamp", fExperiment
.getTimestamp( 2000).equals(new TmfTimestamp(2001, (byte) -3)));
167 assertTrue("getTimestamp", fExperiment
.getTimestamp( 2500).equals(new TmfTimestamp(2501, (byte) -3)));
168 assertNull("getTimestamp", fExperiment
.getTimestamp(10000));
171 // ------------------------------------------------------------------------
172 // Bookmarks file handling
173 // ------------------------------------------------------------------------
175 public void testBookmarks() throws Exception
{
176 assertNull("GetBookmarksFile", fExperiment
.getBookmarksFile());
177 IFile bookmarks
= (IFile
) fTestTraces
[0].getResource();
178 fExperiment
.setBookmarksFile(bookmarks
);
179 assertEquals("GetBookmarksFile", bookmarks
, fExperiment
.getBookmarksFile());
182 // ------------------------------------------------------------------------
183 // seekEvent by location
184 // ------------------------------------------------------------------------
186 public void testSeekBadLocation() throws Exception
{
187 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
<?
>) new TmfLocation
<Long
>(0L));
188 assertNull("seekEvent", context
);
191 public void testSeekNoTrace() throws Exception
{
192 TmfExperiment
<TmfEvent
> experiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, null);
193 ITmfContext context
= experiment
.seekEvent((TmfExperimentLocation
) null);
194 assertNull("seekEvent", context
);
195 experiment
.dispose();
198 // ------------------------------------------------------------------------
199 // seekEvent on ratio
200 // ------------------------------------------------------------------------
202 public void testSeekEventOnRatio() throws Exception
{
205 ITmfContext context
= fExperiment
.seekEvent(0.0);
206 assertEquals("Context rank", 0, context
.getRank());
207 ITmfEvent event
= fExperiment
.parseEvent(context
);
208 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
209 assertEquals("Context rank", 0, context
.getRank());
212 int midTrace
= NB_EVENTS
/ 2;
213 context
= fExperiment
.seekEvent(0.5);
214 assertEquals("Context rank", midTrace
, context
.getRank());
215 event
= fExperiment
.parseEvent(context
);
216 assertEquals("Event timestamp", midTrace
+ 1, event
.getTimestamp().getValue());
217 assertEquals("Context rank", midTrace
, context
.getRank());
220 context
= fExperiment
.seekEvent(1.0);
221 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
222 event
= fExperiment
.parseEvent(context
);
223 assertNull("Event timestamp", event
);
224 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
227 context
= fExperiment
.seekEvent(1.1);
228 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
229 event
= fExperiment
.parseEvent(context
);
230 assertNull("Event timestamp", event
);
231 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
234 context
= fExperiment
.seekEvent(-0.5);
235 assertEquals("Context rank", 0, context
.getRank());
236 event
= fExperiment
.parseEvent(context
);
237 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
238 assertEquals("Context rank", 0, context
.getRank());
241 @SuppressWarnings("rawtypes")
242 public void testGetLocationRatio() throws Exception
{
245 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
) null);
246 double ratio
= fExperiment
.getLocationRatio(context
.getLocation());
247 context
= fExperiment
.seekEvent(ratio
);
248 double ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
249 assertEquals("getLocationRatio", ratio
, ratio2
);
252 context
= fExperiment
.seekEvent(NB_EVENTS
/ 2);
253 ratio
= fExperiment
.getLocationRatio(context
.getLocation());
254 context
= fExperiment
.seekEvent(ratio
);
255 ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
256 assertEquals("getLocationRatio", ratio
, ratio2
);
259 context
= fExperiment
.seekEvent(NB_EVENTS
- 1);
260 ratio
= fExperiment
.getLocationRatio(context
.getLocation());
261 context
= fExperiment
.seekEvent(ratio
);
262 ratio2
= fExperiment
.getLocationRatio(context
.getLocation());
263 assertEquals("getLocationRatio", ratio
, ratio2
);
266 // @SuppressWarnings({ "unchecked", "rawtypes" })
267 // public void testGetCurrentLocation() throws Exception {
268 // ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
269 // ITmfLocation location = fExperiment.getCurrentLocation();
270 // assertEquals("getCurrentLocation", location, context.getLocation());
273 // ------------------------------------------------------------------------
275 // ------------------------------------------------------------------------
277 public void testSeekRankOnCacheBoundary() throws Exception
{
279 long cacheSize
= fExperiment
.getCacheSize();
281 // On lower bound, returns the first event (TS = 1)
282 ITmfContext context
= fExperiment
.seekEvent(0);
283 assertEquals("Context rank", 0, context
.getRank());
285 ITmfEvent event
= fExperiment
.getNext(context
);
286 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
287 assertEquals("Context rank", 1, context
.getRank());
289 // Position trace at event rank [cacheSize]
290 context
= fExperiment
.seekEvent(cacheSize
);
291 assertEquals("Context rank", cacheSize
, context
.getRank());
293 event
= fExperiment
.getNext(context
);
294 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
295 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
297 // Position trace at event rank [4 * cacheSize]
298 context
= fExperiment
.seekEvent(4 * cacheSize
);
299 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
301 event
= fExperiment
.getNext(context
);
302 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
303 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
306 public void testSeekRankNotOnCacheBoundary() throws Exception
{
308 long cacheSize
= fExperiment
.getCacheSize();
310 // Position trace at event rank 9
311 ITmfContext context
= fExperiment
.seekEvent(9);
312 assertEquals("Context rank", 9, context
.getRank());
314 ITmfEvent event
= fExperiment
.getNext(context
);
315 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
316 assertEquals("Context rank", 10, context
.getRank());
318 // Position trace at event rank [cacheSize - 1]
319 context
= fExperiment
.seekEvent(cacheSize
- 1);
320 assertEquals("Context rank", cacheSize
- 1, context
.getRank());
322 event
= fExperiment
.getNext(context
);
323 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
324 assertEquals("Context rank", cacheSize
, context
.getRank());
326 // Position trace at event rank [cacheSize + 1]
327 context
= fExperiment
.seekEvent(cacheSize
+ 1);
328 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
330 event
= fExperiment
.getNext(context
);
331 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
332 assertEquals("Context rank", cacheSize
+ 2, context
.getRank());
334 // Position trace at event rank 4500
335 context
= fExperiment
.seekEvent(4500);
336 assertEquals("Context rank", 4500, context
.getRank());
338 event
= fExperiment
.getNext(context
);
339 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
340 assertEquals("Context rank", 4501, context
.getRank());
343 public void testSeekRankOutOfScope() throws Exception
{
345 // Position trace at beginning
346 ITmfContext context
= fExperiment
.seekEvent(-1);
347 assertEquals("Event rank", 0, context
.getRank());
349 ITmfEvent event
= fExperiment
.getNext(context
);
350 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
351 assertEquals("Context rank", 1, context
.getRank());
353 // Position trace at event passed the end
354 context
= fExperiment
.seekEvent(NB_EVENTS
);
355 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
357 event
= fExperiment
.getNext(context
);
358 assertNull("Event", event
);
359 assertEquals("Context rank", NB_EVENTS
, context
.getRank());
362 // ------------------------------------------------------------------------
363 // seekEvent on timestamp
364 // ------------------------------------------------------------------------
366 public void testSeekTimestampOnCacheBoundary() throws Exception
{
368 long cacheSize
= fExperiment
.getCacheSize();
370 // Position trace at event rank 0
371 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
372 assertEquals("Context rank", 0, context
.getRank());
374 ITmfEvent event
= fExperiment
.getNext(context
);
375 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
376 assertEquals("Context rank", 1, context
.getRank());
378 // Position trace at event rank [cacheSize]
379 context
= fExperiment
.seekEvent(new TmfTimestamp(cacheSize
+ 1, SCALE
, 0));
380 assertEquals("Event rank", cacheSize
, context
.getRank());
382 event
= fExperiment
.getNext(context
);
383 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
384 assertEquals("Context rank", cacheSize
+ 1, context
.getRank());
386 // Position trace at event rank [4 * cacheSize]
387 context
= fExperiment
.seekEvent(new TmfTimestamp(4 * cacheSize
+ 1, SCALE
, 0));
388 assertEquals("Context rank", 4 * cacheSize
, context
.getRank());
390 event
= fExperiment
.getNext(context
);
391 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
392 assertEquals("Context rank", 4 * cacheSize
+ 1, context
.getRank());
395 public void testSeekTimestampNotOnCacheBoundary() throws Exception
{
397 // Position trace at event rank 1 (TS = 2)
398 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
399 assertEquals("Context rank", 1, context
.getRank());
401 ITmfEvent event
= fExperiment
.getNext(context
);
402 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
403 assertEquals("Context rank", 2, context
.getRank());
405 // Position trace at event rank 9 (TS = 10)
406 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
407 assertEquals("Context rank", 9, context
.getRank());
409 event
= fExperiment
.getNext(context
);
410 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
411 assertEquals("Context rank", 10, context
.getRank());
413 // Position trace at event rank 999 (TS = 1000)
414 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
415 assertEquals("Context rank", 999, context
.getRank());
417 event
= fExperiment
.getNext(context
);
418 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
419 assertEquals("Context rank", 1000, context
.getRank());
421 // Position trace at event rank 1001 (TS = 1002)
422 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
423 assertEquals("Context rank", 1001, context
.getRank());
425 event
= fExperiment
.getNext(context
);
426 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
427 assertEquals("Context rank", 1002, context
.getRank());
429 // Position trace at event rank 4500 (TS = 4501)
430 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
431 assertEquals("Context rank", 4500, context
.getRank());
433 event
= fExperiment
.getNext(context
);
434 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
435 assertEquals("Context rank", 4501, context
.getRank());
438 public void testSeekTimestampOutOfScope() throws Exception
{
440 // Position trace at beginning
441 ITmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
442 assertEquals("Event rank", 0, context
.getRank());
444 ITmfEvent event
= fExperiment
.getNext(context
);
445 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
446 assertEquals("Event rank", 1, context
.getRank());
448 // Position trace at event passed the end
449 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
450 event
= fExperiment
.getNext(context
);
451 assertNull("Event location", event
);
452 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
455 // ------------------------------------------------------------------------
456 // seekEvent by location (context rank is undefined)
457 // ------------------------------------------------------------------------
459 public void testSeekLocationOnCacheBoundary() throws Exception
{
461 long cacheSize
= fExperiment
.getCacheSize();
463 // Position trace at event rank 0
464 ITmfContext tmpContext
= fExperiment
.seekEvent(0);
465 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
467 ITmfEvent event
= fExperiment
.getNext(context
);
468 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
470 event
= fExperiment
.getNext(context
);
471 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
473 // Position trace at event rank 'cacheSize'
474 tmpContext
= fExperiment
.seekEvent(cacheSize
);
475 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
477 event
= fExperiment
.getNext(context
);
478 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
480 event
= fExperiment
.getNext(context
);
481 assertEquals("Event timestamp", cacheSize
+ 2, event
.getTimestamp().getValue());
483 // Position trace at event rank 4 * 'cacheSize'
484 tmpContext
= fExperiment
.seekEvent(4 * cacheSize
);
485 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
487 event
= fExperiment
.getNext(context
);
488 assertEquals("Event timestamp", 4 * cacheSize
+ 1, event
.getTimestamp().getValue());
490 event
= fExperiment
.getNext(context
);
491 assertEquals("Event timestamp", 4 * cacheSize
+ 2, event
.getTimestamp().getValue());
494 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
496 long cacheSize
= fExperiment
.getCacheSize();
498 // Position trace at event 'cacheSize' - 1
499 ITmfContext tmpContext
= fExperiment
.seekEvent(cacheSize
- 1);
500 ITmfContext context
= fExperiment
.seekEvent(tmpContext
.getLocation());
502 ITmfEvent event
= fExperiment
.getNext(context
);
503 assertEquals("Event timestamp", cacheSize
, event
.getTimestamp().getValue());
505 event
= fExperiment
.getNext(context
);
506 assertEquals("Event timestamp", cacheSize
+ 1, event
.getTimestamp().getValue());
508 // Position trace at event rank 2 * 'cacheSize' - 1
509 tmpContext
= fExperiment
.seekEvent(2 * cacheSize
- 1);
510 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
511 context
= fExperiment
.seekEvent(2 * cacheSize
- 1);
513 event
= fExperiment
.getNext(context
);
514 assertEquals("Event timestamp", 2 * cacheSize
, event
.getTimestamp().getValue());
516 event
= fExperiment
.getNext(context
);
517 assertEquals("Event timestamp", 2 * cacheSize
+ 1, event
.getTimestamp().getValue());
519 // Position trace at event rank 4500
520 tmpContext
= fExperiment
.seekEvent(4500);
521 context
= fExperiment
.seekEvent(tmpContext
.getLocation());
523 event
= fExperiment
.getNext(context
);
524 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
526 event
= fExperiment
.getNext(context
);
527 assertEquals("Event timestamp", 4502, event
.getTimestamp().getValue());
530 public void testSeekLocationOutOfScope() throws Exception
{
532 // Position trace at beginning
533 ITmfContext context
= fExperiment
.seekEvent((ITmfLocation
<?
>) null);
535 ITmfEvent event
= fExperiment
.getNext(context
);
536 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
539 // ------------------------------------------------------------------------
540 // getNext - updates the context
541 // ------------------------------------------------------------------------
543 public void testGetNext() throws Exception
{
545 // On lower bound, returns the first event (ts = 0)
546 final ITmfContext context
= fExperiment
.seekEvent(0);
547 ITmfEvent event
= fExperiment
.getNext(context
);
548 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
550 for (int i
= 2; i
< 20; i
++) {
551 event
= fExperiment
.getNext(context
);
552 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
556 public void testGetNextLocation() throws Exception
{
558 ITmfContext context1
= fExperiment
.seekEvent(0);
559 fExperiment
.getNext(context1
);
560 ITmfLocation
<?
> location
= context1
.getLocation().clone();
561 ITmfEvent event1
= fExperiment
.getNext(context1
);
562 ITmfContext context2
= fExperiment
.seekEvent(location
);
563 ITmfEvent event2
= fExperiment
.getNext(context2
);
564 assertEquals("Event timestamp", event1
.getTimestamp().getValue(), event2
.getTimestamp().getValue());
567 public void testGetNextEndLocation() throws Exception
{
568 ITmfContext context1
= fExperiment
.seekEvent(fExperiment
.getNbEvents() - 1);
569 fExperiment
.getNext(context1
);
570 ITmfLocation
<?
> location
= context1
.getLocation().clone();
571 ITmfContext context2
= fExperiment
.seekEvent(location
);
572 ITmfEvent event
= fExperiment
.getNext(context2
);
573 assertNull("Event", event
);
576 // ------------------------------------------------------------------------
578 // ------------------------------------------------------------------------
580 public void testProcessRequestForNbEvents() throws Exception
{
582 final int blockSize
= 100;
583 final int nbEvents
= 1000;
584 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
586 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
587 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
589 public void handleData(final TmfEvent event
) {
590 super.handleData(event
);
591 requestedEvents
.add(event
);
594 fExperiment
.sendRequest(request
);
595 request
.waitForCompletion();
597 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
598 assertTrue("isCompleted", request
.isCompleted());
599 assertFalse("isCancelled", request
.isCancelled());
601 // Ensure that we have distinct events.
602 // Don't go overboard: we are not validating the stub!
603 for (int i
= 0; i
< nbEvents
; i
++) {
604 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
608 public void testProcessRequestForNbEvents2() throws Exception
{
610 final int blockSize
= 2 * NB_EVENTS
;
611 final int nbEvents
= 1000;
612 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
614 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
615 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
617 public void handleData(final TmfEvent event
) {
618 super.handleData(event
);
619 requestedEvents
.add(event
);
622 fExperiment
.sendRequest(request
);
623 request
.waitForCompletion();
625 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
626 assertTrue("isCompleted", request
.isCompleted());
627 assertFalse("isCancelled", request
.isCancelled());
629 // Ensure that we have distinct events.
630 // Don't go overboard: we are not validating the stub!
631 for (int i
= 0; i
< nbEvents
; i
++) {
632 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
636 public void testProcessRequestForAllEvents() throws Exception
{
638 final int nbEvents
= TmfEventRequest
.ALL_DATA
;
639 final int blockSize
= 1;
640 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
641 final long nbExpectedEvents
= NB_EVENTS
;
643 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
644 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
646 public void handleData(final TmfEvent event
) {
647 super.handleData(event
);
648 requestedEvents
.add(event
);
651 fExperiment
.sendRequest(request
);
652 request
.waitForCompletion();
654 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
655 assertTrue("isCompleted", request
.isCompleted());
656 assertFalse("isCancelled", request
.isCancelled());
658 // Ensure that we have distinct events.
659 // Don't go overboard: we are not validating the stub!
660 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
661 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
665 // ------------------------------------------------------------------------
667 // ------------------------------------------------------------------------
669 public void testCancel() throws Exception
{
671 final int nbEvents
= NB_EVENTS
;
672 final int blockSize
= BLOCK_SIZE
;
673 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
675 final TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
676 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
679 public void handleData(final TmfEvent event
) {
680 super.handleData(event
);
681 requestedEvents
.add(event
);
682 if (++nbRead
== blockSize
) {
687 public void handleCancel() {
688 if (requestedEvents
.size() < blockSize
) {
689 System
.out
.println("aie");
693 fExperiment
.sendRequest(request
);
694 request
.waitForCompletion();
696 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
697 assertTrue("isCompleted", request
.isCompleted());
698 assertTrue("isCancelled", request
.isCancelled());
This page took 0.046208 seconds and 5 git commands to generate.