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