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
.request
;
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
.TmfEventReference
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
30 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
31 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
32 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.request
.TmfCoalescedDataRequest
;
34 import org
.eclipse
.linuxtools
.tmf
.request
.TmfCoalescedEventRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
36 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequestStub
;
37 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
38 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequestStub
;
39 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
41 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalManager
;
42 import org
.eclipse
.linuxtools
.tmf
.tests
.TmfCoreTestPlugin
;
43 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
46 * <b><u>TmfCoalescedEventRequestTest</u></b>
48 * Test suite for the TmfCoalescedEventRequest class.
50 public class TmfCoalescedEventRequestTest
extends TestCase
{
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 private static TmfTimeRange range1
= new TmfTimeRange(TmfTimeRange
.Eternity
);
57 private static TmfTimeRange range2
= new TmfTimeRange(new TmfTimestamp(), TmfTimestamp
.BigCrunch
);
59 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest1
;
60 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest2
;
61 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest3
;
62 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest4
;
64 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest1b
;
65 private static TmfCoalescedEventRequest
<TmfEvent
> fRequest1c
;
67 private static int fRequestCount
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 public TmfCoalescedEventRequestTest(String name
) {
78 public void setUp() throws Exception
{
80 TmfEventRequest
.reset();
81 fRequest1
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
82 fRequest2
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range2
, 100, 200);
83 fRequest3
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range2
, 200, 200);
84 fRequest4
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range2
, 200, 300);
86 fRequest1b
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
87 fRequest1c
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
89 fRequestCount
= fRequest1c
.getRequestId() + 1;
93 public void tearDown() throws Exception
{
97 private TmfCoalescedEventRequest
<TmfEvent
> setupTestRequest(final boolean[] flags
) {
99 TmfCoalescedEventRequest
<TmfEvent
> request
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200) {
101 public void handleCompleted() {
102 super.handleCompleted();
106 public void handleSuccess() {
107 super.handleSuccess();
111 public void handleFailure() {
112 super.handleFailure();
116 public void handleCancel() {
117 super.handleCancel();
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
128 public void testTmfCoalescedEventRequest() {
129 TmfCoalescedEventRequest
<TmfEvent
> request
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class);
131 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
132 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
134 assertEquals("getRange", range1
, request
.getRange());
135 assertEquals("getNbRequestedEvents", TmfEventRequest
.ALL_DATA
, request
.getNbRequested());
136 assertEquals("getBlockize", TmfEventRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
138 assertFalse("isCompleted", request
.isCompleted());
139 assertFalse("isFailed", request
.isFailed());
140 assertFalse("isCancelled", request
.isCancelled());
142 assertEquals("getNbRead", 0, request
.getNbRead());
145 public void testTmfCoalescedEventRequestIndex() {
146 TmfCoalescedEventRequest
<TmfEvent
> request
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
);
148 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
149 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
151 assertEquals("getRange", range1
, request
.getRange());
152 assertEquals("getNbRequestedEvents", TmfEventRequest
.ALL_DATA
, request
.getNbRequested());
153 assertEquals("getBlockize", TmfEventRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
155 assertFalse("isCompleted", request
.isCompleted());
156 assertFalse("isFailed", request
.isFailed());
157 assertFalse("isCancelled", request
.isCancelled());
159 assertEquals("getNbRead", 0, request
.getNbRead());
162 public void testTmfCoalescedEventRequestIndexNbRequested() {
163 TmfCoalescedEventRequest
<TmfEvent
> request
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100);
165 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
166 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
168 assertEquals("getRange", range1
, request
.getRange());
169 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
170 assertEquals("getBlockize", TmfEventRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
172 assertFalse("isCompleted", request
.isCompleted());
173 assertFalse("isFailed", request
.isFailed());
174 assertFalse("isCancelled", request
.isCancelled());
176 assertEquals("getNbRead", 0, request
.getNbRead());
179 public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() {
180 TmfCoalescedEventRequest
<TmfEvent
> request
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
182 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
183 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
185 assertEquals("getRange", range1
, request
.getRange());
186 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
187 assertEquals("getBlockize", 200, request
.getBlockize());
189 assertFalse("isCompleted", request
.isCompleted());
190 assertFalse("isFailed", request
.isFailed());
191 assertFalse("isCancelled", request
.isCancelled());
193 assertEquals("getNbRead", 0, request
.getNbRead());
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
200 public void testEqualsReflexivity() throws Exception
{
201 assertTrue("equals", fRequest1
.equals(fRequest1
));
202 assertTrue("equals", fRequest2
.equals(fRequest2
));
204 assertFalse("equals", fRequest1
.equals(fRequest2
));
205 assertFalse("equals", fRequest2
.equals(fRequest1
));
208 public void testEqualsSymmetry() throws Exception
{
209 assertTrue("equals", fRequest1
.equals(fRequest1b
));
210 assertTrue("equals", fRequest1b
.equals(fRequest1
));
212 assertFalse("equals", fRequest1
.equals(fRequest3
));
213 assertFalse("equals", fRequest2
.equals(fRequest3
));
214 assertFalse("equals", fRequest3
.equals(fRequest1
));
215 assertFalse("equals", fRequest3
.equals(fRequest2
));
218 public void testEqualsTransivity() throws Exception
{
219 assertTrue("equals", fRequest1
.equals(fRequest1b
));
220 assertTrue("equals", fRequest1b
.equals(fRequest1c
));
221 assertTrue("equals", fRequest1
.equals(fRequest1c
));
224 public void testEqualsConsistency() throws Exception
{
225 assertTrue("equals", fRequest1
.equals(fRequest1
));
226 assertTrue("equals", fRequest1
.equals(fRequest1
));
228 assertTrue("equals", fRequest2
.equals(fRequest2
));
229 assertTrue("equals", fRequest2
.equals(fRequest2
));
232 public void testEqualsNull() throws Exception
{
233 assertFalse("equals", fRequest1
.equals(null));
234 assertFalse("equals", fRequest2
.equals(null));
237 public void testEqualsSuper() throws Exception
{
238 TmfCoalescedDataRequest
<TmfEvent
> dataRequest1
= new TmfCoalescedDataRequest
<TmfEvent
>(
239 fRequest1
.getDataType(), fRequest1
.getIndex(), fRequest1
.getNbRequested(), fRequest1
.getBlockize());
240 TmfCoalescedDataRequest
<TmfEvent
> dataRequest2
= new TmfCoalescedDataRequest
<TmfEvent
>(
241 fRequest1
.getDataType(), fRequest1
.getIndex(), fRequest1
.getNbRequested(), fRequest1
.getBlockize());
242 TmfCoalescedDataRequest
<TmfEvent
> dataRequest3
= new TmfCoalescedDataRequest
<TmfEvent
>(
243 fRequest3
.getDataType(), fRequest3
.getIndex(), fRequest3
.getNbRequested(), fRequest3
.getBlockize());
245 assertTrue("equals", fRequest1
.equals(dataRequest2
));
246 assertTrue("equals", fRequest2
.equals(dataRequest1
));
247 assertFalse("equals", fRequest1
.equals(dataRequest3
));
248 assertFalse("equals", fRequest3
.equals(dataRequest1
));
251 // ------------------------------------------------------------------------
253 // ------------------------------------------------------------------------
255 public void testHashCode() throws Exception
{
256 assertTrue("hashCode", fRequest1
.hashCode() == fRequest1
.hashCode());
257 assertTrue("hashCode", fRequest2
.hashCode() == fRequest2
.hashCode());
258 assertTrue("hashCode", fRequest1
.hashCode() != fRequest2
.hashCode());
261 // ------------------------------------------------------------------------
263 // ------------------------------------------------------------------------
265 public void testToString() {
266 String expected1
= "[TmfCoalescedEventRequest(0,TmfEvent," + range1
+ ",100,200)]";
267 String expected2
= "[TmfCoalescedEventRequest(1,TmfEvent," + range2
+ ",100,200)]";
268 String expected3
= "[TmfCoalescedEventRequest(2,TmfEvent," + range2
+ ",200,200)]";
269 String expected4
= "[TmfCoalescedEventRequest(3,TmfEvent," + range2
+ ",200,300)]";
271 assertEquals("toString", expected1
, fRequest1
.toString());
272 assertEquals("toString", expected2
, fRequest2
.toString());
273 assertEquals("toString", expected3
, fRequest3
.toString());
274 assertEquals("toString", expected4
, fRequest4
.toString());
277 // ------------------------------------------------------------------------
279 // ------------------------------------------------------------------------
281 public void testIsCompatible() {
282 TmfCoalescedEventRequest
<TmfEvent
> coalescedRequest
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
283 TmfEventRequest
<TmfEvent
> request1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
284 TmfEventRequest
<TmfEvent
> request2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range2
, 100, 200);
285 TmfEventRequest
<TmfEvent
> request3
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 101, 200);
286 TmfEventRequest
<TmfEvent
> request4
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 201);
287 TmfDataRequest
<TmfEvent
> request5
= new TmfDataRequestStub
<TmfEvent
> (TmfEvent
.class, 10, 100, 201);
289 assertTrue ("isCompatible", coalescedRequest
.isCompatible(request1
));
290 assertFalse("isCompatible", coalescedRequest
.isCompatible(request2
));
291 assertFalse("isCompatible", coalescedRequest
.isCompatible(request3
));
292 assertFalse("isCompatible", coalescedRequest
.isCompatible(request4
));
293 assertFalse("isCompatible", coalescedRequest
.isCompatible(request5
));
296 // ------------------------------------------------------------------------
298 // ------------------------------------------------------------------------
300 public void testSetData() {
302 TmfCoalescedEventRequest
<TmfEvent
> coalescedRequest
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
303 TmfEventRequest
<TmfEvent
> request1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
304 TmfEventRequest
<TmfEvent
> request2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
305 coalescedRequest
.addRequest(request1
);
306 coalescedRequest
.addRequest(request2
);
308 // Initialize the data
310 TmfEvent
[] events
= new TmfEvent
[nbEvents
];
311 for (int i
= 0; i
< nbEvents
; i
++) {
312 events
[i
] = new TmfEvent(new TmfTimestamp(i
), new TmfEventSource(),
313 new TmfEventType(), new TmfEventReference());
316 coalescedRequest
.setData(events
);
317 coalescedRequest
.handleData();
319 // Validate the coalescing request
320 assertEquals("setData", nbEvents
, coalescedRequest
.getNbRead());
321 TmfEvent
[] eventsRead1
= coalescedRequest
.getData();
322 assertEquals("getData", nbEvents
, eventsRead1
.length
);
323 for (int i
= 0; i
< nbEvents
; i
++) {
324 assertEquals("getData", i
, eventsRead1
[i
].getTimestamp().getValue());
327 // Validate the first coalesced request
328 assertEquals("setData", nbEvents
, request1
.getNbRead());
329 TmfEvent
[] eventsRead2
= request1
.getData();
330 assertEquals("getData", nbEvents
, eventsRead2
.length
);
331 for (int i
= 0; i
< nbEvents
; i
++) {
332 assertEquals("getData", i
, eventsRead2
[i
].getTimestamp().getValue());
335 // Validate the second coalesced request
336 assertEquals("setData", nbEvents
, request2
.getNbRead());
337 TmfEvent
[] eventsRead3
= request2
.getData();
338 assertEquals("getData", nbEvents
, eventsRead3
.length
);
339 for (int i
= 0; i
< nbEvents
; i
++) {
340 assertEquals("getData", i
, eventsRead3
[i
].getTimestamp().getValue());
344 // ------------------------------------------------------------------------
346 // ------------------------------------------------------------------------
348 public void testDone() {
351 final boolean[] crFlags
= new boolean[4];
352 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
353 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
354 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
355 request
.addRequest(subRequest1
);
356 request
.addRequest(subRequest2
);
360 // Validate the coalescing request
361 assertTrue ("isCompleted", request
.isCompleted());
362 assertFalse("isFailed", request
.isFailed());
363 assertFalse("isCancelled", request
.isCancelled());
365 assertTrue ("handleCompleted", crFlags
[0]);
366 assertTrue ("handleSuccess", crFlags
[1]);
367 assertFalse("handleFailure", crFlags
[2]);
368 assertFalse("handleCancel", crFlags
[3]);
370 // Validate the first coalesced request
371 assertTrue ("isCompleted", subRequest1
.isCompleted());
372 assertFalse("isFailed", subRequest1
.isFailed());
373 assertFalse("isCancelled", subRequest1
.isCancelled());
375 // Validate the second coalesced request
376 assertTrue ("isCompleted", subRequest2
.isCompleted());
377 assertFalse("isFailed", subRequest2
.isFailed());
378 assertFalse("isCancelled", subRequest2
.isCancelled());
381 // ------------------------------------------------------------------------
383 // ------------------------------------------------------------------------
385 public void testFail() {
387 final boolean[] crFlags
= new boolean[4];
388 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
389 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
390 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
391 request
.addRequest(subRequest1
);
392 request
.addRequest(subRequest2
);
396 // Validate the coalescing request
397 assertTrue ("isCompleted", request
.isCompleted());
398 assertTrue ("isFailed", request
.isFailed());
399 assertFalse("isCancelled", request
.isCancelled());
401 assertTrue ("handleCompleted", crFlags
[0]);
402 assertFalse("handleSuccess", crFlags
[1]);
403 assertTrue ("handleFailure", crFlags
[2]);
404 assertFalse("handleCancel", crFlags
[3]);
406 // Validate the first coalesced request
407 assertTrue ("isCompleted", subRequest1
.isCompleted());
408 assertTrue ("isFailed", subRequest1
.isFailed());
409 assertFalse("isCancelled", subRequest1
.isCancelled());
411 // Validate the second coalesced request
412 assertTrue ("isCompleted", subRequest2
.isCompleted());
413 assertTrue ("isFailed", subRequest2
.isFailed());
414 assertFalse("isCancelled", subRequest2
.isCancelled());
417 // ------------------------------------------------------------------------
419 // ------------------------------------------------------------------------
421 public void testCancel() {
423 final boolean[] crFlags
= new boolean[4];
424 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
425 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
426 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
427 request
.addRequest(subRequest1
);
428 request
.addRequest(subRequest2
);
432 // Validate the coalescing request
433 assertTrue ("isCompleted", request
.isCompleted());
434 assertFalse("isFailed", request
.isFailed());
435 assertTrue ("isCancelled", request
.isCancelled());
437 assertTrue ("handleCompleted", crFlags
[0]);
438 assertFalse("handleSuccess", crFlags
[1]);
439 assertFalse("handleFailure", crFlags
[2]);
440 assertTrue ("handleCancel", crFlags
[3]);
442 // Validate the first coalesced request
443 assertTrue ("isCompleted", subRequest1
.isCompleted());
444 assertFalse("isFailed", subRequest1
.isFailed());
445 assertTrue ("isCancelled", subRequest1
.isCancelled());
447 // Validate the second coalesced request
448 assertTrue ("isCompleted", subRequest2
.isCompleted());
449 assertFalse("isFailed", subRequest2
.isFailed());
450 assertTrue ("isCancelled", subRequest2
.isCancelled());
453 // ------------------------------------------------------------------------
455 // ------------------------------------------------------------------------
457 // ------------------------------------------------------------------------
459 // ------------------------------------------------------------------------
461 private static final String DIRECTORY
= "testfiles";
462 private static final String TEST_STREAM
= "A-Test-10K";
463 private static final int NB_EVENTS
= 10000;
464 private static final int BLOCK_SIZE
= 100;
466 // Initialize the test trace
467 private static TmfTraceStub fTrace
= null;
468 private TmfTraceStub
setupTrace(String path
) {
469 if (fTrace
== null) {
471 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
472 File test
= new File(FileLocator
.toFileURL(location
).toURI());
473 fTrace
= new TmfTraceStub(test
.getPath(), 500, true);
474 } catch (URISyntaxException e
) {
476 } catch (IOException e
) {
483 Vector
<TmfEvent
> requestedEvents1
;
484 Vector
<TmfEvent
> requestedEvents2
;
485 Vector
<TmfEvent
> requestedEvents3
;
487 TmfEventRequest
<TmfEvent
> request1
;
488 TmfEventRequest
<TmfEvent
> request2
;
489 TmfEventRequest
<TmfEvent
> request3
;
491 ITmfDataProvider
<TmfEvent
>[] providers
;
493 private class TmfTestTriggerSignal
extends TmfSignal
{
494 public final boolean forceCancel
;
495 public TmfTestTriggerSignal(Object source
, boolean cancel
) {
497 forceCancel
= cancel
;
502 @SuppressWarnings("unchecked")
504 public void trigger(final TmfTestTriggerSignal signal
) {
506 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
508 requestedEvents1
= new Vector
<TmfEvent
>();
509 request1
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
511 public void handleData() {
512 if (!isCompleted()) {
513 TmfEvent
[] events
= getData();
514 for (TmfEvent e
: events
) {
515 requestedEvents1
.add(e
);
517 if (signal
.forceCancel
)
523 requestedEvents2
= new Vector
<TmfEvent
>();
524 request2
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
526 public void handleData() {
527 if (!isCompleted()) {
528 TmfEvent
[] events
= getData();
529 for (TmfEvent e
: events
) {
530 requestedEvents2
.add(e
);
536 requestedEvents3
= new Vector
<TmfEvent
>();
537 request3
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
539 public void handleData() {
540 if (!isCompleted()) {
541 TmfEvent
[] events
= getData();
542 for (TmfEvent e
: events
) {
543 requestedEvents3
.add(e
);
549 providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
550 providers
[0].sendRequest(request1
);
551 providers
[0].sendRequest(request2
);
552 providers
[0].sendRequest(request3
);
555 public void testCoalescedRequest() throws Exception
{
557 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
559 TmfSignalManager
.register(this);
560 TmfTestTriggerSignal signal
= new TmfTestTriggerSignal(this, false);
561 TmfSignalManager
.dispatchSignal(signal
);
563 request1
.waitForCompletion();
564 request2
.waitForCompletion();
565 request3
.waitForCompletion();
567 assertEquals("Request1: nbEvents", NB_EVENTS
, requestedEvents1
.size());
568 assertTrue ("Request1: isCompleted", request1
.isCompleted());
569 assertFalse ("Request1: isCancelled", request1
.isCancelled());
571 assertEquals("Request2: nbEvents", NB_EVENTS
, requestedEvents2
.size());
572 assertTrue ("Request2: isCompleted", request2
.isCompleted());
573 assertFalse ("Request2: isCancelled", request2
.isCancelled());
575 assertEquals("Request3: nbEvents", NB_EVENTS
, requestedEvents3
.size());
576 assertTrue ("Request3: isCompleted", request3
.isCompleted());
577 assertFalse ("Request3: isCancelled", request3
.isCancelled());
579 // Ensure that we have distinct events.
580 // Don't go overboard: we are not validating the stub!
581 for (int i
= 0; i
< NB_EVENTS
; i
++) {
582 assertEquals("Distinct events", i
+1, requestedEvents1
.get(i
).getTimestamp().getValue());
583 assertEquals("Distinct events", i
+1, requestedEvents2
.get(i
).getTimestamp().getValue());
584 assertEquals("Distinct events", i
+1, requestedEvents3
.get(i
).getTimestamp().getValue());
587 TmfSignalManager
.deregister(this);
592 public void testCancelCoalescedRequest() throws Exception
{
594 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
596 TmfSignalManager
.register(this);
597 TmfTestTriggerSignal signal
= new TmfTestTriggerSignal(this, true);
598 TmfSignalManager
.dispatchSignal(signal
);
600 request1
.waitForCompletion();
601 request2
.waitForCompletion();
602 request3
.waitForCompletion();
604 assertEquals("Request1: nbEvents", BLOCK_SIZE
, requestedEvents1
.size());
605 assertTrue ("Request1: isCompleted", request1
.isCompleted());
606 assertTrue ("Request1: isCancelled", request1
.isCancelled());
608 assertEquals("Request2: nbEvents", NB_EVENTS
, requestedEvents2
.size());
609 assertTrue ("Request2: isCompleted", request2
.isCompleted());
610 assertFalse ("Request2: isCancelled", request2
.isCancelled());
612 assertEquals("Request3: nbEvents", NB_EVENTS
, requestedEvents3
.size());
613 assertTrue ("Request3: isCompleted", request3
.isCompleted());
614 assertFalse ("Request3: isCancelled", request3
.isCancelled());
616 // Ensure that we have distinct events.
617 // Don't go overboard: we are not validating the stub!
618 for (int i
= 0; i
< NB_EVENTS
; i
++) {
619 assertEquals("Distinct events", i
+1, requestedEvents2
.get(i
).getTimestamp().getValue());
620 assertEquals("Distinct events", i
+1, requestedEvents3
.get(i
).getTimestamp().getValue());
623 TmfSignalManager
.deregister(this);