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