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