Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2013 Ericsson |
20658947 | 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 | |
20658947 | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
20658947 | 11 | * Francois Chouinard - Adapted for TMF Trace Model 1.0 |
6e1886bc | 12 | * Alexandre Montplaisir - Port to JUnit4 |
d18dd09b ASL |
13 | *******************************************************************************/ |
14 | ||
6c13869b | 15 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b | 16 | |
6e1886bc AM |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertFalse; | |
6e1886bc AM |
19 | import static org.junit.Assert.assertNull; |
20 | import static org.junit.Assert.assertTrue; | |
21 | import static org.junit.Assert.fail; | |
22 | ||
d18dd09b | 23 | import java.io.File; |
e1ab8984 FC |
24 | import java.io.IOException; |
25 | import java.net.URISyntaxException; | |
26 | import java.net.URL; | |
35c160d9 | 27 | import java.util.Map; |
d18dd09b ASL |
28 | import java.util.Vector; |
29 | ||
e1ab8984 FC |
30 | import org.eclipse.core.runtime.FileLocator; |
31 | import org.eclipse.core.runtime.Path; | |
8fd82db5 | 32 | import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; |
5419a136 | 33 | import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; |
72f1e62a | 34 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
b4f71e4a | 35 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
7e6347b0 | 36 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
6c13869b | 37 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
a51b2b9f AM |
38 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
39 | import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; | |
6c13869b | 40 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; |
9c4d52ee | 41 | import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; |
3bd46eef AM |
42 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
43 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
44 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
6c13869b | 45 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
17324c9a | 46 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
0316808c | 47 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
7e6347b0 | 48 | import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; |
6c13869b | 49 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
4918b8f2 | 50 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
6e1886bc AM |
51 | import org.junit.After; |
52 | import org.junit.Before; | |
53 | import org.junit.Test; | |
d18dd09b ASL |
54 | |
55 | /** | |
ff4ed569 | 56 | * Test suite for the TmfTrace class. |
d18dd09b | 57 | */ |
cad06250 | 58 | @SuppressWarnings("javadoc") |
6e1886bc | 59 | public class TmfTraceTest { |
d18dd09b | 60 | |
f17b2f70 FC |
61 | // ------------------------------------------------------------------------ |
62 | // Variables | |
63 | // ------------------------------------------------------------------------ | |
6e1886bc | 64 | |
9c4d52ee | 65 | private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K; |
66262ad8 | 66 | private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec |
ff4ed569 | 67 | private static final int BLOCK_SIZE = 500; |
e31e01e8 FC |
68 | private static final int NB_EVENTS = 10000; |
69 | private static TmfTraceStub fTrace = null; | |
d18dd09b | 70 | |
20658947 | 71 | private static int SCALE = -3; |
d18dd09b | 72 | |
e31e01e8 | 73 | // ------------------------------------------------------------------------ |
d18dd09b | 74 | // Housekeeping |
e31e01e8 | 75 | // ------------------------------------------------------------------------ |
d18dd09b | 76 | |
6e1886bc AM |
77 | @Before |
78 | public void setUp() { | |
9c4d52ee | 79 | fTrace = setupTrace(TEST_TRACE.getFullPath()); |
f17b2f70 FC |
80 | } |
81 | ||
6e1886bc AM |
82 | @After |
83 | public void tearDown() { | |
f17b2f70 FC |
84 | fTrace.dispose(); |
85 | fTrace = null; | |
86 | } | |
ff4ed569 FC |
87 | |
88 | // ------------------------------------------------------------------------ | |
89 | // Helper functions | |
90 | // ------------------------------------------------------------------------ | |
91 | ||
9b749023 | 92 | private static TmfTraceStub setupTrace(final String path) { |
20658947 | 93 | if (fTrace == null) { |
f17b2f70 FC |
94 | try { |
95 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); | |
96 | final File test = new File(FileLocator.toFileURL(location).toURI()); | |
20658947 | 97 | fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE); |
51e75066 | 98 | fTrace.indexTrace(true); |
b4f71e4a FC |
99 | } catch (final TmfTraceException e) { |
100 | e.printStackTrace(); | |
f17b2f70 FC |
101 | } catch (final URISyntaxException e) { |
102 | e.printStackTrace(); | |
103 | } catch (final IOException e) { | |
104 | e.printStackTrace(); | |
105 | } | |
20658947 | 106 | } |
f17b2f70 | 107 | return fTrace; |
e1ab8984 FC |
108 | } |
109 | ||
e31e01e8 | 110 | // ------------------------------------------------------------------------ |
d18dd09b | 111 | // Constructors |
e31e01e8 | 112 | // ------------------------------------------------------------------------ |
d18dd09b | 113 | |
6e1886bc | 114 | @Test |
54a7a54c | 115 | public void testStandardConstructor() throws TmfTraceException { |
f17b2f70 | 116 | try { |
9c4d52ee | 117 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
118 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
119 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath()); | |
51e75066 | 120 | trace.indexTrace(true); |
631d2ce9 AM |
121 | |
122 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
123 | assertNull("getResource", trace.getResource()); | |
124 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
125 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); | |
126 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 127 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
128 | |
129 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
130 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
131 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
132 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
133 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
134 | ||
f17b2f70 FC |
135 | } catch (final URISyntaxException e) { |
136 | fail("URISyntaxException"); | |
137 | } catch (final IOException e) { | |
138 | fail("IOException"); | |
139 | } | |
ff4ed569 FC |
140 | } |
141 | ||
6e1886bc | 142 | @Test |
54a7a54c | 143 | public void testStandardConstructorCacheSize() throws TmfTraceException { |
f17b2f70 | 144 | try { |
9c4d52ee | 145 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
146 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
147 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), 0); | |
51e75066 | 148 | trace.indexTrace(true); |
631d2ce9 AM |
149 | |
150 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
151 | assertNull("getResource", trace.getResource()); | |
152 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
153 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); | |
154 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 155 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
156 | |
157 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
158 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
159 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
160 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
161 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
162 | ||
20658947 FC |
163 | } catch (final URISyntaxException e) { |
164 | fail("URISyntaxException"); | |
165 | } catch (final IOException e) { | |
166 | fail("IOException"); | |
167 | } | |
168 | ||
20658947 | 169 | try { |
9c4d52ee | 170 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
171 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
172 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE); | |
51e75066 | 173 | trace.indexTrace(true); |
631d2ce9 AM |
174 | |
175 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
176 | assertNull("getResource", trace.getResource()); | |
177 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
178 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); | |
179 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 180 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
181 | |
182 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
183 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
184 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
185 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
186 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
187 | ||
20658947 FC |
188 | } catch (final URISyntaxException e) { |
189 | fail("URISyntaxException"); | |
190 | } catch (final IOException e) { | |
191 | fail("IOException"); | |
192 | } | |
20658947 FC |
193 | } |
194 | ||
6e1886bc | 195 | @Test |
54a7a54c | 196 | public void testFullConstructor() throws TmfTraceException { |
20658947 | 197 | try { |
9c4d52ee | 198 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
199 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
200 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null); | |
51e75066 | 201 | trace.indexTrace(true); |
631d2ce9 AM |
202 | |
203 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
204 | assertNull("getResource", trace.getResource()); | |
205 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
206 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); | |
207 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 208 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
209 | |
210 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
211 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
212 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
213 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
214 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
215 | ||
20658947 FC |
216 | } catch (final URISyntaxException e) { |
217 | fail("URISyntaxException"); | |
218 | } catch (final IOException e) { | |
219 | fail("IOException"); | |
220 | } | |
20658947 FC |
221 | } |
222 | ||
6e1886bc | 223 | @Test |
54a7a54c | 224 | public void testLiveTraceConstructor() throws TmfTraceException { |
1703b536 FC |
225 | final long interval = 100; |
226 | try { | |
9c4d52ee | 227 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
228 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
229 | TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, interval); | |
51e75066 | 230 | trace.indexTrace(true); |
631d2ce9 AM |
231 | |
232 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
233 | assertNull("getResource", trace.getResource()); | |
234 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
235 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); | |
236 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
9c4d52ee | 237 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
238 | |
239 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
240 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
241 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
242 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
243 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
244 | ||
1703b536 FC |
245 | } catch (final URISyntaxException e) { |
246 | fail("URISyntaxException"); | |
247 | } catch (final IOException e) { | |
248 | fail("IOException"); | |
249 | } | |
1703b536 FC |
250 | } |
251 | ||
6e1886bc | 252 | @Test |
54a7a54c | 253 | public void testCopyConstructor() throws TmfTraceException { |
20658947 | 254 | try { |
9c4d52ee | 255 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
631d2ce9 AM |
256 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
257 | TmfTraceStub original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfCheckpointIndexer(null)); | |
258 | TmfTraceStub trace = new TmfTraceStub(original); | |
51e75066 | 259 | trace.indexTrace(true); |
631d2ce9 AM |
260 | |
261 | assertEquals("getType", ITmfEvent.class, trace.getType()); | |
262 | assertNull("getResource", trace.getResource()); | |
263 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); | |
264 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); | |
265 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
9c4d52ee | 266 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
631d2ce9 AM |
267 | |
268 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
269 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
270 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
271 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
272 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
273 | ||
f17b2f70 FC |
274 | } catch (final URISyntaxException e) { |
275 | fail("URISyntaxException"); | |
276 | } catch (final IOException e) { | |
277 | fail("IOException"); | |
278 | } | |
20658947 | 279 | |
20658947 FC |
280 | // Test the copy of a null trace |
281 | try { | |
282 | new TmfTraceStub((TmfTraceStub) null); | |
283 | fail("Missing exception"); | |
284 | } catch (final IllegalArgumentException e) { | |
285 | // test passed | |
286 | } catch (final Exception e) { | |
287 | fail("Unexpected exception"); | |
288 | } | |
d18dd09b ASL |
289 | } |
290 | ||
20658947 | 291 | // ------------------------------------------------------------------------ |
1703b536 | 292 | // Trace initialization |
20658947 FC |
293 | // ------------------------------------------------------------------------ |
294 | ||
6e1886bc | 295 | @Test |
54a7a54c | 296 | public void testInitializeNullPath() { |
1703b536 FC |
297 | // Instantiate an "empty" trace |
298 | final TmfTraceStub trace = new TmfTraceStub(); | |
20658947 | 299 | |
1703b536 | 300 | try { |
2771b032 | 301 | trace.initialize(null, null, ITmfEvent.class); |
1703b536 | 302 | fail("TmfTrace.initialize() - no exception thrown"); |
b4f71e4a | 303 | } catch (TmfTraceException e) { |
1703b536 FC |
304 | // Success |
305 | } catch (Exception e) { | |
306 | fail("TmfTrace.initialize() - wrong exception thrown"); | |
307 | } | |
ff4ed569 | 308 | } |
54a7a54c | 309 | |
6e1886bc | 310 | @Test |
54a7a54c | 311 | public void testInitializeSimplePath() { |
1703b536 FC |
312 | // Instantiate an "empty" trace |
313 | final TmfTraceStub trace = new TmfTraceStub(); | |
314 | ||
315 | // Path == trace name | |
316 | String path = "TraceName"; | |
317 | try { | |
2771b032 | 318 | trace.initialize(null, path, ITmfEvent.class); |
1703b536 FC |
319 | } catch (Exception e) { |
320 | fail("TmfTrace.initialize() - Exception thrown"); | |
321 | } | |
9b749023 | 322 | |
2771b032 | 323 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
1703b536 FC |
324 | assertNull ("getResource", trace.getResource()); |
325 | assertEquals("getPath", path, trace.getPath()); | |
0316808c | 326 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
1703b536 FC |
327 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
328 | assertEquals("getName", path, trace.getName()); | |
329 | ||
330 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 331 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
1703b536 | 332 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 333 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
1703b536 FC |
334 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
335 | } | |
336 | ||
6e1886bc | 337 | @Test |
54a7a54c | 338 | public void testInitializeNormalPath() { |
1703b536 FC |
339 | // Instantiate an "empty" trace |
340 | final TmfTraceStub trace = new TmfTraceStub(); | |
341 | ||
342 | // Path == trace name | |
343 | String name = "TraceName"; | |
344 | String path = "/my/trace/path/" + name; | |
345 | try { | |
2771b032 | 346 | trace.initialize(null, path, ITmfEvent.class); |
1703b536 FC |
347 | } catch (Exception e) { |
348 | fail("TmfTrace.initialize() - Exception thrown"); | |
349 | } | |
9b749023 | 350 | |
2771b032 | 351 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
1703b536 FC |
352 | assertNull ("getResource", trace.getResource()); |
353 | assertEquals("getPath", path, trace.getPath()); | |
0316808c | 354 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
1703b536 FC |
355 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
356 | assertEquals("getName", name, trace.getName()); | |
357 | ||
358 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 359 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
1703b536 | 360 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 361 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
1703b536 FC |
362 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
363 | } | |
20658947 | 364 | |
6e1886bc | 365 | @Test |
54a7a54c | 366 | public void testInitTrace() throws URISyntaxException, IOException, TmfTraceException, InterruptedException { |
20658947 FC |
367 | // Instantiate an "empty" trace |
368 | final TmfTraceStub trace = new TmfTraceStub(); | |
369 | ||
20658947 FC |
370 | assertNull ("getType", trace.getType()); |
371 | assertNull ("getResource", trace.getResource()); | |
0316808c | 372 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
20658947 FC |
373 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
374 | assertEquals("getName", "", trace.getName()); | |
375 | ||
376 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
9cbe7899 | 377 | assertEquals("getRange-start", Long.MIN_VALUE, trace.getTimeRange().getStartTime().getValue()); |
20658947 | 378 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
9cbe7899 | 379 | assertEquals("getStartTime", Long.MIN_VALUE, trace.getStartTime().getValue()); |
20658947 FC |
380 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
381 | ||
382 | // Validate | |
9c4d52ee | 383 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
20658947 | 384 | final File testfile = new File(FileLocator.toFileURL(location).toURI()); |
a94410d9 | 385 | assertTrue("validate", trace.validate(null, testfile.getPath()).isOK()); |
20658947 FC |
386 | |
387 | // InitTrace and wait for indexing completion... | |
2771b032 | 388 | trace.initTrace(null, testfile.toURI().getPath(), ITmfEvent.class); |
51e75066 | 389 | trace.indexTrace(true); |
20658947 FC |
390 | int nbSecs = 0; |
391 | while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) { | |
392 | Thread.sleep(1000); | |
393 | nbSecs++; | |
394 | } | |
395 | if (trace.getNbEvents() < NB_EVENTS) { | |
396 | fail("indexing"); | |
397 | } | |
398 | ||
2771b032 | 399 | assertEquals("getType", ITmfEvent.class, trace.getType()); |
20658947 | 400 | assertNull ("getResource", trace.getResource()); |
0316808c | 401 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
20658947 | 402 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
9c4d52ee | 403 | assertEquals("getName", TEST_TRACE.getPath(), trace.getName()); |
20658947 FC |
404 | |
405 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
406 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
407 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
408 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
409 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
410 | } | |
d18dd09b | 411 | |
ff4ed569 | 412 | // ------------------------------------------------------------------------ |
1703b536 FC |
413 | // Set/Get streaming interval |
414 | // ------------------------------------------------------------------------ | |
415 | ||
6e1886bc | 416 | @Test |
54a7a54c | 417 | public void testSetStreamingInterval() throws TmfTraceException { |
1703b536 FC |
418 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
419 | ||
420 | long interval = 0; | |
421 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
422 | ||
423 | interval = 100; | |
424 | trace.setStreamingInterval(interval); | |
425 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
54a7a54c | 426 | |
1703b536 FC |
427 | interval = -1; |
428 | trace.setStreamingInterval(interval); | |
429 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); | |
54a7a54c | 430 | |
1703b536 FC |
431 | interval = 0; |
432 | trace.setStreamingInterval(interval); | |
433 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); | |
54a7a54c | 434 | |
1703b536 FC |
435 | trace.dispose(); |
436 | } | |
437 | ||
438 | // ------------------------------------------------------------------------ | |
439 | // Set/Get time range | |
ff4ed569 FC |
440 | // ------------------------------------------------------------------------ |
441 | ||
6e1886bc | 442 | @Test |
54a7a54c | 443 | public void testSetTimeRange() throws TmfTraceException { |
f17b2f70 | 444 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 445 | trace.indexTrace(true); |
f17b2f70 | 446 | |
ff4ed569 FC |
447 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
448 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
449 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
450 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
451 | ||
452 | trace.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200))); | |
453 | assertEquals("setTimeRange", 100, trace.getTimeRange().getStartTime().getValue()); | |
454 | assertEquals("setTimeRange", 200, trace.getTimeRange().getEndTime().getValue()); | |
455 | assertEquals("setTimeRange", 100, trace.getStartTime().getValue()); | |
456 | assertEquals("setTimeRange", 200, trace.getEndTime().getValue()); | |
f17b2f70 FC |
457 | |
458 | trace.dispose(); | |
ff4ed569 | 459 | } |
f17b2f70 | 460 | |
6e1886bc | 461 | @Test |
54a7a54c | 462 | public void testSetStartTime() throws TmfTraceException { |
f17b2f70 | 463 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 464 | trace.indexTrace(true); |
f17b2f70 | 465 | |
ff4ed569 FC |
466 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
467 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
468 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
469 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
470 | ||
471 | trace.setStartTime(new TmfTimestamp(100)); | |
472 | assertEquals("setStartTime", 100, trace.getTimeRange().getStartTime().getValue()); | |
473 | assertEquals("setStartTime", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
474 | assertEquals("setStartTime", 100, trace.getStartTime().getValue()); | |
475 | assertEquals("setStartTime", NB_EVENTS, trace.getEndTime().getValue()); | |
f17b2f70 FC |
476 | |
477 | trace.dispose(); | |
ff4ed569 | 478 | } |
f17b2f70 | 479 | |
6e1886bc | 480 | @Test |
54a7a54c | 481 | public void testSetEndTime() throws TmfTraceException { |
f17b2f70 | 482 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 483 | trace.indexTrace(true); |
f17b2f70 | 484 | |
ff4ed569 FC |
485 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
486 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
487 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
488 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
489 | ||
490 | trace.setEndTime(new TmfTimestamp(100)); | |
491 | assertEquals("setEndTime", 1, trace.getTimeRange().getStartTime().getValue()); | |
492 | assertEquals("setEndTime", 100, trace.getTimeRange().getEndTime().getValue()); | |
493 | assertEquals("setEndTime", 1, trace.getStartTime().getValue()); | |
494 | assertEquals("setEndTime", 100, trace.getEndTime().getValue()); | |
f17b2f70 FC |
495 | |
496 | trace.dispose(); | |
ff4ed569 | 497 | } |
f17b2f70 | 498 | |
6e1886bc | 499 | @Test |
54a7a54c | 500 | public void testSetNbEvents() throws TmfTraceException { |
b75d6b65 | 501 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
51e75066 | 502 | trace.indexTrace(true); |
b75d6b65 FC |
503 | |
504 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
505 | ||
506 | trace.setNbEvents(0); | |
507 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
508 | ||
509 | trace.setNbEvents(-1); | |
510 | assertEquals("getNbEvents", 0, trace.getNbEvents()); | |
511 | ||
512 | trace.setNbEvents(NB_EVENTS + 1); | |
513 | assertEquals("getNbEvents", NB_EVENTS + 1, trace.getNbEvents()); | |
514 | ||
515 | trace.setNbEvents(NB_EVENTS); | |
516 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); | |
517 | ||
518 | trace.dispose(); | |
519 | } | |
520 | ||
a51b2b9f AM |
521 | // ------------------------------------------------------------------------ |
522 | // State system and statistics methods | |
523 | // ------------------------------------------------------------------------ | |
524 | ||
6e1886bc | 525 | @Test |
a51b2b9f AM |
526 | public void testGetStatistics() { |
527 | /* Should be null in unit tests */ | |
528 | ITmfStatistics stats = fTrace.getStatistics(); | |
529 | assertNull(stats); | |
530 | } | |
531 | ||
6e1886bc | 532 | @Test |
a51b2b9f AM |
533 | public void testGetStateSystem() { |
534 | /* There should be no state system registered so far */ | |
35c160d9 | 535 | ITmfStateSystem ss = fTrace.getStateSystems().get("something"); |
a51b2b9f AM |
536 | assertNull(ss); |
537 | } | |
538 | ||
35c160d9 AM |
539 | /** |
540 | * Make sure the returned map is unmodifiable. | |
541 | */ | |
542 | @Test(expected=UnsupportedOperationException.class) | |
543 | public void testGetStateSystem_readOnly() { | |
544 | Map<String, ITmfStateSystem> sss = fTrace.getStateSystems(); | |
545 | sss.put("something", null); | |
a51b2b9f AM |
546 | } |
547 | ||
e31e01e8 | 548 | // ------------------------------------------------------------------------ |
7e6347b0 FC |
549 | // seekEvent on location (note: does not reliably set the rank) |
550 | // ------------------------------------------------------------------------ | |
551 | ||
6e1886bc | 552 | @Test |
54a7a54c | 553 | public void testSeekEventOnCacheBoundary() { |
7e6347b0 FC |
554 | // Position trace at event rank 0 |
555 | ITmfContext context = fTrace.seekEvent(0); | |
556 | ITmfEvent event = fTrace.parseEvent(context); | |
557 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
558 | assertEquals("Event rank", 0, context.getRank()); | |
559 | ||
560 | context = fTrace.seekEvent(context.getLocation()); | |
561 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
562 | ||
563 | event = fTrace.parseEvent(context); | |
564 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
565 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
566 | ||
c32744d6 | 567 | event = fTrace.getNext(context); |
7e6347b0 FC |
568 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
569 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
570 | ||
571 | // Position trace at event rank 1000 | |
572 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); | |
573 | context = fTrace.seekEvent(tmpContext.getLocation()); | |
574 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
575 | ||
576 | event = fTrace.parseEvent(context); | |
577 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
578 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
579 | ||
c32744d6 | 580 | event = fTrace.getNext(context); |
7e6347b0 FC |
581 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
582 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
583 | ||
584 | // Position trace at event rank 4000 | |
585 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); | |
586 | context = fTrace.seekEvent(tmpContext.getLocation()); | |
587 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
588 | ||
589 | event = fTrace.parseEvent(context); | |
590 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
591 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
592 | ||
c32744d6 | 593 | event = fTrace.getNext(context); |
7e6347b0 FC |
594 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
595 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
596 | } | |
597 | ||
6e1886bc | 598 | @Test |
54a7a54c | 599 | public void testSeekEventNotOnCacheBoundary() { |
7e6347b0 FC |
600 | // Position trace at event rank 9 |
601 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); | |
602 | TmfContext context = fTrace.seekEvent(tmpContext.getLocation()); | |
603 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
604 | ||
605 | ITmfEvent event = fTrace.parseEvent(context); | |
606 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
607 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
608 | ||
c32744d6 | 609 | event = fTrace.getNext(context); |
7e6347b0 FC |
610 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
611 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
612 | ||
613 | // Position trace at event rank 999 | |
614 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); | |
615 | context = fTrace.seekEvent(tmpContext.getLocation()); | |
616 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
617 | ||
618 | event = fTrace.parseEvent(context); | |
619 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
620 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
621 | ||
c32744d6 | 622 | event = fTrace.getNext(context); |
7e6347b0 FC |
623 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
624 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
625 | ||
626 | // Position trace at event rank 1001 | |
627 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); | |
628 | context = fTrace.seekEvent(tmpContext.getLocation()); | |
629 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
630 | ||
631 | event = fTrace.parseEvent(context); | |
632 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
633 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
634 | ||
c32744d6 | 635 | event = fTrace.getNext(context); |
7e6347b0 FC |
636 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
637 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
638 | ||
639 | // Position trace at event rank 4500 | |
640 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); | |
641 | context = fTrace.seekEvent(tmpContext.getLocation()); | |
642 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
643 | ||
644 | event = fTrace.parseEvent(context); | |
645 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
646 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
647 | ||
c32744d6 | 648 | event = fTrace.getNext(context); |
7e6347b0 FC |
649 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
650 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
651 | } | |
652 | ||
6e1886bc | 653 | @Test |
54a7a54c | 654 | public void testSeekEventOutOfScope() { |
7e6347b0 FC |
655 | // Position trace at beginning |
656 | ITmfContext tmpContext = fTrace.seekEvent(0); | |
657 | ITmfContext context = fTrace.seekEvent(tmpContext.getLocation()); | |
658 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
659 | ||
660 | ITmfEvent event = fTrace.parseEvent(context); | |
661 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
662 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
663 | ||
c32744d6 | 664 | event = fTrace.getNext(context); |
7e6347b0 FC |
665 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
666 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); | |
667 | ||
668 | // Position trace at event passed the end | |
0316808c FC |
669 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
670 | assertNull("Event timestamp", context.getLocation()); | |
7e6347b0 FC |
671 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
672 | ||
c32744d6 | 673 | event = fTrace.getNext(context); |
0316808c | 674 | assertNull("Event", event); |
7e6347b0 FC |
675 | } |
676 | ||
677 | // ------------------------------------------------------------------------ | |
678 | // seekEvent on timestamp (note: does not reliably set the rank) | |
54d55ced FC |
679 | // ------------------------------------------------------------------------ |
680 | ||
6e1886bc | 681 | @Test |
54a7a54c | 682 | public void testSeekEventOnNullTimestamp() { |
f17b2f70 | 683 | // Position trace at event rank 0 |
7e6347b0 | 684 | ITmfContext context = fTrace.seekEvent((ITmfTimestamp) null); |
ff4ed569 | 685 | assertEquals("Event rank", 0, context.getRank()); |
9b635e61 | 686 | |
72f1e62a | 687 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced | 688 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
20658947 | 689 | assertEquals("Event rank", 0, context.getRank()); |
54d55ced FC |
690 | } |
691 | ||
6e1886bc | 692 | @Test |
54a7a54c | 693 | public void testSeekEventOnTimestampOnCacheBoundary() { |
f17b2f70 FC |
694 | // Position trace at event rank 0 |
695 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0)); | |
54d55ced | 696 | assertEquals("Event rank", 0, context.getRank()); |
9b635e61 | 697 | |
72f1e62a | 698 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
699 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
700 | assertEquals("Event rank", 0, context.getRank()); | |
f17b2f70 | 701 | |
c32744d6 | 702 | event = fTrace.getNext(context); |
75828b1a | 703 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
e31e01e8 | 704 | assertEquals("Event rank", 1, context.getRank()); |
d18dd09b | 705 | |
f17b2f70 | 706 | // Position trace at event rank 1000 |
54d55ced FC |
707 | context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); |
708 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 709 | |
9b635e61 | 710 | event = fTrace.parseEvent(context); |
54d55ced FC |
711 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
712 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 713 | |
c32744d6 | 714 | event = fTrace.getNext(context); |
e31e01e8 FC |
715 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
716 | assertEquals("Event rank", 1001, context.getRank()); | |
d18dd09b | 717 | |
f17b2f70 | 718 | // Position trace at event rank 4000 |
54d55ced FC |
719 | context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); |
720 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 721 | |
9b635e61 | 722 | event = fTrace.parseEvent(context); |
54d55ced FC |
723 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
724 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 725 | |
c32744d6 | 726 | event = fTrace.getNext(context); |
e31e01e8 FC |
727 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
728 | assertEquals("Event rank", 4001, context.getRank()); | |
75828b1a | 729 | } |
d18dd09b | 730 | |
6e1886bc | 731 | @Test |
54a7a54c | 732 | public void testSeekEventOnTimestampNotOnCacheBoundary() { |
f17b2f70 FC |
733 | // Position trace at event rank 1 |
734 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE, 0)); | |
54d55ced | 735 | assertEquals("Event rank", 1, context.getRank()); |
f17b2f70 | 736 | |
72f1e62a | 737 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
738 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
739 | assertEquals("Event rank", 1, context.getRank()); | |
f17b2f70 | 740 | |
c32744d6 | 741 | event = fTrace.getNext(context); |
54d55ced FC |
742 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
743 | assertEquals("Event rank", 2, context.getRank()); | |
d18dd09b | 744 | |
f17b2f70 FC |
745 | // Position trace at event rank 9 |
746 | context = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); | |
54d55ced | 747 | assertEquals("Event rank", 9, context.getRank()); |
f17b2f70 | 748 | |
9b635e61 | 749 | event = fTrace.parseEvent(context); |
54d55ced FC |
750 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
751 | assertEquals("Event rank", 9, context.getRank()); | |
f17b2f70 | 752 | |
c32744d6 | 753 | event = fTrace.getNext(context); |
e31e01e8 FC |
754 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
755 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 756 | |
f17b2f70 | 757 | // Position trace at event rank 999 |
54d55ced FC |
758 | context = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
759 | assertEquals("Event rank", 999, context.getRank()); | |
f17b2f70 | 760 | |
9b635e61 | 761 | event = fTrace.parseEvent(context); |
54d55ced | 762 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
e31e01e8 | 763 | assertEquals("Event rank", 999, context.getRank()); |
f17b2f70 | 764 | |
c32744d6 | 765 | event = fTrace.getNext(context); |
54d55ced FC |
766 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
767 | assertEquals("Event rank", 1000, context.getRank()); | |
e31e01e8 | 768 | |
f17b2f70 | 769 | // Position trace at event rank 1001 |
54d55ced | 770 | context = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
e31e01e8 | 771 | assertEquals("Event rank", 1001, context.getRank()); |
f17b2f70 | 772 | |
9b635e61 | 773 | event = fTrace.parseEvent(context); |
54d55ced FC |
774 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
775 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 776 | |
c32744d6 | 777 | event = fTrace.getNext(context); |
54d55ced FC |
778 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
779 | assertEquals("Event rank", 1002, context.getRank()); | |
780 | ||
f17b2f70 | 781 | // Position trace at event rank 4500 |
54d55ced FC |
782 | context = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
783 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 784 | |
9b635e61 | 785 | event = fTrace.parseEvent(context); |
54d55ced FC |
786 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
787 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 788 | |
c32744d6 | 789 | event = fTrace.getNext(context); |
54d55ced FC |
790 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
791 | assertEquals("Event rank", 4501, context.getRank()); | |
75828b1a | 792 | } |
d18dd09b | 793 | |
6e1886bc | 794 | @Test |
54a7a54c | 795 | public void testSeekEventOnTimestampOutOfScope() { |
f17b2f70 FC |
796 | // Position trace at beginning |
797 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0)); | |
54d55ced | 798 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 799 | |
72f1e62a | 800 | ITmfEvent event = fTrace.parseEvent(context); |
75828b1a | 801 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced | 802 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 803 | |
c32744d6 | 804 | event = fTrace.getNext(context); |
54d55ced FC |
805 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
806 | assertEquals("Event rank", 1, context.getRank()); | |
75828b1a | 807 | |
f17b2f70 | 808 | // Position trace at event passed the end |
54d55ced | 809 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
0316808c | 810 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
f17b2f70 | 811 | |
9b635e61 | 812 | event = fTrace.parseEvent(context); |
75828b1a | 813 | assertEquals("Event timestamp", null, event); |
0316808c | 814 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
f17b2f70 | 815 | |
c32744d6 | 816 | event = fTrace.getNext(context); |
54d55ced | 817 | assertEquals("Event timestamp", null, event); |
0316808c | 818 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
d18dd09b ASL |
819 | } |
820 | ||
54d55ced FC |
821 | // ------------------------------------------------------------------------ |
822 | // seekEvent on rank | |
823 | // ------------------------------------------------------------------------ | |
824 | ||
6e1886bc | 825 | @Test |
54a7a54c | 826 | public void testSeekEventOnNegativeRank() { |
20658947 FC |
827 | // Position trace at event rank 0 |
828 | ITmfContext context = fTrace.seekEvent(-1); | |
829 | assertEquals("Event rank", 0, context.getRank()); | |
830 | ||
831 | ITmfEvent event = fTrace.parseEvent(context); | |
832 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
833 | assertEquals("Event rank", 0, context.getRank()); | |
834 | } | |
835 | ||
6e1886bc | 836 | @Test |
54a7a54c | 837 | public void testSeekOnRankOnCacheBoundary() { |
f17b2f70 FC |
838 | // On lower bound, returns the first event (ts = 1) |
839 | ITmfContext context = fTrace.seekEvent(0); | |
54d55ced | 840 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 841 | |
72f1e62a | 842 | ITmfEvent event = fTrace.parseEvent(context); |
e31e01e8 | 843 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced | 844 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 845 | |
c32744d6 | 846 | event = fTrace.getNext(context); |
54d55ced FC |
847 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
848 | assertEquals("Event rank", 1, context.getRank()); | |
e31e01e8 | 849 | |
f17b2f70 | 850 | // Position trace at event rank 1000 |
54d55ced FC |
851 | context = fTrace.seekEvent(1000); |
852 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 853 | |
9b635e61 | 854 | event = fTrace.parseEvent(context); |
54d55ced FC |
855 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
856 | assertEquals("Event rank", 1000, context.getRank()); | |
f17b2f70 | 857 | |
c32744d6 | 858 | event = fTrace.getNext(context); |
54d55ced FC |
859 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
860 | assertEquals("Event rank", 1001, context.getRank()); | |
e31e01e8 | 861 | |
f17b2f70 | 862 | // Position trace at event rank 4000 |
54d55ced FC |
863 | context = fTrace.seekEvent(4000); |
864 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 865 | |
9b635e61 | 866 | event = fTrace.parseEvent(context); |
54d55ced FC |
867 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
868 | assertEquals("Event rank", 4000, context.getRank()); | |
f17b2f70 | 869 | |
c32744d6 | 870 | event = fTrace.getNext(context); |
54d55ced FC |
871 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
872 | assertEquals("Event rank", 4001, context.getRank()); | |
e31e01e8 FC |
873 | } |
874 | ||
6e1886bc | 875 | @Test |
54a7a54c | 876 | public void testSeekOnRankNotOnCacheBoundary() { |
f17b2f70 FC |
877 | // Position trace at event rank 9 |
878 | ITmfContext context = fTrace.seekEvent(9); | |
54d55ced | 879 | assertEquals("Event rank", 9, context.getRank()); |
f17b2f70 | 880 | |
72f1e62a | 881 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
882 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
883 | assertEquals("Event rank", 9, context.getRank()); | |
f17b2f70 | 884 | |
c32744d6 | 885 | event = fTrace.getNext(context); |
54d55ced FC |
886 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
887 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 888 | |
f17b2f70 | 889 | // Position trace at event rank 999 |
54d55ced FC |
890 | context = fTrace.seekEvent(999); |
891 | assertEquals("Event rank", 999, context.getRank()); | |
f17b2f70 | 892 | |
9b635e61 | 893 | event = fTrace.parseEvent(context); |
54d55ced FC |
894 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
895 | assertEquals("Event rank", 999, context.getRank()); | |
f17b2f70 | 896 | |
c32744d6 | 897 | event = fTrace.getNext(context); |
54d55ced FC |
898 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
899 | assertEquals("Event rank", 1000, context.getRank()); | |
d18dd09b | 900 | |
f17b2f70 | 901 | // Position trace at event rank 1001 |
54d55ced FC |
902 | context = fTrace.seekEvent(1001); |
903 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 904 | |
9b635e61 | 905 | event = fTrace.parseEvent(context); |
54d55ced FC |
906 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
907 | assertEquals("Event rank", 1001, context.getRank()); | |
f17b2f70 | 908 | |
c32744d6 | 909 | event = fTrace.getNext(context); |
54d55ced FC |
910 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
911 | assertEquals("Event rank", 1002, context.getRank()); | |
912 | ||
f17b2f70 | 913 | // Position trace at event rank 4500 |
54d55ced FC |
914 | context = fTrace.seekEvent(4500); |
915 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 916 | |
9b635e61 | 917 | event = fTrace.parseEvent(context); |
54d55ced FC |
918 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
919 | assertEquals("Event rank", 4500, context.getRank()); | |
f17b2f70 | 920 | |
c32744d6 | 921 | event = fTrace.getNext(context); |
54d55ced FC |
922 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
923 | assertEquals("Event rank", 4501, context.getRank()); | |
d18dd09b ASL |
924 | } |
925 | ||
6e1886bc | 926 | @Test |
54a7a54c | 927 | public void testSeekEventOnRankOutOfScope() { |
f17b2f70 FC |
928 | // Position trace at beginning |
929 | ITmfContext context = fTrace.seekEvent(-1); | |
54d55ced | 930 | assertEquals("Event rank", 0, context.getRank()); |
f17b2f70 | 931 | |
72f1e62a | 932 | ITmfEvent event = fTrace.parseEvent(context); |
54d55ced FC |
933 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
934 | assertEquals("Event rank", 0, context.getRank()); | |
f17b2f70 | 935 | |
c32744d6 | 936 | event = fTrace.getNext(context); |
54d55ced FC |
937 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
938 | assertEquals("Event rank", 1, context.getRank()); | |
939 | ||
f17b2f70 | 940 | // Position trace at event passed the end |
54d55ced FC |
941 | context = fTrace.seekEvent(NB_EVENTS); |
942 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
f17b2f70 | 943 | |
9b635e61 | 944 | event = fTrace.parseEvent(context); |
0316808c | 945 | assertNull("Event", event); |
54d55ced | 946 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
f17b2f70 | 947 | |
c32744d6 | 948 | event = fTrace.getNext(context); |
0316808c | 949 | assertNull("Event", event); |
54d55ced FC |
950 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
951 | } | |
f17b2f70 | 952 | |
20658947 FC |
953 | // ------------------------------------------------------------------------ |
954 | // parseEvent - make sure parseEvent doesn't update the context | |
955 | // ------------------------------------------------------------------------ | |
956 | ||
6e1886bc | 957 | @Test |
54a7a54c | 958 | public void testParseEvent() { |
20658947 FC |
959 | final int NB_READS = 20; |
960 | ||
961 | // On lower bound, returns the first event (ts = 0) | |
962 | final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); | |
963 | TmfContext svContext = new TmfContext(context); | |
964 | ||
965 | ITmfEvent event = fTrace.parseEvent(context); | |
966 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
967 | assertEquals("Event rank", 0, context.getRank()); | |
968 | assertTrue("parseEvent", context.equals(svContext)); | |
969 | ||
970 | event = fTrace.parseEvent(context); | |
971 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
972 | assertEquals("Event rank", 0, context.getRank()); | |
973 | assertTrue("parseEvent", context.equals(svContext)); | |
974 | ||
975 | event = fTrace.parseEvent(context); | |
976 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
977 | assertEquals("Event rank", 0, context.getRank()); | |
978 | assertTrue("parseEvent", context.equals(svContext)); | |
979 | ||
980 | // Position the trace at event NB_READS | |
981 | for (int i = 1; i < NB_READS; i++) { | |
c32744d6 | 982 | event = fTrace.getNext(context); |
20658947 FC |
983 | assertEquals("Event timestamp", i, event.getTimestamp().getValue()); |
984 | } | |
985 | ||
986 | svContext = new TmfContext(context); | |
987 | event = fTrace.parseEvent(context); | |
988 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); | |
989 | assertEquals("Event rank", NB_READS -1 , context.getRank()); | |
990 | assertTrue("parseEvent", context.equals(svContext)); | |
991 | ||
992 | event = fTrace.parseEvent(context); | |
993 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); | |
994 | assertEquals("Event rank", NB_READS - 1, context.getRank()); | |
995 | assertTrue("parseEvent", context.equals(svContext)); | |
996 | } | |
997 | ||
998 | // ------------------------------------------------------------------------ | |
17324c9a | 999 | // getNext - updates the context |
20658947 FC |
1000 | // ------------------------------------------------------------------------ |
1001 | ||
6e1886bc | 1002 | @Test |
54a7a54c | 1003 | public void testGetNextAfteSeekingOnTS_1() { |
17324c9a | 1004 | final long INITIAL_TS = 1; |
20658947 FC |
1005 | final int NB_READS = 20; |
1006 | ||
1007 | // On lower bound, returns the first event (ts = 1) | |
17324c9a | 1008 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); |
20658947 FC |
1009 | |
1010 | // Read NB_EVENTS | |
1011 | ITmfEvent event; | |
1012 | for (int i = 0; i < NB_READS; i++) { | |
c32744d6 | 1013 | event = fTrace.getNext(context); |
17324c9a FC |
1014 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
1015 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
20658947 FC |
1016 | } |
1017 | ||
1018 | // Make sure we stay positioned | |
1019 | event = fTrace.parseEvent(context); | |
17324c9a FC |
1020 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
1021 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
1022 | } | |
1023 | ||
6e1886bc | 1024 | @Test |
54a7a54c | 1025 | public void testGetNextAfteSeekingOnTS_2() { |
17324c9a FC |
1026 | final long INITIAL_TS = 2; |
1027 | final int NB_READS = 20; | |
1028 | ||
1029 | // On lower bound, returns the first event (ts = 500) | |
1030 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
1031 | ||
1032 | // Read NB_EVENTS | |
1033 | ITmfEvent event; | |
1034 | for (int i = 0; i < NB_READS; i++) { | |
1035 | event = fTrace.getNext(context); | |
1036 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1037 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
1038 | } | |
1039 | ||
1040 | // Make sure we stay positioned | |
1041 | event = fTrace.parseEvent(context); | |
1042 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1043 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
1044 | } | |
1045 | ||
6e1886bc | 1046 | @Test |
54a7a54c | 1047 | public void testGetNextAfteSeekingOnTS_3() { |
17324c9a FC |
1048 | final long INITIAL_TS = 500; |
1049 | final int NB_READS = 20; | |
1050 | ||
1051 | // On lower bound, returns the first event (ts = 500) | |
1052 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
1053 | ||
1054 | // Read NB_EVENTS | |
1055 | ITmfEvent event; | |
1056 | for (int i = 0; i < NB_READS; i++) { | |
1057 | event = fTrace.getNext(context); | |
1058 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1059 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
1060 | } | |
1061 | ||
1062 | // Make sure we stay positioned | |
1063 | event = fTrace.parseEvent(context); | |
1064 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1065 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
1066 | } | |
1067 | ||
6e1886bc | 1068 | @Test |
54a7a54c | 1069 | public void testGetNextAfterSeekingOnRank_1() { |
17324c9a FC |
1070 | final long INITIAL_RANK = 0L; |
1071 | final int NB_READS = 20; | |
1072 | ||
1073 | // On lower bound, returns the first event (rank = 0) | |
1074 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1075 | ||
1076 | // Read NB_EVENTS | |
1077 | ITmfEvent event; | |
1078 | for (int i = 0; i < NB_READS; i++) { | |
1079 | event = fTrace.getNext(context); | |
1080 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1081 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1082 | } | |
1083 | ||
1084 | // Make sure we stay positioned | |
1085 | event = fTrace.parseEvent(context); | |
1086 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1087 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1088 | } | |
1089 | ||
6e1886bc | 1090 | @Test |
54a7a54c | 1091 | public void testGetNextAfterSeekingOnRank_2() { |
17324c9a FC |
1092 | final long INITIAL_RANK = 1L; |
1093 | final int NB_READS = 20; | |
1094 | ||
1095 | // On lower bound, returns the first event (rank = 0) | |
1096 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1097 | ||
1098 | // Read NB_EVENTS | |
1099 | ITmfEvent event; | |
1100 | for (int i = 0; i < NB_READS; i++) { | |
1101 | event = fTrace.getNext(context); | |
1102 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1103 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1104 | } | |
1105 | ||
1106 | // Make sure we stay positioned | |
1107 | event = fTrace.parseEvent(context); | |
1108 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1109 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1110 | } | |
1111 | ||
6e1886bc | 1112 | @Test |
54a7a54c | 1113 | public void testGetNextAfterSeekingOnRank_3() { |
17324c9a FC |
1114 | final long INITIAL_RANK = 500L; |
1115 | final int NB_READS = 20; | |
1116 | ||
1117 | // On lower bound, returns the first event (rank = 0) | |
1118 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); | |
1119 | ||
1120 | // Read NB_EVENTS | |
1121 | ITmfEvent event; | |
1122 | for (int i = 0; i < NB_READS; i++) { | |
1123 | event = fTrace.getNext(context); | |
1124 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
1125 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
1126 | } | |
1127 | ||
1128 | // Make sure we stay positioned | |
1129 | event = fTrace.parseEvent(context); | |
1130 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
1131 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
1132 | } | |
1133 | ||
6e1886bc | 1134 | @Test |
54a7a54c | 1135 | public void testGetNextAfterSeekingOnLocation_1() { |
1e1bef82 | 1136 | final ITmfLocation INITIAL_LOC = null; |
17324c9a FC |
1137 | final long INITIAL_TS = 1; |
1138 | final int NB_READS = 20; | |
1139 | ||
1140 | // On lower bound, returns the first event (ts = 1) | |
1141 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1142 | ||
1143 | // Read NB_EVENTS | |
1144 | ITmfEvent event; | |
1145 | for (int i = 0; i < NB_READS; i++) { | |
1146 | event = fTrace.getNext(context); | |
1147 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1148 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
1149 | } | |
1150 | ||
1151 | // Make sure we stay positioned | |
1152 | event = fTrace.parseEvent(context); | |
1153 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1154 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
1155 | } | |
1156 | ||
6e1886bc | 1157 | @Test |
54a7a54c | 1158 | public void testGetNextAfterSeekingOnLocation_2() { |
1e1bef82 | 1159 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(1L).getLocation(); |
17324c9a FC |
1160 | final long INITIAL_TS = 2; |
1161 | final int NB_READS = 20; | |
1162 | ||
1163 | // On lower bound, returns the first event (ts = 501) | |
1164 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1165 | ||
1166 | // Read NB_EVENTS | |
1167 | ITmfEvent event; | |
1168 | for (int i = 0; i < NB_READS; i++) { | |
1169 | event = fTrace.getNext(context); | |
1170 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1171 | } | |
1172 | ||
1173 | // Make sure we stay positioned | |
1174 | event = fTrace.parseEvent(context); | |
1175 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1176 | } | |
1177 | ||
6e1886bc | 1178 | @Test |
54a7a54c | 1179 | public void testGetNextAfterSeekingOnLocation_3() { |
1e1bef82 | 1180 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(500L).getLocation(); |
17324c9a FC |
1181 | final long INITIAL_TS = 501; |
1182 | final int NB_READS = 20; | |
1183 | ||
1184 | // On lower bound, returns the first event (ts = 501) | |
1185 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); | |
1186 | ||
1187 | // Read NB_EVENTS | |
1188 | ITmfEvent event; | |
1189 | for (int i = 0; i < NB_READS; i++) { | |
1190 | event = fTrace.getNext(context); | |
1191 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
1192 | } | |
1193 | ||
1194 | // Make sure we stay positioned | |
1195 | event = fTrace.parseEvent(context); | |
1196 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
1197 | } | |
1198 | ||
6e1886bc | 1199 | @Test |
54a7a54c | 1200 | public void testGetNextLocation() { |
17324c9a FC |
1201 | ITmfContext context1 = fTrace.seekEvent(0); |
1202 | fTrace.getNext(context1); | |
d62bb185 | 1203 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
1204 | ITmfEvent event1 = fTrace.getNext(context1); |
1205 | ITmfContext context2 = fTrace.seekEvent(location); | |
1206 | ITmfEvent event2 = fTrace.getNext(context2); | |
1207 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); | |
1208 | } | |
1209 | ||
6e1886bc | 1210 | @Test |
54a7a54c | 1211 | public void testGetNextEndLocation() { |
17324c9a FC |
1212 | ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); |
1213 | fTrace.getNext(context1); | |
d62bb185 | 1214 | ITmfLocation location = context1.getLocation(); |
17324c9a FC |
1215 | ITmfContext context2 = fTrace.seekEvent(location); |
1216 | ITmfEvent event = fTrace.getNext(context2); | |
1217 | assertNull("Event", event); | |
20658947 FC |
1218 | } |
1219 | ||
e31e01e8 | 1220 | // ------------------------------------------------------------------------ |
d18dd09b | 1221 | // processRequest |
e31e01e8 | 1222 | // ------------------------------------------------------------------------ |
d18dd09b | 1223 | |
6e1886bc | 1224 | @Test |
54a7a54c | 1225 | public void testProcessEventRequestForAllEvents() throws InterruptedException { |
6e1886bc | 1226 | final int blockSize = 1; |
6256d8ad | 1227 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
7e6347b0 FC |
1228 | |
1229 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); | |
6e1886bc | 1230 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, blockSize) { |
7e6347b0 | 1231 | @Override |
6256d8ad | 1232 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1233 | super.handleData(event); |
1234 | requestedEvents.add(event); | |
1235 | } | |
1236 | }; | |
2771b032 | 1237 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1238 | providers[0].sendRequest(request); |
1239 | request.waitForCompletion(); | |
1240 | ||
1241 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); | |
1242 | assertTrue("isCompleted", request.isCompleted()); | |
1243 | assertFalse("isCancelled", request.isCancelled()); | |
1244 | ||
1245 | // Ensure that we have distinct events. | |
1246 | // Don't go overboard: we are not validating the stub! | |
1247 | for (int i = 0; i < NB_EVENTS; i++) { | |
1248 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); | |
1249 | } | |
1250 | } | |
1251 | ||
6e1886bc | 1252 | @Test |
54a7a54c | 1253 | public void testProcessEventRequestForNbEvents() throws InterruptedException { |
6e1886bc AM |
1254 | final int blockSize = 100; |
1255 | final int nbEvents = 1000; | |
6256d8ad | 1256 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 1257 | |
f17b2f70 | 1258 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
6e1886bc | 1259 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
f17b2f70 | 1260 | @Override |
6256d8ad | 1261 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1262 | super.handleData(event); |
1263 | requestedEvents.add(event); | |
1264 | } | |
d18dd09b | 1265 | }; |
2771b032 | 1266 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1267 | providers[0].sendRequest(request); |
1268 | request.waitForCompletion(); | |
d18dd09b | 1269 | |
6e1886bc | 1270 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
d18dd09b ASL |
1271 | assertTrue("isCompleted", request.isCompleted()); |
1272 | assertFalse("isCancelled", request.isCancelled()); | |
1273 | ||
1274 | // Ensure that we have distinct events. | |
f17b2f70 | 1275 | // Don't go overboard: we are not validating the stub! |
6e1886bc | 1276 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 | 1277 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 1278 | } |
d18dd09b | 1279 | } |
f17b2f70 | 1280 | |
6e1886bc | 1281 | @Test |
54a7a54c | 1282 | public void testProcessEventRequestForSomeEvents() throws InterruptedException { |
6e1886bc | 1283 | final int blockSize = 1; |
7e6347b0 | 1284 | final long startTime = 100; |
6e1886bc | 1285 | final int nbEvents = 1000; |
6256d8ad | 1286 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 1287 | |
7e6347b0 | 1288 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); |
6e1886bc | 1289 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { |
f17b2f70 | 1290 | @Override |
6256d8ad | 1291 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1292 | super.handleData(event); |
1293 | requestedEvents.add(event); | |
1294 | } | |
d18dd09b | 1295 | }; |
2771b032 | 1296 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1297 | providers[0].sendRequest(request); |
1298 | request.waitForCompletion(); | |
d18dd09b | 1299 | |
6e1886bc | 1300 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
d18dd09b ASL |
1301 | assertTrue("isCompleted", request.isCompleted()); |
1302 | assertFalse("isCancelled", request.isCancelled()); | |
1303 | ||
1304 | // Ensure that we have distinct events. | |
f17b2f70 | 1305 | // Don't go overboard: we are not validating the stub! |
6e1886bc | 1306 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 FC |
1307 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
1308 | } | |
1309 | } | |
1310 | ||
6e1886bc | 1311 | @Test |
54a7a54c | 1312 | public void testProcessEventRequestForOtherEvents() throws InterruptedException { |
6e1886bc | 1313 | final int blockSize = 1; |
7e6347b0 FC |
1314 | final int startIndex = 99; |
1315 | final long startTime = 100; | |
6e1886bc | 1316 | final int nbEvents = 1000; |
6256d8ad | 1317 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
7e6347b0 FC |
1318 | |
1319 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); | |
6e1886bc | 1320 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, nbEvents, blockSize) { |
7e6347b0 | 1321 | @Override |
6256d8ad | 1322 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1323 | super.handleData(event); |
1324 | requestedEvents.add(event); | |
1325 | } | |
1326 | }; | |
2771b032 | 1327 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1328 | providers[0].sendRequest(request); |
1329 | request.waitForCompletion(); | |
1330 | ||
6e1886bc | 1331 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
7e6347b0 FC |
1332 | assertTrue("isCompleted", request.isCompleted()); |
1333 | assertFalse("isCancelled", request.isCancelled()); | |
1334 | ||
1335 | // Ensure that we have distinct events. | |
1336 | // Don't go overboard: we are not validating the stub! | |
6e1886bc | 1337 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 FC |
1338 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
1339 | } | |
1340 | } | |
1341 | ||
6e1886bc | 1342 | @Test |
54a7a54c | 1343 | public void testProcessDataRequestForSomeEvents() throws InterruptedException { |
7e6347b0 | 1344 | final int startIndex = 100; |
6e1886bc | 1345 | final int nbEvents = 1000; |
6256d8ad | 1346 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
7e6347b0 | 1347 | |
6e1886bc | 1348 | final TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbEvents) { |
7e6347b0 | 1349 | @Override |
6256d8ad | 1350 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1351 | super.handleData(event); |
1352 | requestedEvents.add(event); | |
1353 | } | |
1354 | }; | |
2771b032 | 1355 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1356 | providers[0].sendRequest(request); |
1357 | request.waitForCompletion(); | |
1358 | ||
6e1886bc | 1359 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
7e6347b0 FC |
1360 | assertTrue("isCompleted", request.isCompleted()); |
1361 | assertFalse("isCancelled", request.isCancelled()); | |
1362 | ||
1363 | // Ensure that we have distinct events. | |
1364 | // Don't go overboard: we are not validating the stub! | |
6e1886bc | 1365 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 | 1366 | assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 1367 | } |
d18dd09b | 1368 | } |
f17b2f70 | 1369 | |
e31e01e8 | 1370 | // ------------------------------------------------------------------------ |
d18dd09b | 1371 | // cancel |
e31e01e8 | 1372 | // ------------------------------------------------------------------------ |
d18dd09b | 1373 | |
6e1886bc | 1374 | @Test |
54a7a54c | 1375 | public void testCancel() throws InterruptedException { |
6256d8ad | 1376 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
d18dd09b | 1377 | |
f17b2f70 | 1378 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
2771b032 | 1379 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
f17b2f70 FC |
1380 | int nbRead = 0; |
1381 | @Override | |
6256d8ad | 1382 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1383 | super.handleData(event); |
1384 | requestedEvents.add(event); | |
20658947 | 1385 | if (++nbRead == BLOCK_SIZE) { |
f17b2f70 | 1386 | cancel(); |
20658947 | 1387 | } |
f17b2f70 | 1388 | } |
d18dd09b | 1389 | }; |
2771b032 | 1390 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1391 | providers[0].sendRequest(request); |
1392 | request.waitForCompletion(); | |
d18dd09b | 1393 | |
cb866e08 | 1394 | assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size()); |
d18dd09b ASL |
1395 | assertTrue("isCompleted", request.isCompleted()); |
1396 | assertTrue("isCancelled", request.isCancelled()); | |
1397 | } | |
e31e01e8 | 1398 | |
1703b536 FC |
1399 | // ------------------------------------------------------------------------ |
1400 | // toString | |
1401 | // ------------------------------------------------------------------------ | |
1402 | ||
6e1886bc | 1403 | @Test |
54a7a54c | 1404 | public void testDefaultTmfTraceStub() { |
1703b536 | 1405 | assertFalse ("Open trace", fTrace == null); |
2771b032 | 1406 | assertEquals("getType", ITmfEvent.class, fTrace.getType()); |
1703b536 FC |
1407 | assertNull ("getResource", fTrace.getResource()); |
1408 | assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); | |
1409 | assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval()); | |
9c4d52ee | 1410 | assertEquals("getName", TEST_TRACE.getPath(), fTrace.getName()); |
1703b536 FC |
1411 | |
1412 | assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents()); | |
1413 | assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); | |
1414 | assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); | |
1415 | assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); | |
1416 | assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); | |
1417 | ||
1418 | String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() + | |
1419 | ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() + | |
1420 | ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() + | |
1421 | "]"; | |
1422 | assertEquals("toString", expected, fTrace.toString()); | |
1423 | } | |
1424 | ||
66262ad8 BH |
1425 | // ------------------------------------------------------------------------ |
1426 | // getInitialRangeOffset, getCurrentRange, getCurrentTime | |
1427 | // ------------------------------------------------------------------------ | |
6e1886bc AM |
1428 | |
1429 | @Test | |
66262ad8 BH |
1430 | public void testCurrentTimeValues() throws TmfTraceException { |
1431 | ||
1432 | TmfTraceStub trace = null; | |
1433 | File testfile = null; | |
1434 | try { | |
9c4d52ee | 1435 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
66262ad8 BH |
1436 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
1437 | trace = new TmfTraceStub(testfile.toURI().getPath()); | |
1438 | // verify initial values | |
1439 | TmfTimestamp defaultInitRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE); | |
1440 | assertEquals("getInitialRangeOffset", defaultInitRange, trace.getInitialRangeOffset()); | |
66262ad8 | 1441 | trace.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE)); |
51e75066 | 1442 | trace.indexTrace(true); |
66262ad8 BH |
1443 | } catch (final URISyntaxException e) { |
1444 | fail("URISyntaxException"); | |
1445 | } catch (final IOException e) { | |
1446 | fail("IOException"); | |
1447 | } | |
1448 | assertFalse ("Open trace", trace == null); | |
1449 | ||
1450 | TmfTimestamp initRange = new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE); | |
1451 | assertEquals("getInitialRangeOffset", initRange, trace.getInitialRangeOffset()); | |
66262ad8 | 1452 | } |
9b749023 | 1453 | } |