Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2013 Ericsson |
9b749023 | 3 | * |
d18dd09b ASL |
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 | |
9b749023 | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Adjusted for new Trace Model |
6e1886bc | 12 | * Alexandre Montplaisir - Port to JUnit4 |
ea271da6 | 13 | * Patrick Tasse - Updated for rank in experiment location |
d18dd09b ASL |
14 | *******************************************************************************/ |
15 | ||
9e0640dc | 16 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b | 17 | |
6e1886bc AM |
18 | import static org.junit.Assert.assertEquals; |
19 | import static org.junit.Assert.assertFalse; | |
6e1886bc AM |
20 | import static org.junit.Assert.assertNull; |
21 | import static org.junit.Assert.assertTrue; | |
22 | ||
d18dd09b ASL |
23 | import java.io.File; |
24 | import java.io.IOException; | |
25 | import java.net.URISyntaxException; | |
26 | import java.net.URL; | |
27 | import java.util.Vector; | |
28 | ||
9e0640dc | 29 | import org.eclipse.core.resources.IFile; |
d18dd09b ASL |
30 | import org.eclipse.core.runtime.FileLocator; |
31 | import org.eclipse.core.runtime.Path; | |
17324c9a | 32 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; |
9e0640dc | 33 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; |
72f1e62a | 34 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
b4f71e4a | 35 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
9b749023 | 36 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
6c13869b | 37 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
a51b2b9f AM |
38 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
39 | import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; | |
6c13869b | 40 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; |
3bd46eef AM |
41 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
42 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
6c13869b | 43 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
0316808c | 44 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
6c13869b | 45 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc | 46 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
cb8c854e | 47 | import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; |
9e0640dc | 48 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; |
4918b8f2 | 49 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
6e1886bc AM |
50 | import org.junit.Before; |
51 | import org.junit.Test; | |
d18dd09b ASL |
52 | |
53 | /** | |
0316808c | 54 | * Test suite for the TmfExperiment class (single trace). |
d18dd09b | 55 | */ |
cad06250 | 56 | @SuppressWarnings("javadoc") |
6e1886bc | 57 | public class TmfExperimentTest { |
d18dd09b | 58 | |
0316808c FC |
59 | // ------------------------------------------------------------------------ |
60 | // Attributes | |
61 | // ------------------------------------------------------------------------ | |
62 | ||
d18dd09b ASL |
63 | private static final String DIRECTORY = "testfiles"; |
64 | private static final String TEST_STREAM = "A-Test-10K"; | |
65 | private static final String EXPERIMENT = "MyExperiment"; | |
66 | private static int NB_EVENTS = 10000; | |
0316808c | 67 | private static int BLOCK_SIZE = 1000; |
d18dd09b | 68 | |
6e1886bc AM |
69 | private static final double DELTA = 1e-15; |
70 | ||
6256d8ad AM |
71 | private ITmfTrace[] fTestTraces; |
72 | private TmfExperimentStub fExperiment; | |
d18dd09b ASL |
73 | |
74 | private static byte SCALE = (byte) -3; | |
75 | ||
76 | // ------------------------------------------------------------------------ | |
77 | // Housekeeping | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
6256d8ad | 80 | private synchronized ITmfTrace[] setupTrace(final String path) { |
9e0640dc FC |
81 | if (fTestTraces == null) { |
82 | fTestTraces = new ITmfTrace[1]; | |
25e48683 FC |
83 | try { |
84 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); | |
85 | final File test = new File(FileLocator.toFileURL(location).toURI()); | |
20658947 | 86 | final TmfTraceStub trace = new TmfTraceStub(test.getPath(), 0, true); |
9e0640dc | 87 | fTestTraces[0] = trace; |
b4f71e4a FC |
88 | } catch (final TmfTraceException e) { |
89 | e.printStackTrace(); | |
25e48683 FC |
90 | } catch (final URISyntaxException e) { |
91 | e.printStackTrace(); | |
92 | } catch (final IOException e) { | |
93 | e.printStackTrace(); | |
94 | } | |
95 | } | |
9e0640dc | 96 | return fTestTraces; |
d18dd09b ASL |
97 | } |
98 | ||
9e0640dc | 99 | private synchronized void setupExperiment() { |
20658947 | 100 | if (fExperiment == null) { |
6256d8ad | 101 | fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE); |
9e0640dc | 102 | fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); |
20658947 | 103 | } |
d18dd09b ASL |
104 | } |
105 | ||
6e1886bc AM |
106 | @Before |
107 | public void setUp() { | |
25e48683 FC |
108 | setupTrace(DIRECTORY + File.separator + TEST_STREAM); |
109 | setupExperiment(); | |
110 | } | |
d18dd09b | 111 | |
d18dd09b ASL |
112 | // ------------------------------------------------------------------------ |
113 | // Constructor | |
114 | // ------------------------------------------------------------------------ | |
115 | ||
6e1886bc | 116 | @Test |
9e0640dc | 117 | public void testSimpleTmfExperimentConstructor() { |
2771b032 | 118 | TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, fTestTraces); |
9e0640dc FC |
119 | assertEquals("GetId", EXPERIMENT, experiment.getName()); |
120 | assertEquals("GetCacheSize", TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, experiment.getCacheSize()); | |
121 | experiment.dispose(); | |
122 | ||
2771b032 | 123 | experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, null); |
9e0640dc FC |
124 | experiment.dispose(); |
125 | } | |
126 | ||
6e1886bc | 127 | @Test |
9e0640dc | 128 | public void testNormalTmfExperimentConstructor() { |
25e48683 | 129 | assertEquals("GetId", EXPERIMENT, fExperiment.getName()); |
d18dd09b ASL |
130 | assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); |
131 | ||
07671572 FC |
132 | final long nbExperimentEvents = fExperiment.getNbEvents(); |
133 | assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents); | |
134 | ||
25e48683 | 135 | final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents(); |
82e04272 FC |
136 | assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents); |
137 | ||
25e48683 | 138 | final TmfTimeRange timeRange = fExperiment.getTimeRange(); |
d18dd09b ASL |
139 | assertEquals("getStartTime", 1, timeRange.getStartTime().getValue()); |
140 | assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue()); | |
25e48683 | 141 | } |
d18dd09b | 142 | |
9e0640dc FC |
143 | // ------------------------------------------------------------------------ |
144 | // getTimestamp | |
145 | // ------------------------------------------------------------------------ | |
146 | ||
6e1886bc | 147 | @Test |
54a7a54c | 148 | public void testGetTimestamp() { |
17324c9a FC |
149 | assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); |
150 | assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); | |
151 | assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment.getTimestamp( 10)); | |
152 | assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment.getTimestamp( 100)); | |
153 | assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp(1000)); | |
154 | assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp(2000)); | |
155 | assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp(2500)); | |
156 | assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp(9999)); | |
9e0640dc FC |
157 | assertNull("getTimestamp", fExperiment.getTimestamp(10000)); |
158 | } | |
159 | ||
160 | // ------------------------------------------------------------------------ | |
161 | // Bookmarks file handling | |
162 | // ------------------------------------------------------------------------ | |
163 | ||
6e1886bc | 164 | @Test |
54a7a54c | 165 | public void testBookmarks() { |
9e0640dc | 166 | assertNull("GetBookmarksFile", fExperiment.getBookmarksFile()); |
9e0640dc FC |
167 | IFile bookmarks = (IFile) fTestTraces[0].getResource(); |
168 | fExperiment.setBookmarksFile(bookmarks); | |
169 | assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile()); | |
170 | } | |
171 | ||
a51b2b9f AM |
172 | // ------------------------------------------------------------------------ |
173 | // State system and statistics methods | |
174 | // ------------------------------------------------------------------------ | |
175 | ||
6e1886bc | 176 | @Test |
a51b2b9f AM |
177 | public void testGetStatistics() { |
178 | /* There should not be any experiment-specific statistics */ | |
179 | ITmfStatistics stats = fExperiment.getStatistics(); | |
180 | assertNull(stats); | |
181 | } | |
182 | ||
6e1886bc | 183 | @Test |
a51b2b9f AM |
184 | public void testGetStateSystem() { |
185 | /* There should not be any experiment-specific state system */ | |
35c160d9 | 186 | ITmfStateSystem ss = fExperiment.getStateSystems().get("something"); |
a51b2b9f AM |
187 | assertNull(ss); |
188 | } | |
189 | ||
9e0640dc FC |
190 | // ------------------------------------------------------------------------ |
191 | // seekEvent by location | |
192 | // ------------------------------------------------------------------------ | |
193 | ||
6e1886bc | 194 | @Test |
54a7a54c | 195 | public void testSeekBadLocation() { |
cb8c854e | 196 | ITmfContext context = fExperiment.seekEvent(new TmfLongLocation(0L)); |
9e0640dc FC |
197 | assertNull("seekEvent", context); |
198 | } | |
199 | ||
6e1886bc | 200 | @Test |
54a7a54c | 201 | public void testSeekNoTrace() { |
2771b032 | 202 | TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, null); |
9e0640dc FC |
203 | ITmfContext context = experiment.seekEvent((TmfExperimentLocation) null); |
204 | assertNull("seekEvent", context); | |
205 | experiment.dispose(); | |
206 | } | |
207 | ||
208 | // ------------------------------------------------------------------------ | |
209 | // seekEvent on ratio | |
210 | // ------------------------------------------------------------------------ | |
211 | ||
6e1886bc | 212 | @Test |
54a7a54c | 213 | public void testSeekEventOnRatio() { |
9e0640dc FC |
214 | // First event |
215 | ITmfContext context = fExperiment.seekEvent(0.0); | |
216 | assertEquals("Context rank", 0, context.getRank()); | |
217 | ITmfEvent event = fExperiment.parseEvent(context); | |
218 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
219 | assertEquals("Context rank", 0, context.getRank()); | |
220 | ||
221 | // Middle event | |
222 | int midTrace = NB_EVENTS / 2; | |
223 | context = fExperiment.seekEvent(0.5); | |
224 | assertEquals("Context rank", midTrace, context.getRank()); | |
225 | event = fExperiment.parseEvent(context); | |
226 | assertEquals("Event timestamp", midTrace + 1, event.getTimestamp().getValue()); | |
227 | assertEquals("Context rank", midTrace, context.getRank()); | |
9b749023 | 228 | |
9e0640dc FC |
229 | // Last event |
230 | context = fExperiment.seekEvent(1.0); | |
231 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
232 | event = fExperiment.parseEvent(context); | |
233 | assertNull("Event timestamp", event); | |
234 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
9b749023 | 235 | |
9e0640dc FC |
236 | // Beyond last event |
237 | context = fExperiment.seekEvent(1.1); | |
238 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
239 | event = fExperiment.parseEvent(context); | |
240 | assertNull("Event timestamp", event); | |
241 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
9b749023 | 242 | |
9e0640dc FC |
243 | // Negative ratio |
244 | context = fExperiment.seekEvent(-0.5); | |
245 | assertEquals("Context rank", 0, context.getRank()); | |
246 | event = fExperiment.parseEvent(context); | |
247 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
248 | assertEquals("Context rank", 0, context.getRank()); | |
249 | } | |
250 | ||
6e1886bc | 251 | @Test |
54a7a54c | 252 | public void testGetLocationRatio() { |
9e0640dc FC |
253 | // First event |
254 | ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); | |
255 | double ratio = fExperiment.getLocationRatio(context.getLocation()); | |
ea271da6 | 256 | assertEquals("getLocationRatio", 0.0, ratio, DELTA); |
9e0640dc FC |
257 | |
258 | // Middle event | |
259 | context = fExperiment.seekEvent(NB_EVENTS / 2); | |
260 | ratio = fExperiment.getLocationRatio(context.getLocation()); | |
ea271da6 | 261 | assertEquals("getLocationRatio", (double) (NB_EVENTS / 2) / NB_EVENTS, ratio, DELTA); |
9e0640dc FC |
262 | |
263 | // Last event | |
264 | context = fExperiment.seekEvent(NB_EVENTS - 1); | |
265 | ratio = fExperiment.getLocationRatio(context.getLocation()); | |
ea271da6 | 266 | assertEquals("getLocationRatio", (double) (NB_EVENTS - 1) / NB_EVENTS, ratio, DELTA); |
9e0640dc FC |
267 | } |
268 | ||
17324c9a | 269 | // @SuppressWarnings("rawtypes") |
54a7a54c | 270 | // public void testGetCurrentLocation() { |
9e0640dc FC |
271 | // ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); |
272 | // ITmfLocation location = fExperiment.getCurrentLocation(); | |
273 | // assertEquals("getCurrentLocation", location, context.getLocation()); | |
274 | // } | |
275 | ||
d18dd09b | 276 | // ------------------------------------------------------------------------ |
0316808c | 277 | // seekEvent on rank |
d18dd09b ASL |
278 | // ------------------------------------------------------------------------ |
279 | ||
6e1886bc | 280 | @Test |
54a7a54c | 281 | public void testSeekRankOnCacheBoundary() { |
0316808c | 282 | long cacheSize = fExperiment.getCacheSize(); |
9b635e61 | 283 | |
0316808c FC |
284 | // On lower bound, returns the first event (TS = 1) |
285 | ITmfContext context = fExperiment.seekEvent(0); | |
286 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 287 | |
c32744d6 | 288 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 289 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 290 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 291 | |
0316808c FC |
292 | // Position trace at event rank [cacheSize] |
293 | context = fExperiment.seekEvent(cacheSize); | |
294 | assertEquals("Context rank", cacheSize, context.getRank()); | |
25e48683 | 295 | |
c32744d6 | 296 | event = fExperiment.getNext(context); |
0316808c FC |
297 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
298 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
d18dd09b | 299 | |
0316808c FC |
300 | // Position trace at event rank [4 * cacheSize] |
301 | context = fExperiment.seekEvent(4 * cacheSize); | |
302 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 303 | |
c32744d6 | 304 | event = fExperiment.getNext(context); |
0316808c FC |
305 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
306 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
d18dd09b ASL |
307 | } |
308 | ||
6e1886bc | 309 | @Test |
54a7a54c | 310 | public void testSeekRankNotOnCacheBoundary() { |
0316808c | 311 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 312 | |
0316808c FC |
313 | // Position trace at event rank 9 |
314 | ITmfContext context = fExperiment.seekEvent(9); | |
315 | assertEquals("Context rank", 9, context.getRank()); | |
25e48683 | 316 | |
c32744d6 | 317 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 318 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 319 | assertEquals("Context rank", 10, context.getRank()); |
d18dd09b | 320 | |
0316808c FC |
321 | // Position trace at event rank [cacheSize - 1] |
322 | context = fExperiment.seekEvent(cacheSize - 1); | |
323 | assertEquals("Context rank", cacheSize - 1, context.getRank()); | |
25e48683 | 324 | |
c32744d6 | 325 | event = fExperiment.getNext(context); |
0316808c FC |
326 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
327 | assertEquals("Context rank", cacheSize, context.getRank()); | |
d18dd09b | 328 | |
0316808c FC |
329 | // Position trace at event rank [cacheSize + 1] |
330 | context = fExperiment.seekEvent(cacheSize + 1); | |
331 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
25e48683 | 332 | |
c32744d6 | 333 | event = fExperiment.getNext(context); |
0316808c FC |
334 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
335 | assertEquals("Context rank", cacheSize + 2, context.getRank()); | |
d18dd09b | 336 | |
25e48683 | 337 | // Position trace at event rank 4500 |
0316808c FC |
338 | context = fExperiment.seekEvent(4500); |
339 | assertEquals("Context rank", 4500, context.getRank()); | |
25e48683 | 340 | |
c32744d6 | 341 | event = fExperiment.getNext(context); |
d18dd09b | 342 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 343 | assertEquals("Context rank", 4501, context.getRank()); |
d18dd09b ASL |
344 | } |
345 | ||
6e1886bc | 346 | @Test |
54a7a54c | 347 | public void testSeekRankOutOfScope() { |
25e48683 | 348 | // Position trace at beginning |
0316808c | 349 | ITmfContext context = fExperiment.seekEvent(-1); |
9b635e61 | 350 | assertEquals("Event rank", 0, context.getRank()); |
25e48683 | 351 | |
c32744d6 | 352 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 353 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 354 | assertEquals("Context rank", 1, context.getRank()); |
d18dd09b | 355 | |
25e48683 | 356 | // Position trace at event passed the end |
0316808c FC |
357 | context = fExperiment.seekEvent(NB_EVENTS); |
358 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
359 | ||
c32744d6 | 360 | event = fExperiment.getNext(context); |
0316808c FC |
361 | assertNull("Event", event); |
362 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
d18dd09b ASL |
363 | } |
364 | ||
365 | // ------------------------------------------------------------------------ | |
366 | // seekEvent on timestamp | |
367 | // ------------------------------------------------------------------------ | |
368 | ||
6e1886bc | 369 | @Test |
54a7a54c | 370 | public void testSeekTimestampOnCacheBoundary() { |
0316808c | 371 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 372 | |
0316808c FC |
373 | // Position trace at event rank 0 |
374 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); | |
375 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 376 | |
c32744d6 | 377 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 378 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 379 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 380 | |
0316808c FC |
381 | // Position trace at event rank [cacheSize] |
382 | context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0)); | |
383 | assertEquals("Event rank", cacheSize, context.getRank()); | |
25e48683 | 384 | |
c32744d6 | 385 | event = fExperiment.getNext(context); |
0316808c FC |
386 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
387 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
d18dd09b | 388 | |
0316808c FC |
389 | // Position trace at event rank [4 * cacheSize] |
390 | context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0)); | |
391 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 392 | |
c32744d6 | 393 | event = fExperiment.getNext(context); |
0316808c FC |
394 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
395 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
d18dd09b ASL |
396 | } |
397 | ||
6e1886bc | 398 | @Test |
54a7a54c | 399 | public void testSeekTimestampNotOnCacheBoundary() { |
0316808c FC |
400 | // Position trace at event rank 1 (TS = 2) |
401 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); | |
402 | assertEquals("Context rank", 1, context.getRank()); | |
25e48683 | 403 | |
c32744d6 | 404 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 405 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
0316808c | 406 | assertEquals("Context rank", 2, context.getRank()); |
d18dd09b | 407 | |
0316808c | 408 | // Position trace at event rank 9 (TS = 10) |
25e48683 | 409 | context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
0316808c | 410 | assertEquals("Context rank", 9, context.getRank()); |
25e48683 | 411 | |
c32744d6 | 412 | event = fExperiment.getNext(context); |
d18dd09b | 413 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 414 | assertEquals("Context rank", 10, context.getRank()); |
d18dd09b | 415 | |
0316808c | 416 | // Position trace at event rank 999 (TS = 1000) |
d18dd09b | 417 | context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
0316808c | 418 | assertEquals("Context rank", 999, context.getRank()); |
25e48683 | 419 | |
c32744d6 | 420 | event = fExperiment.getNext(context); |
d18dd09b | 421 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
0316808c | 422 | assertEquals("Context rank", 1000, context.getRank()); |
d18dd09b | 423 | |
0316808c | 424 | // Position trace at event rank 1001 (TS = 1002) |
d18dd09b | 425 | context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
0316808c | 426 | assertEquals("Context rank", 1001, context.getRank()); |
25e48683 | 427 | |
c32744d6 | 428 | event = fExperiment.getNext(context); |
d18dd09b | 429 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
0316808c | 430 | assertEquals("Context rank", 1002, context.getRank()); |
d18dd09b | 431 | |
0316808c | 432 | // Position trace at event rank 4500 (TS = 4501) |
d18dd09b | 433 | context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
0316808c | 434 | assertEquals("Context rank", 4500, context.getRank()); |
25e48683 | 435 | |
c32744d6 | 436 | event = fExperiment.getNext(context); |
d18dd09b | 437 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 438 | assertEquals("Context rank", 4501, context.getRank()); |
d18dd09b ASL |
439 | } |
440 | ||
6e1886bc | 441 | @Test |
54a7a54c | 442 | public void testSeekTimestampOutOfScope() { |
25e48683 | 443 | // Position trace at beginning |
0316808c | 444 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); |
d18dd09b | 445 | assertEquals("Event rank", 0, context.getRank()); |
25e48683 | 446 | |
c32744d6 | 447 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b ASL |
448 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
449 | assertEquals("Event rank", 1, context.getRank()); | |
450 | ||
25e48683 | 451 | // Position trace at event passed the end |
d18dd09b | 452 | context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
c32744d6 | 453 | event = fExperiment.getNext(context); |
0316808c | 454 | assertNull("Event location", event); |
9b635e61 | 455 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
d18dd09b ASL |
456 | } |
457 | ||
458 | // ------------------------------------------------------------------------ | |
0316808c | 459 | // seekEvent by location (context rank is undefined) |
d18dd09b ASL |
460 | // ------------------------------------------------------------------------ |
461 | ||
6e1886bc | 462 | @Test |
54a7a54c | 463 | public void testSeekLocationOnCacheBoundary() { |
0316808c | 464 | long cacheSize = fExperiment.getCacheSize(); |
d18dd09b | 465 | |
0316808c FC |
466 | // Position trace at event rank 0 |
467 | ITmfContext tmpContext = fExperiment.seekEvent(0); | |
468 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 469 | |
c32744d6 | 470 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 471 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
25e48683 | 472 | |
c32744d6 | 473 | event = fExperiment.getNext(context); |
0316808c | 474 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
d18dd09b | 475 | |
0316808c FC |
476 | // Position trace at event rank 'cacheSize' |
477 | tmpContext = fExperiment.seekEvent(cacheSize); | |
478 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 479 | |
c32744d6 | 480 | event = fExperiment.getNext(context); |
0316808c | 481 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 482 | |
c32744d6 | 483 | event = fExperiment.getNext(context); |
0316808c | 484 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
d18dd09b | 485 | |
0316808c FC |
486 | // Position trace at event rank 4 * 'cacheSize' |
487 | tmpContext = fExperiment.seekEvent(4 * cacheSize); | |
488 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 489 | |
c32744d6 | 490 | event = fExperiment.getNext(context); |
0316808c | 491 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 492 | |
c32744d6 | 493 | event = fExperiment.getNext(context); |
0316808c | 494 | assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); |
d18dd09b ASL |
495 | } |
496 | ||
6e1886bc | 497 | @Test |
54a7a54c | 498 | public void testSeekLocationNotOnCacheBoundary() { |
0316808c | 499 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 500 | |
0316808c FC |
501 | // Position trace at event 'cacheSize' - 1 |
502 | ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1); | |
503 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
d18dd09b | 504 | |
c32744d6 | 505 | ITmfEvent event = fExperiment.getNext(context); |
0316808c | 506 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
25e48683 | 507 | |
c32744d6 | 508 | event = fExperiment.getNext(context); |
0316808c | 509 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
d18dd09b | 510 | |
0316808c FC |
511 | // Position trace at event rank 2 * 'cacheSize' - 1 |
512 | tmpContext = fExperiment.seekEvent(2 * cacheSize - 1); | |
513 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
514 | context = fExperiment.seekEvent(2 * cacheSize - 1); | |
25e48683 | 515 | |
c32744d6 | 516 | event = fExperiment.getNext(context); |
0316808c | 517 | assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue()); |
25e48683 | 518 | |
c32744d6 | 519 | event = fExperiment.getNext(context); |
0316808c | 520 | assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue()); |
d18dd09b | 521 | |
25e48683 | 522 | // Position trace at event rank 4500 |
0316808c FC |
523 | tmpContext = fExperiment.seekEvent(4500); |
524 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 525 | |
c32744d6 | 526 | event = fExperiment.getNext(context); |
d18dd09b | 527 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
25e48683 | 528 | |
c32744d6 | 529 | event = fExperiment.getNext(context); |
0316808c | 530 | assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); |
d18dd09b ASL |
531 | } |
532 | ||
6e1886bc | 533 | @Test |
54a7a54c | 534 | public void testSeekLocationOutOfScope() { |
25e48683 | 535 | // Position trace at beginning |
1e1bef82 | 536 | ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); |
25e48683 | 537 | |
c32744d6 | 538 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 539 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
d18dd09b | 540 | } |
25e48683 | 541 | |
9b635e61 | 542 | // ------------------------------------------------------------------------ |
17324c9a | 543 | // getNext - updates the context |
9b635e61 FC |
544 | // ------------------------------------------------------------------------ |
545 | ||
54a7a54c | 546 | private static void validateContextRanks(ITmfContext context) { |
17324c9a FC |
547 | assertTrue("Experiment context type", context instanceof TmfExperimentContext); |
548 | TmfExperimentContext ctx = (TmfExperimentContext) context; | |
9b635e61 | 549 | |
17324c9a FC |
550 | int nbTraces = ctx.getContexts().length; |
551 | ||
552 | // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE) | |
553 | long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0); | |
554 | for (int i = 0; i < nbTraces; i++) { | |
555 | long rank = ctx.getContexts()[i].getRank(); | |
556 | if (rank == -1) { | |
557 | expRank = -1; | |
558 | break; | |
559 | } | |
560 | expRank += rank; | |
561 | } | |
562 | assertEquals("Experiment context rank", expRank, ctx.getRank()); | |
563 | } | |
564 | ||
6e1886bc | 565 | @Test |
54a7a54c | 566 | public void testGetNextAfteSeekingOnTS_1() { |
9b635e61 | 567 | |
17324c9a FC |
568 | final long INITIAL_TS = 1; |
569 | final int NB_READS = 20; | |
570 | ||
571 | // On lower bound, returns the first event (ts = 1) | |
572 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
573 | ||
574 | validateContextRanks(context); | |
575 | ||
576 | // Read NB_EVENTS | |
577 | ITmfEvent event; | |
578 | for (int i = 0; i < NB_READS; i++) { | |
c32744d6 | 579 | event = fExperiment.getNext(context); |
17324c9a FC |
580 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
581 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
9b635e61 | 582 | } |
17324c9a FC |
583 | |
584 | // Make sure we stay positioned | |
585 | event = fExperiment.parseEvent(context); | |
586 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
587 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
588 | ||
589 | validateContextRanks(context); | |
9b635e61 FC |
590 | } |
591 | ||
6e1886bc | 592 | @Test |
54a7a54c | 593 | public void testGetNextAfteSeekingOnTS_2() { |
17324c9a FC |
594 | final long INITIAL_TS = 2; |
595 | final int NB_READS = 20; | |
596 | ||
597 | // On lower bound, returns the first event (ts = 2) | |
598 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
599 | ||
600 | validateContextRanks(context); | |
601 | ||
602 | // Read NB_EVENTS | |
603 | ITmfEvent event; | |
604 | for (int i = 0; i < NB_READS; i++) { | |
605 | event = fExperiment.getNext(context); | |
606 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
607 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
608 | } | |
609 | ||
610 | // Make sure we stay positioned | |
611 | event = fExperiment.parseEvent(context); | |
612 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
613 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
614 | ||
615 | validateContextRanks(context); | |
616 | } | |
617 | ||
6e1886bc | 618 | @Test |
54a7a54c | 619 | public void testGetNextAfteSeekingOnTS_3() { |
17324c9a FC |
620 | |
621 | final long INITIAL_TS = 500; | |
622 | final int NB_READS = 20; | |
623 | ||
624 | // On lower bound, returns the first event (ts = 500) | |
625 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
626 | ||
627 | validateContextRanks(context); | |
628 | ||
629 | // Read NB_EVENTS | |
630 | ITmfEvent event; | |
631 | for (int i = 0; i < NB_READS; i++) { | |
632 | event = fExperiment.getNext(context); | |
633 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
634 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
635 | } | |
636 | ||
637 | // Make sure we stay positioned | |
638 | event = fExperiment.parseEvent(context); | |
639 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
640 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
641 | ||
642 | validateContextRanks(context); | |
643 | } | |
644 | ||
6e1886bc | 645 | @Test |
54a7a54c | 646 | public void testGetNextAfterSeekingOnRank_1() { |
17324c9a FC |
647 | final long INITIAL_RANK = 0L; |
648 | final int NB_READS = 20; | |
649 | ||
650 | // On lower bound, returns the first event (rank = 0) | |
651 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
652 | ||
653 | validateContextRanks(context); | |
654 | ||
655 | // Read NB_EVENTS | |
656 | ITmfEvent event; | |
657 | for (int i = 0; i < NB_READS; i++) { | |
658 | event = fExperiment.getNext(context); | |
659 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
660 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
661 | } | |
662 | ||
663 | // Make sure we stay positioned | |
664 | event = fExperiment.parseEvent(context); | |
665 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
666 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
667 | ||
668 | validateContextRanks(context); | |
669 | } | |
670 | ||
6e1886bc | 671 | @Test |
54a7a54c | 672 | public void testGetNextAfterSeekingOnRank_2() { |
17324c9a FC |
673 | final long INITIAL_RANK = 1L; |
674 | final int NB_READS = 20; | |
675 | ||
676 | // On lower bound, returns the first event (rank = 0) | |
677 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
678 | ||
679 | validateContextRanks(context); | |
680 | ||
681 | // Read NB_EVENTS | |
682 | ITmfEvent event; | |
683 | for (int i = 0; i < NB_READS; i++) { | |
684 | event = fExperiment.getNext(context); | |
685 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
686 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
687 | } | |
688 | ||
689 | // Make sure we stay positioned | |
690 | event = fExperiment.parseEvent(context); | |
691 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
692 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
693 | ||
694 | validateContextRanks(context); | |
695 | } | |
696 | ||
6e1886bc | 697 | @Test |
54a7a54c | 698 | public void testGetNextAfterSeekingOnRank_3() { |
17324c9a FC |
699 | final long INITIAL_RANK = 500L; |
700 | final int NB_READS = 20; | |
701 | ||
702 | // On lower bound, returns the first event (rank = 0) | |
703 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
704 | ||
705 | validateContextRanks(context); | |
706 | ||
707 | // Read NB_EVENTS | |
708 | ITmfEvent event; | |
709 | for (int i = 0; i < NB_READS; i++) { | |
710 | event = fExperiment.getNext(context); | |
711 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
712 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
713 | } | |
714 | ||
715 | // Make sure we stay positioned | |
716 | event = fExperiment.parseEvent(context); | |
717 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
718 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
719 | ||
720 | validateContextRanks(context); | |
721 | } | |
722 | ||
6e1886bc | 723 | @Test |
54a7a54c | 724 | public void testGetNextAfterSeekingOnLocation_1() { |
1e1bef82 | 725 | final ITmfLocation INITIAL_LOC = null; |
17324c9a FC |
726 | final long INITIAL_TS = 1; |
727 | final int NB_READS = 20; | |
728 | ||
729 | // On lower bound, returns the first event (ts = 1) | |
730 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
731 | ||
732 | validateContextRanks(context); | |
733 | ||
734 | // Read NB_EVENTS | |
735 | ITmfEvent event; | |
736 | for (int i = 0; i < NB_READS; i++) { | |
737 | event = fExperiment.getNext(context); | |
738 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
739 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
740 | } | |
741 | ||
742 | // Make sure we stay positioned | |
743 | event = fExperiment.parseEvent(context); | |
744 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
745 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
746 | ||
747 | validateContextRanks(context); | |
748 | } | |
749 | ||
6e1886bc | 750 | @Test |
54a7a54c | 751 | public void testGetNextAfterSeekingOnLocation_2() { |
1e1bef82 | 752 | final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); |
17324c9a FC |
753 | final long INITIAL_TS = 2; |
754 | final int NB_READS = 20; | |
755 | ||
756 | // On lower bound, returns the first event (ts = 2) | |
757 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
758 | ||
759 | validateContextRanks(context); | |
760 | ||
761 | // Read NB_EVENTS | |
762 | ITmfEvent event; | |
763 | for (int i = 0; i < NB_READS; i++) { | |
764 | event = fExperiment.getNext(context); | |
765 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
766 | } | |
767 | ||
768 | // Make sure we stay positioned | |
769 | event = fExperiment.parseEvent(context); | |
770 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
771 | ||
772 | validateContextRanks(context); | |
773 | } | |
774 | ||
6e1886bc | 775 | @Test |
54a7a54c | 776 | public void testGetNextAfterSeekingOnLocation_3() { |
1e1bef82 | 777 | final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); |
17324c9a FC |
778 | final long INITIAL_TS = 501; |
779 | final int NB_READS = 20; | |
780 | ||
781 | // On lower bound, returns the first event (ts = 501) | |
782 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
783 | ||
784 | validateContextRanks(context); | |
785 | ||
786 | // Read NB_EVENTS | |
787 | ITmfEvent event; | |
788 | for (int i = 0; i < NB_READS; i++) { | |
789 | event = fExperiment.getNext(context); | |
790 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
791 | } | |
792 | ||
793 | // Make sure we stay positioned | |
794 | event = fExperiment.parseEvent(context); | |
795 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
796 | ||
797 | validateContextRanks(context); | |
798 | } | |
799 | ||
6e1886bc | 800 | @Test |
54a7a54c | 801 | public void testGetNextLocation() { |
17324c9a FC |
802 | ITmfContext context1 = fExperiment.seekEvent(0); |
803 | fExperiment.getNext(context1); | |
d62bb185 | 804 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
805 | ITmfEvent event1 = fExperiment.getNext(context1); |
806 | ITmfContext context2 = fExperiment.seekEvent(location); | |
807 | ITmfEvent event2 = fExperiment.getNext(context2); | |
808 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); | |
809 | } | |
810 | ||
6e1886bc | 811 | @Test |
54a7a54c | 812 | public void testGetNextEndLocation() { |
17324c9a FC |
813 | ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); |
814 | fExperiment.getNext(context1); | |
d62bb185 | 815 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
816 | ITmfContext context2 = fExperiment.seekEvent(location); |
817 | ITmfEvent event = fExperiment.getNext(context2); | |
818 | assertNull("Event", event); | |
819 | } | |
54a7a54c | 820 | |
d18dd09b ASL |
821 | // ------------------------------------------------------------------------ |
822 | // processRequest | |
823 | // ------------------------------------------------------------------------ | |
824 | ||
6e1886bc | 825 | @Test |
54a7a54c | 826 | public void testProcessRequestForNbEvents() throws InterruptedException { |
25e48683 | 827 | final int blockSize = 100; |
d18dd09b | 828 | final int nbEvents = 1000; |
6256d8ad | 829 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 830 | |
25e48683 | 831 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
2771b032 | 832 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
d18dd09b | 833 | @Override |
6256d8ad | 834 | public void handleData(final ITmfEvent event) { |
25e48683 | 835 | super.handleData(event); |
f9673903 | 836 | requestedEvents.add(event); |
d18dd09b ASL |
837 | } |
838 | }; | |
839 | fExperiment.sendRequest(request); | |
840 | request.waitForCompletion(); | |
841 | ||
842 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); | |
843 | assertTrue("isCompleted", request.isCompleted()); | |
844 | assertFalse("isCancelled", request.isCancelled()); | |
845 | ||
846 | // Ensure that we have distinct events. | |
25e48683 | 847 | // Don't go overboard: we are not validating the stub! |
20658947 | 848 | for (int i = 0; i < nbEvents; i++) { |
d18dd09b | 849 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 850 | } |
d18dd09b | 851 | } |
25e48683 | 852 | |
6e1886bc | 853 | @Test |
54a7a54c | 854 | public void testProcessRequestForNbEvents2() throws InterruptedException { |
25e48683 | 855 | final int blockSize = 2 * NB_EVENTS; |
d18dd09b | 856 | final int nbEvents = 1000; |
6256d8ad | 857 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 858 | |
25e48683 | 859 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
2771b032 | 860 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
25e48683 | 861 | @Override |
6256d8ad | 862 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
863 | super.handleData(event); |
864 | requestedEvents.add(event); | |
865 | } | |
d18dd09b ASL |
866 | }; |
867 | fExperiment.sendRequest(request); | |
868 | request.waitForCompletion(); | |
869 | ||
870 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); | |
871 | assertTrue("isCompleted", request.isCompleted()); | |
872 | assertFalse("isCancelled", request.isCancelled()); | |
873 | ||
874 | // Ensure that we have distinct events. | |
25e48683 | 875 | // Don't go overboard: we are not validating the stub! |
20658947 | 876 | for (int i = 0; i < nbEvents; i++) { |
d18dd09b | 877 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 878 | } |
d18dd09b | 879 | } |
25e48683 | 880 | |
6e1886bc | 881 | @Test |
54a7a54c | 882 | public void testProcessRequestForAllEvents() throws InterruptedException { |
9b749023 | 883 | final int nbEvents = TmfDataRequest.ALL_DATA; |
d18dd09b | 884 | final int blockSize = 1; |
6256d8ad | 885 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
25e48683 | 886 | final long nbExpectedEvents = NB_EVENTS; |
d18dd09b | 887 | |
25e48683 | 888 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
2771b032 | 889 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
25e48683 | 890 | @Override |
6256d8ad | 891 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
892 | super.handleData(event); |
893 | requestedEvents.add(event); | |
894 | } | |
d18dd09b ASL |
895 | }; |
896 | fExperiment.sendRequest(request); | |
897 | request.waitForCompletion(); | |
898 | ||
899 | assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size()); | |
900 | assertTrue("isCompleted", request.isCompleted()); | |
901 | assertFalse("isCancelled", request.isCancelled()); | |
902 | ||
903 | // Ensure that we have distinct events. | |
25e48683 | 904 | // Don't go overboard: we are not validating the stub! |
20658947 | 905 | for (int i = 0; i < nbExpectedEvents; i++) { |
d18dd09b | 906 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 907 | } |
d18dd09b | 908 | } |
25e48683 | 909 | |
d18dd09b ASL |
910 | // ------------------------------------------------------------------------ |
911 | // cancel | |
912 | // ------------------------------------------------------------------------ | |
913 | ||
6e1886bc | 914 | @Test |
54a7a54c | 915 | public void testCancel() throws InterruptedException { |
25e48683 | 916 | final int nbEvents = NB_EVENTS; |
0316808c | 917 | final int blockSize = BLOCK_SIZE; |
6256d8ad | 918 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 919 | |
25e48683 | 920 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
2771b032 | 921 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
25e48683 FC |
922 | int nbRead = 0; |
923 | @Override | |
6256d8ad | 924 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
925 | super.handleData(event); |
926 | requestedEvents.add(event); | |
20658947 | 927 | if (++nbRead == blockSize) { |
25e48683 | 928 | cancel(); |
20658947 | 929 | } |
25e48683 | 930 | } |
cb866e08 FC |
931 | @Override |
932 | public void handleCancel() { | |
20658947 | 933 | if (requestedEvents.size() < blockSize) { |
25e48683 | 934 | System.out.println("aie"); |
20658947 | 935 | } |
cb866e08 | 936 | } |
d18dd09b ASL |
937 | }; |
938 | fExperiment.sendRequest(request); | |
939 | request.waitForCompletion(); | |
940 | ||
941 | assertEquals("nbEvents", blockSize, requestedEvents.size()); | |
942 | assertTrue("isCompleted", request.isCompleted()); | |
943 | assertTrue("isCancelled", request.isCancelled()); | |
944 | } | |
25e48683 | 945 | |
17324c9a | 946 | } |