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
.getDefault().getBundle(), new Path(path
), null);
58 File test
= new File(FileLocator
.toFileURL(location
).toURI());
59 fTrace
= new TmfTraceStub(test
.getPath(), 500, true);
60 } catch (URISyntaxException e
) {
62 } catch (IOException e
) {
69 public TmfTraceTest(String name
) throws Exception
{
74 protected void setUp() throws Exception
{
76 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
80 protected void tearDown() throws Exception
{
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
88 public void testTmfTraceDefault() throws Exception
{
89 TmfTraceStub trace
= null;
91 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
92 File test
= new File(FileLocator
.toFileURL(location
).toURI());
93 trace
= new TmfTraceStub(test
.getPath(), true);
94 } catch (URISyntaxException e
) {
96 } catch (IOException e
) {
99 assertTrue("Open trace", trace
!= null);
100 assertEquals("getCacheSize", TmfTraceStub
.DEFAULT_CACHE_SIZE
, trace
.getCacheSize());
101 assertEquals("getTraceSize", NB_EVENTS
, trace
.getNbEvents());
104 public void testTmfTrace() throws Exception
{
105 assertEquals("getCacheSize", 500, fTrace
.getCacheSize());
106 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
107 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
108 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
111 // ------------------------------------------------------------------------
112 // Verify checkpoints
113 // ------------------------------------------------------------------------
115 public void testValidateCheckpoints() throws Exception
{
117 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getCheckpoints();
118 int pageSize
= fTrace
.getCacheSize();
119 assertTrue("Checkpoints exist", checkpoints
!= null);
121 // Validate that each checkpoint points to the right event
122 for (int i
= 0; i
< checkpoints
.size(); i
++) {
123 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
124 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
125 TmfEvent event
= fTrace
.parseEvent(context
);
126 assertTrue(context
.getRank() == i
* pageSize
);
127 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
131 // ------------------------------------------------------------------------
132 // parseEvent - make sure parseEvent doesn't update the context
133 // ------------------------------------------------------------------------
135 public void testParseEvent() throws Exception
{
137 // On lower bound, returns the first event (ts = 0)
138 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
140 TmfEvent event
= fTrace
.parseEvent(context
);
141 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
143 event
= fTrace
.parseEvent(context
);
144 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
146 event
= fTrace
.parseEvent(context
);
147 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
149 for (int i
= 1; i
< 20; i
++) {
150 event
= fTrace
.getNextEvent(context
);
151 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
154 event
= fTrace
.parseEvent(context
);
155 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
157 event
= fTrace
.parseEvent(context
);
158 assertEquals("Event timestamp", 20, event
.getTimestamp().getValue());
161 // ------------------------------------------------------------------------
162 // getNextEvent - updates the context
163 // ------------------------------------------------------------------------
165 public void testGetNextEvent() throws Exception
{
167 // On lower bound, returns the first event (ts = 0)
168 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(0, SCALE
, 0));
169 TmfEvent event
= fTrace
.getNextEvent(context
);
170 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
172 for (int i
= 2; i
< 20; i
++) {
173 event
= fTrace
.getNextEvent(context
);
174 assertEquals("Event timestamp", i
, event
.getTimestamp().getValue());
178 // ------------------------------------------------------------------------
180 // Note: seekLocation() does not reliably set the rank
181 // ------------------------------------------------------------------------
183 public void testSeekLocationOnCacheBoundary() throws Exception
{
185 // Position trace at event rank 0
186 TmfContext context
= fTrace
.seekLocation(null);
187 // assertEquals("Event rank", 0, context.getRank());
188 TmfEvent event
= fTrace
.parseEvent(context
);
189 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
190 // assertEquals("Event rank", 0, context.getRank());
191 event
= fTrace
.getNextEvent(context
);
192 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
193 // assertEquals("Event rank", 1, context.getRank());
195 // Position trace at event rank 1000
196 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
197 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
198 // assertEquals("Event rank", 1000, context.getRank());
199 event
= fTrace
.parseEvent(context
);
200 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
201 // assertEquals("Event rank", 1000, context.getRank());
202 event
= fTrace
.getNextEvent(context
);
203 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
204 // assertEquals("Event rank", 1001, context.getRank());
206 // Position trace at event rank 4000
207 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
208 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
209 // assertEquals("Event rank", 4000, context.getRank());
210 event
= fTrace
.parseEvent(context
);
211 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
212 // assertEquals("Event rank", 4000, context.getRank());
213 event
= fTrace
.getNextEvent(context
);
214 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
215 // assertEquals("Event rank", 4001, context.getRank());
218 public void testSeekLocationNotOnCacheBoundary() throws Exception
{
220 // Position trace at event rank 9
221 TmfContext tmpContext
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
222 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
223 // assertEquals("Event rank", 9, context.getRank());
224 TmfEvent event
= fTrace
.parseEvent(context
);
225 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
226 // assertEquals("Event rank", 9, context.getRank());
227 event
= fTrace
.getNextEvent(context
);
228 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
229 // assertEquals("Event rank", 10, context.getRank());
231 // Position trace at event rank 999
232 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
233 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
234 // assertEquals("Event rank", 999, context.getRank());
235 event
= fTrace
.parseEvent(context
);
236 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
237 // assertEquals("Event rank", 999, context.getRank());
238 event
= fTrace
.getNextEvent(context
);
239 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
240 // assertEquals("Event rank", 1000, context.getRank());
242 // Position trace at event rank 1001
243 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
244 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
245 // assertEquals("Event rank", 1001, context.getRank());
246 event
= fTrace
.parseEvent(context
);
247 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
248 // assertEquals("Event rank", 1001, context.getRank());
249 event
= fTrace
.getNextEvent(context
);
250 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
251 // assertEquals("Event rank", 1002, context.getRank());
253 // Position trace at event rank 4500
254 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
255 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
256 // assertEquals("Event rank", 4500, context.getRank());
257 event
= fTrace
.parseEvent(context
);
258 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
259 // assertEquals("Event rank", 4500, context.getRank());
260 event
= fTrace
.getNextEvent(context
);
261 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
262 // assertEquals("Event rank", 4501, context.getRank());
265 public void testSeekLocationOutOfScope() throws Exception
{
267 // Position trace at beginning
268 TmfContext tmpContext
= fTrace
.seekLocation(null);
269 TmfContext context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
270 // assertEquals("Event rank", 0, context.getRank());
271 TmfEvent event
= fTrace
.parseEvent(context
);
272 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
273 // assertEquals("Event rank", 0, context.getRank());
274 event
= fTrace
.getNextEvent(context
);
275 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
276 // assertEquals("Event rank", 1, context.getRank());
278 // Position trace at event passed the end
279 tmpContext
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
280 context
= fTrace
.seekLocation(tmpContext
.getLocation().clone());
281 // assertEquals("Event rank", NB_EVENTS, context.getRank());
282 event
= fTrace
.parseEvent(context
);
283 assertEquals("Event timestamp", null, event
);
284 // assertEquals("Event rank", NB_EVENTS, context.getRank());
285 event
= fTrace
.getNextEvent(context
);
286 assertEquals("Event timestamp", null, event
);
287 // assertEquals("Event rank", NB_EVENTS, context.getRank());
290 // ------------------------------------------------------------------------
291 // seekEvent on timestamp
292 // ------------------------------------------------------------------------
294 public void testSeekEventOnTimestampOnCacheBoundary() throws Exception
{
296 // Position trace at event rank 0
297 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(1, SCALE
, 0));
298 assertEquals("Event rank", 0, context
.getRank());
299 TmfEvent event
= fTrace
.parseEvent(context
);
300 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
301 assertEquals("Event rank", 0, context
.getRank());
302 event
= fTrace
.getNextEvent(context
);
303 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
304 assertEquals("Event rank", 1, context
.getRank());
306 // Position trace at event rank 1000
307 context
= fTrace
.seekEvent(new TmfTimestamp(1001, SCALE
, 0));
308 assertEquals("Event rank", 1000, context
.getRank());
309 event
= fTrace
.parseEvent(context
);
310 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
311 assertEquals("Event rank", 1000, context
.getRank());
312 event
= fTrace
.getNextEvent(context
);
313 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
314 assertEquals("Event rank", 1001, context
.getRank());
316 // Position trace at event rank 4000
317 context
= fTrace
.seekEvent(new TmfTimestamp(4001, SCALE
, 0));
318 assertEquals("Event rank", 4000, context
.getRank());
319 event
= fTrace
.parseEvent(context
);
320 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
321 assertEquals("Event rank", 4000, context
.getRank());
322 event
= fTrace
.getNextEvent(context
);
323 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
324 assertEquals("Event rank", 4001, context
.getRank());
327 public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception
{
329 // Position trace at event rank 1
330 TmfContext context
= fTrace
.seekEvent(new TmfTimestamp(2, SCALE
, 0));
331 assertEquals("Event rank", 1, context
.getRank());
332 TmfEvent event
= fTrace
.parseEvent(context
);
333 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
334 assertEquals("Event rank", 1, context
.getRank());
335 event
= fTrace
.getNextEvent(context
);
336 assertEquals("Event timestamp", 2, event
.getTimestamp().getValue());
337 assertEquals("Event rank", 2, context
.getRank());
339 // Position trace at event rank 9
340 context
= fTrace
.seekEvent(new TmfTimestamp(10, SCALE
, 0));
341 assertEquals("Event rank", 9, context
.getRank());
342 event
= fTrace
.parseEvent(context
);
343 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
344 assertEquals("Event rank", 9, context
.getRank());
345 event
= fTrace
.getNextEvent(context
);
346 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
347 assertEquals("Event rank", 10, context
.getRank());
349 // Position trace at event rank 999
350 context
= fTrace
.seekEvent(new TmfTimestamp(1000, SCALE
, 0));
351 assertEquals("Event rank", 999, context
.getRank());
352 event
= fTrace
.parseEvent(context
);
353 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
354 assertEquals("Event rank", 999, context
.getRank());
355 event
= fTrace
.getNextEvent(context
);
356 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
357 assertEquals("Event rank", 1000, context
.getRank());
359 // Position trace at event rank 1001
360 context
= fTrace
.seekEvent(new TmfTimestamp(1002, SCALE
, 0));
361 assertEquals("Event rank", 1001, context
.getRank());
362 event
= fTrace
.parseEvent(context
);
363 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
364 assertEquals("Event rank", 1001, context
.getRank());
365 event
= fTrace
.getNextEvent(context
);
366 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
367 assertEquals("Event rank", 1002, context
.getRank());
369 // Position trace at event rank 4500
370 context
= fTrace
.seekEvent(new TmfTimestamp(4501, SCALE
, 0));
371 assertEquals("Event rank", 4500, context
.getRank());
372 event
= fTrace
.parseEvent(context
);
373 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
374 assertEquals("Event rank", 4500, context
.getRank());
375 event
= fTrace
.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
= fTrace
.seekEvent(new TmfTimestamp(-1, SCALE
, 0));
384 assertEquals("Event rank", 0, context
.getRank());
385 TmfEvent event
= fTrace
.parseEvent(context
);
386 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
387 assertEquals("Event rank", 0, context
.getRank());
388 event
= fTrace
.getNextEvent(context
);
389 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
390 assertEquals("Event rank", 1, context
.getRank());
392 // Position trace at event passed the end
393 context
= fTrace
.seekEvent(new TmfTimestamp(NB_EVENTS
+ 1, SCALE
, 0));
394 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
395 event
= fTrace
.parseEvent(context
);
396 assertEquals("Event timestamp", null, event
);
397 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
398 event
= fTrace
.getNextEvent(context
);
399 assertEquals("Event timestamp", null, event
);
400 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
403 // ------------------------------------------------------------------------
405 // ------------------------------------------------------------------------
407 public void testSeekOnRankOnCacheBoundary() throws Exception
{
409 // On lower bound, returns the first event (ts = 1)
410 TmfContext context
= fTrace
.seekEvent(0);
411 assertEquals("Event rank", 0, context
.getRank());
412 TmfEvent event
= fTrace
.parseEvent(context
);
413 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
414 assertEquals("Event rank", 0, context
.getRank());
415 event
= fTrace
.getNextEvent(context
);
416 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
417 assertEquals("Event rank", 1, context
.getRank());
419 // Position trace at event rank 1000
420 context
= fTrace
.seekEvent(1000);
421 assertEquals("Event rank", 1000, context
.getRank());
422 event
= fTrace
.parseEvent(context
);
423 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
424 assertEquals("Event rank", 1000, context
.getRank());
425 event
= fTrace
.getNextEvent(context
);
426 assertEquals("Event timestamp", 1001, event
.getTimestamp().getValue());
427 assertEquals("Event rank", 1001, context
.getRank());
429 // Position trace at event rank 4000
430 context
= fTrace
.seekEvent(4000);
431 assertEquals("Event rank", 4000, context
.getRank());
432 event
= fTrace
.parseEvent(context
);
433 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
434 assertEquals("Event rank", 4000, context
.getRank());
435 event
= fTrace
.getNextEvent(context
);
436 assertEquals("Event timestamp", 4001, event
.getTimestamp().getValue());
437 assertEquals("Event rank", 4001, context
.getRank());
440 public void testSeekOnRankNotOnCacheBoundary() throws Exception
{
442 // Position trace at event rank 9
443 TmfContext context
= fTrace
.seekEvent(9);
444 assertEquals("Event rank", 9, context
.getRank());
445 TmfEvent event
= fTrace
.parseEvent(context
);
446 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
447 assertEquals("Event rank", 9, context
.getRank());
448 event
= fTrace
.getNextEvent(context
);
449 assertEquals("Event timestamp", 10, event
.getTimestamp().getValue());
450 assertEquals("Event rank", 10, context
.getRank());
452 // Position trace at event rank 999
453 context
= fTrace
.seekEvent(999);
454 assertEquals("Event rank", 999, context
.getRank());
455 event
= fTrace
.parseEvent(context
);
456 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
457 assertEquals("Event rank", 999, context
.getRank());
458 event
= fTrace
.getNextEvent(context
);
459 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
460 assertEquals("Event rank", 1000, context
.getRank());
462 // Position trace at event rank 1001
463 context
= fTrace
.seekEvent(1001);
464 assertEquals("Event rank", 1001, context
.getRank());
465 event
= fTrace
.parseEvent(context
);
466 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
467 assertEquals("Event rank", 1001, context
.getRank());
468 event
= fTrace
.getNextEvent(context
);
469 assertEquals("Event timestamp", 1002, event
.getTimestamp().getValue());
470 assertEquals("Event rank", 1002, context
.getRank());
472 // Position trace at event rank 4500
473 context
= fTrace
.seekEvent(4500);
474 assertEquals("Event rank", 4500, context
.getRank());
475 event
= fTrace
.parseEvent(context
);
476 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
477 assertEquals("Event rank", 4500, context
.getRank());
478 event
= fTrace
.getNextEvent(context
);
479 assertEquals("Event timestamp", 4501, event
.getTimestamp().getValue());
480 assertEquals("Event rank", 4501, context
.getRank());
483 public void testSeekEventOnRankOfScope() throws Exception
{
485 // Position trace at beginning
486 TmfContext context
= fTrace
.seekEvent(-1);
487 assertEquals("Event rank", 0, context
.getRank());
488 TmfEvent event
= fTrace
.parseEvent(context
);
489 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
490 assertEquals("Event rank", 0, context
.getRank());
491 event
= fTrace
.getNextEvent(context
);
492 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
493 assertEquals("Event rank", 1, context
.getRank());
495 // Position trace at event passed the end
496 context
= fTrace
.seekEvent(NB_EVENTS
);
497 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
498 event
= fTrace
.parseEvent(context
);
499 assertEquals("Event timestamp", null, event
);
500 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
501 event
= fTrace
.getNextEvent(context
);
502 assertEquals("Event timestamp", null, event
);
503 assertEquals("Event rank", NB_EVENTS
, context
.getRank());
506 // ------------------------------------------------------------------------
508 // ------------------------------------------------------------------------
510 @SuppressWarnings("unchecked")
511 public void testProcessRequestForNbEvents() throws Exception
{
512 final int BLOCK_SIZE
= 100;
513 final int NB_EVENTS
= 1000;
514 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
516 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
517 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
519 public void handleData() {
520 TmfEvent
[] events
= getData();
521 for (TmfEvent e
: events
) {
522 requestedEvents
.add(e
);
526 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
527 providers
[0].sendRequest(request
);
528 request
.waitForCompletion();
530 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
531 assertTrue("isCompleted", request
.isCompleted());
532 assertFalse("isCancelled", request
.isCancelled());
534 // Ensure that we have distinct events.
535 // Don't go overboard: we are not validating the stub!
536 for (int i
= 0; i
< NB_EVENTS
; i
++) {
537 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
541 @SuppressWarnings("unchecked")
542 public void testProcessRequestForAllEvents() throws Exception
{
543 final int BLOCK_SIZE
= 1;
544 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
546 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
547 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
549 public void handleData() {
550 TmfEvent
[] events
= getData();
551 for (TmfEvent e
: events
) {
552 requestedEvents
.add(e
);
556 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
557 providers
[0].sendRequest(request
);
558 request
.waitForCompletion();
560 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
561 assertTrue("isCompleted", request
.isCompleted());
562 assertFalse("isCancelled", request
.isCancelled());
564 // Ensure that we have distinct events.
565 // Don't go overboard: we are not validating the stub!
566 for (int i
= 0; i
< NB_EVENTS
; i
++) {
567 assertEquals("Distinct events", i
+1, requestedEvents
.get(i
).getTimestamp().getValue());
571 // ------------------------------------------------------------------------
573 // ------------------------------------------------------------------------
575 @SuppressWarnings("unchecked")
576 public void testCancel() throws Exception
{
577 final Vector
<TmfEvent
> requestedEvents
= new Vector
<TmfEvent
>();
579 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
580 final TmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, NB_EVENTS
) {
582 public void handleData() {
583 TmfEvent
[] events
= getData();
584 for (TmfEvent e
: events
) {
585 requestedEvents
.add(e
);
587 // Cancel request after the first chunk is received
591 ITmfDataProvider
<TmfEvent
>[] providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
592 providers
[0].sendRequest(request
);
593 request
.waitForCompletion();
595 assertEquals("nbEvents", NB_EVENTS
, requestedEvents
.size());
596 assertTrue("isCompleted", request
.isCompleted());
597 assertTrue("isCancelled", request
.isCancelled());
600 // // ------------------------------------------------------------------------
602 // // ------------------------------------------------------------------------
604 // public void testGetRank() throws Exception {
605 // assertEquals("getRank", 0, fTrace.getRank(new TmfTimestamp()));
606 // assertEquals("getRank", 0, fTrace.getRank(new TmfTimestamp( 1, (byte) -3)));
607 // assertEquals("getRank", 10, fTrace.getRank(new TmfTimestamp( 11, (byte) -3)));
608 // assertEquals("getRank", 100, fTrace.getRank(new TmfTimestamp( 101, (byte) -3)));
609 // assertEquals("getRank", 1000, fTrace.getRank(new TmfTimestamp(1001, (byte) -3)));
610 // assertEquals("getRank", 2000, fTrace.getRank(new TmfTimestamp(2001, (byte) -3)));
611 // assertEquals("getRank", 2500, fTrace.getRank(new TmfTimestamp(2501, (byte) -3)));
614 // // ------------------------------------------------------------------------
616 // // ------------------------------------------------------------------------
618 // public void testGetTimestamp() throws Exception {
619 // assertTrue("getTimestamp", fTrace.getTimestamp( 0).equals(new TmfTimestamp( 1, (byte) -3)));
620 // assertTrue("getTimestamp", fTrace.getTimestamp( 10).equals(new TmfTimestamp( 11, (byte) -3)));
621 // assertTrue("getTimestamp", fTrace.getTimestamp( 100).equals(new TmfTimestamp( 101, (byte) -3)));
622 // assertTrue("getTimestamp", fTrace.getTimestamp(1000).equals(new TmfTimestamp(1001, (byte) -3)));
623 // assertTrue("getTimestamp", fTrace.getTimestamp(2000).equals(new TmfTimestamp(2001, (byte) -3)));
624 // assertTrue("getTimestamp", fTrace.getTimestamp(2500).equals(new TmfTimestamp(2501, (byte) -3)));
This page took 0.045665 seconds and 6 git commands to generate.