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