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