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