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