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
.trace
;
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
.component
.ITmfDataProvider
;
26 import org
.eclipse
.linuxtools
.tmf
.component
.TmfProviderManager
;
27 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
31 import org
.eclipse
.linuxtools
.tmf
.tests
.TmfCoreTestPlugin
;
32 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
37 * <b><u>TmfTraceTest</u></b>
39 * TODO: Implement me. Please.
41 public class TmfTraceTest
extends TestCase
{
43 private static final String DIRECTORY
= "testfiles";
44 private static final String TEST_STREAM
= "A-Test-10K";
45 private static final int NB_EVENTS
= 10000;
46 private static TmfTraceStub fTrace
= null;
48 private static byte SCALE
= (byte) -3;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 private TmfTraceStub
setupTrace(String path
) {
57 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getPlugin().getBundle(), new Path(path
), null);
58 File test
= new File(FileLocator
.toFileURL(location
).toURI());
59 TmfTraceStub trace
= new TmfTraceStub(test
.getPath(), 500, true);
61 } catch (URISyntaxException e
) {
63 } catch (IOException e
) {
70 public TmfTraceTest(String name
) throws Exception
{
75 protected void setUp() throws Exception
{
77 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
81 protected void tearDown() throws Exception
{
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
89 public void testTmfTraceDefault() throws Exception
{
90 TmfTraceStub trace
= null;
92 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getPlugin().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
93 File test
= new File(FileLocator
.toFileURL(location
).toURI());
94 trace
= new TmfTraceStub(test
.getPath(), true);
95 } catch (URISyntaxException e
) {
97 } catch (IOException e
) {
100 assertTrue("Open trace", trace
!= null);
101 assertEquals("getCacheSize", TmfTraceStub
.DEFAULT_CACHE_SIZE
, trace
.getCacheSize());
102 assertEquals("getTraceSize", NB_EVENTS
, trace
.getNbEvents());
105 public void testTmfTrace() throws Exception
{
106 assertEquals("getCacheSize", 500, fTrace
.getCacheSize());
107 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
108 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
109 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
112 // ------------------------------------------------------------------------
113 // Verify checkpoints
114 // ------------------------------------------------------------------------
116 public void testValidateCheckpoints() throws Exception
{
118 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
119 int pageSize
= fTrace
.getCacheSize();
120 assertTrue("Checkpoints exist", checkpoints
!= null);
122 // Validate that each checkpoint points to the right event
123 for (int i
= 0; i
< checkpoints
.size(); i
++) {
124 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
125 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
126 TmfEvent event
= fTrace
.parseEvent(context
);
127 assertTrue(context
.getRank() == i
* pageSize
);
128 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
132 // ------------------------------------------------------------------------
133 // parseEvent - make sure parseEvent doesn't update the context
134 // ------------------------------------------------------------------------
136 public void testParseEvent() throws Exception
{
138 // On lower bound, returns the first event (ts = 0)
139 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
141 TmfEvent event
= fTrace
.parseEvent(context
);
142 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
144 event
= fTrace
.parseEvent(context
);
145 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
147 event
= fTrace
.parseEvent(context
);
148 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
150 for (int i
= 1; i
< 20; i
++) {
151 event
= fTrace
.getNextEvent(context
);
152 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
155 event
= fTrace
.parseEvent(context
);
156 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
158 event
= fTrace
.parseEvent(context
);
159 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
162 // ------------------------------------------------------------------------
163 // getNextEvent - updates the context
164 // ------------------------------------------------------------------------
166 public void testGetNextEvent() throws Exception
{
168 // On lower bound, returns the first event (ts = 0)
169 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
170 TmfEvent event
= fTrace
.getNextEvent(context
);
171 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
173 for (int i
= 2; i
< 20; i
++) {
174 event
= fTrace
.getNextEvent(context
);
175 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
179 // ------------------------------------------------------------------------
181 // Note: seekLocation() does not reliably set the rank
182 // ------------------------------------------------------------------------
184 public void testSeekLocationOnCacheBoundary() throws Exception
{
186 // Position trace at event rank 0
187 TmfContext context
= fTrace
.seekLocation(null);
188 // assertEquals("Event rank", 0, context.getRank());
189 TmfEvent event
= fTrace
.parseEvent(context
);
190 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
191 // assertEquals("Event rank", 0, context.getRank());
192 event
= fTrace
.getNextEvent(context
);
193 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
194 // assertEquals("Event rank", 1, context.getRank());
196 // Position trace at event rank 1000
197 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
198 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
199 // assertEquals("Event rank", 1000, context.getRank());
200 event
= fTrace
.parseEvent(context
);
201 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
202 // assertEquals("Event rank", 1000, context.getRank());
203 event
= fTrace
.getNextEvent(context
);
204 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
205 // assertEquals("Event rank", 1001, context.getRank());
207 // Position trace at event rank 4000
208 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
209 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
210 // assertEquals("Event rank", 4000, context.getRank());
211 event
= fTrace
.parseEvent(context
);
212 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
213 // assertEquals("Event rank", 4000, context.getRank());
214 event
= fTrace
.getNextEvent(context
);
215 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
216 // assertEquals("Event rank", 4001, context.getRank());
219 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
221 // Position trace at event rank 9
222 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
223 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
224 // assertEquals("Event rank", 9, context.getRank());
225 TmfEvent event
= fTrace
.parseEvent(context
);
226 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
227 // assertEquals("Event rank", 9, context.getRank());
228 event
= fTrace
.getNextEvent(context
);
229 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
230 // assertEquals("Event rank", 10, context.getRank());
232 // Position trace at event rank 999
233 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
234 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
235 // assertEquals("Event rank", 999, context.getRank());
236 event
= fTrace
.parseEvent(context
);
237 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
238 // assertEquals("Event rank", 999, context.getRank());
239 event
= fTrace
.getNextEvent(context
);
240 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
241 // assertEquals("Event rank", 1000, context.getRank());
243 // Position trace at event rank 1001
244 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
245 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
246 // assertEquals("Event rank", 1001, context.getRank());
247 event
= fTrace
.parseEvent(context
);
248 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
249 // assertEquals("Event rank", 1001, context.getRank());
250 event
= fTrace
.getNextEvent(context
);
251 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
252 // assertEquals("Event rank", 1002, context.getRank());
254 // Position trace at event rank 4500
255 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
256 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
257 // assertEquals("Event rank", 4500, context.getRank());
258 event
= fTrace
.parseEvent(context
);
259 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
260 // assertEquals("Event rank", 4500, context.getRank());
261 event
= fTrace
.getNextEvent(context
);
262 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
263 // assertEquals("Event rank", 4501, context.getRank());
266 public void testSeekLocationOutOfScope() throws Exception
{
268 // Position trace at beginning
269 TmfContext tmpContext
= fTrace
.seekLocation(null);
270 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
271 // assertEquals("Event rank", 0, context.getRank());
272 TmfEvent event
= fTrace
.parseEvent(context
);
273 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
274 // assertEquals("Event rank", 0, context.getRank());
275 event
= fTrace
.getNextEvent(context
);
276 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
277 // assertEquals("Event rank", 1, context.getRank());
279 // Position trace at event passed the end
280 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
281 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
282 // assertEquals("Event rank", NB_EVENTS, context.getRank());
283 event
= fTrace
.parseEvent(context
);
284 assertEquals("Event timestamp", null, event
);
285 // assertEquals("Event rank", NB_EVENTS, context.getRank());
286 event
= fTrace
.getNextEvent(context
);
287 assertEquals("Event timestamp", null, event
);
288 // assertEquals("Event rank", NB_EVENTS, context.getRank());
291 // ------------------------------------------------------------------------
292 // seekEvent on timestamp
293 // ------------------------------------------------------------------------
295 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
297 // Position trace at event rank 0
298 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
299 assertEquals("Event rank", 0, context
.getRank());
300 TmfEvent event
= fTrace
.parseEvent(context
);
301 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
302 assertEquals("Event rank", 0, context
.getRank());
303 event
= fTrace
.getNextEvent(context
);
304 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
305 assertEquals("Event rank", 1, context
.getRank());
307 // Position trace at event rank 1000
308 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
309 assertEquals("Event rank", 1000, context
.getRank());
310 event
= fTrace
.parseEvent(context
);
311 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
312 assertEquals("Event rank", 1000, context
.getRank());
313 event
= fTrace
.getNextEvent(context
);
314 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
315 assertEquals("Event rank", 1001, context
.getRank());
317 // Position trace at event rank 4000
318 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
319 assertEquals("Event rank", 4000, context
.getRank());
320 event
= fTrace
.parseEvent(context
);
321 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
322 assertEquals("Event rank", 4000, context
.getRank());
323 event
= fTrace
.getNextEvent(context
);
324 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
325 assertEquals("Event rank", 4001, context
.getRank());
328 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
330 // Position trace at event rank 1
331 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
332 assertEquals("Event rank", 1, context
.getRank());
333 TmfEvent event
= fTrace
.parseEvent(context
);
334 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
335 assertEquals("Event rank", 1, context
.getRank());
336 event
= fTrace
.getNextEvent(context
);
337 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
338 assertEquals("Event rank", 2, context
.getRank());
340 // Position trace at event rank 9
341 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
342 assertEquals("Event rank", 9, context
.getRank());
343 event
= fTrace
.parseEvent(context
);
344 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
345 assertEquals("Event rank", 9, context
.getRank());
346 event
= fTrace
.getNextEvent(context
);
347 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
348 assertEquals("Event rank", 10, context
.getRank());
350 // Position trace at event rank 999
351 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
352 assertEquals("Event rank", 999, context
.getRank());
353 event
= fTrace
.parseEvent(context
);
354 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
355 assertEquals("Event rank", 999, context
.getRank());
356 event
= fTrace
.getNextEvent(context
);
357 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
358 assertEquals("Event rank", 1000, context
.getRank());
360 // Position trace at event rank 1001
361 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
362 assertEquals("Event rank", 1001, context
.getRank());
363 event
= fTrace
.parseEvent(context
);
364 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
365 assertEquals("Event rank", 1001, context
.getRank());
366 event
= fTrace
.getNextEvent(context
);
367 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
368 assertEquals("Event rank", 1002, context
.getRank());
370 // Position trace at event rank 4500
371 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
372 assertEquals("Event rank", 4500, context
.getRank());
373 event
= fTrace
.parseEvent(context
);
374 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
375 assertEquals("Event rank", 4500, context
.getRank());
376 event
= fTrace
.getNextEvent(context
);
377 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
378 assertEquals("Event rank", 4501, context
.getRank());
381 public void testSeekEventOnTimestampOutOfScope() throws Exception
{
383 // Position trace at beginning
384 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
385 assertEquals("Event rank", 0, context
.getRank());
386 TmfEvent event
= fTrace
.parseEvent(context
);
387 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
388 assertEquals("Event rank", 0, context
.getRank());
389 event
= fTrace
.getNextEvent(context
);
390 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
391 assertEquals("Event rank", 1, context
.getRank());
393 // Position trace at event passed the end
394 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
395 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
396 event
= fTrace
.parseEvent(context
);
397 assertEquals("Event timestamp", null, event
);
398 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
399 event
= fTrace
.getNextEvent(context
);
400 assertEquals("Event timestamp", null, event
);
401 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
404 // ------------------------------------------------------------------------
406 // ------------------------------------------------------------------------
408 public void testSeekOnRankOnCacheBoundary() throws Exception
{
410 // On lower bound, returns the first event (ts = 1)
411 TmfContext context
= fTrace
.seekEvent(0);
412 assertEquals("Event rank", 0, context
.getRank());
413 TmfEvent event
= fTrace
.parseEvent(context
);
414 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
415 assertEquals("Event rank", 0, context
.getRank());
416 event
= fTrace
.getNextEvent(context
);
417 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
418 assertEquals("Event rank", 1, context
.getRank());
420 // Position trace at event rank 1000
421 context
= fTrace
.seekEvent(1000);
422 assertEquals("Event rank", 1000, context
.getRank());
423 event
= fTrace
.parseEvent(context
);
424 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
425 assertEquals("Event rank", 1000, context
.getRank());
426 event
= fTrace
.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
= fTrace
.seekEvent(4000);
432 assertEquals("Event rank", 4000, context
.getRank());
433 event
= fTrace
.parseEvent(context
);
434 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
435 assertEquals("Event rank", 4000, context
.getRank());
436 event
= fTrace
.getNextEvent(context
);
437 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
438 assertEquals("Event rank", 4001, context
.getRank());
441 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
443 // Position trace at event rank 9
444 TmfContext context
= fTrace
.seekEvent(9);
445 assertEquals("Event rank", 9, context
.getRank());
446 TmfEvent event
= fTrace
.parseEvent(context
);
447 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
448 assertEquals("Event rank", 9, context
.getRank());
449 event
= fTrace
.getNextEvent(context
);
450 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
451 assertEquals("Event rank", 10, context
.getRank());
453 // Position trace at event rank 999
454 context
= fTrace
.seekEvent(999);
455 assertEquals("Event rank", 999, context
.getRank());
456 event
= fTrace
.parseEvent(context
);
457 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
458 assertEquals("Event rank", 999, context
.getRank());
459 event
= fTrace
.getNextEvent(context
);
460 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
461 assertEquals("Event rank", 1000, context
.getRank());
463 // Position trace at event rank 1001
464 context
= fTrace
.seekEvent(1001);
465 assertEquals("Event rank", 1001, context
.getRank());
466 event
= fTrace
.parseEvent(context
);
467 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
468 assertEquals("Event rank", 1001, context
.getRank());
469 event
= fTrace
.getNextEvent(context
);
470 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
471 assertEquals("Event rank", 1002, context
.getRank());
473 // Position trace at event rank 4500
474 context
= fTrace
.seekEvent(4500);
475 assertEquals("Event rank", 4500, context
.getRank());
476 event
= fTrace
.parseEvent(context
);
477 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
478 assertEquals("Event rank", 4500, context
.getRank());
479 event
= fTrace
.getNextEvent(context
);
480 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
481 assertEquals("Event rank", 4501, context
.getRank());
484 public void testSeekEventOnRankOfScope() throws Exception
{
486 // Position trace at beginning
487 TmfContext context
= fTrace
.seekEvent(-1);
488 assertEquals("Event rank", 0, context
.getRank());
489 TmfEvent event
= fTrace
.parseEvent(context
);
490 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
491 assertEquals("Event rank", 0, context
.getRank());
492 event
= fTrace
.getNextEvent(context
);
493 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
494 assertEquals("Event rank", 1, context
.getRank());
496 // Position trace at event passed the end
497 context
= fTrace
.seekEvent(NB_EVENTS
);
498 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
499 event
= fTrace
.parseEvent(context
);
500 assertEquals("Event timestamp", null, event
);
501 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
502 event
= fTrace
.getNextEvent(context
);
503 assertEquals("Event timestamp", null, event
);
504 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
507 // ------------------------------------------------------------------------
509 // ------------------------------------------------------------------------
511 @SuppressWarnings("unchecked")
512 public void testProcessRequestForNbEvents() throws Exception
{
513 final int BLOCK_SIZE
= 100;
514 final int NB_EVENTS
= 1000;
515 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
517 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
518 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
520 public void handleData() {
521 TmfEvent
[] events
= getData();
522 for (TmfEvent e
: events
) {
523 requestedEvents
.add(e
);
527 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
528 providers
[0].sendRequest(request
);
529 request
.waitForCompletion();
531 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
532 assertTrue("isCompleted", request
.isCompleted());
533 assertFalse("isCancelled", request
.isCancelled());
535 // Ensure that we have distinct events.
536 // Don't go overboard: we are not validating the stub!
537 for (int i
= 0; i
< NB_EVENTS
; i
++) {
538 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
542 @SuppressWarnings("unchecked")
543 public void testProcessRequestForAllEvents() throws Exception
{
544 final int BLOCK_SIZE
= 1;
545 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
547 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
548 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
550 public void handleData() {
551 TmfEvent
[] events
= getData();
552 for (TmfEvent e
: events
) {
553 requestedEvents
.add(e
);
557 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
558 providers
[0].sendRequest(request
);
559 request
.waitForCompletion();
561 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
562 assertTrue("isCompleted", request
.isCompleted());
563 assertFalse("isCancelled", request
.isCancelled());
565 // Ensure that we have distinct events.
566 // Don't go overboard: we are not validating the stub!
567 for (int i
= 0; i
< NB_EVENTS
; i
++) {
568 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
572 // ------------------------------------------------------------------------
574 // ------------------------------------------------------------------------
576 @SuppressWarnings("unchecked")
577 public void testCancel() throws Exception
{
578 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
580 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
581 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, NB_EVENTS
) {
583 public void handleData() {
584 TmfEvent
[] events
= getData();
585 for (TmfEvent e
: events
) {
586 requestedEvents
.add(e
);
588 // Cancel request after the first chunk is received
592 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
593 providers
[0].sendRequest(request
);
594 request
.waitForCompletion();
596 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
597 assertTrue("isCompleted", request
.isCompleted());
598 assertTrue("isCancelled", request
.isCancelled());
601 // // ------------------------------------------------------------------------
603 // // ------------------------------------------------------------------------
605 // public void testGetRank() throws Exception {
606 // assertEquals("getRank", 0, fTrace.getRank(new TmfTimestamp()));
607 // assertEquals("getRank", 0, fTrace.getRank(new TmfTimestamp( 1, (byte) -3)));
608 // assertEquals("getRank", 10, fTrace.getRank(new TmfTimestamp( 11, (byte) -3)));
609 // assertEquals("getRank", 100, fTrace.getRank(new TmfTimestamp( 101, (byte) -3)));
610 // assertEquals("getRank", 1000, fTrace.getRank(new TmfTimestamp(1001, (byte) -3)));
611 // assertEquals("getRank", 2000, fTrace.getRank(new TmfTimestamp(2001, (byte) -3)));
612 // assertEquals("getRank", 2500, fTrace.getRank(new TmfTimestamp(2501, (byte) -3)));
615 // // ------------------------------------------------------------------------
617 // // ------------------------------------------------------------------------
619 // public void testGetTimestamp() throws Exception {
620 // assertTrue("getTimestamp", fTrace.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
621 // assertTrue("getTimestamp", fTrace.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
622 // assertTrue("getTimestamp", fTrace.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
623 // assertTrue("getTimestamp", fTrace.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3)));
624 // assertTrue("getTimestamp", fTrace.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3)));
625 // assertTrue("getTimestamp", fTrace.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3)));
This page took 0.045584 seconds and 6 git commands to generate.