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