Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
0316808c | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
9b749023 | 3 | * |
d18dd09b ASL |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
9b749023 | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Adjusted for new Trace Model |
d18dd09b ASL |
12 | *******************************************************************************/ |
13 | ||
9e0640dc | 14 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b ASL |
15 | |
16 | import java.io.File; | |
17 | import java.io.IOException; | |
18 | import java.net.URISyntaxException; | |
19 | import java.net.URL; | |
20 | import java.util.Vector; | |
21 | ||
22 | import junit.framework.TestCase; | |
23 | ||
9e0640dc | 24 | import org.eclipse.core.resources.IFile; |
d18dd09b ASL |
25 | import org.eclipse.core.runtime.FileLocator; |
26 | import org.eclipse.core.runtime.Path; | |
17324c9a | 27 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; |
9e0640dc | 28 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; |
72f1e62a | 29 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
6c13869b FC |
30 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
31 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
32 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
b4f71e4a | 33 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
9b749023 | 34 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
6c13869b FC |
35 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
36 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; | |
37 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; | |
0316808c | 38 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
6c13869b | 39 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc FC |
40 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
41 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; | |
42 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; | |
4918b8f2 | 43 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
d18dd09b ASL |
44 | |
45 | /** | |
0316808c | 46 | * Test suite for the TmfExperiment class (single trace). |
d18dd09b | 47 | */ |
54a7a54c | 48 | @SuppressWarnings({"nls","javadoc"}) |
d18dd09b ASL |
49 | public class TmfExperimentTest extends TestCase { |
50 | ||
0316808c FC |
51 | // ------------------------------------------------------------------------ |
52 | // Attributes | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
d18dd09b ASL |
55 | private static final String DIRECTORY = "testfiles"; |
56 | private static final String TEST_STREAM = "A-Test-10K"; | |
57 | private static final String EXPERIMENT = "MyExperiment"; | |
58 | private static int NB_EVENTS = 10000; | |
0316808c | 59 | private static int BLOCK_SIZE = 1000; |
d18dd09b | 60 | |
9e0640dc | 61 | private ITmfTrace<TmfEvent>[] fTestTraces; |
0879b6b9 | 62 | private TmfExperimentStub<ITmfEvent> fExperiment; |
d18dd09b ASL |
63 | |
64 | private static byte SCALE = (byte) -3; | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Housekeeping | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
9e0640dc FC |
70 | @SuppressWarnings("unchecked") |
71 | private synchronized ITmfTrace<?>[] setupTrace(final String path) { | |
72 | if (fTestTraces == null) { | |
73 | fTestTraces = new ITmfTrace[1]; | |
25e48683 FC |
74 | try { |
75 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); | |
76 | final File test = new File(FileLocator.toFileURL(location).toURI()); | |
20658947 | 77 | final TmfTraceStub trace = new TmfTraceStub(test.getPath(), 0, true); |
9e0640dc | 78 | fTestTraces[0] = trace; |
b4f71e4a FC |
79 | } catch (final TmfTraceException e) { |
80 | e.printStackTrace(); | |
25e48683 FC |
81 | } catch (final URISyntaxException e) { |
82 | e.printStackTrace(); | |
83 | } catch (final IOException e) { | |
84 | e.printStackTrace(); | |
85 | } | |
86 | } | |
9e0640dc | 87 | return fTestTraces; |
d18dd09b ASL |
88 | } |
89 | ||
9e0640dc | 90 | private synchronized void setupExperiment() { |
20658947 | 91 | if (fExperiment == null) { |
9e0640dc FC |
92 | fExperiment = new TmfExperimentStub<ITmfEvent>(EXPERIMENT, fTestTraces, BLOCK_SIZE); |
93 | fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); | |
20658947 | 94 | } |
d18dd09b ASL |
95 | } |
96 | ||
54a7a54c FC |
97 | /** |
98 | * @param name the test name | |
99 | */ | |
100 | public TmfExperimentTest(final String name) { | |
25e48683 FC |
101 | super(name); |
102 | } | |
d18dd09b | 103 | |
25e48683 FC |
104 | @Override |
105 | protected void setUp() throws Exception { | |
106 | super.setUp(); | |
107 | setupTrace(DIRECTORY + File.separator + TEST_STREAM); | |
108 | setupExperiment(); | |
109 | } | |
d18dd09b | 110 | |
25e48683 FC |
111 | @Override |
112 | protected void tearDown() throws Exception { | |
113 | super.tearDown(); | |
114 | } | |
d18dd09b ASL |
115 | |
116 | // ------------------------------------------------------------------------ | |
117 | // Constructor | |
118 | // ------------------------------------------------------------------------ | |
119 | ||
9e0640dc FC |
120 | public void testSimpleTmfExperimentConstructor() { |
121 | ||
122 | TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTestTraces); | |
123 | assertEquals("GetId", EXPERIMENT, experiment.getName()); | |
124 | assertEquals("GetCacheSize", TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, experiment.getCacheSize()); | |
125 | experiment.dispose(); | |
126 | ||
127 | experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null); | |
128 | experiment.dispose(); | |
129 | } | |
130 | ||
131 | public void testNormalTmfExperimentConstructor() { | |
cb866e08 | 132 | |
25e48683 | 133 | assertEquals("GetId", EXPERIMENT, fExperiment.getName()); |
d18dd09b ASL |
134 | assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); |
135 | ||
07671572 FC |
136 | final long nbExperimentEvents = fExperiment.getNbEvents(); |
137 | assertEquals("GetNbEvents", NB_EVENTS, nbExperimentEvents); | |
138 | ||
25e48683 | 139 | final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents(); |
82e04272 FC |
140 | assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents); |
141 | ||
25e48683 | 142 | final TmfTimeRange timeRange = fExperiment.getTimeRange(); |
d18dd09b ASL |
143 | assertEquals("getStartTime", 1, timeRange.getStartTime().getValue()); |
144 | assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue()); | |
25e48683 | 145 | } |
d18dd09b | 146 | |
9e0640dc FC |
147 | @SuppressWarnings("static-access") |
148 | public void testSetCurrentExperiment() { | |
149 | ||
150 | TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTestTraces); | |
151 | experiment.setCurrentExperiment(experiment); | |
152 | assertEquals("getCurrentExperiment", experiment, experiment.getCurrentExperiment()); | |
153 | ||
154 | TmfExperiment<TmfEvent> experiment2 = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null); | |
155 | experiment.setCurrentExperiment(experiment2); | |
156 | assertEquals("getCurrentExperiment", experiment2, experiment.getCurrentExperiment()); | |
157 | ||
158 | experiment.dispose(); | |
159 | experiment2.dispose(); | |
160 | } | |
161 | ||
162 | // ------------------------------------------------------------------------ | |
163 | // getTimestamp | |
164 | // ------------------------------------------------------------------------ | |
165 | ||
54a7a54c | 166 | public void testGetTimestamp() { |
17324c9a FC |
167 | assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); |
168 | assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); | |
169 | assertEquals("getTimestamp", new TmfTimestamp( 11, (byte) -3), fExperiment.getTimestamp( 10)); | |
170 | assertEquals("getTimestamp", new TmfTimestamp( 101, (byte) -3), fExperiment.getTimestamp( 100)); | |
171 | assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp(1000)); | |
172 | assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp(2000)); | |
173 | assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp(2500)); | |
174 | assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp(9999)); | |
9e0640dc FC |
175 | assertNull("getTimestamp", fExperiment.getTimestamp(10000)); |
176 | } | |
177 | ||
178 | // ------------------------------------------------------------------------ | |
179 | // Bookmarks file handling | |
180 | // ------------------------------------------------------------------------ | |
181 | ||
54a7a54c | 182 | public void testBookmarks() { |
9e0640dc | 183 | assertNull("GetBookmarksFile", fExperiment.getBookmarksFile()); |
9e0640dc FC |
184 | IFile bookmarks = (IFile) fTestTraces[0].getResource(); |
185 | fExperiment.setBookmarksFile(bookmarks); | |
186 | assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile()); | |
187 | } | |
188 | ||
189 | // ------------------------------------------------------------------------ | |
190 | // seekEvent by location | |
191 | // ------------------------------------------------------------------------ | |
192 | ||
54a7a54c | 193 | public void testSeekBadLocation() { |
9b749023 | 194 | ITmfContext context = fExperiment.seekEvent(new TmfLocation<Long>(0L)); |
9e0640dc FC |
195 | assertNull("seekEvent", context); |
196 | } | |
197 | ||
54a7a54c | 198 | public void testSeekNoTrace() { |
9e0640dc | 199 | TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null); |
9e0640dc FC |
200 | ITmfContext context = experiment.seekEvent((TmfExperimentLocation) null); |
201 | assertNull("seekEvent", context); | |
202 | experiment.dispose(); | |
203 | } | |
204 | ||
205 | // ------------------------------------------------------------------------ | |
206 | // seekEvent on ratio | |
207 | // ------------------------------------------------------------------------ | |
208 | ||
54a7a54c | 209 | public void testSeekEventOnRatio() { |
9e0640dc FC |
210 | |
211 | // First event | |
212 | ITmfContext context = fExperiment.seekEvent(0.0); | |
213 | assertEquals("Context rank", 0, context.getRank()); | |
214 | ITmfEvent event = fExperiment.parseEvent(context); | |
215 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
216 | assertEquals("Context rank", 0, context.getRank()); | |
217 | ||
218 | // Middle event | |
219 | int midTrace = NB_EVENTS / 2; | |
220 | context = fExperiment.seekEvent(0.5); | |
221 | assertEquals("Context rank", midTrace, context.getRank()); | |
222 | event = fExperiment.parseEvent(context); | |
223 | assertEquals("Event timestamp", midTrace + 1, event.getTimestamp().getValue()); | |
224 | assertEquals("Context rank", midTrace, context.getRank()); | |
9b749023 | 225 | |
9e0640dc FC |
226 | // Last event |
227 | context = fExperiment.seekEvent(1.0); | |
228 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
229 | event = fExperiment.parseEvent(context); | |
230 | assertNull("Event timestamp", event); | |
231 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
9b749023 | 232 | |
9e0640dc FC |
233 | // Beyond last event |
234 | context = fExperiment.seekEvent(1.1); | |
235 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
236 | event = fExperiment.parseEvent(context); | |
237 | assertNull("Event timestamp", event); | |
238 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
9b749023 | 239 | |
9e0640dc FC |
240 | // Negative ratio |
241 | context = fExperiment.seekEvent(-0.5); | |
242 | assertEquals("Context rank", 0, context.getRank()); | |
243 | event = fExperiment.parseEvent(context); | |
244 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); | |
245 | assertEquals("Context rank", 0, context.getRank()); | |
246 | } | |
247 | ||
0879b6b9 | 248 | @SuppressWarnings("rawtypes") |
54a7a54c | 249 | public void testGetLocationRatio() { |
9e0640dc FC |
250 | |
251 | // First event | |
252 | ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); | |
253 | double ratio = fExperiment.getLocationRatio(context.getLocation()); | |
5cc97265 FC |
254 | context = fExperiment.seekEvent(ratio); |
255 | double ratio2 = fExperiment.getLocationRatio(context.getLocation()); | |
256 | assertEquals("getLocationRatio", ratio, ratio2); | |
9e0640dc FC |
257 | |
258 | // Middle event | |
259 | context = fExperiment.seekEvent(NB_EVENTS / 2); | |
260 | ratio = fExperiment.getLocationRatio(context.getLocation()); | |
5cc97265 FC |
261 | context = fExperiment.seekEvent(ratio); |
262 | ratio2 = fExperiment.getLocationRatio(context.getLocation()); | |
263 | assertEquals("getLocationRatio", ratio, ratio2); | |
9e0640dc FC |
264 | |
265 | // Last event | |
266 | context = fExperiment.seekEvent(NB_EVENTS - 1); | |
267 | ratio = fExperiment.getLocationRatio(context.getLocation()); | |
5cc97265 FC |
268 | context = fExperiment.seekEvent(ratio); |
269 | ratio2 = fExperiment.getLocationRatio(context.getLocation()); | |
270 | assertEquals("getLocationRatio", ratio, ratio2); | |
9e0640dc FC |
271 | } |
272 | ||
17324c9a | 273 | // @SuppressWarnings("rawtypes") |
54a7a54c | 274 | // public void testGetCurrentLocation() { |
9e0640dc FC |
275 | // ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); |
276 | // ITmfLocation location = fExperiment.getCurrentLocation(); | |
277 | // assertEquals("getCurrentLocation", location, context.getLocation()); | |
278 | // } | |
279 | ||
d18dd09b | 280 | // ------------------------------------------------------------------------ |
0316808c | 281 | // seekEvent on rank |
d18dd09b ASL |
282 | // ------------------------------------------------------------------------ |
283 | ||
54a7a54c | 284 | public void testSeekRankOnCacheBoundary() { |
d18dd09b | 285 | |
0316808c | 286 | long cacheSize = fExperiment.getCacheSize(); |
9b635e61 | 287 | |
0316808c FC |
288 | // On lower bound, returns the first event (TS = 1) |
289 | ITmfContext context = fExperiment.seekEvent(0); | |
290 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 291 | |
c32744d6 | 292 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 293 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 294 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 295 | |
0316808c FC |
296 | // Position trace at event rank [cacheSize] |
297 | context = fExperiment.seekEvent(cacheSize); | |
298 | assertEquals("Context rank", cacheSize, context.getRank()); | |
25e48683 | 299 | |
c32744d6 | 300 | event = fExperiment.getNext(context); |
0316808c FC |
301 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
302 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
d18dd09b | 303 | |
0316808c FC |
304 | // Position trace at event rank [4 * cacheSize] |
305 | context = fExperiment.seekEvent(4 * cacheSize); | |
306 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 307 | |
c32744d6 | 308 | event = fExperiment.getNext(context); |
0316808c FC |
309 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
310 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
d18dd09b ASL |
311 | } |
312 | ||
54a7a54c | 313 | public void testSeekRankNotOnCacheBoundary() { |
d18dd09b | 314 | |
0316808c | 315 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 316 | |
0316808c FC |
317 | // Position trace at event rank 9 |
318 | ITmfContext context = fExperiment.seekEvent(9); | |
319 | assertEquals("Context rank", 9, context.getRank()); | |
25e48683 | 320 | |
c32744d6 | 321 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 322 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 323 | assertEquals("Context rank", 10, context.getRank()); |
d18dd09b | 324 | |
0316808c FC |
325 | // Position trace at event rank [cacheSize - 1] |
326 | context = fExperiment.seekEvent(cacheSize - 1); | |
327 | assertEquals("Context rank", cacheSize - 1, context.getRank()); | |
25e48683 | 328 | |
c32744d6 | 329 | event = fExperiment.getNext(context); |
0316808c FC |
330 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
331 | assertEquals("Context rank", cacheSize, context.getRank()); | |
d18dd09b | 332 | |
0316808c FC |
333 | // Position trace at event rank [cacheSize + 1] |
334 | context = fExperiment.seekEvent(cacheSize + 1); | |
335 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
25e48683 | 336 | |
c32744d6 | 337 | event = fExperiment.getNext(context); |
0316808c FC |
338 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
339 | assertEquals("Context rank", cacheSize + 2, context.getRank()); | |
d18dd09b | 340 | |
25e48683 | 341 | // Position trace at event rank 4500 |
0316808c FC |
342 | context = fExperiment.seekEvent(4500); |
343 | assertEquals("Context rank", 4500, context.getRank()); | |
25e48683 | 344 | |
c32744d6 | 345 | event = fExperiment.getNext(context); |
d18dd09b | 346 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 347 | assertEquals("Context rank", 4501, context.getRank()); |
d18dd09b ASL |
348 | } |
349 | ||
54a7a54c | 350 | public void testSeekRankOutOfScope() { |
d18dd09b | 351 | |
25e48683 | 352 | // Position trace at beginning |
0316808c | 353 | ITmfContext context = fExperiment.seekEvent(-1); |
9b635e61 | 354 | assertEquals("Event rank", 0, context.getRank()); |
25e48683 | 355 | |
c32744d6 | 356 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 357 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 358 | assertEquals("Context rank", 1, context.getRank()); |
d18dd09b | 359 | |
25e48683 | 360 | // Position trace at event passed the end |
0316808c FC |
361 | context = fExperiment.seekEvent(NB_EVENTS); |
362 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
363 | ||
c32744d6 | 364 | event = fExperiment.getNext(context); |
0316808c FC |
365 | assertNull("Event", event); |
366 | assertEquals("Context rank", NB_EVENTS, context.getRank()); | |
d18dd09b ASL |
367 | } |
368 | ||
369 | // ------------------------------------------------------------------------ | |
370 | // seekEvent on timestamp | |
371 | // ------------------------------------------------------------------------ | |
372 | ||
54a7a54c | 373 | public void testSeekTimestampOnCacheBoundary() { |
d18dd09b | 374 | |
0316808c | 375 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 376 | |
0316808c FC |
377 | // Position trace at event rank 0 |
378 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(1, SCALE, 0)); | |
379 | assertEquals("Context rank", 0, context.getRank()); | |
25e48683 | 380 | |
c32744d6 | 381 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 382 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
0316808c | 383 | assertEquals("Context rank", 1, context.getRank()); |
25e48683 | 384 | |
0316808c FC |
385 | // Position trace at event rank [cacheSize] |
386 | context = fExperiment.seekEvent(new TmfTimestamp(cacheSize + 1, SCALE, 0)); | |
387 | assertEquals("Event rank", cacheSize, context.getRank()); | |
25e48683 | 388 | |
c32744d6 | 389 | event = fExperiment.getNext(context); |
0316808c FC |
390 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
391 | assertEquals("Context rank", cacheSize + 1, context.getRank()); | |
d18dd09b | 392 | |
0316808c FC |
393 | // Position trace at event rank [4 * cacheSize] |
394 | context = fExperiment.seekEvent(new TmfTimestamp(4 * cacheSize + 1, SCALE, 0)); | |
395 | assertEquals("Context rank", 4 * cacheSize, context.getRank()); | |
25e48683 | 396 | |
c32744d6 | 397 | event = fExperiment.getNext(context); |
0316808c FC |
398 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
399 | assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); | |
d18dd09b ASL |
400 | } |
401 | ||
54a7a54c | 402 | public void testSeekTimestampNotOnCacheBoundary() { |
d18dd09b | 403 | |
0316808c FC |
404 | // Position trace at event rank 1 (TS = 2) |
405 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); | |
406 | assertEquals("Context rank", 1, context.getRank()); | |
25e48683 | 407 | |
c32744d6 | 408 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 409 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
0316808c | 410 | assertEquals("Context rank", 2, context.getRank()); |
d18dd09b | 411 | |
0316808c | 412 | // Position trace at event rank 9 (TS = 10) |
25e48683 | 413 | context = fExperiment.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
0316808c | 414 | assertEquals("Context rank", 9, context.getRank()); |
25e48683 | 415 | |
c32744d6 | 416 | event = fExperiment.getNext(context); |
d18dd09b | 417 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
0316808c | 418 | assertEquals("Context rank", 10, context.getRank()); |
d18dd09b | 419 | |
0316808c | 420 | // Position trace at event rank 999 (TS = 1000) |
d18dd09b | 421 | context = fExperiment.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
0316808c | 422 | assertEquals("Context rank", 999, context.getRank()); |
25e48683 | 423 | |
c32744d6 | 424 | event = fExperiment.getNext(context); |
d18dd09b | 425 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
0316808c | 426 | assertEquals("Context rank", 1000, context.getRank()); |
d18dd09b | 427 | |
0316808c | 428 | // Position trace at event rank 1001 (TS = 1002) |
d18dd09b | 429 | context = fExperiment.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
0316808c | 430 | assertEquals("Context rank", 1001, context.getRank()); |
25e48683 | 431 | |
c32744d6 | 432 | event = fExperiment.getNext(context); |
d18dd09b | 433 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
0316808c | 434 | assertEquals("Context rank", 1002, context.getRank()); |
d18dd09b | 435 | |
0316808c | 436 | // Position trace at event rank 4500 (TS = 4501) |
d18dd09b | 437 | context = fExperiment.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
0316808c | 438 | assertEquals("Context rank", 4500, context.getRank()); |
25e48683 | 439 | |
c32744d6 | 440 | event = fExperiment.getNext(context); |
d18dd09b | 441 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
0316808c | 442 | assertEquals("Context rank", 4501, context.getRank()); |
d18dd09b ASL |
443 | } |
444 | ||
54a7a54c | 445 | public void testSeekTimestampOutOfScope() { |
d18dd09b | 446 | |
25e48683 | 447 | // Position trace at beginning |
0316808c | 448 | ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); |
d18dd09b | 449 | assertEquals("Event rank", 0, context.getRank()); |
25e48683 | 450 | |
c32744d6 | 451 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b ASL |
452 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
453 | assertEquals("Event rank", 1, context.getRank()); | |
454 | ||
25e48683 | 455 | // Position trace at event passed the end |
d18dd09b | 456 | context = fExperiment.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
c32744d6 | 457 | event = fExperiment.getNext(context); |
0316808c | 458 | assertNull("Event location", event); |
9b635e61 | 459 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
d18dd09b ASL |
460 | } |
461 | ||
462 | // ------------------------------------------------------------------------ | |
0316808c | 463 | // seekEvent by location (context rank is undefined) |
d18dd09b ASL |
464 | // ------------------------------------------------------------------------ |
465 | ||
54a7a54c | 466 | public void testSeekLocationOnCacheBoundary() { |
9b749023 | 467 | |
0316808c | 468 | long cacheSize = fExperiment.getCacheSize(); |
d18dd09b | 469 | |
0316808c FC |
470 | // Position trace at event rank 0 |
471 | ITmfContext tmpContext = fExperiment.seekEvent(0); | |
472 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 473 | |
c32744d6 | 474 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 475 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
25e48683 | 476 | |
c32744d6 | 477 | event = fExperiment.getNext(context); |
0316808c | 478 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
d18dd09b | 479 | |
0316808c FC |
480 | // Position trace at event rank 'cacheSize' |
481 | tmpContext = fExperiment.seekEvent(cacheSize); | |
482 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 483 | |
c32744d6 | 484 | event = fExperiment.getNext(context); |
0316808c | 485 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 486 | |
c32744d6 | 487 | event = fExperiment.getNext(context); |
0316808c | 488 | assertEquals("Event timestamp", cacheSize + 2, event.getTimestamp().getValue()); |
d18dd09b | 489 | |
0316808c FC |
490 | // Position trace at event rank 4 * 'cacheSize' |
491 | tmpContext = fExperiment.seekEvent(4 * cacheSize); | |
492 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 493 | |
c32744d6 | 494 | event = fExperiment.getNext(context); |
0316808c | 495 | assertEquals("Event timestamp", 4 * cacheSize + 1, event.getTimestamp().getValue()); |
25e48683 | 496 | |
c32744d6 | 497 | event = fExperiment.getNext(context); |
0316808c | 498 | assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); |
d18dd09b ASL |
499 | } |
500 | ||
54a7a54c | 501 | public void testSeekLocationNotOnCacheBoundary() { |
25e48683 | 502 | |
0316808c | 503 | long cacheSize = fExperiment.getCacheSize(); |
25e48683 | 504 | |
0316808c FC |
505 | // Position trace at event 'cacheSize' - 1 |
506 | ITmfContext tmpContext = fExperiment.seekEvent(cacheSize - 1); | |
507 | ITmfContext context = fExperiment.seekEvent(tmpContext.getLocation()); | |
d18dd09b | 508 | |
c32744d6 | 509 | ITmfEvent event = fExperiment.getNext(context); |
0316808c | 510 | assertEquals("Event timestamp", cacheSize, event.getTimestamp().getValue()); |
25e48683 | 511 | |
c32744d6 | 512 | event = fExperiment.getNext(context); |
0316808c | 513 | assertEquals("Event timestamp", cacheSize + 1, event.getTimestamp().getValue()); |
d18dd09b | 514 | |
0316808c FC |
515 | // Position trace at event rank 2 * 'cacheSize' - 1 |
516 | tmpContext = fExperiment.seekEvent(2 * cacheSize - 1); | |
517 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
518 | context = fExperiment.seekEvent(2 * cacheSize - 1); | |
25e48683 | 519 | |
c32744d6 | 520 | event = fExperiment.getNext(context); |
0316808c | 521 | assertEquals("Event timestamp", 2 * cacheSize, event.getTimestamp().getValue()); |
25e48683 | 522 | |
c32744d6 | 523 | event = fExperiment.getNext(context); |
0316808c | 524 | assertEquals("Event timestamp", 2 * cacheSize + 1, event.getTimestamp().getValue()); |
d18dd09b | 525 | |
25e48683 | 526 | // Position trace at event rank 4500 |
0316808c FC |
527 | tmpContext = fExperiment.seekEvent(4500); |
528 | context = fExperiment.seekEvent(tmpContext.getLocation()); | |
25e48683 | 529 | |
c32744d6 | 530 | event = fExperiment.getNext(context); |
d18dd09b | 531 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
25e48683 | 532 | |
c32744d6 | 533 | event = fExperiment.getNext(context); |
0316808c | 534 | assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); |
d18dd09b ASL |
535 | } |
536 | ||
54a7a54c | 537 | public void testSeekLocationOutOfScope() { |
d18dd09b | 538 | |
25e48683 | 539 | // Position trace at beginning |
0316808c | 540 | ITmfContext context = fExperiment.seekEvent((ITmfLocation<?>) null); |
25e48683 | 541 | |
c32744d6 | 542 | ITmfEvent event = fExperiment.getNext(context); |
d18dd09b | 543 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
d18dd09b | 544 | } |
25e48683 | 545 | |
9b635e61 | 546 | // ------------------------------------------------------------------------ |
17324c9a | 547 | // getNext - updates the context |
9b635e61 FC |
548 | // ------------------------------------------------------------------------ |
549 | ||
54a7a54c | 550 | private static void validateContextRanks(ITmfContext context) { |
17324c9a FC |
551 | assertTrue("Experiment context type", context instanceof TmfExperimentContext); |
552 | TmfExperimentContext ctx = (TmfExperimentContext) context; | |
9b635e61 | 553 | |
17324c9a FC |
554 | int nbTraces = ctx.getContexts().length; |
555 | ||
556 | // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE) | |
557 | long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0); | |
558 | for (int i = 0; i < nbTraces; i++) { | |
559 | long rank = ctx.getContexts()[i].getRank(); | |
560 | if (rank == -1) { | |
561 | expRank = -1; | |
562 | break; | |
563 | } | |
564 | expRank += rank; | |
565 | } | |
566 | assertEquals("Experiment context rank", expRank, ctx.getRank()); | |
567 | } | |
568 | ||
54a7a54c | 569 | public void testGetNextAfteSeekingOnTS_1() { |
9b635e61 | 570 | |
17324c9a FC |
571 | final long INITIAL_TS = 1; |
572 | final int NB_READS = 20; | |
573 | ||
574 | // On lower bound, returns the first event (ts = 1) | |
575 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
576 | ||
577 | validateContextRanks(context); | |
578 | ||
579 | // Read NB_EVENTS | |
580 | ITmfEvent event; | |
581 | for (int i = 0; i < NB_READS; i++) { | |
c32744d6 | 582 | event = fExperiment.getNext(context); |
17324c9a FC |
583 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
584 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
9b635e61 | 585 | } |
17324c9a FC |
586 | |
587 | // Make sure we stay positioned | |
588 | event = fExperiment.parseEvent(context); | |
589 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
590 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
591 | ||
592 | validateContextRanks(context); | |
9b635e61 FC |
593 | } |
594 | ||
54a7a54c | 595 | public void testGetNextAfteSeekingOnTS_2() { |
17324c9a FC |
596 | |
597 | final long INITIAL_TS = 2; | |
598 | final int NB_READS = 20; | |
599 | ||
600 | // On lower bound, returns the first event (ts = 2) | |
601 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
602 | ||
603 | validateContextRanks(context); | |
604 | ||
605 | // Read NB_EVENTS | |
606 | ITmfEvent event; | |
607 | for (int i = 0; i < NB_READS; i++) { | |
608 | event = fExperiment.getNext(context); | |
609 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
610 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
611 | } | |
612 | ||
613 | // Make sure we stay positioned | |
614 | event = fExperiment.parseEvent(context); | |
615 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
616 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
617 | ||
618 | validateContextRanks(context); | |
619 | } | |
620 | ||
54a7a54c | 621 | public void testGetNextAfteSeekingOnTS_3() { |
17324c9a FC |
622 | |
623 | final long INITIAL_TS = 500; | |
624 | final int NB_READS = 20; | |
625 | ||
626 | // On lower bound, returns the first event (ts = 500) | |
627 | final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); | |
628 | ||
629 | validateContextRanks(context); | |
630 | ||
631 | // Read NB_EVENTS | |
632 | ITmfEvent event; | |
633 | for (int i = 0; i < NB_READS; i++) { | |
634 | event = fExperiment.getNext(context); | |
635 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
636 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
637 | } | |
638 | ||
639 | // Make sure we stay positioned | |
640 | event = fExperiment.parseEvent(context); | |
641 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
642 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
643 | ||
644 | validateContextRanks(context); | |
645 | } | |
646 | ||
54a7a54c | 647 | public void testGetNextAfterSeekingOnRank_1() { |
17324c9a FC |
648 | |
649 | final long INITIAL_RANK = 0L; | |
650 | final int NB_READS = 20; | |
651 | ||
652 | // On lower bound, returns the first event (rank = 0) | |
653 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
654 | ||
655 | validateContextRanks(context); | |
656 | ||
657 | // Read NB_EVENTS | |
658 | ITmfEvent event; | |
659 | for (int i = 0; i < NB_READS; i++) { | |
660 | event = fExperiment.getNext(context); | |
661 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
662 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
663 | } | |
664 | ||
665 | // Make sure we stay positioned | |
666 | event = fExperiment.parseEvent(context); | |
667 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
668 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
669 | ||
670 | validateContextRanks(context); | |
671 | } | |
672 | ||
54a7a54c | 673 | public void testGetNextAfterSeekingOnRank_2() { |
17324c9a FC |
674 | |
675 | final long INITIAL_RANK = 1L; | |
676 | final int NB_READS = 20; | |
677 | ||
678 | // On lower bound, returns the first event (rank = 0) | |
679 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
680 | ||
681 | validateContextRanks(context); | |
682 | ||
683 | // Read NB_EVENTS | |
684 | ITmfEvent event; | |
685 | for (int i = 0; i < NB_READS; i++) { | |
686 | event = fExperiment.getNext(context); | |
687 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
688 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
689 | } | |
690 | ||
691 | // Make sure we stay positioned | |
692 | event = fExperiment.parseEvent(context); | |
693 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
694 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
695 | ||
696 | validateContextRanks(context); | |
697 | } | |
698 | ||
54a7a54c | 699 | public void testGetNextAfterSeekingOnRank_3() { |
17324c9a FC |
700 | |
701 | final long INITIAL_RANK = 500L; | |
702 | final int NB_READS = 20; | |
703 | ||
704 | // On lower bound, returns the first event (rank = 0) | |
705 | final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK); | |
706 | ||
707 | validateContextRanks(context); | |
708 | ||
709 | // Read NB_EVENTS | |
710 | ITmfEvent event; | |
711 | for (int i = 0; i < NB_READS; i++) { | |
712 | event = fExperiment.getNext(context); | |
713 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); | |
714 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); | |
715 | } | |
716 | ||
717 | // Make sure we stay positioned | |
718 | event = fExperiment.parseEvent(context); | |
719 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); | |
720 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); | |
721 | ||
722 | validateContextRanks(context); | |
723 | } | |
724 | ||
54a7a54c | 725 | public void testGetNextAfterSeekingOnLocation_1() { |
17324c9a FC |
726 | |
727 | final ITmfLocation<?> INITIAL_LOC = null; | |
728 | final long INITIAL_TS = 1; | |
729 | final int NB_READS = 20; | |
730 | ||
731 | // On lower bound, returns the first event (ts = 1) | |
732 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
733 | ||
734 | validateContextRanks(context); | |
735 | ||
736 | // Read NB_EVENTS | |
737 | ITmfEvent event; | |
738 | for (int i = 0; i < NB_READS; i++) { | |
739 | event = fExperiment.getNext(context); | |
740 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
741 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); | |
742 | } | |
743 | ||
744 | // Make sure we stay positioned | |
745 | event = fExperiment.parseEvent(context); | |
746 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
747 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); | |
748 | ||
749 | validateContextRanks(context); | |
750 | } | |
751 | ||
54a7a54c | 752 | public void testGetNextAfterSeekingOnLocation_2() { |
17324c9a FC |
753 | |
754 | final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); | |
755 | final long INITIAL_TS = 2; | |
756 | final int NB_READS = 20; | |
757 | ||
758 | // On lower bound, returns the first event (ts = 2) | |
759 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
760 | ||
761 | validateContextRanks(context); | |
762 | ||
763 | // Read NB_EVENTS | |
764 | ITmfEvent event; | |
765 | for (int i = 0; i < NB_READS; i++) { | |
766 | event = fExperiment.getNext(context); | |
767 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
768 | } | |
769 | ||
770 | // Make sure we stay positioned | |
771 | event = fExperiment.parseEvent(context); | |
772 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
773 | ||
774 | validateContextRanks(context); | |
775 | } | |
776 | ||
54a7a54c | 777 | public void testGetNextAfterSeekingOnLocation_3() { |
17324c9a FC |
778 | |
779 | final ITmfLocation<?> INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); | |
780 | final long INITIAL_TS = 501; | |
781 | final int NB_READS = 20; | |
782 | ||
783 | // On lower bound, returns the first event (ts = 501) | |
784 | final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC); | |
785 | ||
786 | validateContextRanks(context); | |
787 | ||
788 | // Read NB_EVENTS | |
789 | ITmfEvent event; | |
790 | for (int i = 0; i < NB_READS; i++) { | |
791 | event = fExperiment.getNext(context); | |
792 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); | |
793 | } | |
794 | ||
795 | // Make sure we stay positioned | |
796 | event = fExperiment.parseEvent(context); | |
797 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); | |
798 | ||
799 | validateContextRanks(context); | |
800 | } | |
801 | ||
54a7a54c | 802 | public void testGetNextLocation() { |
17324c9a FC |
803 | ITmfContext context1 = fExperiment.seekEvent(0); |
804 | fExperiment.getNext(context1); | |
805 | ITmfLocation<?> location = context1.getLocation().clone(); | |
806 | ITmfEvent event1 = fExperiment.getNext(context1); | |
807 | ITmfContext context2 = fExperiment.seekEvent(location); | |
808 | ITmfEvent event2 = fExperiment.getNext(context2); | |
809 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); | |
810 | } | |
811 | ||
54a7a54c | 812 | public void testGetNextEndLocation() { |
17324c9a FC |
813 | ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); |
814 | fExperiment.getNext(context1); | |
815 | ITmfLocation<?> location = context1.getLocation().clone(); | |
816 | ITmfContext context2 = fExperiment.seekEvent(location); | |
817 | ITmfEvent event = fExperiment.getNext(context2); | |
818 | assertNull("Event", event); | |
819 | } | |
54a7a54c | 820 | |
d18dd09b ASL |
821 | // ------------------------------------------------------------------------ |
822 | // processRequest | |
823 | // ------------------------------------------------------------------------ | |
824 | ||
54a7a54c | 825 | public void testProcessRequestForNbEvents() throws InterruptedException { |
cb866e08 | 826 | |
25e48683 | 827 | final int blockSize = 100; |
d18dd09b ASL |
828 | final int nbEvents = 1000; |
829 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); | |
830 | ||
25e48683 | 831 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
d18dd09b ASL |
832 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) { |
833 | @Override | |
25e48683 FC |
834 | public void handleData(final TmfEvent event) { |
835 | super.handleData(event); | |
f9673903 | 836 | requestedEvents.add(event); |
d18dd09b ASL |
837 | } |
838 | }; | |
839 | fExperiment.sendRequest(request); | |
840 | request.waitForCompletion(); | |
841 | ||
842 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); | |
843 | assertTrue("isCompleted", request.isCompleted()); | |
844 | assertFalse("isCancelled", request.isCancelled()); | |
845 | ||
846 | // Ensure that we have distinct events. | |
25e48683 | 847 | // Don't go overboard: we are not validating the stub! |
20658947 | 848 | for (int i = 0; i < nbEvents; i++) { |
d18dd09b | 849 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 850 | } |
d18dd09b | 851 | } |
25e48683 | 852 | |
54a7a54c | 853 | public void testProcessRequestForNbEvents2() throws InterruptedException { |
cb866e08 | 854 | |
25e48683 | 855 | final int blockSize = 2 * NB_EVENTS; |
d18dd09b ASL |
856 | final int nbEvents = 1000; |
857 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); | |
858 | ||
25e48683 | 859 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
d18dd09b | 860 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) { |
25e48683 FC |
861 | @Override |
862 | public void handleData(final TmfEvent event) { | |
863 | super.handleData(event); | |
864 | requestedEvents.add(event); | |
865 | } | |
d18dd09b ASL |
866 | }; |
867 | fExperiment.sendRequest(request); | |
868 | request.waitForCompletion(); | |
869 | ||
870 | assertEquals("nbEvents", nbEvents, requestedEvents.size()); | |
871 | assertTrue("isCompleted", request.isCompleted()); | |
872 | assertFalse("isCancelled", request.isCancelled()); | |
873 | ||
874 | // Ensure that we have distinct events. | |
25e48683 | 875 | // Don't go overboard: we are not validating the stub! |
20658947 | 876 | for (int i = 0; i < nbEvents; i++) { |
d18dd09b | 877 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 878 | } |
d18dd09b | 879 | } |
25e48683 | 880 | |
54a7a54c | 881 | public void testProcessRequestForAllEvents() throws InterruptedException { |
cb866e08 | 882 | |
9b749023 | 883 | final int nbEvents = TmfDataRequest.ALL_DATA; |
d18dd09b ASL |
884 | final int blockSize = 1; |
885 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); | |
25e48683 | 886 | final long nbExpectedEvents = NB_EVENTS; |
d18dd09b | 887 | |
25e48683 | 888 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
d18dd09b | 889 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) { |
25e48683 FC |
890 | @Override |
891 | public void handleData(final TmfEvent event) { | |
892 | super.handleData(event); | |
893 | requestedEvents.add(event); | |
894 | } | |
d18dd09b ASL |
895 | }; |
896 | fExperiment.sendRequest(request); | |
897 | request.waitForCompletion(); | |
898 | ||
899 | assertEquals("nbEvents", nbExpectedEvents, requestedEvents.size()); | |
900 | assertTrue("isCompleted", request.isCompleted()); | |
901 | assertFalse("isCancelled", request.isCancelled()); | |
902 | ||
903 | // Ensure that we have distinct events. | |
25e48683 | 904 | // Don't go overboard: we are not validating the stub! |
20658947 | 905 | for (int i = 0; i < nbExpectedEvents; i++) { |
d18dd09b | 906 | assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue()); |
20658947 | 907 | } |
d18dd09b | 908 | } |
25e48683 | 909 | |
d18dd09b ASL |
910 | // ------------------------------------------------------------------------ |
911 | // cancel | |
912 | // ------------------------------------------------------------------------ | |
913 | ||
54a7a54c | 914 | public void testCancel() throws InterruptedException { |
cb866e08 | 915 | |
25e48683 | 916 | final int nbEvents = NB_EVENTS; |
0316808c | 917 | final int blockSize = BLOCK_SIZE; |
d18dd09b ASL |
918 | final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>(); |
919 | ||
25e48683 | 920 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
d18dd09b | 921 | final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) { |
25e48683 FC |
922 | int nbRead = 0; |
923 | @Override | |
924 | public void handleData(final TmfEvent event) { | |
925 | super.handleData(event); | |
926 | requestedEvents.add(event); | |
20658947 | 927 | if (++nbRead == blockSize) { |
25e48683 | 928 | cancel(); |
20658947 | 929 | } |
25e48683 | 930 | } |
cb866e08 FC |
931 | @Override |
932 | public void handleCancel() { | |
20658947 | 933 | if (requestedEvents.size() < blockSize) { |
25e48683 | 934 | System.out.println("aie"); |
20658947 | 935 | } |
cb866e08 | 936 | } |
d18dd09b ASL |
937 | }; |
938 | fExperiment.sendRequest(request); | |
939 | request.waitForCompletion(); | |
940 | ||
941 | assertEquals("nbEvents", blockSize, requestedEvents.size()); | |
942 | assertTrue("isCompleted", request.isCompleted()); | |
943 | assertTrue("isCancelled", request.isCancelled()); | |
944 | } | |
25e48683 | 945 | |
17324c9a | 946 | } |