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 GB |
454 | |
455 | /* Make sure all modules of type TestAnalysis are returned in the second call */ | |
ff3f02c8 AM |
456 | for (IAnalysisModule module : modules) { |
457 | if (module instanceof TestAnalysis) { | |
458 | IAnalysisModule otherModule = fTrace.getAnalysisModule(module.getId()); | |
459 | assertNotNull(otherModule); | |
460 | assertTrue(otherModule.equals(module)); | |
8a6ff07f GB |
461 | } |
462 | } | |
a51b2b9f | 463 | |
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 { |
ccf2bbb4 | 1144 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
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 | }; | |
fd3f1eff | 1155 | final ITmfEventProvider[] 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; |
ccf2bbb4 | 1173 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
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 | }; |
fd3f1eff | 1184 | final ITmfEventProvider[] 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; |
ccf2bbb4 | 1203 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
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 | }; |
fd3f1eff | 1214 | final ITmfEventProvider[] 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; |
ccf2bbb4 | 1234 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
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 | }; | |
fd3f1eff | 1245 | final ITmfEventProvider[] 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; |
ccf2bbb4 | 1264 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
7e6347b0 | 1265 | |
fd3f1eff AM |
1266 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
1267 | TmfTimeRange.ETERNITY, | |
9765b9f1 AM |
1268 | startIndex, |
1269 | nbEvents, | |
fd3f1eff | 1270 | TmfEventRequest.ExecutionType.FOREGROUND) { |
7e6347b0 | 1271 | @Override |
6256d8ad | 1272 | public void handleData(final ITmfEvent event) { |
7e6347b0 FC |
1273 | super.handleData(event); |
1274 | requestedEvents.add(event); | |
1275 | } | |
1276 | }; | |
fd3f1eff | 1277 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
7e6347b0 FC |
1278 | providers[0].sendRequest(request); |
1279 | request.waitForCompletion(); | |
1280 | ||
6e1886bc | 1281 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); |
7e6347b0 FC |
1282 | assertTrue("isCompleted", request.isCompleted()); |
1283 | assertFalse("isCancelled", request.isCancelled()); | |
1284 | ||
1285 | // Ensure that we have distinct events. | |
1286 | // Don't go overboard: we are not validating the stub! | |
6e1886bc | 1287 | for (int i = 0; i < nbEvents; i++) { |
7e6347b0 | 1288 | assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 1289 | } |
d18dd09b | 1290 | } |
f17b2f70 | 1291 | |
e31e01e8 | 1292 | // ------------------------------------------------------------------------ |
d18dd09b | 1293 | // cancel |
e31e01e8 | 1294 | // ------------------------------------------------------------------------ |
d18dd09b | 1295 | |
6e1886bc | 1296 | @Test |
54a7a54c | 1297 | public void testCancel() throws InterruptedException { |
7886b91f | 1298 | final int limit = 500; |
ccf2bbb4 | 1299 | final Vector<ITmfEvent> requestedEvents = new Vector<>(); |
d18dd09b | 1300 | |
f17b2f70 | 1301 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
7184fc40 | 1302 | final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, |
672a642a | 1303 | range, 0, NB_EVENTS, ExecutionType.FOREGROUND) { |
f17b2f70 | 1304 | int nbRead = 0; |
672a642a | 1305 | |
f17b2f70 | 1306 | @Override |
6256d8ad | 1307 | public void handleData(final ITmfEvent event) { |
f17b2f70 FC |
1308 | super.handleData(event); |
1309 | requestedEvents.add(event); | |
672a642a | 1310 | if (++nbRead == limit) { |
f17b2f70 | 1311 | cancel(); |
20658947 | 1312 | } |
f17b2f70 | 1313 | } |
d18dd09b | 1314 | }; |
fd3f1eff | 1315 | final ITmfEventProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, TmfTraceStub.class); |
951d134a FC |
1316 | providers[0].sendRequest(request); |
1317 | request.waitForCompletion(); | |
d18dd09b | 1318 | |
672a642a | 1319 | assertEquals("nbEvents", limit, requestedEvents.size()); |
d18dd09b ASL |
1320 | assertTrue("isCompleted", request.isCompleted()); |
1321 | assertTrue("isCancelled", request.isCancelled()); | |
1322 | } | |
e31e01e8 | 1323 | |
1703b536 FC |
1324 | // ------------------------------------------------------------------------ |
1325 | // toString | |
1326 | // ------------------------------------------------------------------------ | |
1327 | ||
6e1886bc | 1328 | @Test |
54a7a54c | 1329 | public void testDefaultTmfTraceStub() { |
1703b536 | 1330 | assertFalse ("Open trace", fTrace == null); |
2771b032 | 1331 | assertEquals("getType", ITmfEvent.class, fTrace.getType()); |
1703b536 | 1332 | assertNull ("getResource", fTrace.getResource()); |
1703b536 | 1333 | assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval()); |
9c4d52ee | 1334 | assertEquals("getName", TEST_TRACE.getPath(), fTrace.getName()); |
1703b536 FC |
1335 | |
1336 | assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents()); | |
1337 | assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); | |
1338 | assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); | |
1339 | assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); | |
1340 | assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); | |
1341 | ||
1342 | String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() + | |
1343 | ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() + | |
1344 | ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() + | |
1345 | "]"; | |
1346 | assertEquals("toString", expected, fTrace.toString()); | |
1347 | } | |
1348 | ||
66262ad8 BH |
1349 | // ------------------------------------------------------------------------ |
1350 | // getInitialRangeOffset, getCurrentRange, getCurrentTime | |
1351 | // ------------------------------------------------------------------------ | |
6e1886bc AM |
1352 | |
1353 | @Test | |
66262ad8 BH |
1354 | public void testCurrentTimeValues() throws TmfTraceException { |
1355 | ||
1356 | TmfTraceStub trace = null; | |
1357 | File testfile = null; | |
1358 | try { | |
9c4d52ee | 1359 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null); |
66262ad8 | 1360 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 1361 | trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); |
66262ad8 BH |
1362 | // verify initial values |
1363 | TmfTimestamp defaultInitRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE); | |
1364 | assertEquals("getInitialRangeOffset", defaultInitRange, trace.getInitialRangeOffset()); | |
66262ad8 | 1365 | trace.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE)); |
51e75066 | 1366 | trace.indexTrace(true); |
e73a4ba5 GB |
1367 | |
1368 | TmfTimestamp initRange = new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE); | |
1369 | assertEquals("getInitialRangeOffset", initRange, trace.getInitialRangeOffset()); | |
1370 | ||
66262ad8 BH |
1371 | } catch (final URISyntaxException e) { |
1372 | fail("URISyntaxException"); | |
1373 | } catch (final IOException e) { | |
1374 | fail("IOException"); | |
1375 | } | |
66262ad8 | 1376 | } |
bb52f9bc GB |
1377 | |
1378 | /** | |
1379 | * Run the String getHostId() method test | |
1380 | */ | |
1381 | @Test | |
1382 | public void testTraceHostId() { | |
1383 | String a = fTrace.getHostId(); | |
1384 | assertEquals("A-Test-10K", a); | |
1385 | } | |
9b749023 | 1386 | } |