Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2013 Ericsson |
9b749023 | 3 | * |
d18dd09b ASL |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
9b749023 | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Adjusted for new Trace Model |
6e1886bc | 12 | * Alexandre Montplaisir - Port to JUnit4 |
850a3ae2 | 13 | * Patrick Tasse - Fix for concurrency |
d18dd09b ASL |
14 | *******************************************************************************/ |
15 | ||
9e0640dc | 16 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b | 17 | |
6e1886bc AM |
18 | import static org.junit.Assert.assertEquals; |
19 | import static org.junit.Assert.assertFalse; | |
20 | import static org.junit.Assert.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 | ||
d18dd09b ASL |
29 | import org.eclipse.core.runtime.FileLocator; |
30 | import org.eclipse.core.runtime.Path; | |
17324c9a | 31 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; |
72f1e62a | 32 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
b4f71e4a | 33 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
2740e05c | 34 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; |
fd3f1eff | 35 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; |
6c13869b FC |
36 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
37 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; | |
9c4d52ee | 38 | import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; |
3bd46eef AM |
39 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
40 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
41 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
6c13869b FC |
42 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
43 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
a3db8436 | 44 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; |
9e0640dc | 45 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; |
4918b8f2 | 46 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
850a3ae2 PT |
47 | import org.junit.AfterClass; |
48 | import org.junit.BeforeClass; | |
6e1886bc | 49 | import org.junit.Test; |
d18dd09b ASL |
50 | |
51 | /** | |
0316808c | 52 | * Test suite for the TmfExperiment class (multiple traces). |
d18dd09b | 53 | */ |
cad06250 | 54 | @SuppressWarnings("javadoc") |
6e1886bc | 55 | public class TmfMultiTraceExperimentTest { |
d18dd09b | 56 | |
0316808c FC |
57 | // ------------------------------------------------------------------------ |
58 | // Attributes | |
59 | // ------------------------------------------------------------------------ | |
6e1886bc | 60 | |
66262ad8 | 61 | private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec |
d18dd09b ASL |
62 | private static final String EXPERIMENT = "MyExperiment"; |
63 | private static int NB_EVENTS = 20000; | |
9b635e61 | 64 | private static int BLOCK_SIZE = 1000; |
d18dd09b | 65 | |
6256d8ad | 66 | private static TmfExperimentStub fExperiment; |
d18dd09b ASL |
67 | |
68 | private static byte SCALE = (byte) -3; | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Housekeeping | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
850a3ae2 PT |
74 | @BeforeClass |
75 | public static void setUp() { | |
76 | ITmfTrace[] traces = setupTraces(); | |
77 | fExperiment = new TmfExperimentStub(EXPERIMENT, traces, BLOCK_SIZE); | |
78 | fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); | |
6e1886bc AM |
79 | } |
80 | ||
850a3ae2 PT |
81 | @AfterClass |
82 | public static void tearDown() { | |
83 | fExperiment.dispose(); | |
84 | } | |
85 | ||
86 | private static ITmfTrace[] setupTraces() { | |
850a3ae2 PT |
87 | try { |
88 | ITmfTrace[] traces = new ITmfTrace[2]; | |
89 | ||
9c4d52ee | 90 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TmfTestTrace.O_TEST_10K.getFullPath()), null); |
850a3ae2 | 91 | File test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 92 | final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null); |
850a3ae2 PT |
93 | traces[0] = trace1; |
94 | ||
9c4d52ee | 95 | location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TmfTestTrace.E_TEST_10K.getFullPath()), null); |
850a3ae2 | 96 | test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 97 | final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null); |
850a3ae2 PT |
98 | traces[1] = trace2; |
99 | ||
100 | return traces; | |
101 | } catch (final TmfTraceException e) { | |
102 | e.printStackTrace(); | |
103 | } catch (final URISyntaxException e) { | |
104 | e.printStackTrace(); | |
105 | } catch (final IOException e) { | |
106 | e.printStackTrace(); | |
25e48683 | 107 | } |
850a3ae2 | 108 | return new ITmfTrace[0]; |
d18dd09b ASL |
109 | } |
110 | ||
d18dd09b ASL |
111 | // ------------------------------------------------------------------------ |
112 | // Constructor | |
113 | // ------------------------------------------------------------------------ | |
114 | ||
6e1886bc | 115 | @Test |
25e48683 | 116 | public void testBasicTmfExperimentConstructor() { |
25e48683 | 117 | assertEquals("GetId", EXPERIMENT, fExperiment.getName()); |
d18dd09b ASL |
118 | assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); |
119 | ||
25e48683 | 120 | final TmfTimeRange timeRange = fExperiment.getTimeRange(); |
d18dd09b ASL |
121 | assertEquals("getStartTime", 1, timeRange.getStartTime().getValue()); |
122 | assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue()); | |
66262ad8 | 123 | |
850a3ae2 | 124 | TmfTimestamp initRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE); |
66262ad8 | 125 | assertEquals("getInitialRangeOffset", initRange, fExperiment.getInitialRangeOffset()); |
25e48683 | 126 | } |
d18dd09b | 127 | |
d18dd09b | 128 | // ------------------------------------------------------------------------ |
0316808c | 129 | // seekEvent on rank |
d18dd09b ASL |
130 | // ------------------------------------------------------------------------ |
131 | ||
6e1886bc | 132 | @Test |
54a7a54c | 133 | public void testSeekRankOnCacheBoundary() { |
0316808c | 134 | long cacheSize = fExperiment.getCacheSize(); |
9b635e61 | 135 | |
0316808c FC |
136 | // On lower bound, returns the first event (TS = 1) |
137 | ITmfContext context = fExperiment.seekEvent(0); | |
138 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 139 | |
c32744d6 | 140 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 141 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 142 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 143 | |
0316808c FC |
144 | // Position trace at event rank [cacheSize] |
145 | context = fExperiment.seekEvent(cacheSize); | |
146 | assertEquals("Context rank", cacheSize, context.getRank()); | |
25e48683 | 147 | |
c32744d6 | 148 | event = fExperiment.getNext(context); |
0316808c FC |
149 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
150 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
d18dd09b | 151 | |
0316808c FC |
152 | // Position trace at event rank [4 * cacheSize] |
153 | context = fExperiment.seekEvent(4 * cacheSize); | |
154 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 155 | |
c32744d6 | 156 | event = fExperiment.getNext(context); |
0316808c FC |
157 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
158 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
d18dd09b ASL |
159 | } |
160 | ||
6e1886bc | 161 | @Test |
54a7a54c | 162 | public void testSeekRankNotOnCacheBoundary() { |
0316808c | 163 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 164 | |
0316808c FC |
165 | // Position trace at event rank 9 |
166 | ITmfContext context = fExperiment.seekEvent(9); | |
167 | assertEquals("Context rank", 9, context.getRank()); | |
25e48683 | 168 | |
c32744d6 | 169 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 170 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 171 | assertEquals("Context rank", 10, context.getRank()); |
d18dd09b | 172 | |
0316808c FC |
173 | // Position trace at event rank [cacheSize - 1] |
174 | context = fExperiment.seekEvent(cacheSize - 1); | |
175 | assertEquals("Context rank", cacheSize - 1, context.getRank()); | |
25e48683 | 176 | |
c32744d6 | 177 | event = fExperiment.getNext(context); |
0316808c FC |
178 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
179 | assertEquals("Context rank", cacheSize, context.getRank()); | |
d18dd09b | 180 | |
0316808c FC |
181 | // Position trace at event rank [cacheSize + 1] |
182 | context = fExperiment.seekEvent(cacheSize + 1); | |
183 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
25e48683 | 184 | |
c32744d6 | 185 | event = fExperiment.getNext(context); |
0316808c FC |
186 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
187 | assertEquals("Context rank", cacheSize + 2, context.getRank()); | |
d18dd09b | 188 | |
25e48683 | 189 | // Position trace at event rank 4500 |
0316808c FC |
190 | context = fExperiment.seekEvent(4500); |
191 | assertEquals("Context rank", 4500, context.getRank()); | |
25e48683 | 192 | |
c32744d6 | 193 | event = fExperiment.getNext(context); |
d18dd09b | 194 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 195 | assertEquals("Context rank", 4501, context.getRank()); |
d18dd09b ASL |
196 | } |
197 | ||
6e1886bc | 198 | @Test |
54a7a54c | 199 | public void testSeekRankOutOfScope() { |
25e48683 | 200 | // Position trace at beginning |
0316808c | 201 | ITmfContext context = fExperiment.seekEvent(-1); |
d18dd09b | 202 | assertEquals("Event rank", 0, context.getRank()); |
25e48683 | 203 | |
c32744d6 | 204 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 205 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 206 | assertEquals("Context rank", 1, context.getRank()); |
d18dd09b | 207 | |
25e48683 | 208 | // Position trace at event passed the end |
0316808c FC |
209 | context = fExperiment.seekEvent(NB_EVENTS); |
210 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
211 | ||
c32744d6 | 212 | event = fExperiment.getNext(context); |
0316808c FC |
213 | assertNull("Event", event); |
214 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
d18dd09b ASL |
215 | } |
216 | ||
25e48683 FC |
217 | // ------------------------------------------------------------------------ |
218 | // seekEvent on timestamp | |
219 | // ------------------------------------------------------------------------ | |
220 | ||
6e1886bc | 221 | @Test |
54a7a54c | 222 | public void testSeekTimestampOnCacheBoundary() { |
0316808c | 223 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 224 | |
0316808c FC |
225 | // Position trace at event rank 0 |
226 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); | |
227 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 228 | |
c32744d6 | 229 | ITmfEvent event = fExperiment.getNext(context); |
25e48683 | 230 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 231 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 232 | |
0316808c FC |
233 | // Position trace at event rank [cacheSize] |
234 | context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0)); | |
235 | assertEquals("Event rank", cacheSize, context.getRank()); | |
25e48683 | 236 | |
c32744d6 | 237 | event = fExperiment.getNext(context); |
0316808c FC |
238 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
239 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
25e48683 | 240 | |
0316808c FC |
241 | // Position trace at event rank [4 * cacheSize] |
242 | context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0)); | |
243 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 244 | |
c32744d6 | 245 | event = fExperiment.getNext(context); |
0316808c FC |
246 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
247 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
25e48683 FC |
248 | } |
249 | ||
6e1886bc | 250 | @Test |
54a7a54c | 251 | public void testSeekTimestampNotOnCacheBoundary() { |
0316808c FC |
252 | // Position trace at event rank 1 (TS = 2) |
253 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); | |
254 | assertEquals("Context rank", 1, context.getRank()); | |
25e48683 | 255 | |
c32744d6 | 256 | ITmfEvent event = fExperiment.getNext(context); |
25e48683 | 257 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
0316808c | 258 | assertEquals("Context rank", 2, context.getRank()); |
25e48683 | 259 | |
0316808c | 260 | // Position trace at event rank 9 (TS = 10) |
25e48683 | 261 | context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
0316808c | 262 | assertEquals("Context rank", 9, context.getRank()); |
25e48683 | 263 | |
c32744d6 | 264 | event = fExperiment.getNext(context); |
25e48683 | 265 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 266 | assertEquals("Context rank", 10, context.getRank()); |
25e48683 | 267 | |
0316808c | 268 | // Position trace at event rank 999 (TS = 1000) |
25e48683 | 269 | context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
0316808c | 270 | assertEquals("Context rank", 999, context.getRank()); |
25e48683 | 271 | |
c32744d6 | 272 | event = fExperiment.getNext(context); |
25e48683 | 273 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
0316808c | 274 | assertEquals("Context rank", 1000, context.getRank()); |
25e48683 | 275 | |
0316808c | 276 | // Position trace at event rank 1001 (TS = 1002) |
25e48683 | 277 | context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
0316808c | 278 | assertEquals("Context rank", 1001, context.getRank()); |
25e48683 | 279 | |
c32744d6 | 280 | event = fExperiment.getNext(context); |
25e48683 | 281 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
0316808c | 282 | assertEquals("Context rank", 1002, context.getRank()); |
25e48683 | 283 | |
0316808c | 284 | // Position trace at event rank 4500 (TS = 4501) |
25e48683 | 285 | context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
0316808c | 286 | assertEquals("Context rank", 4500, context.getRank()); |
25e48683 | 287 | |
c32744d6 | 288 | event = fExperiment.getNext(context); |
25e48683 | 289 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 290 | assertEquals("Context rank", 4501, context.getRank()); |
25e48683 FC |
291 | } |
292 | ||
6e1886bc | 293 | @Test |
54a7a54c | 294 | public void testSeekTimestampOutOfScope() { |
25e48683 | 295 | // Position trace at beginning |
0316808c | 296 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); |
25e48683 FC |
297 | assertEquals("Event rank", 0, context.getRank()); |
298 | ||
c32744d6 | 299 | ITmfEvent event = fExperiment.getNext(context); |
25e48683 FC |
300 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
301 | assertEquals("Event rank", 1, context.getRank()); | |
302 | ||
303 | // Position trace at event passed the end | |
304 | context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); | |
c32744d6 | 305 | event = fExperiment.getNext(context); |
0316808c | 306 | assertNull("Event location", event); |
9b635e61 | 307 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
25e48683 FC |
308 | } |
309 | ||
310 | // ------------------------------------------------------------------------ | |
0316808c | 311 | // seekEvent by location (context rank is undefined) |
25e48683 FC |
312 | // ------------------------------------------------------------------------ |
313 | ||
6e1886bc | 314 | @Test |
54a7a54c | 315 | public void testSeekLocationOnCacheBoundary() { |
0316808c | 316 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 317 | |
0316808c FC |
318 | // Position trace at event rank 0 |
319 | ITmfContext tmpContext = fExperiment.seekEvent(0); | |
320 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 321 | |
c32744d6 | 322 | ITmfEvent event = fExperiment.getNext(context); |
25e48683 | 323 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
25e48683 | 324 | |
c32744d6 | 325 | event = fExperiment.getNext(context); |
0316808c | 326 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
25e48683 | 327 | |
0316808c FC |
328 | // Position trace at event rank 'cacheSize' |
329 | tmpContext = fExperiment.seekEvent(cacheSize); | |
330 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 331 | |
c32744d6 | 332 | event = fExperiment.getNext(context); |
0316808c | 333 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 334 | |
c32744d6 | 335 | event = fExperiment.getNext(context); |
0316808c | 336 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
25e48683 | 337 | |
0316808c FC |
338 | // Position trace at event rank 4 * 'cacheSize' |
339 | tmpContext = fExperiment.seekEvent(4 * cacheSize); | |
340 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 341 | |
c32744d6 | 342 | event = fExperiment.getNext(context); |
0316808c | 343 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 344 | |
c32744d6 | 345 | event = fExperiment.getNext(context); |
0316808c | 346 | assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); |
25e48683 FC |
347 | } |
348 | ||
6e1886bc | 349 | @Test |
54a7a54c | 350 | public void testSeekLocationNotOnCacheBoundary() { |
0316808c | 351 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 352 | |
0316808c FC |
353 | // Position trace at event 'cacheSize' - 1 |
354 | ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1); | |
355 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 356 | |
c32744d6 | 357 | ITmfEvent event = fExperiment.getNext(context); |
0316808c | 358 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
25e48683 | 359 | |
c32744d6 | 360 | event = fExperiment.getNext(context); |
0316808c | 361 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 362 | |
0316808c FC |
363 | // Position trace at event rank 2 * 'cacheSize' - 1 |
364 | tmpContext = fExperiment.seekEvent(2 * cacheSize - 1); | |
365 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
366 | context = fExperiment.seekEvent(2 * cacheSize - 1); | |
25e48683 | 367 | |
c32744d6 | 368 | event = fExperiment.getNext(context); |
0316808c | 369 | assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue()); |
25e48683 | 370 | |
c32744d6 | 371 | event = fExperiment.getNext(context); |
0316808c | 372 | assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 FC |
373 | |
374 | // Position trace at event rank 4500 | |
0316808c FC |
375 | tmpContext = fExperiment.seekEvent(4500); |
376 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 377 | |
c32744d6 | 378 | event = fExperiment.getNext(context); |
25e48683 | 379 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
25e48683 | 380 | |
c32744d6 | 381 | event = fExperiment.getNext(context); |
0316808c | 382 | assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); |
25e48683 FC |
383 | } |
384 | ||
6e1886bc | 385 | @Test |
54a7a54c | 386 | public void testSeekLocationOutOfScope() { |
25e48683 | 387 | // Position trace at beginning |
1e1bef82 | 388 | ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); |
25e48683 | 389 | |
c32744d6 | 390 | ITmfEvent event = fExperiment.getNext(context); |
25e48683 | 391 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
25e48683 | 392 | } |
d18dd09b | 393 | |
9b635e61 | 394 | // ------------------------------------------------------------------------ |
17324c9a | 395 | // getNext - updates the context |
9b635e61 | 396 | // ------------------------------------------------------------------------ |
d18dd09b | 397 | |
54a7a54c | 398 | private static void validateContextRanks(ITmfContext context) { |
17324c9a FC |
399 | assertTrue("Experiment context type", context instanceof TmfExperimentContext); |
400 | TmfExperimentContext ctx = (TmfExperimentContext) context; | |
9b635e61 | 401 | |
17324c9a FC |
402 | int nbTraces = ctx.getContexts().length; |
403 | ||
404 | // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE) | |
405 | long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0); | |
406 | for (int i = 0; i < nbTraces; i++) { | |
407 | long rank = ctx.getContexts()[i].getRank(); | |
408 | if (rank == -1) { | |
409 | expRank = -1; | |
410 | break; | |
411 | } | |
412 | expRank += rank; | |
413 | } | |
414 | assertEquals("Experiment context rank", expRank, ctx.getRank()); | |
415 | } | |
416 | ||
6e1886bc | 417 | @Test |
54a7a54c | 418 | public void testGetNextAfteSeekingOnTS_1() { |
17324c9a FC |
419 | final long INITIAL_TS = 1; |
420 | final int NB_READS = 20; | |
421 | ||
422 | // On lower bound, returns the first event (ts = 1) | |
423 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
424 | ||
425 | validateContextRanks(context); | |
426 | ||
427 | // Read NB_EVENTS | |
428 | ITmfEvent event; | |
429 | for (int i = 0; i < NB_READS; i++) { | |
430 | event = fExperiment.getNext(context); | |
431 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
432 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
433 | } | |
434 | ||
435 | // Make sure we stay positioned | |
436 | event = fExperiment.parseEvent(context); | |
437 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
438 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
439 | ||
440 | validateContextRanks(context); | |
441 | } | |
442 | ||
6e1886bc | 443 | @Test |
54a7a54c | 444 | public void testGetNextAfteSeekingOnTS_2() { |
17324c9a FC |
445 | final long INITIAL_TS = 2; |
446 | final int NB_READS = 20; | |
447 | ||
448 | // On lower bound, returns the first event (ts = 2) | |
449 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
450 | ||
451 | validateContextRanks(context); | |
452 | ||
453 | // Read NB_EVENTS | |
454 | ITmfEvent event; | |
455 | for (int i = 0; i < NB_READS; i++) { | |
456 | event = fExperiment.getNext(context); | |
457 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
458 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
459 | } | |
460 | ||
461 | // Make sure we stay positioned | |
462 | event = fExperiment.parseEvent(context); | |
463 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
464 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
465 | ||
466 | validateContextRanks(context); | |
467 | } | |
468 | ||
6e1886bc | 469 | @Test |
54a7a54c | 470 | public void testGetNextAfteSeekingOnTS_3() { |
17324c9a FC |
471 | final long INITIAL_TS = 500; |
472 | final int NB_READS = 20; | |
473 | ||
474 | // On lower bound, returns the first event (ts = 500) | |
475 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
476 | ||
477 | validateContextRanks(context); | |
478 | ||
479 | // Read NB_EVENTS | |
480 | ITmfEvent event; | |
481 | for (int i = 0; i < NB_READS; i++) { | |
482 | event = fExperiment.getNext(context); | |
483 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
484 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
485 | } | |
486 | ||
487 | // Make sure we stay positioned | |
488 | event = fExperiment.parseEvent(context); | |
489 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
490 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
491 | ||
492 | validateContextRanks(context); | |
493 | } | |
494 | ||
6e1886bc | 495 | @Test |
54a7a54c | 496 | public void testGetNextAfterSeekingOnRank_1() { |
17324c9a FC |
497 | final long INITIAL_RANK = 0L; |
498 | final int NB_READS = 20; | |
499 | ||
500 | // On lower bound, returns the first event (rank = 0) | |
501 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
502 | ||
503 | validateContextRanks(context); | |
504 | ||
505 | // Read NB_EVENTS | |
506 | ITmfEvent event; | |
507 | for (int i = 0; i < NB_READS; i++) { | |
508 | event = fExperiment.getNext(context); | |
509 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
510 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
511 | } | |
512 | ||
513 | // Make sure we stay positioned | |
514 | event = fExperiment.parseEvent(context); | |
515 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
516 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
517 | ||
518 | validateContextRanks(context); | |
519 | } | |
520 | ||
6e1886bc | 521 | @Test |
54a7a54c | 522 | public void testGetNextAfterSeekingOnRank_2() { |
17324c9a FC |
523 | final long INITIAL_RANK = 1L; |
524 | final int NB_READS = 20; | |
525 | ||
526 | // On lower bound, returns the first event (rank = 0) | |
527 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
d18dd09b | 528 | |
17324c9a FC |
529 | validateContextRanks(context); |
530 | ||
531 | // Read NB_EVENTS | |
532 | ITmfEvent event; | |
533 | for (int i = 0; i < NB_READS; i++) { | |
c32744d6 | 534 | event = fExperiment.getNext(context); |
17324c9a FC |
535 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); |
536 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
9b635e61 | 537 | } |
17324c9a FC |
538 | |
539 | // Make sure we stay positioned | |
540 | event = fExperiment.parseEvent(context); | |
541 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
542 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
543 | ||
544 | validateContextRanks(context); | |
545 | } | |
546 | ||
6e1886bc | 547 | @Test |
54a7a54c | 548 | public void testGetNextAfterSeekingOnRank_3() { |
17324c9a FC |
549 | final long INITIAL_RANK = 500L; |
550 | final int NB_READS = 20; | |
551 | ||
552 | // On lower bound, returns the first event (rank = 0) | |
553 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
554 | ||
555 | validateContextRanks(context); | |
556 | ||
557 | // Read NB_EVENTS | |
558 | ITmfEvent event; | |
559 | for (int i = 0; i < NB_READS; i++) { | |
560 | event = fExperiment.getNext(context); | |
561 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
562 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
563 | } | |
564 | ||
565 | // Make sure we stay positioned | |
566 | event = fExperiment.parseEvent(context); | |
567 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
568 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
569 | ||
570 | validateContextRanks(context); | |
571 | } | |
572 | ||
6e1886bc | 573 | @Test |
54a7a54c | 574 | public void testGetNextAfterSeekingOnLocation_1() { |
1e1bef82 | 575 | final ITmfLocation INITIAL_LOC = null; |
17324c9a FC |
576 | final long INITIAL_TS = 1; |
577 | final int NB_READS = 20; | |
578 | ||
579 | // On lower bound, returns the first event (ts = 1) | |
580 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
581 | ||
582 | validateContextRanks(context); | |
583 | ||
584 | // Read NB_EVENTS | |
585 | ITmfEvent event; | |
586 | for (int i = 0; i < NB_READS; i++) { | |
587 | event = fExperiment.getNext(context); | |
588 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
589 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
590 | } | |
591 | ||
592 | // Make sure we stay positioned | |
593 | event = fExperiment.parseEvent(context); | |
594 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
595 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
596 | ||
597 | validateContextRanks(context); | |
598 | } | |
599 | ||
6e1886bc | 600 | @Test |
54a7a54c | 601 | public void testGetNextAfterSeekingOnLocation_2() { |
1e1bef82 | 602 | final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); |
17324c9a FC |
603 | final long INITIAL_TS = 2; |
604 | final int NB_READS = 20; | |
605 | ||
606 | // On lower bound, returns the first event (ts = 2) | |
607 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
608 | ||
609 | validateContextRanks(context); | |
610 | ||
611 | // Read NB_EVENTS | |
612 | ITmfEvent event; | |
613 | for (int i = 0; i < NB_READS; i++) { | |
614 | event = fExperiment.getNext(context); | |
615 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
616 | } | |
617 | ||
618 | // Make sure we stay positioned | |
619 | event = fExperiment.parseEvent(context); | |
620 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
621 | ||
622 | validateContextRanks(context); | |
623 | } | |
624 | ||
6e1886bc | 625 | @Test |
54a7a54c | 626 | public void testGetNextAfterSeekingOnLocation_3() { |
1e1bef82 | 627 | final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); |
17324c9a FC |
628 | final long INITIAL_TS = 501; |
629 | final int NB_READS = 20; | |
630 | ||
631 | // On lower bound, returns the first event (ts = 501) | |
632 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
633 | ||
634 | validateContextRanks(context); | |
635 | ||
636 | // Read NB_EVENTS | |
637 | ITmfEvent event; | |
638 | for (int i = 0; i < NB_READS; i++) { | |
639 | event = fExperiment.getNext(context); | |
640 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
641 | } | |
642 | ||
643 | // Make sure we stay positioned | |
644 | event = fExperiment.parseEvent(context); | |
645 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
646 | ||
647 | validateContextRanks(context); | |
648 | } | |
649 | ||
6e1886bc | 650 | @Test |
54a7a54c | 651 | public void testGetNextLocation() { |
17324c9a FC |
652 | ITmfContext context1 = fExperiment.seekEvent(0); |
653 | fExperiment.getNext(context1); | |
d62bb185 | 654 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
655 | ITmfEvent event1 = fExperiment.getNext(context1); |
656 | ITmfContext context2 = fExperiment.seekEvent(location); | |
657 | ITmfEvent event2 = fExperiment.getNext(context2); | |
658 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); | |
659 | } | |
660 | ||
6e1886bc | 661 | @Test |
54a7a54c | 662 | public void testGetNextEndLocation() { |
17324c9a FC |
663 | ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); |
664 | fExperiment.getNext(context1); | |
d62bb185 | 665 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
666 | ITmfContext context2 = fExperiment.seekEvent(location); |
667 | ITmfEvent event = fExperiment.getNext(context2); | |
668 | assertNull("Event", event); | |
d18dd09b | 669 | } |
9b635e61 | 670 | |
d18dd09b ASL |
671 | // ------------------------------------------------------------------------ |
672 | // processRequest | |
673 | // ------------------------------------------------------------------------ | |
674 | ||
6e1886bc | 675 | @Test |
54a7a54c | 676 | public void testProcessRequestForNbEvents() throws InterruptedException { |
d18dd09b | 677 | final int nbEvents = 1000; |
ccf2bbb4 | 678 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 679 | |
25e48683 | 680 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 681 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 682 | range, 0, nbEvents, ExecutionType.FOREGROUND) { |
25e48683 | 683 | @Override |
6256d8ad | 684 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
685 | super.handleData(event); |
686 | requestedEvents.add(event); | |
687 | } | |
d18dd09b ASL |
688 | }; |
689 | fExperiment.sendRequest(request); | |
690 | request.waitForCompletion(); | |
691 | ||
692 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); | |
693 | assertTrue("isCompleted", request.isCompleted()); | |
694 | assertFalse("isCancelled", request.isCancelled()); | |
695 | ||
696 | // Ensure that we have distinct events. | |
25e48683 | 697 | // Don't go overboard: we are not validating the stub! |
20658947 | 698 | for (int i = 0; i < nbEvents; i++) { |
d18dd09b | 699 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 700 | } |
d18dd09b | 701 | } |
25e48683 | 702 | |
6e1886bc | 703 | @Test |
54a7a54c | 704 | public void testProcessRequestForAllEvents() throws InterruptedException { |
2740e05c | 705 | final int nbEvents = ITmfEventRequest.ALL_DATA; |
ccf2bbb4 | 706 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
25e48683 | 707 | final long nbExpectedEvents = NB_EVENTS; |
d18dd09b | 708 | |
25e48683 | 709 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 710 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 711 | range, 0, nbEvents, ExecutionType.FOREGROUND) { |
25e48683 | 712 | @Override |
6256d8ad | 713 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
714 | super.handleData(event); |
715 | requestedEvents.add(event); | |
716 | } | |
d18dd09b ASL |
717 | }; |
718 | fExperiment.sendRequest(request); | |
719 | request.waitForCompletion(); | |
720 | ||
9b635e61 | 721 | assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size()); |
d18dd09b ASL |
722 | assertTrue("isCompleted", request.isCompleted()); |
723 | assertFalse("isCancelled", request.isCancelled()); | |
724 | ||
725 | // Ensure that we have distinct events. | |
25e48683 | 726 | // Don't go overboard: we are not validating the stub! |
20658947 | 727 | for (int i = 0; i < nbExpectedEvents; i++) { |
d18dd09b | 728 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 729 | } |
d18dd09b | 730 | } |
25e48683 | 731 | |
d18dd09b ASL |
732 | // ------------------------------------------------------------------------ |
733 | // cancel | |
734 | // ------------------------------------------------------------------------ | |
735 | ||
6e1886bc | 736 | @Test |
54a7a54c | 737 | public void testCancel() throws InterruptedException { |
25e48683 | 738 | final int nbEvents = NB_EVENTS; |
672a642a | 739 | final int limit = BLOCK_SIZE; |
ccf2bbb4 | 740 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 741 | |
25e48683 | 742 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 743 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 744 | range, 0, nbEvents, ExecutionType.FOREGROUND) { |
25e48683 | 745 | int nbRead = 0; |
672a642a | 746 | |
25e48683 | 747 | @Override |
6256d8ad | 748 | public void handleData(final ITmfEvent event) { |
25e48683 FC |
749 | super.handleData(event); |
750 | requestedEvents.add(event); | |
672a642a | 751 | if (++nbRead == limit) { |
25e48683 | 752 | cancel(); |
20658947 | 753 | } |
25e48683 | 754 | } |
d18dd09b ASL |
755 | }; |
756 | fExperiment.sendRequest(request); | |
757 | request.waitForCompletion(); | |
758 | ||
672a642a | 759 | assertEquals("nbEvents", limit, requestedEvents.size()); |
d18dd09b ASL |
760 | assertTrue("isCompleted", request.isCompleted()); |
761 | assertTrue("isCancelled", request.isCancelled()); | |
762 | } | |
25e48683 | 763 | |
d18dd09b ASL |
764 | // ------------------------------------------------------------------------ |
765 | // getTimestamp | |
766 | // ------------------------------------------------------------------------ | |
767 | ||
6e1886bc | 768 | @Test |
54a7a54c | 769 | public void testGetTimestamp() { |
17324c9a FC |
770 | assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); |
771 | assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); | |
772 | assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment.getTimestamp( 10)); | |
773 | assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment.getTimestamp( 100)); | |
774 | assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp( 1000)); | |
775 | assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp( 2000)); | |
776 | assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp( 2500)); | |
777 | assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp( 9999)); | |
778 | assertEquals("getTimestamp", new TmfTimestamp(20000, (byte) -3), fExperiment.getTimestamp(19999)); | |
779 | assertNull("getTimestamp", fExperiment.getTimestamp(20000)); | |
d18dd09b ASL |
780 | } |
781 | ||
66262ad8 BH |
782 | // ------------------------------------------------------------------------ |
783 | // getInitialRangeOffset, getCurrentRange, getCurrentTime | |
784 | // ------------------------------------------------------------------------ | |
2771b032 | 785 | |
6e1886bc | 786 | @Test |
66262ad8 | 787 | public void testDefaultCurrentTimeValues() { |
850a3ae2 PT |
788 | ITmfTrace[] traces = setupTraces(); |
789 | TmfExperimentStub exp = new TmfExperimentStub(EXPERIMENT, traces, BLOCK_SIZE); | |
66262ad8 BH |
790 | |
791 | // verify initial values | |
792 | TmfTimestamp initRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE); | |
793 | assertEquals("getInitialRangeOffset", initRange, exp.getInitialRangeOffset()); | |
850a3ae2 PT |
794 | |
795 | exp.dispose(); | |
796 | } | |
797 | ||
798 | @Test | |
799 | public void testInitialRangeOffset() { | |
800 | ITmfTrace[] traces = setupTraces(); | |
801 | ((TmfTraceStub) traces[0]).setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE)); | |
802 | ((TmfTraceStub) traces[1]).setInitialRangeOffset(new TmfTimestamp(2, ITmfTimestamp.MILLISECOND_SCALE)); | |
803 | TmfExperimentStub exp = new TmfExperimentStub(EXPERIMENT, traces, BLOCK_SIZE); | |
804 | ||
805 | TmfTimestamp initRange = new TmfTimestamp(2, ITmfTimestamp.MILLISECOND_SCALE); | |
806 | assertEquals("getInitialRangeOffset", initRange, exp.getInitialRangeOffset()); | |
807 | ||
808 | exp.dispose(); | |
66262ad8 | 809 | } |
6e1886bc | 810 | |
17324c9a | 811 | } |