Commit | Line | Data |
---|---|---|
5419a136 | 1 | /******************************************************************************* |
6e1886bc | 2 | * Copyright (c) 2009, 2010, 2012, 2013 Ericsson |
5419a136 AM |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | * Francois Chouinard - Added tests to check offsets | |
6e1886bc | 12 | * Alexandre Montplaisir - Port to JUnit4 |
5419a136 AM |
13 | *******************************************************************************/ |
14 | ||
15 | package org.eclipse.linuxtools.tmf.core.tests.request; | |
16 | ||
6e1886bc AM |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertFalse; | |
19 | import static org.junit.Assert.assertTrue; | |
5419a136 AM |
20 | |
21 | import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest; | |
22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
5419a136 AM |
23 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
24 | import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub; | |
6e1886bc AM |
25 | import org.junit.Before; |
26 | import org.junit.Test; | |
5419a136 AM |
27 | |
28 | /** | |
29 | * Test suite for the TmfCoalescedDataRequest class. | |
30 | */ | |
6e1886bc AM |
31 | @SuppressWarnings({ "nls", "javadoc" }) |
32 | public class TmfCoalescedDataRequestTest { | |
33 | ||
34 | // ------------------------------------------------------------------------ | |
35 | // Variables | |
36 | // ------------------------------------------------------------------------ | |
37 | ||
38 | private TmfCoalescedDataRequest fRequest1; | |
39 | private TmfCoalescedDataRequest fRequest2; | |
40 | private TmfCoalescedDataRequest fRequest3; | |
41 | private TmfCoalescedDataRequest fRequest4; | |
42 | ||
43 | private TmfCoalescedDataRequest fRequest1b; | |
44 | private TmfCoalescedDataRequest fRequest1c; | |
45 | ||
46 | private int fRequestCount; | |
47 | ||
48 | // ------------------------------------------------------------------------ | |
49 | // Housekeeping | |
50 | // ------------------------------------------------------------------------ | |
51 | ||
52 | @Before | |
53 | public void setUp() { | |
54 | TmfDataRequest.reset(); | |
55 | fRequest1 = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); | |
56 | fRequest2 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 100, 200); | |
57 | fRequest3 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 200); | |
58 | fRequest4 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 300); | |
59 | ||
60 | fRequest1b = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); | |
61 | fRequest1c = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); | |
62 | ||
63 | fRequestCount = fRequest1c.getRequestId() + 1; | |
64 | } | |
65 | ||
66 | private static TmfCoalescedDataRequest setupTestRequest(final boolean[] flags) { | |
67 | ||
68 | TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200) { | |
69 | @Override | |
70 | public void handleCompleted() { | |
71 | super.handleCompleted(); | |
72 | flags[0] = true; | |
73 | } | |
74 | ||
75 | @Override | |
76 | public void handleSuccess() { | |
77 | super.handleSuccess(); | |
78 | flags[1] = true; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public void handleFailure() { | |
83 | super.handleFailure(); | |
84 | flags[2] = true; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public void handleCancel() { | |
89 | super.handleCancel(); | |
90 | flags[3] = true; | |
91 | } | |
92 | }; | |
93 | return request; | |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Constructors | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | @Test | |
101 | public void testTmfCoalescedDataRequest() { | |
102 | TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class); | |
5419a136 AM |
103 | |
104 | assertEquals("getRequestId", fRequestCount++, request.getRequestId()); | |
6e1886bc | 105 | assertEquals("getDataType", ITmfEvent.class, request.getDataType()); |
5419a136 AM |
106 | |
107 | assertEquals("getIndex", 0, request.getIndex()); | |
108 | assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); | |
109 | ||
110 | assertFalse("isCompleted", request.isCompleted()); | |
111 | assertFalse("isFailed", request.isFailed()); | |
112 | assertFalse("isCancelled", request.isCancelled()); | |
113 | ||
114 | assertEquals("getNbRead", 0, request.getNbRead()); | |
6e1886bc | 115 | } |
5419a136 | 116 | |
6e1886bc AM |
117 | @Test |
118 | public void testTmfCoalescedDataRequestIndex() { | |
119 | TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10); | |
5419a136 AM |
120 | |
121 | assertEquals("getRequestId", fRequestCount++, request.getRequestId()); | |
6e1886bc | 122 | assertEquals("getDataType", ITmfEvent.class, request.getDataType()); |
5419a136 AM |
123 | |
124 | assertEquals("getIndex", 10, request.getIndex()); | |
125 | assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); | |
126 | ||
127 | assertFalse("isCompleted", request.isCompleted()); | |
128 | assertFalse("isFailed", request.isFailed()); | |
129 | assertFalse("isCancelled", request.isCancelled()); | |
130 | ||
131 | assertEquals("getNbRead", 0, request.getNbRead()); | |
6e1886bc | 132 | } |
5419a136 | 133 | |
6e1886bc AM |
134 | @Test |
135 | public void testTmfCoalescedDataRequestIndexNbRequested() { | |
136 | TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100); | |
5419a136 AM |
137 | |
138 | assertEquals("getRequestId", fRequestCount++, request.getRequestId()); | |
6e1886bc | 139 | assertEquals("getDataType", ITmfEvent.class, request.getDataType()); |
5419a136 AM |
140 | |
141 | assertEquals("getIndex", 10, request.getIndex()); | |
142 | assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); | |
143 | ||
144 | assertFalse("isCompleted", request.isCompleted()); | |
145 | assertFalse("isFailed", request.isFailed()); | |
146 | assertFalse("isCancelled", request.isCancelled()); | |
147 | ||
148 | assertEquals("getNbRead", 0, request.getNbRead()); | |
6e1886bc | 149 | } |
5419a136 | 150 | |
6e1886bc AM |
151 | @Test |
152 | public void testTmfCoalescedDataRequestIndexNbEventsBlocksize() { | |
153 | TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); | |
5419a136 AM |
154 | |
155 | assertEquals("getRequestId", fRequestCount++, request.getRequestId()); | |
6e1886bc | 156 | assertEquals("getDataType", ITmfEvent.class, request.getDataType()); |
5419a136 AM |
157 | |
158 | assertEquals("getIndex", 10, request.getIndex()); | |
159 | assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); | |
160 | ||
161 | assertFalse("isCompleted", request.isCompleted()); | |
162 | assertFalse("isFailed", request.isFailed()); | |
163 | assertFalse("isCancelled", request.isCancelled()); | |
164 | ||
165 | assertEquals("getNbRead", 0, request.getNbRead()); | |
6e1886bc | 166 | } |
5419a136 | 167 | |
6e1886bc AM |
168 | // ------------------------------------------------------------------------ |
169 | // equals | |
170 | // ------------------------------------------------------------------------ | |
5419a136 | 171 | |
6e1886bc AM |
172 | @Test |
173 | public void testEqualsReflexivity() { | |
5419a136 AM |
174 | assertTrue("equals", fRequest1.equals(fRequest1)); |
175 | assertTrue("equals", fRequest2.equals(fRequest2)); | |
176 | ||
177 | assertFalse("equals", fRequest1.equals(fRequest2)); | |
178 | assertFalse("equals", fRequest2.equals(fRequest1)); | |
6e1886bc | 179 | } |
5419a136 | 180 | |
6e1886bc AM |
181 | @Test |
182 | public void testEqualsSymmetry() { | |
5419a136 AM |
183 | assertTrue("equals", fRequest1.equals(fRequest1b)); |
184 | assertTrue("equals", fRequest1b.equals(fRequest1)); | |
185 | ||
186 | assertFalse("equals", fRequest1.equals(fRequest3)); | |
187 | assertFalse("equals", fRequest2.equals(fRequest3)); | |
188 | assertFalse("equals", fRequest3.equals(fRequest1)); | |
189 | assertFalse("equals", fRequest3.equals(fRequest2)); | |
6e1886bc | 190 | } |
5419a136 | 191 | |
6e1886bc AM |
192 | @Test |
193 | public void testEqualsTransivity() { | |
5419a136 AM |
194 | assertTrue("equals", fRequest1.equals(fRequest1b)); |
195 | assertTrue("equals", fRequest1b.equals(fRequest1c)); | |
196 | assertTrue("equals", fRequest1.equals(fRequest1c)); | |
6e1886bc | 197 | } |
5419a136 | 198 | |
6e1886bc AM |
199 | @Test |
200 | public void testEqualsNull() { | |
5419a136 AM |
201 | assertFalse("equals", fRequest1.equals(null)); |
202 | assertFalse("equals", fRequest2.equals(null)); | |
6e1886bc | 203 | } |
5419a136 | 204 | |
6e1886bc AM |
205 | // ------------------------------------------------------------------------ |
206 | // hashCode | |
207 | // ------------------------------------------------------------------------ | |
5419a136 | 208 | |
6e1886bc AM |
209 | @Test |
210 | public void testHashCode() { | |
5419a136 AM |
211 | assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode()); |
212 | assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode()); | |
6e1886bc AM |
213 | assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); |
214 | } | |
5419a136 | 215 | |
6e1886bc AM |
216 | // ------------------------------------------------------------------------ |
217 | // toString | |
218 | // ------------------------------------------------------------------------ | |
5419a136 | 219 | |
6e1886bc AM |
220 | @Test |
221 | public void testToString() { | |
5419a136 AM |
222 | String expected1 = "[TmfCoalescedDataRequest(0,ITmfEvent,10,100,200)]"; |
223 | String expected2 = "[TmfCoalescedDataRequest(1,ITmfEvent,20,100,200)]"; | |
224 | String expected3 = "[TmfCoalescedDataRequest(2,ITmfEvent,20,200,200)]"; | |
225 | String expected4 = "[TmfCoalescedDataRequest(3,ITmfEvent,20,200,300)]"; | |
226 | ||
227 | assertEquals("toString", expected1, fRequest1.toString()); | |
228 | assertEquals("toString", expected2, fRequest2.toString()); | |
229 | assertEquals("toString", expected3, fRequest3.toString()); | |
230 | assertEquals("toString", expected4, fRequest4.toString()); | |
2771b032 | 231 | } |
5419a136 | 232 | |
2771b032 AM |
233 | // ------------------------------------------------------------------------ |
234 | // isCompatible | |
235 | // ------------------------------------------------------------------------ | |
5419a136 | 236 | |
6e1886bc | 237 | @Test |
2771b032 AM |
238 | public void testIsCompatible() { |
239 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); | |
6e1886bc AM |
240 | TmfDataRequest request1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); |
241 | TmfDataRequest request2 = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200); | |
242 | TmfDataRequest request3 = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200); | |
243 | TmfDataRequest request4 = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200); | |
244 | TmfDataRequest request5 = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200); | |
2771b032 AM |
245 | TmfDataRequest request6 = new TmfDataRequestStub(ITmfEvent.class, 100, 100, 200); |
246 | TmfDataRequest request7 = new TmfDataRequestStub(ITmfEvent.class, 110, 100, 200); | |
247 | TmfDataRequest request8 = new TmfDataRequestStub(ITmfEvent.class, 111, 100, 200); | |
5419a136 AM |
248 | |
249 | assertTrue("isCompatible", coalescedRequest.isCompatible(request1)); | |
250 | assertTrue("isCompatible", coalescedRequest.isCompatible(request2)); | |
251 | assertTrue("isCompatible", coalescedRequest.isCompatible(request3)); | |
252 | assertTrue("isCompatible", coalescedRequest.isCompatible(request4)); | |
253 | assertTrue("isCompatible", coalescedRequest.isCompatible(request5)); | |
254 | assertTrue("isCompatible", coalescedRequest.isCompatible(request6)); | |
255 | assertTrue("isCompatible", coalescedRequest.isCompatible(request7)); | |
256 | assertTrue("isCompatible", coalescedRequest.isCompatible(request8)); | |
257 | ||
2771b032 AM |
258 | TmfDataRequest request9 = new TmfDataRequestStub(ITmfEvent.class, 5, 3, 200); |
259 | TmfDataRequest request10 = new TmfDataRequestStub(ITmfEvent.class, 112, 100, 200); | |
5419a136 AM |
260 | |
261 | assertFalse("isCompatible", coalescedRequest.isCompatible(request9)); | |
262 | assertFalse("isCompatible", coalescedRequest.isCompatible(request10)); | |
2771b032 | 263 | } |
5419a136 AM |
264 | |
265 | // ------------------------------------------------------------------------ | |
266 | // addRequest | |
267 | // ------------------------------------------------------------------------ | |
268 | ||
6e1886bc | 269 | @Test |
5419a136 | 270 | public void testAddRequest1() { |
2771b032 AM |
271 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
272 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
5419a136 AM |
273 | |
274 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
275 | coalescedRequest.addRequest(request); | |
6e1886bc | 276 | assertEquals("addRequest", 10, coalescedRequest.getIndex()); |
5419a136 AM |
277 | assertEquals("addRequest", 100, coalescedRequest.getNbRequested()); |
278 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
279 | } | |
280 | ||
6e1886bc | 281 | @Test |
5419a136 | 282 | public void testAddRequest2() { |
2771b032 AM |
283 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
284 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200); | |
5419a136 AM |
285 | |
286 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
287 | coalescedRequest.addRequest(request); | |
6e1886bc | 288 | assertEquals("addRequest", 5, coalescedRequest.getIndex()); |
5419a136 AM |
289 | assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); |
290 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
291 | } | |
292 | ||
6e1886bc | 293 | @Test |
5419a136 | 294 | public void testAddRequest3() { |
2771b032 AM |
295 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
296 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200); | |
5419a136 AM |
297 | |
298 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
299 | coalescedRequest.addRequest(request); | |
6e1886bc | 300 | assertEquals("addRequest", 5, coalescedRequest.getIndex()); |
5419a136 AM |
301 | assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); |
302 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
303 | } | |
304 | ||
6e1886bc | 305 | @Test |
5419a136 | 306 | public void testAddRequest4() { |
2771b032 AM |
307 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
308 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200); | |
5419a136 AM |
309 | |
310 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
311 | coalescedRequest.addRequest(request); | |
6e1886bc | 312 | assertEquals("addRequest", 5, coalescedRequest.getIndex()); |
5419a136 AM |
313 | assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); |
314 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
315 | } | |
316 | ||
6e1886bc | 317 | @Test |
5419a136 | 318 | public void testAddRequest5() { |
2771b032 AM |
319 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
320 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200); | |
5419a136 AM |
321 | |
322 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
323 | coalescedRequest.addRequest(request); | |
6e1886bc | 324 | assertEquals("addRequest", 10, coalescedRequest.getIndex()); |
5419a136 AM |
325 | assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); |
326 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
327 | } | |
328 | ||
6e1886bc | 329 | @Test |
5419a136 | 330 | public void testAddRequest6() { |
2771b032 AM |
331 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
332 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 100, 100, 200); | |
5419a136 AM |
333 | |
334 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
335 | coalescedRequest.addRequest(request); | |
6e1886bc | 336 | assertEquals("addRequest", 10, coalescedRequest.getIndex()); |
5419a136 AM |
337 | assertEquals("addRequest", 190, coalescedRequest.getNbRequested()); |
338 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
339 | } | |
340 | ||
6e1886bc | 341 | @Test |
5419a136 | 342 | public void testAddRequest7() { |
2771b032 AM |
343 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
344 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 110, 100, 200); | |
5419a136 AM |
345 | |
346 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
347 | coalescedRequest.addRequest(request); | |
6e1886bc | 348 | assertEquals("addRequest", 10, coalescedRequest.getIndex()); |
5419a136 AM |
349 | assertEquals("addRequest", 200, coalescedRequest.getNbRequested()); |
350 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
351 | } | |
352 | ||
6e1886bc | 353 | @Test |
5419a136 | 354 | public void testAddRequest8() { |
2771b032 AM |
355 | TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); |
356 | TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 111, 100, 200); | |
5419a136 AM |
357 | |
358 | assertTrue("isCompatible", coalescedRequest.isCompatible(request)); | |
359 | coalescedRequest.addRequest(request); | |
6e1886bc | 360 | assertEquals("addRequest", 10, coalescedRequest.getIndex()); |
5419a136 AM |
361 | assertEquals("addRequest", 201, coalescedRequest.getNbRequested()); |
362 | assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); | |
363 | } | |
364 | ||
6e1886bc AM |
365 | // ------------------------------------------------------------------------ |
366 | // done | |
2771b032 | 367 | // ------------------------------------------------------------------------ |
5419a136 | 368 | |
6e1886bc | 369 | @Test |
2771b032 | 370 | public void testDone() { |
2771b032 AM |
371 | // Test request |
372 | final boolean[] crFlags = new boolean[4]; | |
373 | TmfCoalescedDataRequest request = setupTestRequest(crFlags); | |
374 | TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
375 | TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
376 | request.addRequest(subRequest1); | |
377 | request.addRequest(subRequest2); | |
5419a136 | 378 | |
6e1886bc | 379 | request.done(); |
5419a136 | 380 | |
6e1886bc AM |
381 | // Validate the coalescing request |
382 | assertTrue("isCompleted", request.isCompleted()); | |
383 | assertFalse("isFailed", request.isFailed()); | |
384 | assertFalse("isCancelled", request.isCancelled()); | |
385 | ||
386 | assertTrue("handleCompleted", crFlags[0]); | |
387 | assertTrue("handleSuccess", crFlags[1]); | |
388 | assertFalse("handleFailure", crFlags[2]); | |
389 | assertFalse("handleCancel", crFlags[3]); | |
390 | ||
391 | // Validate the first coalesced request | |
392 | assertTrue("isCompleted", subRequest1.isCompleted()); | |
393 | assertFalse("isFailed", subRequest1.isFailed()); | |
394 | assertFalse("isCancelled", subRequest1.isCancelled()); | |
395 | ||
396 | // Validate the second coalesced request | |
397 | assertTrue("isCompleted", subRequest2.isCompleted()); | |
398 | assertFalse("isFailed", subRequest2.isFailed()); | |
399 | assertFalse("isCancelled", subRequest2.isCancelled()); | |
400 | } | |
401 | ||
402 | // ------------------------------------------------------------------------ | |
403 | // fail | |
404 | // ------------------------------------------------------------------------ | |
5419a136 | 405 | |
6e1886bc AM |
406 | @Test |
407 | public void testFail() { | |
408 | final boolean[] crFlags = new boolean[4]; | |
409 | TmfCoalescedDataRequest request = setupTestRequest(crFlags); | |
410 | TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
411 | TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
412 | request.addRequest(subRequest1); | |
413 | request.addRequest(subRequest2); | |
414 | ||
415 | request.fail(); | |
416 | ||
417 | // Validate the coalescing request | |
418 | assertTrue("isCompleted", request.isCompleted()); | |
419 | assertTrue("isFailed", request.isFailed()); | |
420 | assertFalse("isCancelled", request.isCancelled()); | |
421 | ||
422 | assertTrue("handleCompleted", crFlags[0]); | |
423 | assertFalse("handleSuccess", crFlags[1]); | |
424 | assertTrue("handleFailure", crFlags[2]); | |
425 | assertFalse("handleCancel", crFlags[3]); | |
426 | ||
427 | // Validate the first coalesced request | |
428 | assertTrue("isCompleted", subRequest1.isCompleted()); | |
429 | assertTrue("isFailed", subRequest1.isFailed()); | |
430 | assertFalse("isCancelled", subRequest1.isCancelled()); | |
431 | ||
432 | // Validate the second coalesced request | |
433 | assertTrue("isCompleted", subRequest2.isCompleted()); | |
434 | assertTrue("isFailed", subRequest2.isFailed()); | |
435 | assertFalse("isCancelled", subRequest2.isCancelled()); | |
436 | } | |
437 | ||
438 | // ------------------------------------------------------------------------ | |
439 | // cancel | |
440 | // ------------------------------------------------------------------------ | |
441 | ||
442 | @Test | |
443 | public void testCancel() { | |
444 | final boolean[] crFlags = new boolean[4]; | |
445 | TmfCoalescedDataRequest request = setupTestRequest(crFlags); | |
446 | TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
447 | TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
448 | request.addRequest(subRequest1); | |
449 | request.addRequest(subRequest2); | |
450 | ||
451 | request.cancel(); | |
452 | ||
453 | // Validate the coalescing request | |
454 | assertTrue("isCompleted", request.isCompleted()); | |
455 | assertFalse("isFailed", request.isFailed()); | |
456 | assertTrue("isCancelled", request.isCancelled()); | |
457 | ||
458 | assertTrue("handleCompleted", crFlags[0]); | |
459 | assertFalse("handleSuccess", crFlags[1]); | |
460 | assertFalse("handleFailure", crFlags[2]); | |
461 | assertTrue("handleCancel", crFlags[3]); | |
462 | ||
463 | // Validate the first coalesced request | |
464 | assertTrue("isCompleted", subRequest1.isCompleted()); | |
465 | assertFalse("isFailed", subRequest1.isFailed()); | |
466 | assertTrue("isCancelled", subRequest1.isCancelled()); | |
467 | ||
468 | // Validate the second coalesced request | |
469 | assertTrue("isCompleted", subRequest2.isCompleted()); | |
470 | assertFalse("isFailed", subRequest2.isFailed()); | |
471 | assertTrue("isCancelled", subRequest2.isCancelled()); | |
472 | } | |
473 | ||
474 | // ------------------------------------------------------------------------ | |
475 | // cancel sub-requests | |
476 | // ------------------------------------------------------------------------ | |
477 | ||
478 | @Test | |
479 | public void testCancelSubRequests() { | |
2771b032 AM |
480 | final boolean[] crFlags = new boolean[4]; |
481 | TmfCoalescedDataRequest request = setupTestRequest(crFlags); | |
482 | TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
483 | TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); | |
484 | request.addRequest(subRequest1); | |
485 | request.addRequest(subRequest2); | |
486 | ||
487 | subRequest1.cancel(); | |
488 | ||
489 | // Validate the first coalesced request | |
490 | assertTrue ("isCompleted", subRequest1.isCompleted()); | |
491 | assertFalse("isFailed", subRequest1.isFailed()); | |
492 | assertTrue ("isCancelled", subRequest1.isCancelled()); | |
493 | ||
494 | // Validate the coalescing request | |
495 | assertFalse("isCompleted", request.isCompleted()); | |
6e1886bc | 496 | assertFalse("isFailed", request.isFailed()); |
2771b032 AM |
497 | assertFalse("isCancelled", request.isCancelled()); |
498 | ||
499 | // Cancel second sub-request | |
500 | subRequest2.cancel(); | |
501 | ||
502 | // Validate the second coalesced request | |
503 | assertTrue ("isCompleted", subRequest2.isCompleted()); | |
504 | assertFalse("isFailed", subRequest2.isFailed()); | |
505 | assertTrue("isCancelled", subRequest2.isCancelled()); | |
506 | ||
507 | // Validate the coalescing request | |
508 | assertTrue("isCompleted", request.isCompleted()); | |
509 | assertFalse("isFailed", request.isFailed()); | |
510 | assertTrue("isCancelled", request.isCancelled()); | |
511 | ||
512 | // Finalize coalescing request - | |
513 | // Note: No need to check "request.isCancelled()" since it was verified | |
514 | // above | |
515 | request.cancel(); | |
516 | ||
517 | assertTrue("handleCompleted", crFlags[0]); | |
518 | assertFalse("handleSuccess", crFlags[1]); | |
519 | assertFalse("handleFailure", crFlags[2]); | |
520 | assertTrue("handleCancel", crFlags[3]); | |
521 | } | |
5419a136 AM |
522 | |
523 | } |