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