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