1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.experiment
;
16 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
19 import java
.util
.Vector
;
21 import junit
.framework
.TestCase
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
27 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
29 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperimentContext
;
30 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
31 import org
.eclipse
.linuxtools
.tmf
.tests
.TmfCoreTestPlugin
;
32 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
35 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
36 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
39 * <b><u>TmfExperimentTest</u></b>
41 * TODO: Implement me. Please.
43 public class TmfMultiTraceExperimentTest
extends TestCase
{
45 private static final String DIRECTORY
= "testfiles";
46 private static final String TEST_STREAM1
= "O-Test-10K";
47 private static final String TEST_STREAM2
= "E-Test-10K";
48 private static final String EXPERIMENT
= "MyExperiment";
49 private static int NB_EVENTS
= 20000;
50 private static int BLOCK_SIZE
= 1000;
52 private static ITmfTrace
[] fTraces
;
53 private static TmfExperiment
<TmfEvent
> fExperiment
;
55 private static byte SCALE
= (byte) -3;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 private synchronized static ITmfTrace
[] setupTrace(String path1
, String path2
) {
62 if (fTraces
== null) {
63 fTraces
= new ITmfTrace
[2];
65 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path1
), null);
66 File test
= new File(FileLocator
.toFileURL(location
).toURI());
67 TmfTraceStub trace1
= new TmfTraceStub(test
.getPath(), true);
69 location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path2
), null);
70 test
= new File(FileLocator
.toFileURL(location
).toURI());
71 TmfTraceStub trace2
= new TmfTraceStub(test
.getPath(), true);
73 } catch (URISyntaxException e
) {
75 } catch (IOException e
) {
82 private synchronized static void setupExperiment() {
83 synchronized (TmfMultiTraceExperimentTest
.class) {
84 if (fExperiment
== null) {
85 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, fTraces
, TmfTimestamp
.Zero
, BLOCK_SIZE
, true);
90 public TmfMultiTraceExperimentTest(String name
) throws Exception
{
95 protected void setUp() throws Exception
{
97 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM1
, DIRECTORY
+ File
.separator
+ TEST_STREAM2
);
102 protected void tearDown() throws Exception
{
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
110 public void testBasicTmfExperimentConstructor() {
112 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
113 assertEquals("GetEpoch", TmfTimestamp
.Zero
, fExperiment
.getEpoch());
114 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
116 TmfTimeRange timeRange
= fExperiment
.getTimeRange();
117 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
118 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
121 // ------------------------------------------------------------------------
122 // Verify checkpoints
123 // ------------------------------------------------------------------------
125 public void testValidateCheckpoints() throws Exception
{
127 Vector
<TmfCheckpoint
> checkpoints
= fExperiment
.getCheckpoints();
128 int pageSize
= fExperiment
.getCacheSize();
129 assertTrue("Checkpoints exist", checkpoints
!= null);
131 // Validate that each checkpoint points to the right event
132 for (int i
= 0; i
< checkpoints
.size(); i
++) {
133 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
134 TmfExperimentContext context
= fExperiment
.seekLocation(checkpoint
.getLocation());
135 TmfEvent event
= fExperiment
.parseEvent(context
);
136 assertEquals("Event rank", context
.getRank(), i
* pageSize
);
137 assertTrue("Timestamp", (checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
141 // ------------------------------------------------------------------------
143 // ------------------------------------------------------------------------
145 public void testSeekLocationOnCacheBoundary() throws Exception
{
147 // Position trace at event rank 0
148 TmfContext context
= fExperiment
.seekLocation(null);
149 assertEquals("Event rank", 0, context
.getRank());
151 TmfEvent event
= fExperiment
.parseEvent(context
);
152 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
153 assertEquals("Event rank", 0, context
.getRank());
155 event
= fExperiment
.getNextEvent(context
);
156 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
157 assertEquals("Event rank", 1, context
.getRank());
159 event
= fExperiment
.getNextEvent(context
);
160 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
161 assertEquals("Event rank", 2, context
.getRank());
163 // Position trace at event rank 1000
164 TmfContext tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
165 context
= fExperiment
.seekLocation(tmpContext
.getLocation());
166 assertEquals("Event rank", 1000, context
.getRank());
168 event
= fExperiment
.parseEvent(context
);
169 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
170 assertEquals("Event rank", 1000, context
.getRank());
172 event
= fExperiment
.getNextEvent(context
);
173 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
174 assertEquals("Event rank", 1001, context
.getRank());
176 event
= fExperiment
.getNextEvent(context
);
177 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
178 assertEquals("Event rank", 1002, context
.getRank());
180 // Position trace at event rank 4000
181 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
182 context
= fExperiment
.seekLocation(tmpContext
.getLocation());
183 assertEquals("Event rank", 4000, context
.getRank());
185 event
= fExperiment
.parseEvent(context
);
186 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
187 assertEquals("Event rank", 4000, context
.getRank());
189 event
= fExperiment
.getNextEvent(context
);
190 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
191 assertEquals("Event rank", 4001, context
.getRank());
193 event
= fExperiment
.getNextEvent(context
);
194 assertEquals("Event timestamp", 4002, event
.getTimestamp().getValue());
195 assertEquals("Event rank", 4002, context
.getRank());
198 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
200 // Position trace at event rank 9
201 TmfContext tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
202 TmfContext context
= fExperiment
.seekLocation(tmpContext
.getLocation());
203 assertEquals("Event rank", 9, context
.getRank());
205 TmfEvent event
= fExperiment
.parseEvent(context
);
206 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
207 assertEquals("Event rank", 9, context
.getRank());
209 event
= fExperiment
.getNextEvent(context
);
210 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
211 assertEquals("Event rank", 10, context
.getRank());
213 // Position trace at event rank 999
214 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
215 context
= fExperiment
.seekLocation(tmpContext
.getLocation());
216 assertEquals("Event rank", 999, context
.getRank());
218 event
= fExperiment
.parseEvent(context
);
219 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
220 assertEquals("Event rank", 999, context
.getRank());
222 event
= fExperiment
.getNextEvent(context
);
223 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
224 assertEquals("Event rank", 1000, context
.getRank());
226 // Position trace at event rank 1001
227 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
228 context
= fExperiment
.seekLocation(tmpContext
.getLocation());
229 assertEquals("Event rank", 1001, context
.getRank());
231 event
= fExperiment
.parseEvent(context
);
232 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
233 assertEquals("Event rank", 1001, context
.getRank());
235 event
= fExperiment
.getNextEvent(context
);
236 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
237 assertEquals("Event rank", 1002, context
.getRank());
239 // Position trace at event rank 4500
240 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
241 context
= fExperiment
.seekLocation(tmpContext
.getLocation());
242 assertEquals("Event rank", 4500, context
.getRank());
244 event
= fExperiment
.parseEvent(context
);
245 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
246 assertEquals("Event rank", 4500, context
.getRank());
248 event
= fExperiment
.getNextEvent(context
);
249 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
250 assertEquals("Event rank", 4501, context
.getRank());
253 public void testSeekLocationOutOfScope() throws Exception
{
255 // Position trace at beginning
256 TmfContext tmpContext
= fExperiment
.seekLocation(null);
257 TmfContext context
= fExperiment
.seekLocation(tmpContext
.getLocation());
258 assertEquals("Event rank", 0, context
.getRank());
260 TmfEvent event
= fExperiment
.parseEvent(context
);
261 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
262 assertEquals("Event rank", 0, context
.getRank());
264 event
= fExperiment
.getNextEvent(context
);
265 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
266 assertEquals("Event rank", 1, context
.getRank());
268 // Position trace at event passed the end
269 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
270 assertEquals("Event location", null, tmpContext
.getLocation());
271 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, tmpContext
.getRank());
274 // ------------------------------------------------------------------------
275 // seekEvent on timestamp
276 // ------------------------------------------------------------------------
278 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
280 // Position trace at event rank 0
281 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
282 assertEquals("Event rank", 0, context
.getRank());
284 TmfEvent event
= fExperiment
.parseEvent(context
);
285 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
286 assertEquals("Event rank", 0, context
.getRank());
288 event
= fExperiment
.getNextEvent(context
);
289 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
290 assertEquals("Event rank", 1, context
.getRank());
292 // Position trace at event rank 1000
293 context
= fExperiment
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
294 assertEquals("Event rank", 1000, context
.getRank());
296 event
= fExperiment
.parseEvent(context
);
297 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
298 assertEquals("Event rank", 1000, context
.getRank());
300 event
= fExperiment
.getNextEvent(context
);
301 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
302 assertEquals("Event rank", 1001, context
.getRank());
304 // Position trace at event rank 4000
305 context
= fExperiment
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
306 assertEquals("Event rank", 4000, context
.getRank());
308 event
= fExperiment
.parseEvent(context
);
309 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
310 assertEquals("Event rank", 4000, context
.getRank());
312 event
= fExperiment
.getNextEvent(context
);
313 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
314 assertEquals("Event rank", 4001, context
.getRank());
317 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
319 // Position trace at event rank 1
320 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
321 assertEquals("Event rank", 1, context
.getRank());
323 TmfEvent event
= fExperiment
.parseEvent(context
);
324 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
325 assertEquals("Event rank", 1, context
.getRank());
327 event
= fExperiment
.getNextEvent(context
);
328 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
329 assertEquals("Event rank", 2, context
.getRank());
331 // Position trace at event rank 9
332 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
333 assertEquals("Event rank", 9, context
.getRank());
335 event
= fExperiment
.parseEvent(context
);
336 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
337 assertEquals("Event rank", 9, context
.getRank());
339 event
= fExperiment
.getNextEvent(context
);
340 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
341 assertEquals("Event rank", 10, context
.getRank());
343 // Position trace at event rank 999
344 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
345 assertEquals("Event rank", 999, context
.getRank());
347 event
= fExperiment
.parseEvent(context
);
348 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
349 assertEquals("Event rank", 999, context
.getRank());
351 event
= fExperiment
.getNextEvent(context
);
352 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
353 assertEquals("Event rank", 1000, context
.getRank());
355 // Position trace at event rank 1001
356 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
357 assertEquals("Event rank", 1001, context
.getRank());
359 event
= fExperiment
.parseEvent(context
);
360 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
361 assertEquals("Event rank", 1001, context
.getRank());
363 event
= fExperiment
.getNextEvent(context
);
364 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
365 assertEquals("Event rank", 1002, context
.getRank());
367 // Position trace at event rank 4500
368 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
369 assertEquals("Event rank", 4500, context
.getRank());
371 event
= fExperiment
.parseEvent(context
);
372 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
373 assertEquals("Event rank", 4500, context
.getRank());
375 event
= fExperiment
.getNextEvent(context
);
376 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
377 assertEquals("Event rank", 4501, context
.getRank());
380 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
382 // Position trace at beginning
383 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
384 assertEquals("Event rank", 0, context
.getRank());
386 TmfEvent event
= fExperiment
.parseEvent(context
);
387 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
388 assertEquals("Event rank", 0, context
.getRank());
390 event
= fExperiment
.getNextEvent(context
);
391 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
392 assertEquals("Event rank", 1, context
.getRank());
394 // Position trace at event passed the end
395 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
396 assertEquals("Event location", null, context
.getLocation());
397 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
400 // ------------------------------------------------------------------------
402 // ------------------------------------------------------------------------
404 public void testSeekOnRankOnCacheBoundary() throws Exception
{
406 // On lower bound, returns the first event (ts = 1)
407 TmfContext context
= fExperiment
.seekEvent(0);
408 assertEquals("Event rank", 0, context
.getRank());
410 TmfEvent event
= fExperiment
.parseEvent(context
);
411 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
412 assertEquals("Event rank", 0, context
.getRank());
414 event
= fExperiment
.getNextEvent(context
);
415 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
416 assertEquals("Event rank", 1, context
.getRank());
418 // Position trace at event rank 1000
419 context
= fExperiment
.seekEvent(1000);
420 assertEquals("Event rank", 1000, context
.getRank());
422 event
= fExperiment
.parseEvent(context
);
423 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
424 assertEquals("Event rank", 1000, context
.getRank());
426 event
= fExperiment
.getNextEvent(context
);
427 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
428 assertEquals("Event rank", 1001, context
.getRank());
430 // Position trace at event rank 4000
431 context
= fExperiment
.seekEvent(4000);
432 assertEquals("Event rank", 4000, context
.getRank());
434 event
= fExperiment
.parseEvent(context
);
435 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
436 assertEquals("Event rank", 4000, context
.getRank());
438 event
= fExperiment
.getNextEvent(context
);
439 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
440 assertEquals("Event rank", 4001, context
.getRank());
443 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
445 // Position trace at event rank 9
446 TmfContext context
= fExperiment
.seekEvent(9);
447 assertEquals("Event rank", 9, context
.getRank());
449 TmfEvent event
= fExperiment
.parseEvent(context
);
450 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
451 assertEquals("Event rank", 9, context
.getRank());
453 event
= fExperiment
.getNextEvent(context
);
454 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
455 assertEquals("Event rank", 10, context
.getRank());
457 // Position trace at event rank 999
458 context
= fExperiment
.seekEvent(999);
459 assertEquals("Event rank", 999, context
.getRank());
461 event
= fExperiment
.parseEvent(context
);
462 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
463 assertEquals("Event rank", 999, context
.getRank());
465 event
= fExperiment
.getNextEvent(context
);
466 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
467 assertEquals("Event rank", 1000, context
.getRank());
469 // Position trace at event rank 1001
470 context
= fExperiment
.seekEvent(1001);
471 assertEquals("Event rank", 1001, context
.getRank());
473 event
= fExperiment
.parseEvent(context
);
474 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
475 assertEquals("Event rank", 1001, context
.getRank());
477 event
= fExperiment
.getNextEvent(context
);
478 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
479 assertEquals("Event rank", 1002, context
.getRank());
481 // Position trace at event rank 4500
482 context
= fExperiment
.seekEvent(4500);
483 assertEquals("Event rank", 4500, context
.getRank());
485 event
= fExperiment
.parseEvent(context
);
486 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
487 assertEquals("Event rank", 4500, context
.getRank());
489 event
= fExperiment
.getNextEvent(context
);
490 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
491 assertEquals("Event rank", 4501, context
.getRank());
494 public void testSeekEventOnRankOutOfScope() throws Exception
{
496 // Position trace at beginning
497 TmfContext context
= fExperiment
.seekEvent(-1);
498 assertEquals("Event rank", 0, context
.getRank());
500 TmfEvent event
= fExperiment
.parseEvent(context
);
501 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
502 assertEquals("Event rank", 0, context
.getRank());
504 event
= fExperiment
.getNextEvent(context
);
505 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
506 assertEquals("Event rank", 1, context
.getRank());
508 // Position trace at event passed the end
509 context
= fExperiment
.seekEvent(NB_EVENTS
);
510 assertEquals("Event location", null, context
.getLocation());
511 assertEquals("Event rank", ITmfContext
.UNKNOWN_RANK
, context
.getRank());
514 // ------------------------------------------------------------------------
515 // parseEvent - make sure parseEvent doesn't update the context
516 // Note: This test is essentially the same as the one from TmfTraceTest
517 // ------------------------------------------------------------------------
519 public void testParseEvent() throws Exception
{
523 // On lower bound, returns the first event (ts = 1)
524 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
527 TmfEvent event
= null;;
528 for (int i
= 0; i
< NB_READS
; i
++) {
529 event
= fExperiment
.getNextEvent(context
);
530 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());
531 assertEquals("Event rank", i
+ 1, context
.getRank());
534 // Make sure we stay positioned
535 event
= fExperiment
.parseEvent(context
);
536 assertEquals("Event timestamp", NB_READS
+ 1, event
.getTimestamp().getValue());
537 assertEquals("Event rank", NB_READS
, context
.getRank());
540 // ------------------------------------------------------------------------
541 // getNextEvent - updates the context
542 // ------------------------------------------------------------------------
544 public void testGetNextEvent() throws Exception
{
546 // On lower bound, returns the first event (ts = 0)
547 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
548 TmfEvent event
= fExperiment
.getNextEvent(context
);
549 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
551 for (int i
= 2; i
< 20; i
++) {
552 event
= fExperiment
.getNextEvent(context
);
553 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
557 // ------------------------------------------------------------------------
559 // ------------------------------------------------------------------------
561 public void testProcessRequestForNbEvents() throws Exception
{
563 final int blockSize
= 100;
564 final int nbEvents
= 1000;
565 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
567 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
568 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
570 public void handleData() {
571 TmfEvent
[] events
= getData();
572 for (TmfEvent e
: events
) {
573 requestedEvents
.add(e
);
577 fExperiment
.sendRequest(request
);
578 request
.waitForCompletion();
580 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
581 assertTrue("isCompleted", request
.isCompleted());
582 assertFalse("isCancelled", request
.isCancelled());
584 // Ensure that we have distinct events.
585 // Don't go overboard: we are not validating the stub!
586 for (int i
= 0; i
< nbEvents
; i
++) {
587 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
591 public void testProcessRequestForNbEvents2() throws Exception
{
593 final int blockSize
= 2 * NB_EVENTS
;
594 final int nbEvents
= 1000;
595 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
597 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
598 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
600 public void handleData() {
601 TmfEvent
[] events
= getData();
602 for (TmfEvent e
: events
) {
603 requestedEvents
.add(e
);
607 fExperiment
.sendRequest(request
);
608 request
.waitForCompletion();
610 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
611 assertTrue("isCompleted", request
.isCompleted());
612 assertFalse("isCancelled", request
.isCancelled());
614 // Ensure that we have distinct events.
615 // Don't go overboard: we are not validating the stub!
616 for (int i
= 0; i
< nbEvents
; i
++) {
617 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
621 public void testProcessRequestForAllEvents() throws Exception
{
623 final int nbEvents
= TmfEventRequest
.ALL_DATA
;
624 final int blockSize
= 1;
625 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
626 long nbExpectedEvents
= NB_EVENTS
;
628 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
629 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
631 public void handleData() {
632 TmfEvent
[] events
= getData();
633 for (TmfEvent e
: events
) {
634 requestedEvents
.add(e
);
638 fExperiment
.sendRequest(request
);
639 request
.waitForCompletion();
641 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
642 assertTrue("isCompleted", request
.isCompleted());
643 assertFalse("isCancelled", request
.isCancelled());
645 // Ensure that we have distinct events.
646 // Don't go overboard: we are not validating the stub!
647 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
648 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
652 // ------------------------------------------------------------------------
654 // ------------------------------------------------------------------------
656 public void testCancel() throws Exception
{
658 final int nbEvents
= NB_EVENTS
;
659 final int blockSize
= BLOCK_SIZE
;
660 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
662 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
663 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
665 public void handleData() {
666 TmfEvent
[] events
= getData();
667 for (TmfEvent e
: events
) {
668 requestedEvents
.add(e
);
670 // Cancel request after the first chunk is received
674 public void handleCancel() {
675 if (requestedEvents
.size() < blockSize
) {
676 System
.out
.println("aie");
680 fExperiment
.sendRequest(request
);
681 request
.waitForCompletion();
683 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
684 assertTrue("isCompleted", request
.isCompleted());
685 assertTrue("isCancelled", request
.isCancelled());
688 // ------------------------------------------------------------------------
690 // ------------------------------------------------------------------------
692 public void testGetRank() throws Exception
{
694 assertEquals("getRank", 0, fExperiment
.getRank(new TmfTimestamp()));
695 assertEquals("getRank", 0, fExperiment
.getRank(new TmfTimestamp( 1, (byte) -3)));
696 assertEquals("getRank", 10, fExperiment
.getRank(new TmfTimestamp( 11, (byte) -3)));
697 assertEquals("getRank", 100, fExperiment
.getRank(new TmfTimestamp( 101, (byte) -3)));
698 assertEquals("getRank", 1000, fExperiment
.getRank(new TmfTimestamp(1001, (byte) -3)));
699 assertEquals("getRank", 2000, fExperiment
.getRank(new TmfTimestamp(2001, (byte) -3)));
700 assertEquals("getRank", 2500, fExperiment
.getRank(new TmfTimestamp(2501, (byte) -3)));
703 // ------------------------------------------------------------------------
705 // ------------------------------------------------------------------------
707 public void testGetTimestamp() throws Exception
{
709 assertTrue("getTimestamp", fExperiment
.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
710 assertTrue("getTimestamp", fExperiment
.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
711 assertTrue("getTimestamp", fExperiment
.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
712 assertTrue("getTimestamp", fExperiment
.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3)));
713 assertTrue("getTimestamp", fExperiment
.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3)));
714 assertTrue("getTimestamp", fExperiment
.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3)));