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