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