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 testEqualsNull() throws Exception
{
225 assertFalse("equals", fRequest1
.equals(null));
226 assertFalse("equals", fRequest2
.equals(null));
229 public void testEqualsSuper() throws Exception
{
230 TmfCoalescedDataRequest
<TmfEvent
> dataRequest1
= new TmfCoalescedDataRequest
<TmfEvent
>(
231 fRequest1
.getDataType(), fRequest1
.getIndex(), fRequest1
.getNbRequested(), fRequest1
.getBlockize());
232 TmfCoalescedDataRequest
<TmfEvent
> dataRequest2
= new TmfCoalescedDataRequest
<TmfEvent
>(
233 fRequest1
.getDataType(), fRequest1
.getIndex(), fRequest1
.getNbRequested(), fRequest1
.getBlockize());
234 TmfCoalescedDataRequest
<TmfEvent
> dataRequest3
= new TmfCoalescedDataRequest
<TmfEvent
>(
235 fRequest3
.getDataType(), fRequest3
.getIndex(), fRequest3
.getNbRequested(), fRequest3
.getBlockize());
237 assertTrue("equals", fRequest1
.equals(dataRequest2
));
238 assertTrue("equals", fRequest2
.equals(dataRequest1
));
239 assertFalse("equals", fRequest1
.equals(dataRequest3
));
240 assertFalse("equals", fRequest3
.equals(dataRequest1
));
243 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
247 public void testHashCode() throws Exception
{
248 assertTrue("hashCode", fRequest1
.hashCode() == fRequest1
.hashCode());
249 assertTrue("hashCode", fRequest2
.hashCode() == fRequest2
.hashCode());
250 assertTrue("hashCode", fRequest1
.hashCode() != fRequest2
.hashCode());
253 // ------------------------------------------------------------------------
255 // ------------------------------------------------------------------------
257 public void testToString() {
258 String expected1
= "[TmfCoalescedEventRequest(0,TmfEvent," + range1
+ ",100,200)]";
259 String expected2
= "[TmfCoalescedEventRequest(1,TmfEvent," + range2
+ ",100,200)]";
260 String expected3
= "[TmfCoalescedEventRequest(2,TmfEvent," + range2
+ ",200,200)]";
261 String expected4
= "[TmfCoalescedEventRequest(3,TmfEvent," + range2
+ ",200,300)]";
263 assertEquals("toString", expected1
, fRequest1
.toString());
264 assertEquals("toString", expected2
, fRequest2
.toString());
265 assertEquals("toString", expected3
, fRequest3
.toString());
266 assertEquals("toString", expected4
, fRequest4
.toString());
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
273 public void testIsCompatible() {
274 TmfCoalescedEventRequest
<TmfEvent
> coalescedRequest
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
275 TmfEventRequest
<TmfEvent
> request1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
276 TmfEventRequest
<TmfEvent
> request2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range2
, 100, 200);
277 TmfEventRequest
<TmfEvent
> request3
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 101, 200);
278 TmfEventRequest
<TmfEvent
> request4
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 201);
279 TmfDataRequest
<TmfEvent
> request5
= new TmfDataRequestStub
<TmfEvent
> (TmfEvent
.class, 10, 100, 201);
281 assertTrue ("isCompatible", coalescedRequest
.isCompatible(request1
));
282 assertTrue ("isCompatible", coalescedRequest
.isCompatible(request2
));
283 assertFalse("isCompatible", coalescedRequest
.isCompatible(request3
));
284 assertFalse("isCompatible", coalescedRequest
.isCompatible(request4
));
285 assertFalse("isCompatible", coalescedRequest
.isCompatible(request5
));
288 // ------------------------------------------------------------------------
290 // ------------------------------------------------------------------------
292 public void testSetData() {
294 TmfCoalescedEventRequest
<TmfEvent
> coalescedRequest
= new TmfCoalescedEventRequest
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
295 TmfEventRequest
<TmfEvent
> request1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
296 TmfEventRequest
<TmfEvent
> request2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
297 coalescedRequest
.addRequest(request1
);
298 coalescedRequest
.addRequest(request2
);
300 // Initialize the data
302 TmfEvent
[] events
= new TmfEvent
[nbEvents
];
303 for (int i
= 0; i
< nbEvents
; i
++) {
304 events
[i
] = new TmfEvent(new TmfTimestamp(i
), new TmfEventSource(),
305 new TmfEventType(), new TmfEventReference());
308 coalescedRequest
.setData(events
);
309 coalescedRequest
.handleData();
311 // Validate the coalescing request
312 assertEquals("setData", nbEvents
, coalescedRequest
.getNbRead());
313 TmfEvent
[] eventsRead1
= coalescedRequest
.getData();
314 assertEquals("getData", nbEvents
, eventsRead1
.length
);
315 for (int i
= 0; i
< nbEvents
; i
++) {
316 assertEquals("getData", i
, eventsRead1
[i
].getTimestamp().getValue());
319 // Validate the first coalesced request
320 assertEquals("setData", nbEvents
, request1
.getNbRead());
321 TmfEvent
[] eventsRead2
= request1
.getData();
322 assertEquals("getData", nbEvents
, eventsRead2
.length
);
323 for (int i
= 0; i
< nbEvents
; i
++) {
324 assertEquals("getData", i
, eventsRead2
[i
].getTimestamp().getValue());
327 // Validate the second coalesced request
328 assertEquals("setData", nbEvents
, request2
.getNbRead());
329 TmfEvent
[] eventsRead3
= request2
.getData();
330 assertEquals("getData", nbEvents
, eventsRead3
.length
);
331 for (int i
= 0; i
< nbEvents
; i
++) {
332 assertEquals("getData", i
, eventsRead3
[i
].getTimestamp().getValue());
336 // ------------------------------------------------------------------------
338 // ------------------------------------------------------------------------
340 public void testDone() {
343 final boolean[] crFlags
= new boolean[4];
344 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
345 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
346 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
347 request
.addRequest(subRequest1
);
348 request
.addRequest(subRequest2
);
352 // Validate the coalescing request
353 assertTrue ("isCompleted", request
.isCompleted());
354 assertFalse("isFailed", request
.isFailed());
355 assertFalse("isCancelled", request
.isCancelled());
357 assertTrue ("handleCompleted", crFlags
[0]);
358 assertTrue ("handleSuccess", crFlags
[1]);
359 assertFalse("handleFailure", crFlags
[2]);
360 assertFalse("handleCancel", crFlags
[3]);
362 // Validate the first coalesced request
363 assertTrue ("isCompleted", subRequest1
.isCompleted());
364 assertFalse("isFailed", subRequest1
.isFailed());
365 assertFalse("isCancelled", subRequest1
.isCancelled());
367 // Validate the second coalesced request
368 assertTrue ("isCompleted", subRequest2
.isCompleted());
369 assertFalse("isFailed", subRequest2
.isFailed());
370 assertFalse("isCancelled", subRequest2
.isCancelled());
373 // ------------------------------------------------------------------------
375 // ------------------------------------------------------------------------
377 public void testFail() {
379 final boolean[] crFlags
= new boolean[4];
380 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
381 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
382 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
383 request
.addRequest(subRequest1
);
384 request
.addRequest(subRequest2
);
388 // Validate the coalescing request
389 assertTrue ("isCompleted", request
.isCompleted());
390 assertTrue ("isFailed", request
.isFailed());
391 assertFalse("isCancelled", request
.isCancelled());
393 assertTrue ("handleCompleted", crFlags
[0]);
394 assertFalse("handleSuccess", crFlags
[1]);
395 assertTrue ("handleFailure", crFlags
[2]);
396 assertFalse("handleCancel", crFlags
[3]);
398 // Validate the first coalesced request
399 assertTrue ("isCompleted", subRequest1
.isCompleted());
400 assertTrue ("isFailed", subRequest1
.isFailed());
401 assertFalse("isCancelled", subRequest1
.isCancelled());
403 // Validate the second coalesced request
404 assertTrue ("isCompleted", subRequest2
.isCompleted());
405 assertTrue ("isFailed", subRequest2
.isFailed());
406 assertFalse("isCancelled", subRequest2
.isCancelled());
409 // ------------------------------------------------------------------------
411 // ------------------------------------------------------------------------
413 public void testCancel() {
415 final boolean[] crFlags
= new boolean[4];
416 TmfCoalescedEventRequest
<TmfEvent
> request
= setupTestRequest(crFlags
);
417 TmfEventRequest
<TmfEvent
> subRequest1
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
418 TmfEventRequest
<TmfEvent
> subRequest2
= new TmfEventRequestStub
<TmfEvent
>(TmfEvent
.class, range1
, 100, 200);
419 request
.addRequest(subRequest1
);
420 request
.addRequest(subRequest2
);
424 // Validate the coalescing request
425 assertTrue ("isCompleted", request
.isCompleted());
426 assertFalse("isFailed", request
.isFailed());
427 assertTrue ("isCancelled", request
.isCancelled());
429 assertTrue ("handleCompleted", crFlags
[0]);
430 assertFalse("handleSuccess", crFlags
[1]);
431 assertFalse("handleFailure", crFlags
[2]);
432 assertTrue ("handleCancel", crFlags
[3]);
434 // Validate the first coalesced request
435 assertTrue ("isCompleted", subRequest1
.isCompleted());
436 assertFalse("isFailed", subRequest1
.isFailed());
437 assertTrue ("isCancelled", subRequest1
.isCancelled());
439 // Validate the second coalesced request
440 assertTrue ("isCompleted", subRequest2
.isCompleted());
441 assertFalse("isFailed", subRequest2
.isFailed());
442 assertTrue ("isCancelled", subRequest2
.isCancelled());
445 // ------------------------------------------------------------------------
447 // ------------------------------------------------------------------------
449 // ------------------------------------------------------------------------
451 // ------------------------------------------------------------------------
453 private static final String DIRECTORY
= "testfiles";
454 private static final String TEST_STREAM
= "A-Test-10K";
455 private static final int NB_EVENTS
= 10000;
456 private static final int BLOCK_SIZE
= 100;
458 // Initialize the test trace
459 private static TmfTraceStub fTrace
= null;
460 private synchronized TmfTraceStub
setupTrace(String path
) {
461 if (fTrace
== null) {
463 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
464 File test
= new File(FileLocator
.toFileURL(location
).toURI());
465 fTrace
= new TmfTraceStub(test
.getPath(), 500);
466 } catch (URISyntaxException e
) {
468 } catch (IOException e
) {
475 Vector
<TmfEvent
> requestedEvents1
;
476 Vector
<TmfEvent
> requestedEvents2
;
477 Vector
<TmfEvent
> requestedEvents3
;
479 TmfEventRequest
<TmfEvent
> request1
;
480 TmfEventRequest
<TmfEvent
> request2
;
481 TmfEventRequest
<TmfEvent
> request3
;
483 ITmfDataProvider
<TmfEvent
>[] providers
;
485 private class TmfTestTriggerSignal
extends TmfSignal
{
486 public final boolean forceCancel
;
487 public TmfTestTriggerSignal(Object source
, boolean cancel
) {
489 forceCancel
= cancel
;
494 @SuppressWarnings("unchecked")
496 public void trigger(final TmfTestTriggerSignal signal
) {
498 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
500 requestedEvents1
= new Vector
<TmfEvent
>();
501 request1
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
503 public void handleData() {
504 if (!isCompleted()) {
505 TmfEvent
[] events
= getData();
506 for (TmfEvent e
: events
) {
507 requestedEvents1
.add(e
);
509 if (signal
.forceCancel
)
515 requestedEvents2
= new Vector
<TmfEvent
>();
516 request2
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
518 public void handleData() {
519 if (!isCompleted()) {
520 TmfEvent
[] events
= getData();
521 for (TmfEvent e
: events
) {
522 requestedEvents2
.add(e
);
528 requestedEvents3
= new Vector
<TmfEvent
>();
529 request3
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, range
, NB_EVENTS
, BLOCK_SIZE
) {
531 public void handleData() {
532 if (!isCompleted()) {
533 TmfEvent
[] events
= getData();
534 for (TmfEvent e
: events
) {
535 requestedEvents3
.add(e
);
541 providers
= (ITmfDataProvider
<TmfEvent
>[]) TmfProviderManager
.getProviders(TmfEvent
.class, TmfTraceStub
.class);
542 providers
[0].sendRequest(request1
);
543 providers
[0].sendRequest(request2
);
544 providers
[0].sendRequest(request3
);
547 public void testCoalescedRequest() throws Exception
{
549 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
551 TmfSignalManager
.register(this);
552 TmfTestTriggerSignal signal
= new TmfTestTriggerSignal(this, false);
553 TmfSignalManager
.dispatchSignal(signal
);
555 request1
.waitForCompletion();
556 request2
.waitForCompletion();
557 request3
.waitForCompletion();
559 assertEquals("Request1: nbEvents", NB_EVENTS
, requestedEvents1
.size());
560 assertTrue ("Request1: isCompleted", request1
.isCompleted());
561 assertFalse ("Request1: isCancelled", request1
.isCancelled());
563 assertEquals("Request2: nbEvents", NB_EVENTS
, requestedEvents2
.size());
564 assertTrue ("Request2: isCompleted", request2
.isCompleted());
565 assertFalse ("Request2: isCancelled", request2
.isCancelled());
567 assertEquals("Request3: nbEvents", NB_EVENTS
, requestedEvents3
.size());
568 assertTrue ("Request3: isCompleted", request3
.isCompleted());
569 assertFalse ("Request3: isCancelled", request3
.isCancelled());
571 // Ensure that we have distinct events.
572 // Don't go overboard: we are not validating the stub!
573 for (int i
= 0; i
< NB_EVENTS
; i
++) {
574 assertEquals("Distinct events", i
+1, requestedEvents1
.get(i
).getTimestamp().getValue());
575 assertEquals("Distinct events", i
+1, requestedEvents2
.get(i
).getTimestamp().getValue());
576 assertEquals("Distinct events", i
+1, requestedEvents3
.get(i
).getTimestamp().getValue());
579 TmfSignalManager
.deregister(this);
584 public void testCancelCoalescedRequest() throws Exception
{
586 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
588 TmfSignalManager
.register(this);
589 TmfTestTriggerSignal signal
= new TmfTestTriggerSignal(this, true);
590 TmfSignalManager
.dispatchSignal(signal
);
592 request1
.waitForCompletion();
593 request2
.waitForCompletion();
594 request3
.waitForCompletion();
596 assertEquals("Request1: nbEvents", BLOCK_SIZE
, requestedEvents1
.size());
597 assertTrue ("Request1: isCompleted", request1
.isCompleted());
598 assertTrue ("Request1: isCancelled", request1
.isCancelled());
600 assertEquals("Request2: nbEvents", NB_EVENTS
, requestedEvents2
.size());
601 assertTrue ("Request2: isCompleted", request2
.isCompleted());
602 assertFalse ("Request2: isCancelled", request2
.isCancelled());
604 assertEquals("Request3: nbEvents", NB_EVENTS
, requestedEvents3
.size());
605 assertTrue ("Request3: isCompleted", request3
.isCompleted());
606 assertFalse ("Request3: isCancelled", request3
.isCancelled());
608 // Ensure that we have distinct events.
609 // Don't go overboard: we are not validating the stub!
610 for (int i
= 0; i
< NB_EVENTS
; i
++) {
611 assertEquals("Distinct events", i
+1, requestedEvents2
.get(i
).getTimestamp().getValue());
612 assertEquals("Distinct events", i
+1, requestedEvents3
.get(i
).getTimestamp().getValue());
615 TmfSignalManager
.deregister(this);