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