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