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
.ITmfTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
35 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
38 * <b><u>TmfExperimentTest</u></b>
40 * TODO: Implement me. Please.
42 public class TmfExperimentTest
extends TestCase
{
44 private static final String DIRECTORY
= "testfiles";
45 private static final String TEST_STREAM
= "A-Test-10K";
46 private static final String EXPERIMENT
= "MyExperiment";
47 private static int NB_EVENTS
= 10000;
48 private static int fDefaultBlockSize
= 1000;
50 private static ITmfTrace
[] fTraces
;
51 private static TmfExperiment
<TmfEvent
> fExperiment
;
53 private static byte SCALE
= (byte) -3;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 private synchronized static ITmfTrace
[] setupTrace(String path
) {
60 if (fTraces
== null) {
61 fTraces
= new ITmfTrace
[1];
63 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
64 File test
= new File(FileLocator
.toFileURL(location
).toURI());
65 TmfTraceStub trace
= new TmfTraceStub(test
.getPath(), true);
67 } catch (URISyntaxException e
) {
69 } catch (IOException e
) {
76 private synchronized static void setupExperiment() {
77 if (fExperiment
== null) {
78 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, EXPERIMENT
, fTraces
, TmfTimestamp
.Zero
, 1000, true);
82 public TmfExperimentTest(String name
) throws Exception
{
87 protected void setUp() throws Exception
{
89 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
94 protected void tearDown() throws Exception
{
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 public void testBasicTmfExperimentConstructor() {
104 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
105 assertEquals("GetEpoch", TmfTimestamp
.Zero
, fExperiment
.getEpoch());
106 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
108 TmfTimeRange timeRange
= fExperiment
.getTimeRange();
109 assertEquals("getStartTime", 1, timeRange
.getStartTime().getValue());
110 assertEquals("getEndTime", NB_EVENTS
, timeRange
.getEndTime().getValue());
113 // ------------------------------------------------------------------------
114 // Verify checkpoints
115 // Note: seekLocation() does not reliably set the rank
116 // ------------------------------------------------------------------------
118 public void testValidateCheckpoints() throws Exception
{
120 Vector
<TmfCheckpoint
> checkpoints
= fExperiment
.getCheckpoints();
121 // int pageSize = fExperiment.getCacheSize();
122 assertTrue("Checkpoints exist", checkpoints
!= null);
124 // Validate that each checkpoint points to the right event
125 for (int i
= 0; i
< checkpoints
.size(); i
++) {
126 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
127 TmfExperimentContext context
= fExperiment
.seekLocation(checkpoint
.getLocation());
128 TmfEvent event
= fExperiment
.parseEvent(context
);
129 // assertEquals("Event rank", context.getRank(), i * pageSize);
130 assertTrue("Timestamp", (checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
134 // ------------------------------------------------------------------------
135 // parseEvent - make sure parseEvent doesn't update the context
136 // ------------------------------------------------------------------------
138 public void testParseEvent() throws Exception
{
140 // On lower bound, returns the first event (ts = 1)
141 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
143 TmfEvent event
= fExperiment
.parseEvent(context
);
144 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
146 event
= fExperiment
.parseEvent(context
);
147 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
149 event
= fExperiment
.parseEvent(context
);
150 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
152 for (int i
= 1; i
< 20; i
++) {
153 event
= fExperiment
.getNextEvent(context
);
154 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
157 event
= fExperiment
.parseEvent(context
);
158 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
160 event
= fExperiment
.parseEvent(context
);
161 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
164 // ------------------------------------------------------------------------
165 // getNextEvent - updates the context
166 // ------------------------------------------------------------------------
168 public void testGetNextEvent() throws Exception
{
170 // On lower bound, returns the first event (ts = 0)
171 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
172 TmfEvent event
= fExperiment
.getNextEvent(context
);
173 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
175 for (int i
= 2; i
< 20; i
++) {
176 event
= fExperiment
.getNextEvent(context
);
177 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
181 // ------------------------------------------------------------------------
183 // Note: seekLocation() does not reliably set the rank
184 // ------------------------------------------------------------------------
186 public void testSeekLocationOnCacheBoundary() throws Exception
{
188 // Position trace at event rank 0
189 TmfContext context
= fExperiment
.seekLocation(null);
190 // assertEquals("Event rank", 0, context.getRank());
191 TmfEvent event
= fExperiment
.parseEvent(context
);
192 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
193 // assertEquals("Event rank", 0, context.getRank());
194 event
= fExperiment
.getNextEvent(context
);
195 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
196 // assertEquals("Event rank", 1, context.getRank());
198 // Position trace at event rank 1000
199 TmfContext tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
200 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
201 // assertEquals("Event rank", 1000, context.getRank());
202 event
= fExperiment
.parseEvent(context
);
203 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
204 // assertEquals("Event rank", 1000, context.getRank());
205 event
= fExperiment
.getNextEvent(context
);
206 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
207 // assertEquals("Event rank", 1001, context.getRank());
209 // Position trace at event rank 4000
210 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
211 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
212 // assertEquals("Event rank", 4000, context.getRank());
213 event
= fExperiment
.parseEvent(context
);
214 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
215 // assertEquals("Event rank", 4000, context.getRank());
216 event
= fExperiment
.getNextEvent(context
);
217 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
218 // assertEquals("Event rank", 4001, context.getRank());
221 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
223 // Position trace at event rank 9
224 TmfContext tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
225 TmfContext context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
226 // assertEquals("Event rank", 9, context.getRank());
227 TmfEvent event
= fExperiment
.parseEvent(context
);
228 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
229 // assertEquals("Event rank", 9, context.getRank());
230 event
= fExperiment
.getNextEvent(context
);
231 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
232 // assertEquals("Event rank", 10, context.getRank());
234 // Position trace at event rank 999
235 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
236 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
237 // assertEquals("Event rank", 999, context.getRank());
238 event
= fExperiment
.parseEvent(context
);
239 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
240 // assertEquals("Event rank", 999, context.getRank());
241 event
= fExperiment
.getNextEvent(context
);
242 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
243 // assertEquals("Event rank", 1000, context.getRank());
245 // Position trace at event rank 1001
246 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
247 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
248 // assertEquals("Event rank", 1001, context.getRank());
249 event
= fExperiment
.parseEvent(context
);
250 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
251 // assertEquals("Event rank", 1001, context.getRank());
252 event
= fExperiment
.getNextEvent(context
);
253 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
254 // assertEquals("Event rank", 1002, context.getRank());
256 // Position trace at event rank 4500
257 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
258 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
259 // assertEquals("Event rank", 4500, context.getRank());
260 event
= fExperiment
.parseEvent(context
);
261 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
262 // assertEquals("Event rank", 4500, context.getRank());
263 event
= fExperiment
.getNextEvent(context
);
264 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
265 // assertEquals("Event rank", 4501, context.getRank());
268 public void testSeekLocationOutOfScope() throws Exception
{
270 // Position trace at beginning
271 TmfContext tmpContext
= fExperiment
.seekLocation(null);
272 TmfContext context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
273 // assertEquals("Event rank", 0, context.getRank());
274 TmfEvent event
= fExperiment
.parseEvent(context
);
275 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
276 // assertEquals("Event rank", 0, context.getRank());
277 event
= fExperiment
.getNextEvent(context
);
278 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
279 // assertEquals("Event rank", 1, context.getRank());
281 // Position trace at event passed the end
282 tmpContext
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
283 context
= fExperiment
.seekLocation(tmpContext
.getLocation().clone());
284 // assertEquals("Event rank", NB_EVENTS, context.getRank());
285 event
= fExperiment
.parseEvent(context
);
286 assertEquals("Event timestamp", null, event
);
287 // assertEquals("Event rank", NB_EVENTS, context.getRank());
288 event
= fExperiment
.getNextEvent(context
);
289 assertEquals("Event timestamp", null, event
);
290 // assertEquals("Event rank", NB_EVENTS, context.getRank());
293 // ------------------------------------------------------------------------
294 // seekEvent on timestamp
295 // ------------------------------------------------------------------------
297 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
299 // Position trace at event rank 0
300 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
301 assertEquals("Event rank", 0, context
.getRank());
302 TmfEvent event
= fExperiment
.parseEvent(context
);
303 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
304 assertEquals("Event rank", 0, context
.getRank());
305 event
= fExperiment
.getNextEvent(context
);
306 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
307 assertEquals("Event rank", 1, context
.getRank());
309 // Position trace at event rank 1000
310 context
= fExperiment
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
311 assertEquals("Event rank", 1000, context
.getRank());
312 event
= fExperiment
.parseEvent(context
);
313 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
314 assertEquals("Event rank", 1000, context
.getRank());
315 event
= fExperiment
.getNextEvent(context
);
316 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
317 assertEquals("Event rank", 1001, context
.getRank());
319 // Position trace at event rank 4000
320 context
= fExperiment
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
321 assertEquals("Event rank", 4000, context
.getRank());
322 event
= fExperiment
.parseEvent(context
);
323 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
324 assertEquals("Event rank", 4000, context
.getRank());
325 event
= fExperiment
.getNextEvent(context
);
326 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
327 assertEquals("Event rank", 4001, context
.getRank());
330 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
332 // Position trace at event rank 1
333 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
334 assertEquals("Event rank", 1, context
.getRank());
335 TmfEvent event
= fExperiment
.parseEvent(context
);
336 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
337 assertEquals("Event rank", 1, context
.getRank());
338 event
= fExperiment
.getNextEvent(context
);
339 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
340 assertEquals("Event rank", 2, context
.getRank());
342 // Position trace at event rank 9
343 context
= fExperiment
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
344 assertEquals("Event rank", 9, context
.getRank());
345 event
= fExperiment
.parseEvent(context
);
346 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
347 assertEquals("Event rank", 9, context
.getRank());
348 event
= fExperiment
.getNextEvent(context
);
349 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
350 assertEquals("Event rank", 10, context
.getRank());
352 // Position trace at event rank 999
353 context
= fExperiment
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
354 assertEquals("Event rank", 999, context
.getRank());
355 event
= fExperiment
.parseEvent(context
);
356 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
357 assertEquals("Event rank", 999, context
.getRank());
358 event
= fExperiment
.getNextEvent(context
);
359 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
360 assertEquals("Event rank", 1000, context
.getRank());
362 // Position trace at event rank 1001
363 context
= fExperiment
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
364 assertEquals("Event rank", 1001, context
.getRank());
365 event
= fExperiment
.parseEvent(context
);
366 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
367 assertEquals("Event rank", 1001, context
.getRank());
368 event
= fExperiment
.getNextEvent(context
);
369 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
370 assertEquals("Event rank", 1002, context
.getRank());
372 // Position trace at event rank 4500
373 context
= fExperiment
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
374 assertEquals("Event rank", 4500, context
.getRank());
375 event
= fExperiment
.parseEvent(context
);
376 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
377 assertEquals("Event rank", 4500, context
.getRank());
378 event
= fExperiment
.getNextEvent(context
);
379 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
380 assertEquals("Event rank", 4501, context
.getRank());
383 public void testSeekEventOnTimestampoutOfScope() throws Exception
{
385 // Position trace at beginning
386 TmfContext context
= fExperiment
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
387 assertEquals("Event rank", 0, context
.getRank());
388 TmfEvent event
= fExperiment
.parseEvent(context
);
389 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
390 assertEquals("Event rank", 0, context
.getRank());
391 event
= fExperiment
.getNextEvent(context
);
392 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
393 assertEquals("Event rank", 1, context
.getRank());
395 // Position trace at event passed the end
396 context
= fExperiment
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
397 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
398 event
= fExperiment
.parseEvent(context
);
399 assertEquals("Event timestamp", null, event
);
400 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
401 event
= fExperiment
.getNextEvent(context
);
402 assertEquals("Event timestamp", null, event
);
403 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
406 // ------------------------------------------------------------------------
408 // ------------------------------------------------------------------------
410 public void testSeekOnRankOnCacheBoundary() throws Exception
{
412 // On lower bound, returns the first event (ts = 1)
413 TmfContext context
= fExperiment
.seekEvent(0);
414 assertEquals("Event rank", 0, context
.getRank());
415 TmfEvent event
= fExperiment
.parseEvent(context
);
416 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
417 assertEquals("Event rank", 0, context
.getRank());
418 event
= fExperiment
.getNextEvent(context
);
419 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
420 assertEquals("Event rank", 1, context
.getRank());
422 // Position trace at event rank 1000
423 context
= fExperiment
.seekEvent(1000);
424 assertEquals("Event rank", 1000, context
.getRank());
425 event
= fExperiment
.parseEvent(context
);
426 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
427 assertEquals("Event rank", 1000, context
.getRank());
428 event
= fExperiment
.getNextEvent(context
);
429 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
430 assertEquals("Event rank", 1001, context
.getRank());
432 // Position trace at event rank 4000
433 context
= fExperiment
.seekEvent(4000);
434 assertEquals("Event rank", 4000, context
.getRank());
435 event
= fExperiment
.parseEvent(context
);
436 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
437 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());
448 TmfEvent event
= fExperiment
.parseEvent(context
);
449 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
450 assertEquals("Event rank", 9, context
.getRank());
451 event
= fExperiment
.getNextEvent(context
);
452 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
453 assertEquals("Event rank", 10, context
.getRank());
455 // Position trace at event rank 999
456 context
= fExperiment
.seekEvent(999);
457 assertEquals("Event rank", 999, context
.getRank());
458 event
= fExperiment
.parseEvent(context
);
459 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
460 assertEquals("Event rank", 999, context
.getRank());
461 event
= fExperiment
.getNextEvent(context
);
462 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
463 assertEquals("Event rank", 1000, context
.getRank());
465 // Position trace at event rank 1001
466 context
= fExperiment
.seekEvent(1001);
467 assertEquals("Event rank", 1001, context
.getRank());
468 event
= fExperiment
.parseEvent(context
);
469 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
470 assertEquals("Event rank", 1001, context
.getRank());
471 event
= fExperiment
.getNextEvent(context
);
472 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
473 assertEquals("Event rank", 1002, context
.getRank());
475 // Position trace at event rank 4500
476 context
= fExperiment
.seekEvent(4500);
477 assertEquals("Event rank", 4500, context
.getRank());
478 event
= fExperiment
.parseEvent(context
);
479 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
480 assertEquals("Event rank", 4500, context
.getRank());
481 event
= fExperiment
.getNextEvent(context
);
482 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
483 assertEquals("Event rank", 4501, context
.getRank());
486 public void testSeekEventOnRankOfScope() throws Exception
{
488 // Position trace at beginning
489 TmfContext context
= fExperiment
.seekEvent(-1);
490 assertEquals("Event rank", 0, context
.getRank());
491 TmfEvent event
= fExperiment
.parseEvent(context
);
492 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
493 assertEquals("Event rank", 0, context
.getRank());
494 event
= fExperiment
.getNextEvent(context
);
495 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
496 assertEquals("Event rank", 1, context
.getRank());
498 // Position trace at event passed the end
499 context
= fExperiment
.seekEvent(NB_EVENTS
);
500 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
501 event
= fExperiment
.parseEvent(context
);
502 assertEquals("Event timestamp", null, event
);
503 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
504 event
= fExperiment
.getNextEvent(context
);
505 assertEquals("Event timestamp", null, event
);
506 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
509 // ------------------------------------------------------------------------
511 // ------------------------------------------------------------------------
513 public void testProcessRequestForNbEvents() throws Exception
{
515 final int blockSize
= 100;
516 final int nbEvents
= 1000;
517 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
519 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
520 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
522 public void handleData() {
523 TmfEvent
[] events
= getData();
524 for (TmfEvent e
: events
) {
525 requestedEvents
.add(e
);
529 fExperiment
.sendRequest(request
);
530 request
.waitForCompletion();
532 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
533 assertTrue("isCompleted", request
.isCompleted());
534 assertFalse("isCancelled", request
.isCancelled());
536 // Ensure that we have distinct events.
537 // Don't go overboard: we are not validating the stub!
538 for (int i
= 0; i
< nbEvents
; i
++) {
539 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
543 public void testProcessRequestForNbEvents2() throws Exception
{
545 final int blockSize
= 2 * NB_EVENTS
;
546 final int nbEvents
= 1000;
547 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
549 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
550 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
552 public void handleData() {
553 TmfEvent
[] events
= getData();
554 for (TmfEvent e
: events
) {
555 requestedEvents
.add(e
);
559 fExperiment
.sendRequest(request
);
560 request
.waitForCompletion();
562 assertEquals("nbEvents", nbEvents
, requestedEvents
.size());
563 assertTrue("isCompleted", request
.isCompleted());
564 assertFalse("isCancelled", request
.isCancelled());
566 // Ensure that we have distinct events.
567 // Don't go overboard: we are not validating the stub!
568 for (int i
= 0; i
< nbEvents
; i
++) {
569 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
573 public void testProcessRequestForAllEvents() throws Exception
{
575 final int nbEvents
= TmfEventRequest
.ALL_DATA
;
576 final int blockSize
= 1;
577 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
578 long nbExpectedEvents
= NB_EVENTS
;
580 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
581 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
583 public void handleData() {
584 TmfEvent
[] events
= getData();
585 for (TmfEvent e
: events
) {
586 requestedEvents
.add(e
);
590 fExperiment
.sendRequest(request
);
591 request
.waitForCompletion();
593 assertEquals("nbEvents", nbExpectedEvents
, requestedEvents
.size());
594 assertTrue("isCompleted", request
.isCompleted());
595 assertFalse("isCancelled", request
.isCancelled());
597 // Ensure that we have distinct events.
598 // Don't go overboard: we are not validating the stub!
599 for (int i
= 0; i
< nbExpectedEvents
; i
++) {
600 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
604 // ------------------------------------------------------------------------
606 // ------------------------------------------------------------------------
608 public void testCancel() throws Exception
{
610 final int nbEvents
= NB_EVENTS
;
611 final int blockSize
= fDefaultBlockSize
;
612 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
614 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
615 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, nbEvents
, blockSize
) {
617 public void handleData() {
618 TmfEvent
[] events
= getData();
619 for (TmfEvent e
: events
) {
620 requestedEvents
.add(e
);
622 // Cancel request after the first chunk is received
626 public void handleCancel() {
627 if (requestedEvents
.size() < blockSize
) {
628 System
.out
.println("aie");
632 fExperiment
.sendRequest(request
);
633 request
.waitForCompletion();
635 assertEquals("nbEvents", blockSize
, requestedEvents
.size());
636 assertTrue("isCompleted", request
.isCompleted());
637 assertTrue("isCancelled", request
.isCancelled());
640 // ------------------------------------------------------------------------
642 // ------------------------------------------------------------------------
644 public void testGetRank() throws Exception
{
646 assertEquals("getRank", 0, fExperiment
.getRank(new TmfTimestamp()));
647 assertEquals("getRank", 0, fExperiment
.getRank(new TmfTimestamp( 1, (byte) -3)));
648 assertEquals("getRank", 10, fExperiment
.getRank(new TmfTimestamp( 11, (byte) -3)));
649 assertEquals("getRank", 100, fExperiment
.getRank(new TmfTimestamp( 101, (byte) -3)));
650 assertEquals("getRank", 1000, fExperiment
.getRank(new TmfTimestamp(1001, (byte) -3)));
651 assertEquals("getRank", 2000, fExperiment
.getRank(new TmfTimestamp(2001, (byte) -3)));
652 assertEquals("getRank", 2500, fExperiment
.getRank(new TmfTimestamp(2501, (byte) -3)));
655 // ------------------------------------------------------------------------
657 // ------------------------------------------------------------------------
659 public void testGetTimestamp() throws Exception
{
661 assertTrue("getTimestamp", fExperiment
.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
662 assertTrue("getTimestamp", fExperiment
.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
663 assertTrue("getTimestamp", fExperiment
.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
664 assertTrue("getTimestamp", fExperiment
.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3)));
665 assertTrue("getTimestamp", fExperiment
.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3)));
666 assertTrue("getTimestamp", fExperiment
.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3)));