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