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