Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
e31e01e8 | 2 | * Copyright (c) 2009, 2010 Ericsson |
d18dd09b ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.tests.trace; | |
14 | ||
15 | import java.io.File; | |
e1ab8984 FC |
16 | import java.io.IOException; |
17 | import java.net.URISyntaxException; | |
18 | import java.net.URL; | |
d18dd09b ASL |
19 | import java.util.Vector; |
20 | ||
e1ab8984 FC |
21 | import junit.framework.TestCase; |
22 | ||
23 | import org.eclipse.core.runtime.FileLocator; | |
24 | import org.eclipse.core.runtime.Path; | |
951d134a | 25 | import org.eclipse.linuxtools.tmf.component.ITmfDataProvider; |
e31e01e8 | 26 | import org.eclipse.linuxtools.tmf.component.TmfProviderManager; |
d18dd09b ASL |
27 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
28 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
29 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
e31e01e8 | 30 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; |
e1ab8984 | 31 | import org.eclipse.linuxtools.tmf.tests.TmfCoreTestPlugin; |
ff4ed569 | 32 | import org.eclipse.linuxtools.tmf.trace.ITmfContext; |
54d55ced | 33 | import org.eclipse.linuxtools.tmf.trace.TmfCheckpoint; |
9f584e4c | 34 | import org.eclipse.linuxtools.tmf.trace.TmfContext; |
ff4ed569 | 35 | import org.eclipse.linuxtools.tmf.trace.TmfTrace; |
d18dd09b ASL |
36 | import org.eclipse.linuxtools.tmf.trace.TmfTraceStub; |
37 | ||
38 | /** | |
39 | * <b><u>TmfTraceTest</u></b> | |
40 | * <p> | |
ff4ed569 | 41 | * Test suite for the TmfTrace class. |
d18dd09b ASL |
42 | */ |
43 | public class TmfTraceTest extends TestCase { | |
44 | ||
ff4ed569 FC |
45 | // ------------------------------------------------------------------------ |
46 | // Variables | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
d18dd09b | 49 | private static final String DIRECTORY = "testfiles"; |
85fb0e54 | 50 | private static final String TEST_STREAM = "A-Test-10K"; |
ff4ed569 | 51 | private static final int BLOCK_SIZE = 500; |
e31e01e8 FC |
52 | private static final int NB_EVENTS = 10000; |
53 | private static TmfTraceStub fTrace = null; | |
d18dd09b ASL |
54 | |
55 | private static byte SCALE = (byte) -3; | |
56 | ||
e31e01e8 | 57 | // ------------------------------------------------------------------------ |
d18dd09b | 58 | // Housekeeping |
e31e01e8 | 59 | // ------------------------------------------------------------------------ |
d18dd09b | 60 | |
ff4ed569 FC |
61 | public TmfTraceTest(String name) throws Exception { |
62 | super(name); | |
63 | } | |
64 | ||
65 | @Override | |
66 | protected void setUp() throws Exception { | |
67 | super.setUp(); | |
68 | fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); | |
cb866e08 FC |
69 | TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class) { |
70 | @Override | |
71 | public void handleData() { | |
72 | } | |
73 | }; | |
74 | fTrace.sendRequest(request); | |
75 | request.waitForCompletion(); | |
ff4ed569 FC |
76 | } |
77 | ||
78 | @Override | |
79 | protected void tearDown() throws Exception { | |
80 | super.tearDown(); | |
81 | fTrace.dispose(); | |
82 | fTrace = null; | |
83 | } | |
84 | ||
85 | // ------------------------------------------------------------------------ | |
86 | // Helper functions | |
87 | // ------------------------------------------------------------------------ | |
88 | ||
e1ab8984 FC |
89 | private TmfTraceStub setupTrace(String path) { |
90 | if (fTrace == null) { | |
91 | try { | |
cbd4ad82 | 92 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); |
e1ab8984 | 93 | File test = new File(FileLocator.toFileURL(location).toURI()); |
ff4ed569 | 94 | fTrace = new TmfTraceStub(test.getPath(), BLOCK_SIZE, false); |
550d787e | 95 | // fTrace.indexTrace(true); |
e1ab8984 FC |
96 | } catch (URISyntaxException e) { |
97 | e.printStackTrace(); | |
98 | } catch (IOException e) { | |
99 | e.printStackTrace(); | |
100 | } | |
101 | } | |
102 | return fTrace; | |
103 | } | |
104 | ||
e31e01e8 | 105 | // ------------------------------------------------------------------------ |
d18dd09b | 106 | // Constructors |
e31e01e8 | 107 | // ------------------------------------------------------------------------ |
d18dd09b ASL |
108 | |
109 | public void testTmfTraceDefault() throws Exception { | |
e1ab8984 | 110 | TmfTraceStub trace = null; |
ff4ed569 | 111 | File testfile = null; |
e1ab8984 | 112 | try { |
cbd4ad82 | 113 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
ff4ed569 FC |
114 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
115 | trace = new TmfTraceStub(testfile.getPath()); | |
e1ab8984 | 116 | } catch (URISyntaxException e) { |
ff4ed569 | 117 | fail("URISyntaxException"); |
e1ab8984 | 118 | } catch (IOException e) { |
ff4ed569 | 119 | fail("IOException"); |
e1ab8984 | 120 | } |
ff4ed569 FC |
121 | assertTrue ("Open trace", trace != null); |
122 | assertEquals("getType", TmfEvent.class, trace.getType()); | |
123 | assertEquals("getPath", testfile.getPath(), trace.getPath()); | |
124 | assertEquals("getName", TEST_STREAM, trace.getName()); | |
125 | assertEquals("getCacheSize", TmfTrace.DEFAULT_CACHE_SIZE, trace.getCacheSize()); | |
126 | } | |
127 | ||
128 | public void testTmfTraceDefaultCacheSize() throws Exception { | |
129 | TmfTraceStub trace = null; | |
130 | File testfile = null; | |
131 | try { | |
132 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); | |
133 | testfile = new File(FileLocator.toFileURL(location).toURI()); | |
134 | trace = new TmfTraceStub(testfile.getPath(), 0); | |
135 | } catch (URISyntaxException e) { | |
136 | fail("URISyntaxException"); | |
137 | } catch (IOException e) { | |
138 | fail("IOException"); | |
139 | } | |
140 | assertTrue ("Open trace", trace != null); | |
141 | assertEquals("getType", TmfEvent.class, trace.getType()); | |
142 | assertEquals("getPath", testfile.getPath(), trace.getPath()); | |
143 | assertEquals("getName", TEST_STREAM, trace.getName()); | |
144 | assertEquals("getCacheSize", TmfTrace.DEFAULT_CACHE_SIZE, trace.getCacheSize()); | |
d18dd09b ASL |
145 | } |
146 | ||
147 | public void testTmfTrace() throws Exception { | |
ff4ed569 FC |
148 | assertEquals("getType", TmfEvent.class, fTrace.getType()); |
149 | assertEquals("getName", TEST_STREAM, fTrace.getName()); | |
150 | assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); | |
151 | } | |
152 | ||
153 | public void testClone() throws Exception { | |
154 | TmfTraceStub trace = fTrace.clone(); | |
155 | assertEquals("getType", TmfEvent.class, trace.getType()); | |
156 | assertEquals("getPath", fTrace.getPath(), trace.getPath()); | |
157 | assertEquals("getName", TEST_STREAM, trace.getName()); | |
158 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); | |
159 | assertEquals("getTimeRange", fTrace.getTimeRange(), trace.getTimeRange()); | |
d18dd09b ASL |
160 | } |
161 | ||
ff4ed569 FC |
162 | // ------------------------------------------------------------------------ |
163 | // Get/Set time range | |
164 | // ------------------------------------------------------------------------ | |
165 | ||
166 | public void testSetTimeRange() throws Exception { | |
167 | TmfTraceStub trace = fTrace.clone(); | |
168 | ||
169 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
170 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
171 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
172 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
173 | ||
174 | trace.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200))); | |
175 | assertEquals("setTimeRange", 100, trace.getTimeRange().getStartTime().getValue()); | |
176 | assertEquals("setTimeRange", 200, trace.getTimeRange().getEndTime().getValue()); | |
177 | assertEquals("setTimeRange", 100, trace.getStartTime().getValue()); | |
178 | assertEquals("setTimeRange", 200, trace.getEndTime().getValue()); | |
179 | } | |
180 | ||
181 | public void testSetStartTime() throws Exception { | |
182 | TmfTraceStub trace = fTrace.clone(); | |
183 | ||
184 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
185 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
186 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
187 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
188 | ||
189 | trace.setStartTime(new TmfTimestamp(100)); | |
190 | assertEquals("setStartTime", 100, trace.getTimeRange().getStartTime().getValue()); | |
191 | assertEquals("setStartTime", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
192 | assertEquals("setStartTime", 100, trace.getStartTime().getValue()); | |
193 | assertEquals("setStartTime", NB_EVENTS, trace.getEndTime().getValue()); | |
194 | } | |
195 | ||
196 | public void testSetEndTime() throws Exception { | |
197 | TmfTraceStub trace = fTrace.clone(); | |
198 | ||
199 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); | |
200 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); | |
201 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); | |
202 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); | |
203 | ||
204 | trace.setEndTime(new TmfTimestamp(100)); | |
205 | assertEquals("setEndTime", 1, trace.getTimeRange().getStartTime().getValue()); | |
206 | assertEquals("setEndTime", 100, trace.getTimeRange().getEndTime().getValue()); | |
207 | assertEquals("setEndTime", 1, trace.getStartTime().getValue()); | |
208 | assertEquals("setEndTime", 100, trace.getEndTime().getValue()); | |
209 | } | |
210 | ||
e31e01e8 | 211 | // ------------------------------------------------------------------------ |
54d55ced | 212 | // Verify checkpoints |
e31e01e8 | 213 | // ------------------------------------------------------------------------ |
d18dd09b | 214 | |
ff4ed569 FC |
215 | public void testTmfTraceIndexing() throws Exception { |
216 | assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); | |
217 | assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents()); | |
218 | assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); | |
219 | assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); | |
220 | assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); | |
221 | assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); | |
54d55ced FC |
222 | |
223 | Vector<TmfCheckpoint> checkpoints = fTrace.getCheckpoints(); | |
224 | int pageSize = fTrace.getCacheSize(); | |
225 | assertTrue("Checkpoints exist", checkpoints != null); | |
226 | ||
227 | // Validate that each checkpoint points to the right event | |
228 | for (int i = 0; i < checkpoints.size(); i++) { | |
229 | TmfCheckpoint checkpoint = checkpoints.get(i); | |
230 | TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize); | |
231 | TmfEvent event = fTrace.parseEvent(context); | |
232 | assertTrue(context.getRank() == i * pageSize); | |
233 | assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); | |
234 | } | |
235 | } | |
236 | ||
237 | // ------------------------------------------------------------------------ | |
238 | // parseEvent - make sure parseEvent doesn't update the context | |
239 | // ------------------------------------------------------------------------ | |
240 | ||
241 | public void testParseEvent() throws Exception { | |
242 | ||
243 | // On lower bound, returns the first event (ts = 0) | |
244 | TmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); | |
245 | ||
246 | TmfEvent event = fTrace.parseEvent(context); | |
247 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
248 | ||
249 | event = fTrace.parseEvent(context); | |
250 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
251 | ||
252 | event = fTrace.parseEvent(context); | |
253 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
254 | ||
255 | for (int i = 1; i < 20; i++) { | |
256 | event = fTrace.getNextEvent(context); | |
257 | assertEquals("Event timestamp", i, event.getTimestamp().getValue()); | |
258 | } | |
259 | ||
260 | event = fTrace.parseEvent(context); | |
261 | assertEquals("Event timestamp", 20, event.getTimestamp().getValue()); | |
262 | ||
263 | event = fTrace.parseEvent(context); | |
264 | assertEquals("Event timestamp", 20, event.getTimestamp().getValue()); | |
265 | } | |
266 | ||
267 | // ------------------------------------------------------------------------ | |
268 | // getNextEvent - updates the context | |
269 | // ------------------------------------------------------------------------ | |
270 | ||
271 | public void testGetNextEvent() throws Exception { | |
272 | ||
273 | // On lower bound, returns the first event (ts = 0) | |
274 | TmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); | |
275 | TmfEvent event = fTrace.getNextEvent(context); | |
276 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
277 | ||
278 | for (int i = 2; i < 20; i++) { | |
279 | event = fTrace.getNextEvent(context); | |
280 | assertEquals("Event timestamp", i, event.getTimestamp().getValue()); | |
281 | } | |
282 | } | |
283 | ||
284 | // ------------------------------------------------------------------------ | |
285 | // seekLocation | |
286 | // Note: seekLocation() does not reliably set the rank | |
287 | // ------------------------------------------------------------------------ | |
288 | ||
289 | public void testSeekLocationOnCacheBoundary() throws Exception { | |
290 | ||
291 | // Position trace at event rank 0 | |
9f584e4c | 292 | TmfContext context = fTrace.seekLocation(null); |
ff4ed569 | 293 | assertEquals("Event rank", 0, context.getRank()); |
54d55ced FC |
294 | TmfEvent event = fTrace.parseEvent(context); |
295 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
ff4ed569 | 296 | assertEquals("Event rank", 0, context.getRank()); |
54d55ced FC |
297 | event = fTrace.getNextEvent(context); |
298 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
ff4ed569 | 299 | assertEquals("Event rank", 1, context.getRank()); |
54d55ced FC |
300 | |
301 | // Position trace at event rank 1000 | |
302 | TmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); | |
303 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 304 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
305 | event = fTrace.parseEvent(context); |
306 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
ff4ed569 | 307 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
308 | event = fTrace.getNextEvent(context); |
309 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
ff4ed569 | 310 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
311 | |
312 | // Position trace at event rank 4000 | |
313 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); | |
314 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 315 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
316 | event = fTrace.parseEvent(context); |
317 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
ff4ed569 | 318 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
319 | event = fTrace.getNextEvent(context); |
320 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
ff4ed569 | 321 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
322 | } |
323 | ||
324 | public void testSeekLocationNotOnCacheBoundary() throws Exception { | |
325 | ||
326 | // Position trace at event rank 9 | |
327 | TmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); | |
328 | TmfContext context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 329 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
330 | TmfEvent event = fTrace.parseEvent(context); |
331 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
ff4ed569 | 332 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
333 | event = fTrace.getNextEvent(context); |
334 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
ff4ed569 | 335 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
336 | |
337 | // Position trace at event rank 999 | |
338 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); | |
339 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 340 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
341 | event = fTrace.parseEvent(context); |
342 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
ff4ed569 | 343 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
344 | event = fTrace.getNextEvent(context); |
345 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
ff4ed569 | 346 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
347 | |
348 | // Position trace at event rank 1001 | |
349 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); | |
350 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 351 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
352 | event = fTrace.parseEvent(context); |
353 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
ff4ed569 | 354 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
355 | event = fTrace.getNextEvent(context); |
356 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
ff4ed569 | 357 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
358 | |
359 | // Position trace at event rank 4500 | |
360 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); | |
361 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 362 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
363 | event = fTrace.parseEvent(context); |
364 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
ff4ed569 | 365 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
366 | event = fTrace.getNextEvent(context); |
367 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
ff4ed569 | 368 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
369 | } |
370 | ||
371 | public void testSeekLocationOutOfScope() throws Exception { | |
372 | ||
373 | // Position trace at beginning | |
374 | TmfContext tmpContext = fTrace.seekLocation(null); | |
375 | TmfContext context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 376 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
377 | TmfEvent event = fTrace.parseEvent(context); |
378 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
ff4ed569 | 379 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
380 | event = fTrace.getNextEvent(context); |
381 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
ff4ed569 | 382 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
383 | |
384 | // Position trace at event passed the end | |
385 | tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); | |
386 | context = fTrace.seekLocation(tmpContext.getLocation().clone()); | |
ff4ed569 | 387 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
388 | event = fTrace.parseEvent(context); |
389 | assertEquals("Event timestamp", null, event); | |
ff4ed569 | 390 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
391 | event = fTrace.getNextEvent(context); |
392 | assertEquals("Event timestamp", null, event); | |
ff4ed569 | 393 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
54d55ced FC |
394 | } |
395 | ||
396 | // ------------------------------------------------------------------------ | |
397 | // seekEvent on timestamp | |
398 | // ------------------------------------------------------------------------ | |
d18dd09b | 399 | |
54d55ced FC |
400 | public void testSeekEventOnTimestampOnCacheBoundary() throws Exception { |
401 | ||
402 | // Position trace at event rank 0 | |
403 | TmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0)); | |
404 | assertEquals("Event rank", 0, context.getRank()); | |
405 | TmfEvent event = fTrace.parseEvent(context); | |
406 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
407 | assertEquals("Event rank", 0, context.getRank()); | |
408 | event = fTrace.getNextEvent(context); | |
75828b1a | 409 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
e31e01e8 | 410 | assertEquals("Event rank", 1, context.getRank()); |
d18dd09b | 411 | |
54d55ced FC |
412 | // Position trace at event rank 1000 |
413 | context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); | |
414 | assertEquals("Event rank", 1000, context.getRank()); | |
415 | event = fTrace.parseEvent(context); | |
416 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
417 | assertEquals("Event rank", 1000, context.getRank()); | |
418 | event = fTrace.getNextEvent(context); | |
e31e01e8 FC |
419 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
420 | assertEquals("Event rank", 1001, context.getRank()); | |
d18dd09b | 421 | |
54d55ced FC |
422 | // Position trace at event rank 4000 |
423 | context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); | |
424 | assertEquals("Event rank", 4000, context.getRank()); | |
425 | event = fTrace.parseEvent(context); | |
426 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
427 | assertEquals("Event rank", 4000, context.getRank()); | |
428 | event = fTrace.getNextEvent(context); | |
e31e01e8 FC |
429 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
430 | assertEquals("Event rank", 4001, context.getRank()); | |
75828b1a | 431 | } |
d18dd09b | 432 | |
54d55ced FC |
433 | public void testSeekEventOnTimestampNotOnCacheBoundary() throws Exception { |
434 | ||
435 | // Position trace at event rank 1 | |
436 | TmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE, 0)); | |
437 | assertEquals("Event rank", 1, context.getRank()); | |
438 | TmfEvent event = fTrace.parseEvent(context); | |
439 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); | |
440 | assertEquals("Event rank", 1, context.getRank()); | |
441 | event = fTrace.getNextEvent(context); | |
442 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); | |
443 | assertEquals("Event rank", 2, context.getRank()); | |
d18dd09b | 444 | |
54d55ced | 445 | // Position trace at event rank 9 |
e31e01e8 | 446 | context = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
54d55ced FC |
447 | assertEquals("Event rank", 9, context.getRank()); |
448 | event = fTrace.parseEvent(context); | |
449 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
450 | assertEquals("Event rank", 9, context.getRank()); | |
451 | event = fTrace.getNextEvent(context); | |
e31e01e8 FC |
452 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
453 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 454 | |
54d55ced FC |
455 | // Position trace at event rank 999 |
456 | context = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); | |
457 | assertEquals("Event rank", 999, context.getRank()); | |
458 | event = fTrace.parseEvent(context); | |
459 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
e31e01e8 | 460 | assertEquals("Event rank", 999, context.getRank()); |
54d55ced FC |
461 | event = fTrace.getNextEvent(context); |
462 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
463 | assertEquals("Event rank", 1000, context.getRank()); | |
e31e01e8 | 464 | |
54d55ced FC |
465 | // Position trace at event rank 1001 |
466 | context = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); | |
e31e01e8 | 467 | assertEquals("Event rank", 1001, context.getRank()); |
54d55ced FC |
468 | event = fTrace.parseEvent(context); |
469 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
470 | assertEquals("Event rank", 1001, context.getRank()); | |
471 | event = fTrace.getNextEvent(context); | |
472 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
473 | assertEquals("Event rank", 1002, context.getRank()); | |
474 | ||
475 | // Position trace at event rank 4500 | |
476 | context = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); | |
477 | assertEquals("Event rank", 4500, context.getRank()); | |
478 | event = fTrace.parseEvent(context); | |
479 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
480 | assertEquals("Event rank", 4500, context.getRank()); | |
481 | event = fTrace.getNextEvent(context); | |
482 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
483 | assertEquals("Event rank", 4501, context.getRank()); | |
75828b1a | 484 | } |
d18dd09b | 485 | |
54d55ced | 486 | public void testSeekEventOnTimestampOutOfScope() throws Exception { |
d18dd09b | 487 | |
54d55ced FC |
488 | // Position trace at beginning |
489 | TmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0)); | |
490 | assertEquals("Event rank", 0, context.getRank()); | |
491 | TmfEvent event = fTrace.parseEvent(context); | |
75828b1a | 492 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced FC |
493 | assertEquals("Event rank", 0, context.getRank()); |
494 | event = fTrace.getNextEvent(context); | |
495 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
496 | assertEquals("Event rank", 1, context.getRank()); | |
75828b1a | 497 | |
54d55ced FC |
498 | // Position trace at event passed the end |
499 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); | |
500 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
501 | event = fTrace.parseEvent(context); | |
75828b1a | 502 | assertEquals("Event timestamp", null, event); |
54d55ced FC |
503 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
504 | event = fTrace.getNextEvent(context); | |
505 | assertEquals("Event timestamp", null, event); | |
506 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
d18dd09b ASL |
507 | } |
508 | ||
54d55ced FC |
509 | // ------------------------------------------------------------------------ |
510 | // seekEvent on rank | |
511 | // ------------------------------------------------------------------------ | |
512 | ||
513 | public void testSeekOnRankOnCacheBoundary() throws Exception { | |
e31e01e8 FC |
514 | |
515 | // On lower bound, returns the first event (ts = 1) | |
54d55ced FC |
516 | TmfContext context = fTrace.seekEvent(0); |
517 | assertEquals("Event rank", 0, context.getRank()); | |
518 | TmfEvent event = fTrace.parseEvent(context); | |
e31e01e8 | 519 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
54d55ced FC |
520 | assertEquals("Event rank", 0, context.getRank()); |
521 | event = fTrace.getNextEvent(context); | |
522 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
523 | assertEquals("Event rank", 1, context.getRank()); | |
e31e01e8 | 524 | |
54d55ced FC |
525 | // Position trace at event rank 1000 |
526 | context = fTrace.seekEvent(1000); | |
527 | assertEquals("Event rank", 1000, context.getRank()); | |
528 | event = fTrace.parseEvent(context); | |
529 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
530 | assertEquals("Event rank", 1000, context.getRank()); | |
531 | event = fTrace.getNextEvent(context); | |
532 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); | |
533 | assertEquals("Event rank", 1001, context.getRank()); | |
e31e01e8 | 534 | |
54d55ced FC |
535 | // Position trace at event rank 4000 |
536 | context = fTrace.seekEvent(4000); | |
537 | assertEquals("Event rank", 4000, context.getRank()); | |
538 | event = fTrace.parseEvent(context); | |
539 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
540 | assertEquals("Event rank", 4000, context.getRank()); | |
541 | event = fTrace.getNextEvent(context); | |
542 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); | |
543 | assertEquals("Event rank", 4001, context.getRank()); | |
e31e01e8 FC |
544 | } |
545 | ||
54d55ced | 546 | public void testSeekOnRankNotOnCacheBoundary() throws Exception { |
d18dd09b | 547 | |
54d55ced FC |
548 | // Position trace at event rank 9 |
549 | TmfContext context = fTrace.seekEvent(9); | |
550 | assertEquals("Event rank", 9, context.getRank()); | |
551 | TmfEvent event = fTrace.parseEvent(context); | |
552 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
553 | assertEquals("Event rank", 9, context.getRank()); | |
554 | event = fTrace.getNextEvent(context); | |
555 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); | |
556 | assertEquals("Event rank", 10, context.getRank()); | |
d18dd09b | 557 | |
54d55ced FC |
558 | // Position trace at event rank 999 |
559 | context = fTrace.seekEvent(999); | |
560 | assertEquals("Event rank", 999, context.getRank()); | |
561 | event = fTrace.parseEvent(context); | |
562 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
563 | assertEquals("Event rank", 999, context.getRank()); | |
564 | event = fTrace.getNextEvent(context); | |
565 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); | |
566 | assertEquals("Event rank", 1000, context.getRank()); | |
d18dd09b | 567 | |
54d55ced FC |
568 | // Position trace at event rank 1001 |
569 | context = fTrace.seekEvent(1001); | |
570 | assertEquals("Event rank", 1001, context.getRank()); | |
571 | event = fTrace.parseEvent(context); | |
572 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
573 | assertEquals("Event rank", 1001, context.getRank()); | |
574 | event = fTrace.getNextEvent(context); | |
575 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); | |
576 | assertEquals("Event rank", 1002, context.getRank()); | |
577 | ||
578 | // Position trace at event rank 4500 | |
579 | context = fTrace.seekEvent(4500); | |
580 | assertEquals("Event rank", 4500, context.getRank()); | |
581 | event = fTrace.parseEvent(context); | |
582 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
583 | assertEquals("Event rank", 4500, context.getRank()); | |
584 | event = fTrace.getNextEvent(context); | |
585 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); | |
586 | assertEquals("Event rank", 4501, context.getRank()); | |
d18dd09b ASL |
587 | } |
588 | ||
54d55ced FC |
589 | public void testSeekEventOnRankOfScope() throws Exception { |
590 | ||
591 | // Position trace at beginning | |
592 | TmfContext context = fTrace.seekEvent(-1); | |
593 | assertEquals("Event rank", 0, context.getRank()); | |
594 | TmfEvent event = fTrace.parseEvent(context); | |
595 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
596 | assertEquals("Event rank", 0, context.getRank()); | |
597 | event = fTrace.getNextEvent(context); | |
598 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
599 | assertEquals("Event rank", 1, context.getRank()); | |
600 | ||
601 | // Position trace at event passed the end | |
602 | context = fTrace.seekEvent(NB_EVENTS); | |
603 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
604 | event = fTrace.parseEvent(context); | |
605 | assertEquals("Event timestamp", null, event); | |
606 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
607 | event = fTrace.getNextEvent(context); | |
608 | assertEquals("Event timestamp", null, event); | |
609 | assertEquals("Event rank", NB_EVENTS, context.getRank()); | |
610 | } | |
611 | ||
e31e01e8 | 612 | // ------------------------------------------------------------------------ |
d18dd09b | 613 | // processRequest |
e31e01e8 | 614 | // ------------------------------------------------------------------------ |
d18dd09b | 615 | |
e31e01e8 FC |
616 | @SuppressWarnings("unchecked") |
617 | public void testProcessRequestForNbEvents() throws Exception { | |
d18dd09b ASL |
618 | final int BLOCK_SIZE = 100; |
619 | final int NB_EVENTS = 1000; | |
620 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); | |
621 | ||
622 | TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); | |
e31e01e8 | 623 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
d18dd09b ASL |
624 | @Override |
625 | public void handleData() { | |
626 | TmfEvent[] events = getData(); | |
627 | for (TmfEvent e : events) { | |
628 | requestedEvents.add(e); | |
629 | } | |
630 | } | |
631 | }; | |
951d134a FC |
632 | ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
633 | providers[0].sendRequest(request); | |
634 | request.waitForCompletion(); | |
d18dd09b ASL |
635 | |
636 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); | |
637 | assertTrue("isCompleted", request.isCompleted()); | |
638 | assertFalse("isCancelled", request.isCancelled()); | |
639 | ||
640 | // Ensure that we have distinct events. | |
641 | // Don't go overboard: we are not validating the stub! | |
642 | for (int i = 0; i < NB_EVENTS; i++) { | |
643 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); | |
644 | } | |
645 | } | |
646 | ||
e31e01e8 FC |
647 | @SuppressWarnings("unchecked") |
648 | public void testProcessRequestForAllEvents() throws Exception { | |
d18dd09b ASL |
649 | final int BLOCK_SIZE = 1; |
650 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); | |
651 | ||
652 | TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); | |
e31e01e8 | 653 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
d18dd09b ASL |
654 | @Override |
655 | public void handleData() { | |
656 | TmfEvent[] events = getData(); | |
657 | for (TmfEvent e : events) { | |
658 | requestedEvents.add(e); | |
659 | } | |
660 | } | |
661 | }; | |
951d134a FC |
662 | ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
663 | providers[0].sendRequest(request); | |
664 | request.waitForCompletion(); | |
d18dd09b ASL |
665 | |
666 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); | |
667 | assertTrue("isCompleted", request.isCompleted()); | |
668 | assertFalse("isCancelled", request.isCancelled()); | |
669 | ||
670 | // Ensure that we have distinct events. | |
671 | // Don't go overboard: we are not validating the stub! | |
672 | for (int i = 0; i < NB_EVENTS; i++) { | |
673 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); | |
674 | } | |
675 | } | |
676 | ||
e31e01e8 | 677 | // ------------------------------------------------------------------------ |
d18dd09b | 678 | // cancel |
e31e01e8 | 679 | // ------------------------------------------------------------------------ |
d18dd09b | 680 | |
e31e01e8 FC |
681 | @SuppressWarnings("unchecked") |
682 | public void testCancel() throws Exception { | |
d18dd09b ASL |
683 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); |
684 | ||
685 | TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); | |
cb866e08 | 686 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
d18dd09b ASL |
687 | @Override |
688 | public void handleData() { | |
689 | TmfEvent[] events = getData(); | |
690 | for (TmfEvent e : events) { | |
691 | requestedEvents.add(e); | |
692 | } | |
693 | // Cancel request after the first chunk is received | |
694 | cancel(); | |
695 | } | |
696 | }; | |
951d134a FC |
697 | ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
698 | providers[0].sendRequest(request); | |
699 | request.waitForCompletion(); | |
d18dd09b | 700 | |
cb866e08 | 701 | assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size()); |
d18dd09b ASL |
702 | assertTrue("isCompleted", request.isCompleted()); |
703 | assertTrue("isCancelled", request.isCancelled()); | |
704 | } | |
e31e01e8 FC |
705 | |
706 | } |