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