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