| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2010, 2012 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 - Adapted for TMF Trace Model 1.0 |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
| 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 | |
| 24 | import org.eclipse.core.runtime.FileLocator; |
| 25 | import org.eclipse.core.runtime.Path; |
| 26 | import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; |
| 27 | import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; |
| 28 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
| 29 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
| 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; |
| 33 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
| 34 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
| 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; |
| 38 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
| 39 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
| 40 | import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; |
| 41 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
| 42 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
| 43 | |
| 44 | /** |
| 45 | * Test suite for the TmfTrace class. |
| 46 | */ |
| 47 | @SuppressWarnings({"nls","javadoc"}) |
| 48 | public class TmfTraceTest extends TestCase { |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | // Variables |
| 52 | // ------------------------------------------------------------------------ |
| 53 | |
| 54 | private static final String DIRECTORY = "testfiles"; |
| 55 | private static final String TEST_STREAM = "A-Test-10K"; |
| 56 | private static final int BLOCK_SIZE = 500; |
| 57 | private static final int NB_EVENTS = 10000; |
| 58 | private static TmfTraceStub fTrace = null; |
| 59 | |
| 60 | private static int SCALE = -3; |
| 61 | |
| 62 | // ------------------------------------------------------------------------ |
| 63 | // Housekeeping |
| 64 | // ------------------------------------------------------------------------ |
| 65 | |
| 66 | /** |
| 67 | * @param name the test name |
| 68 | */ |
| 69 | public TmfTraceTest(final String name) { |
| 70 | super(name); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void setUp() throws Exception { |
| 75 | super.setUp(); |
| 76 | fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | protected void tearDown() throws Exception { |
| 81 | super.tearDown(); |
| 82 | fTrace.dispose(); |
| 83 | fTrace = null; |
| 84 | } |
| 85 | |
| 86 | // ------------------------------------------------------------------------ |
| 87 | // Helper functions |
| 88 | // ------------------------------------------------------------------------ |
| 89 | |
| 90 | private static TmfTraceStub setupTrace(final String path) { |
| 91 | if (fTrace == null) { |
| 92 | try { |
| 93 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); |
| 94 | final File test = new File(FileLocator.toFileURL(location).toURI()); |
| 95 | fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE); |
| 96 | fTrace.indexTrace(); |
| 97 | } catch (final TmfTraceException e) { |
| 98 | e.printStackTrace(); |
| 99 | } catch (final URISyntaxException e) { |
| 100 | e.printStackTrace(); |
| 101 | } catch (final IOException e) { |
| 102 | e.printStackTrace(); |
| 103 | } |
| 104 | } |
| 105 | return fTrace; |
| 106 | } |
| 107 | |
| 108 | // ------------------------------------------------------------------------ |
| 109 | // Constructors |
| 110 | // ------------------------------------------------------------------------ |
| 111 | |
| 112 | @SuppressWarnings("null") |
| 113 | public void testStandardConstructor() throws TmfTraceException { |
| 114 | TmfTraceStub trace = null; |
| 115 | File testfile = null; |
| 116 | try { |
| 117 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 118 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 119 | trace = new TmfTraceStub(testfile.toURI().getPath()); |
| 120 | trace.indexTrace(); |
| 121 | } catch (final URISyntaxException e) { |
| 122 | fail("URISyntaxException"); |
| 123 | } catch (final IOException e) { |
| 124 | fail("IOException"); |
| 125 | } |
| 126 | |
| 127 | assertFalse ("Open trace", trace == null); |
| 128 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 129 | assertNull ("getResource", trace.getResource()); |
| 130 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 131 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 132 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 133 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 134 | |
| 135 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 136 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 137 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 138 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 139 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 140 | } |
| 141 | |
| 142 | @SuppressWarnings("null") |
| 143 | public void testStandardConstructorCacheSize() throws TmfTraceException { |
| 144 | TmfTraceStub trace = null; |
| 145 | File testfile = null; |
| 146 | try { |
| 147 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 148 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 149 | trace = new TmfTraceStub(testfile.toURI().getPath(), 0); |
| 150 | trace.indexTrace(); |
| 151 | } catch (final URISyntaxException e) { |
| 152 | fail("URISyntaxException"); |
| 153 | } catch (final IOException e) { |
| 154 | fail("IOException"); |
| 155 | } |
| 156 | |
| 157 | assertFalse ("Open trace", trace == null); |
| 158 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 159 | assertNull ("getResource", trace.getResource()); |
| 160 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 161 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 162 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 163 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 164 | |
| 165 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 166 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 167 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 168 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 169 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 170 | |
| 171 | try { |
| 172 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 173 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 174 | trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE); |
| 175 | trace.indexTrace(); |
| 176 | } catch (final URISyntaxException e) { |
| 177 | fail("URISyntaxException"); |
| 178 | } catch (final IOException e) { |
| 179 | fail("IOException"); |
| 180 | } |
| 181 | |
| 182 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 183 | assertNull ("getResource", trace.getResource()); |
| 184 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 185 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); |
| 186 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 187 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 188 | |
| 189 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 190 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 191 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 192 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 193 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 194 | } |
| 195 | |
| 196 | @SuppressWarnings("null") |
| 197 | public void testFullConstructor() throws TmfTraceException { |
| 198 | TmfTraceStub trace = null; |
| 199 | File testfile = null; |
| 200 | try { |
| 201 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 202 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 203 | trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null); |
| 204 | trace.indexTrace(); |
| 205 | } catch (final URISyntaxException e) { |
| 206 | fail("URISyntaxException"); |
| 207 | } catch (final IOException e) { |
| 208 | fail("IOException"); |
| 209 | } |
| 210 | |
| 211 | assertFalse ("Open trace", trace == null); |
| 212 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 213 | assertNull ("getResource", trace.getResource()); |
| 214 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 215 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); |
| 216 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 217 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 218 | |
| 219 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 220 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 221 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 222 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 223 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 224 | } |
| 225 | |
| 226 | @SuppressWarnings("null") |
| 227 | public void testLiveTraceConstructor() throws TmfTraceException { |
| 228 | TmfTraceStub trace = null; |
| 229 | File testfile = null; |
| 230 | final long interval = 100; |
| 231 | try { |
| 232 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 233 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 234 | trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, interval); |
| 235 | trace.indexTrace(); |
| 236 | } catch (final URISyntaxException e) { |
| 237 | fail("URISyntaxException"); |
| 238 | } catch (final IOException e) { |
| 239 | fail("IOException"); |
| 240 | } |
| 241 | |
| 242 | assertFalse ("Open trace", trace == null); |
| 243 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 244 | assertNull ("getResource", trace.getResource()); |
| 245 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 246 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); |
| 247 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); |
| 248 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 249 | |
| 250 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 251 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 252 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 253 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 254 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 255 | } |
| 256 | |
| 257 | @SuppressWarnings("null") |
| 258 | public void testCopyConstructor() throws TmfTraceException { |
| 259 | TmfTraceStub original = null; |
| 260 | TmfTraceStub trace = null; |
| 261 | File testfile = null; |
| 262 | try { |
| 263 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 264 | testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 265 | original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfCheckpointIndexer(null)); |
| 266 | trace = new TmfTraceStub(original); |
| 267 | trace.indexTrace(); |
| 268 | } catch (final URISyntaxException e) { |
| 269 | fail("URISyntaxException"); |
| 270 | } catch (final IOException e) { |
| 271 | fail("IOException"); |
| 272 | } |
| 273 | |
| 274 | assertFalse ("Open trace", trace == null); |
| 275 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 276 | assertNull ("getResource", trace.getResource()); |
| 277 | assertEquals("getPath", testfile.toURI().getPath(), trace.getPath()); |
| 278 | assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize()); |
| 279 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 280 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 281 | |
| 282 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 283 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 284 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 285 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 286 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 287 | |
| 288 | // Test the copy of a null trace |
| 289 | try { |
| 290 | new TmfTraceStub((TmfTraceStub) null); |
| 291 | fail("Missing exception"); |
| 292 | } catch (final IllegalArgumentException e) { |
| 293 | // test passed |
| 294 | } catch (final Exception e) { |
| 295 | fail("Unexpected exception"); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // ------------------------------------------------------------------------ |
| 300 | // Trace initialization |
| 301 | // ------------------------------------------------------------------------ |
| 302 | |
| 303 | public void testInitializeNullPath() { |
| 304 | |
| 305 | // Instantiate an "empty" trace |
| 306 | final TmfTraceStub trace = new TmfTraceStub(); |
| 307 | |
| 308 | try { |
| 309 | trace.initialize(null, null, TmfEvent.class); |
| 310 | fail("TmfTrace.initialize() - no exception thrown"); |
| 311 | } catch (TmfTraceException e) { |
| 312 | // Success |
| 313 | } catch (Exception e) { |
| 314 | fail("TmfTrace.initialize() - wrong exception thrown"); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | public void testInitializeSimplePath() { |
| 319 | |
| 320 | // Instantiate an "empty" trace |
| 321 | final TmfTraceStub trace = new TmfTraceStub(); |
| 322 | |
| 323 | // Path == trace name |
| 324 | String path = "TraceName"; |
| 325 | try { |
| 326 | trace.initialize(null, path, TmfEvent.class); |
| 327 | } catch (Exception e) { |
| 328 | fail("TmfTrace.initialize() - Exception thrown"); |
| 329 | } |
| 330 | |
| 331 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 332 | assertNull ("getResource", trace.getResource()); |
| 333 | assertEquals("getPath", path, trace.getPath()); |
| 334 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 335 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 336 | assertEquals("getName", path, trace.getName()); |
| 337 | |
| 338 | assertEquals("getNbEvents", 0, trace.getNbEvents()); |
| 339 | assertEquals("getRange-start", Long.MAX_VALUE, trace.getTimeRange().getStartTime().getValue()); |
| 340 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
| 341 | assertEquals("getStartTime", Long.MAX_VALUE, trace.getStartTime().getValue()); |
| 342 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
| 343 | } |
| 344 | |
| 345 | public void testInitializeNormalPath() { |
| 346 | |
| 347 | // Instantiate an "empty" trace |
| 348 | final TmfTraceStub trace = new TmfTraceStub(); |
| 349 | |
| 350 | // Path == trace name |
| 351 | String name = "TraceName"; |
| 352 | String path = "/my/trace/path/" + name; |
| 353 | try { |
| 354 | trace.initialize(null, path, TmfEvent.class); |
| 355 | } catch (Exception e) { |
| 356 | fail("TmfTrace.initialize() - Exception thrown"); |
| 357 | } |
| 358 | |
| 359 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 360 | assertNull ("getResource", trace.getResource()); |
| 361 | assertEquals("getPath", path, trace.getPath()); |
| 362 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 363 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 364 | assertEquals("getName", name, trace.getName()); |
| 365 | |
| 366 | assertEquals("getNbEvents", 0, trace.getNbEvents()); |
| 367 | assertEquals("getRange-start", Long.MAX_VALUE, trace.getTimeRange().getStartTime().getValue()); |
| 368 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
| 369 | assertEquals("getStartTime", Long.MAX_VALUE, trace.getStartTime().getValue()); |
| 370 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
| 371 | } |
| 372 | |
| 373 | public void testInitTrace() throws URISyntaxException, IOException, TmfTraceException, InterruptedException { |
| 374 | |
| 375 | // Instantiate an "empty" trace |
| 376 | final TmfTraceStub trace = new TmfTraceStub(); |
| 377 | |
| 378 | assertNull ("getType", trace.getType()); |
| 379 | assertNull ("getResource", trace.getResource()); |
| 380 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 381 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 382 | assertEquals("getName", "", trace.getName()); |
| 383 | |
| 384 | assertEquals("getNbEvents", 0, trace.getNbEvents()); |
| 385 | assertEquals("getRange-start", Long.MAX_VALUE, trace.getTimeRange().getStartTime().getValue()); |
| 386 | assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue()); |
| 387 | assertEquals("getStartTime", Long.MAX_VALUE, trace.getStartTime().getValue()); |
| 388 | assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); |
| 389 | |
| 390 | // Validate |
| 391 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 392 | final File testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 393 | assertTrue("validate", trace.validate(null, testfile.getPath())); |
| 394 | |
| 395 | // InitTrace and wait for indexing completion... |
| 396 | trace.initTrace(null, testfile.toURI().getPath(), TmfEvent.class); |
| 397 | trace.indexTrace(); |
| 398 | int nbSecs = 0; |
| 399 | while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) { |
| 400 | Thread.sleep(1000); |
| 401 | nbSecs++; |
| 402 | } |
| 403 | if (trace.getNbEvents() < NB_EVENTS) { |
| 404 | fail("indexing"); |
| 405 | } |
| 406 | |
| 407 | assertEquals("getType", TmfEvent.class, trace.getType()); |
| 408 | assertNull ("getResource", trace.getResource()); |
| 409 | assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize()); |
| 410 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 411 | assertEquals("getName", TEST_STREAM, trace.getName()); |
| 412 | |
| 413 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 414 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 415 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 416 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 417 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 418 | } |
| 419 | |
| 420 | // ------------------------------------------------------------------------ |
| 421 | // Set/Get streaming interval |
| 422 | // ------------------------------------------------------------------------ |
| 423 | |
| 424 | public void testSetStreamingInterval() throws TmfTraceException { |
| 425 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
| 426 | |
| 427 | long interval = 0; |
| 428 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); |
| 429 | |
| 430 | interval = 100; |
| 431 | trace.setStreamingInterval(interval); |
| 432 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); |
| 433 | |
| 434 | interval = -1; |
| 435 | trace.setStreamingInterval(interval); |
| 436 | assertEquals("getStreamingInterval", 0, trace.getStreamingInterval()); |
| 437 | |
| 438 | interval = 0; |
| 439 | trace.setStreamingInterval(interval); |
| 440 | assertEquals("getStreamingInterval", interval, trace.getStreamingInterval()); |
| 441 | |
| 442 | trace.dispose(); |
| 443 | } |
| 444 | |
| 445 | // ------------------------------------------------------------------------ |
| 446 | // Set/Get time range |
| 447 | // ------------------------------------------------------------------------ |
| 448 | |
| 449 | public void testSetTimeRange() throws TmfTraceException { |
| 450 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
| 451 | trace.indexTrace(); |
| 452 | |
| 453 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 454 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 455 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 456 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 457 | |
| 458 | trace.setTimeRange(new TmfTimeRange(new TmfTimestamp(100), new TmfTimestamp(200))); |
| 459 | assertEquals("setTimeRange", 100, trace.getTimeRange().getStartTime().getValue()); |
| 460 | assertEquals("setTimeRange", 200, trace.getTimeRange().getEndTime().getValue()); |
| 461 | assertEquals("setTimeRange", 100, trace.getStartTime().getValue()); |
| 462 | assertEquals("setTimeRange", 200, trace.getEndTime().getValue()); |
| 463 | |
| 464 | trace.dispose(); |
| 465 | } |
| 466 | |
| 467 | public void testSetStartTime() throws TmfTraceException { |
| 468 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
| 469 | trace.indexTrace(); |
| 470 | |
| 471 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 472 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 473 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 474 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 475 | |
| 476 | trace.setStartTime(new TmfTimestamp(100)); |
| 477 | assertEquals("setStartTime", 100, trace.getTimeRange().getStartTime().getValue()); |
| 478 | assertEquals("setStartTime", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 479 | assertEquals("setStartTime", 100, trace.getStartTime().getValue()); |
| 480 | assertEquals("setStartTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 481 | |
| 482 | trace.dispose(); |
| 483 | } |
| 484 | |
| 485 | public void testSetEndTime() throws TmfTraceException { |
| 486 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
| 487 | trace.indexTrace(); |
| 488 | |
| 489 | assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue()); |
| 490 | assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue()); |
| 491 | assertEquals("getStartTime", 1, trace.getStartTime().getValue()); |
| 492 | assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); |
| 493 | |
| 494 | trace.setEndTime(new TmfTimestamp(100)); |
| 495 | assertEquals("setEndTime", 1, trace.getTimeRange().getStartTime().getValue()); |
| 496 | assertEquals("setEndTime", 100, trace.getTimeRange().getEndTime().getValue()); |
| 497 | assertEquals("setEndTime", 1, trace.getStartTime().getValue()); |
| 498 | assertEquals("setEndTime", 100, trace.getEndTime().getValue()); |
| 499 | |
| 500 | trace.dispose(); |
| 501 | } |
| 502 | |
| 503 | public void testSetNbEvents() throws TmfTraceException { |
| 504 | final TmfTraceStub trace = new TmfTraceStub(fTrace); |
| 505 | trace.indexTrace(); |
| 506 | |
| 507 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 508 | |
| 509 | trace.setNbEvents(0); |
| 510 | assertEquals("getNbEvents", 0, trace.getNbEvents()); |
| 511 | |
| 512 | trace.setNbEvents(-1); |
| 513 | assertEquals("getNbEvents", 0, trace.getNbEvents()); |
| 514 | |
| 515 | trace.setNbEvents(NB_EVENTS + 1); |
| 516 | assertEquals("getNbEvents", NB_EVENTS + 1, trace.getNbEvents()); |
| 517 | |
| 518 | trace.setNbEvents(NB_EVENTS); |
| 519 | assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents()); |
| 520 | |
| 521 | trace.dispose(); |
| 522 | } |
| 523 | |
| 524 | // ------------------------------------------------------------------------ |
| 525 | // seekEvent on location (note: does not reliably set the rank) |
| 526 | // ------------------------------------------------------------------------ |
| 527 | |
| 528 | public void testSeekEventOnCacheBoundary() { |
| 529 | |
| 530 | // Position trace at event rank 0 |
| 531 | ITmfContext context = fTrace.seekEvent(0); |
| 532 | ITmfEvent event = fTrace.parseEvent(context); |
| 533 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 534 | assertEquals("Event rank", 0, context.getRank()); |
| 535 | |
| 536 | context = fTrace.seekEvent(context.getLocation()); |
| 537 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 538 | |
| 539 | event = fTrace.parseEvent(context); |
| 540 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 541 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 542 | |
| 543 | event = fTrace.getNext(context); |
| 544 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 545 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 546 | |
| 547 | // Position trace at event rank 1000 |
| 548 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); |
| 549 | context = fTrace.seekEvent(tmpContext.getLocation()); |
| 550 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 551 | |
| 552 | event = fTrace.parseEvent(context); |
| 553 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 554 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 555 | |
| 556 | event = fTrace.getNext(context); |
| 557 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 558 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 559 | |
| 560 | // Position trace at event rank 4000 |
| 561 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); |
| 562 | context = fTrace.seekEvent(tmpContext.getLocation()); |
| 563 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 564 | |
| 565 | event = fTrace.parseEvent(context); |
| 566 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 567 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 568 | |
| 569 | event = fTrace.getNext(context); |
| 570 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 571 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 572 | } |
| 573 | |
| 574 | public void testSeekEventNotOnCacheBoundary() { |
| 575 | |
| 576 | // Position trace at event rank 9 |
| 577 | ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
| 578 | TmfContext context = fTrace.seekEvent(tmpContext.getLocation()); |
| 579 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 580 | |
| 581 | ITmfEvent event = fTrace.parseEvent(context); |
| 582 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 583 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 584 | |
| 585 | event = fTrace.getNext(context); |
| 586 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 587 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 588 | |
| 589 | // Position trace at event rank 999 |
| 590 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
| 591 | context = fTrace.seekEvent(tmpContext.getLocation()); |
| 592 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 593 | |
| 594 | event = fTrace.parseEvent(context); |
| 595 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 596 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 597 | |
| 598 | event = fTrace.getNext(context); |
| 599 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 600 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 601 | |
| 602 | // Position trace at event rank 1001 |
| 603 | tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
| 604 | context = fTrace.seekEvent(tmpContext.getLocation()); |
| 605 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 606 | |
| 607 | event = fTrace.parseEvent(context); |
| 608 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 609 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 610 | |
| 611 | event = fTrace.getNext(context); |
| 612 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 613 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 614 | |
| 615 | // Position trace at event rank 4500 |
| 616 | tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
| 617 | context = fTrace.seekEvent(tmpContext.getLocation()); |
| 618 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 619 | |
| 620 | event = fTrace.parseEvent(context); |
| 621 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 622 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 623 | |
| 624 | event = fTrace.getNext(context); |
| 625 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 626 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 627 | } |
| 628 | |
| 629 | public void testSeekEventOutOfScope() { |
| 630 | |
| 631 | // Position trace at beginning |
| 632 | ITmfContext tmpContext = fTrace.seekEvent(0); |
| 633 | ITmfContext context = fTrace.seekEvent(tmpContext.getLocation()); |
| 634 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 635 | |
| 636 | ITmfEvent event = fTrace.parseEvent(context); |
| 637 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 638 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 639 | |
| 640 | event = fTrace.getNext(context); |
| 641 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 642 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 643 | |
| 644 | // Position trace at event passed the end |
| 645 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
| 646 | assertNull("Event timestamp", context.getLocation()); |
| 647 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 648 | |
| 649 | event = fTrace.getNext(context); |
| 650 | assertNull("Event", event); |
| 651 | } |
| 652 | |
| 653 | // ------------------------------------------------------------------------ |
| 654 | // seekEvent on timestamp (note: does not reliably set the rank) |
| 655 | // ------------------------------------------------------------------------ |
| 656 | |
| 657 | public void testSeekEventOnNullTimestamp() { |
| 658 | |
| 659 | // Position trace at event rank 0 |
| 660 | ITmfContext context = fTrace.seekEvent((ITmfTimestamp) null); |
| 661 | assertEquals("Event rank", 0, context.getRank()); |
| 662 | |
| 663 | ITmfEvent event = fTrace.parseEvent(context); |
| 664 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 665 | assertEquals("Event rank", 0, context.getRank()); |
| 666 | } |
| 667 | |
| 668 | public void testSeekEventOnTimestampOnCacheBoundary() { |
| 669 | |
| 670 | // Position trace at event rank 0 |
| 671 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0)); |
| 672 | assertEquals("Event rank", 0, context.getRank()); |
| 673 | |
| 674 | ITmfEvent event = fTrace.parseEvent(context); |
| 675 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 676 | assertEquals("Event rank", 0, context.getRank()); |
| 677 | |
| 678 | event = fTrace.getNext(context); |
| 679 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 680 | assertEquals("Event rank", 1, context.getRank()); |
| 681 | |
| 682 | // Position trace at event rank 1000 |
| 683 | context = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0)); |
| 684 | assertEquals("Event rank", 1000, context.getRank()); |
| 685 | |
| 686 | event = fTrace.parseEvent(context); |
| 687 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 688 | assertEquals("Event rank", 1000, context.getRank()); |
| 689 | |
| 690 | event = fTrace.getNext(context); |
| 691 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 692 | assertEquals("Event rank", 1001, context.getRank()); |
| 693 | |
| 694 | // Position trace at event rank 4000 |
| 695 | context = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0)); |
| 696 | assertEquals("Event rank", 4000, context.getRank()); |
| 697 | |
| 698 | event = fTrace.parseEvent(context); |
| 699 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 700 | assertEquals("Event rank", 4000, context.getRank()); |
| 701 | |
| 702 | event = fTrace.getNext(context); |
| 703 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 704 | assertEquals("Event rank", 4001, context.getRank()); |
| 705 | } |
| 706 | |
| 707 | public void testSeekEventOnTimestampNotOnCacheBoundary() { |
| 708 | |
| 709 | // Position trace at event rank 1 |
| 710 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE, 0)); |
| 711 | assertEquals("Event rank", 1, context.getRank()); |
| 712 | |
| 713 | ITmfEvent event = fTrace.parseEvent(context); |
| 714 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
| 715 | assertEquals("Event rank", 1, context.getRank()); |
| 716 | |
| 717 | event = fTrace.getNext(context); |
| 718 | assertEquals("Event timestamp", 2, event.getTimestamp().getValue()); |
| 719 | assertEquals("Event rank", 2, context.getRank()); |
| 720 | |
| 721 | // Position trace at event rank 9 |
| 722 | context = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); |
| 723 | assertEquals("Event rank", 9, context.getRank()); |
| 724 | |
| 725 | event = fTrace.parseEvent(context); |
| 726 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 727 | assertEquals("Event rank", 9, context.getRank()); |
| 728 | |
| 729 | event = fTrace.getNext(context); |
| 730 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 731 | assertEquals("Event rank", 10, context.getRank()); |
| 732 | |
| 733 | // Position trace at event rank 999 |
| 734 | context = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0)); |
| 735 | assertEquals("Event rank", 999, context.getRank()); |
| 736 | |
| 737 | event = fTrace.parseEvent(context); |
| 738 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 739 | assertEquals("Event rank", 999, context.getRank()); |
| 740 | |
| 741 | event = fTrace.getNext(context); |
| 742 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 743 | assertEquals("Event rank", 1000, context.getRank()); |
| 744 | |
| 745 | // Position trace at event rank 1001 |
| 746 | context = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0)); |
| 747 | assertEquals("Event rank", 1001, context.getRank()); |
| 748 | |
| 749 | event = fTrace.parseEvent(context); |
| 750 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 751 | assertEquals("Event rank", 1001, context.getRank()); |
| 752 | |
| 753 | event = fTrace.getNext(context); |
| 754 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 755 | assertEquals("Event rank", 1002, context.getRank()); |
| 756 | |
| 757 | // Position trace at event rank 4500 |
| 758 | context = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0)); |
| 759 | assertEquals("Event rank", 4500, context.getRank()); |
| 760 | |
| 761 | event = fTrace.parseEvent(context); |
| 762 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 763 | assertEquals("Event rank", 4500, context.getRank()); |
| 764 | |
| 765 | event = fTrace.getNext(context); |
| 766 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 767 | assertEquals("Event rank", 4501, context.getRank()); |
| 768 | } |
| 769 | |
| 770 | public void testSeekEventOnTimestampOutOfScope() { |
| 771 | |
| 772 | // Position trace at beginning |
| 773 | ITmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0)); |
| 774 | assertEquals("Event rank", 0, context.getRank()); |
| 775 | |
| 776 | ITmfEvent event = fTrace.parseEvent(context); |
| 777 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 778 | assertEquals("Event rank", 0, context.getRank()); |
| 779 | |
| 780 | event = fTrace.getNext(context); |
| 781 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 782 | assertEquals("Event rank", 1, context.getRank()); |
| 783 | |
| 784 | // Position trace at event passed the end |
| 785 | context = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0)); |
| 786 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 787 | |
| 788 | event = fTrace.parseEvent(context); |
| 789 | assertEquals("Event timestamp", null, event); |
| 790 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 791 | |
| 792 | event = fTrace.getNext(context); |
| 793 | assertEquals("Event timestamp", null, event); |
| 794 | assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); |
| 795 | } |
| 796 | |
| 797 | // ------------------------------------------------------------------------ |
| 798 | // seekEvent on rank |
| 799 | // ------------------------------------------------------------------------ |
| 800 | |
| 801 | public void testSeekEventOnNegativeRank() { |
| 802 | |
| 803 | // Position trace at event rank 0 |
| 804 | ITmfContext context = fTrace.seekEvent(-1); |
| 805 | assertEquals("Event rank", 0, context.getRank()); |
| 806 | |
| 807 | ITmfEvent event = fTrace.parseEvent(context); |
| 808 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 809 | assertEquals("Event rank", 0, context.getRank()); |
| 810 | } |
| 811 | |
| 812 | public void testSeekOnRankOnCacheBoundary() { |
| 813 | |
| 814 | // On lower bound, returns the first event (ts = 1) |
| 815 | ITmfContext context = fTrace.seekEvent(0); |
| 816 | assertEquals("Event rank", 0, context.getRank()); |
| 817 | |
| 818 | ITmfEvent event = fTrace.parseEvent(context); |
| 819 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 820 | assertEquals("Event rank", 0, context.getRank()); |
| 821 | |
| 822 | event = fTrace.getNext(context); |
| 823 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 824 | assertEquals("Event rank", 1, context.getRank()); |
| 825 | |
| 826 | // Position trace at event rank 1000 |
| 827 | context = fTrace.seekEvent(1000); |
| 828 | assertEquals("Event rank", 1000, context.getRank()); |
| 829 | |
| 830 | event = fTrace.parseEvent(context); |
| 831 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 832 | assertEquals("Event rank", 1000, context.getRank()); |
| 833 | |
| 834 | event = fTrace.getNext(context); |
| 835 | assertEquals("Event timestamp", 1001, event.getTimestamp().getValue()); |
| 836 | assertEquals("Event rank", 1001, context.getRank()); |
| 837 | |
| 838 | // Position trace at event rank 4000 |
| 839 | context = fTrace.seekEvent(4000); |
| 840 | assertEquals("Event rank", 4000, context.getRank()); |
| 841 | |
| 842 | event = fTrace.parseEvent(context); |
| 843 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 844 | assertEquals("Event rank", 4000, context.getRank()); |
| 845 | |
| 846 | event = fTrace.getNext(context); |
| 847 | assertEquals("Event timestamp", 4001, event.getTimestamp().getValue()); |
| 848 | assertEquals("Event rank", 4001, context.getRank()); |
| 849 | } |
| 850 | |
| 851 | public void testSeekOnRankNotOnCacheBoundary() { |
| 852 | |
| 853 | // Position trace at event rank 9 |
| 854 | ITmfContext context = fTrace.seekEvent(9); |
| 855 | assertEquals("Event rank", 9, context.getRank()); |
| 856 | |
| 857 | ITmfEvent event = fTrace.parseEvent(context); |
| 858 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 859 | assertEquals("Event rank", 9, context.getRank()); |
| 860 | |
| 861 | event = fTrace.getNext(context); |
| 862 | assertEquals("Event timestamp", 10, event.getTimestamp().getValue()); |
| 863 | assertEquals("Event rank", 10, context.getRank()); |
| 864 | |
| 865 | // Position trace at event rank 999 |
| 866 | context = fTrace.seekEvent(999); |
| 867 | assertEquals("Event rank", 999, context.getRank()); |
| 868 | |
| 869 | event = fTrace.parseEvent(context); |
| 870 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 871 | assertEquals("Event rank", 999, context.getRank()); |
| 872 | |
| 873 | event = fTrace.getNext(context); |
| 874 | assertEquals("Event timestamp", 1000, event.getTimestamp().getValue()); |
| 875 | assertEquals("Event rank", 1000, context.getRank()); |
| 876 | |
| 877 | // Position trace at event rank 1001 |
| 878 | context = fTrace.seekEvent(1001); |
| 879 | assertEquals("Event rank", 1001, context.getRank()); |
| 880 | |
| 881 | event = fTrace.parseEvent(context); |
| 882 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 883 | assertEquals("Event rank", 1001, context.getRank()); |
| 884 | |
| 885 | event = fTrace.getNext(context); |
| 886 | assertEquals("Event timestamp", 1002, event.getTimestamp().getValue()); |
| 887 | assertEquals("Event rank", 1002, context.getRank()); |
| 888 | |
| 889 | // Position trace at event rank 4500 |
| 890 | context = fTrace.seekEvent(4500); |
| 891 | assertEquals("Event rank", 4500, context.getRank()); |
| 892 | |
| 893 | event = fTrace.parseEvent(context); |
| 894 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 895 | assertEquals("Event rank", 4500, context.getRank()); |
| 896 | |
| 897 | event = fTrace.getNext(context); |
| 898 | assertEquals("Event timestamp", 4501, event.getTimestamp().getValue()); |
| 899 | assertEquals("Event rank", 4501, context.getRank()); |
| 900 | } |
| 901 | |
| 902 | public void testSeekEventOnRankOutOfScope() { |
| 903 | |
| 904 | // Position trace at beginning |
| 905 | ITmfContext context = fTrace.seekEvent(-1); |
| 906 | assertEquals("Event rank", 0, context.getRank()); |
| 907 | |
| 908 | ITmfEvent event = fTrace.parseEvent(context); |
| 909 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 910 | assertEquals("Event rank", 0, context.getRank()); |
| 911 | |
| 912 | event = fTrace.getNext(context); |
| 913 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 914 | assertEquals("Event rank", 1, context.getRank()); |
| 915 | |
| 916 | // Position trace at event passed the end |
| 917 | context = fTrace.seekEvent(NB_EVENTS); |
| 918 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
| 919 | |
| 920 | event = fTrace.parseEvent(context); |
| 921 | assertNull("Event", event); |
| 922 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
| 923 | |
| 924 | event = fTrace.getNext(context); |
| 925 | assertNull("Event", event); |
| 926 | assertEquals("Event rank", NB_EVENTS, context.getRank()); |
| 927 | } |
| 928 | |
| 929 | // ------------------------------------------------------------------------ |
| 930 | // parseEvent - make sure parseEvent doesn't update the context |
| 931 | // ------------------------------------------------------------------------ |
| 932 | |
| 933 | public void testParseEvent() { |
| 934 | |
| 935 | final int NB_READS = 20; |
| 936 | |
| 937 | // On lower bound, returns the first event (ts = 0) |
| 938 | final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0)); |
| 939 | TmfContext svContext = new TmfContext(context); |
| 940 | |
| 941 | ITmfEvent event = fTrace.parseEvent(context); |
| 942 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 943 | assertEquals("Event rank", 0, context.getRank()); |
| 944 | assertTrue("parseEvent", context.equals(svContext)); |
| 945 | |
| 946 | event = fTrace.parseEvent(context); |
| 947 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 948 | assertEquals("Event rank", 0, context.getRank()); |
| 949 | assertTrue("parseEvent", context.equals(svContext)); |
| 950 | |
| 951 | event = fTrace.parseEvent(context); |
| 952 | assertEquals("Event timestamp", 1, event.getTimestamp().getValue()); |
| 953 | assertEquals("Event rank", 0, context.getRank()); |
| 954 | assertTrue("parseEvent", context.equals(svContext)); |
| 955 | |
| 956 | // Position the trace at event NB_READS |
| 957 | for (int i = 1; i < NB_READS; i++) { |
| 958 | event = fTrace.getNext(context); |
| 959 | assertEquals("Event timestamp", i, event.getTimestamp().getValue()); |
| 960 | } |
| 961 | |
| 962 | svContext = new TmfContext(context); |
| 963 | event = fTrace.parseEvent(context); |
| 964 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); |
| 965 | assertEquals("Event rank", NB_READS -1 , context.getRank()); |
| 966 | assertTrue("parseEvent", context.equals(svContext)); |
| 967 | |
| 968 | event = fTrace.parseEvent(context); |
| 969 | assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue()); |
| 970 | assertEquals("Event rank", NB_READS - 1, context.getRank()); |
| 971 | assertTrue("parseEvent", context.equals(svContext)); |
| 972 | } |
| 973 | |
| 974 | // ------------------------------------------------------------------------ |
| 975 | // getNext - updates the context |
| 976 | // ------------------------------------------------------------------------ |
| 977 | |
| 978 | public void testGetNextAfteSeekingOnTS_1() { |
| 979 | |
| 980 | final long INITIAL_TS = 1; |
| 981 | final int NB_READS = 20; |
| 982 | |
| 983 | // On lower bound, returns the first event (ts = 1) |
| 984 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); |
| 985 | |
| 986 | // Read NB_EVENTS |
| 987 | ITmfEvent event; |
| 988 | for (int i = 0; i < NB_READS; i++) { |
| 989 | event = fTrace.getNext(context); |
| 990 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 991 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); |
| 992 | } |
| 993 | |
| 994 | // Make sure we stay positioned |
| 995 | event = fTrace.parseEvent(context); |
| 996 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 997 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); |
| 998 | } |
| 999 | |
| 1000 | public void testGetNextAfteSeekingOnTS_2() { |
| 1001 | |
| 1002 | final long INITIAL_TS = 2; |
| 1003 | final int NB_READS = 20; |
| 1004 | |
| 1005 | // On lower bound, returns the first event (ts = 500) |
| 1006 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); |
| 1007 | |
| 1008 | // Read NB_EVENTS |
| 1009 | ITmfEvent event; |
| 1010 | for (int i = 0; i < NB_READS; i++) { |
| 1011 | event = fTrace.getNext(context); |
| 1012 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 1013 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); |
| 1014 | } |
| 1015 | |
| 1016 | // Make sure we stay positioned |
| 1017 | event = fTrace.parseEvent(context); |
| 1018 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 1019 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); |
| 1020 | } |
| 1021 | |
| 1022 | public void testGetNextAfteSeekingOnTS_3() { |
| 1023 | |
| 1024 | final long INITIAL_TS = 500; |
| 1025 | final int NB_READS = 20; |
| 1026 | |
| 1027 | // On lower bound, returns the first event (ts = 500) |
| 1028 | final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0)); |
| 1029 | |
| 1030 | // Read NB_EVENTS |
| 1031 | ITmfEvent event; |
| 1032 | for (int i = 0; i < NB_READS; i++) { |
| 1033 | event = fTrace.getNext(context); |
| 1034 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 1035 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); |
| 1036 | } |
| 1037 | |
| 1038 | // Make sure we stay positioned |
| 1039 | event = fTrace.parseEvent(context); |
| 1040 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 1041 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); |
| 1042 | } |
| 1043 | |
| 1044 | public void testGetNextAfterSeekingOnRank_1() { |
| 1045 | |
| 1046 | final long INITIAL_RANK = 0L; |
| 1047 | final int NB_READS = 20; |
| 1048 | |
| 1049 | // On lower bound, returns the first event (rank = 0) |
| 1050 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); |
| 1051 | |
| 1052 | // Read NB_EVENTS |
| 1053 | ITmfEvent event; |
| 1054 | for (int i = 0; i < NB_READS; i++) { |
| 1055 | event = fTrace.getNext(context); |
| 1056 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); |
| 1057 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); |
| 1058 | } |
| 1059 | |
| 1060 | // Make sure we stay positioned |
| 1061 | event = fTrace.parseEvent(context); |
| 1062 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); |
| 1063 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); |
| 1064 | } |
| 1065 | |
| 1066 | public void testGetNextAfterSeekingOnRank_2() { |
| 1067 | |
| 1068 | final long INITIAL_RANK = 1L; |
| 1069 | final int NB_READS = 20; |
| 1070 | |
| 1071 | // On lower bound, returns the first event (rank = 0) |
| 1072 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); |
| 1073 | |
| 1074 | // Read NB_EVENTS |
| 1075 | ITmfEvent event; |
| 1076 | for (int i = 0; i < NB_READS; i++) { |
| 1077 | event = fTrace.getNext(context); |
| 1078 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); |
| 1079 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); |
| 1080 | } |
| 1081 | |
| 1082 | // Make sure we stay positioned |
| 1083 | event = fTrace.parseEvent(context); |
| 1084 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); |
| 1085 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); |
| 1086 | } |
| 1087 | |
| 1088 | public void testGetNextAfterSeekingOnRank_3() { |
| 1089 | |
| 1090 | final long INITIAL_RANK = 500L; |
| 1091 | final int NB_READS = 20; |
| 1092 | |
| 1093 | // On lower bound, returns the first event (rank = 0) |
| 1094 | final ITmfContext context = fTrace.seekEvent(INITIAL_RANK); |
| 1095 | |
| 1096 | // Read NB_EVENTS |
| 1097 | ITmfEvent event; |
| 1098 | for (int i = 0; i < NB_READS; i++) { |
| 1099 | event = fTrace.getNext(context); |
| 1100 | assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue()); |
| 1101 | assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank()); |
| 1102 | } |
| 1103 | |
| 1104 | // Make sure we stay positioned |
| 1105 | event = fTrace.parseEvent(context); |
| 1106 | assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue()); |
| 1107 | assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); |
| 1108 | } |
| 1109 | |
| 1110 | public void testGetNextAfterSeekingOnLocation_1() { |
| 1111 | |
| 1112 | final ITmfLocation INITIAL_LOC = null; |
| 1113 | final long INITIAL_TS = 1; |
| 1114 | final int NB_READS = 20; |
| 1115 | |
| 1116 | // On lower bound, returns the first event (ts = 1) |
| 1117 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); |
| 1118 | |
| 1119 | // Read NB_EVENTS |
| 1120 | ITmfEvent event; |
| 1121 | for (int i = 0; i < NB_READS; i++) { |
| 1122 | event = fTrace.getNext(context); |
| 1123 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 1124 | assertEquals("Event rank", INITIAL_TS + i, context.getRank()); |
| 1125 | } |
| 1126 | |
| 1127 | // Make sure we stay positioned |
| 1128 | event = fTrace.parseEvent(context); |
| 1129 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 1130 | assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); |
| 1131 | } |
| 1132 | |
| 1133 | public void testGetNextAfterSeekingOnLocation_2() { |
| 1134 | |
| 1135 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(1L).getLocation(); |
| 1136 | final long INITIAL_TS = 2; |
| 1137 | final int NB_READS = 20; |
| 1138 | |
| 1139 | // On lower bound, returns the first event (ts = 501) |
| 1140 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); |
| 1141 | |
| 1142 | // Read NB_EVENTS |
| 1143 | ITmfEvent event; |
| 1144 | for (int i = 0; i < NB_READS; i++) { |
| 1145 | event = fTrace.getNext(context); |
| 1146 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 1147 | } |
| 1148 | |
| 1149 | // Make sure we stay positioned |
| 1150 | event = fTrace.parseEvent(context); |
| 1151 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 1152 | } |
| 1153 | |
| 1154 | public void testGetNextAfterSeekingOnLocation_3() { |
| 1155 | |
| 1156 | final ITmfLocation INITIAL_LOC = fTrace.seekEvent(500L).getLocation(); |
| 1157 | final long INITIAL_TS = 501; |
| 1158 | final int NB_READS = 20; |
| 1159 | |
| 1160 | // On lower bound, returns the first event (ts = 501) |
| 1161 | final ITmfContext context = fTrace.seekEvent(INITIAL_LOC); |
| 1162 | |
| 1163 | // Read NB_EVENTS |
| 1164 | ITmfEvent event; |
| 1165 | for (int i = 0; i < NB_READS; i++) { |
| 1166 | event = fTrace.getNext(context); |
| 1167 | assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue()); |
| 1168 | } |
| 1169 | |
| 1170 | // Make sure we stay positioned |
| 1171 | event = fTrace.parseEvent(context); |
| 1172 | assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); |
| 1173 | } |
| 1174 | |
| 1175 | public void testGetNextLocation() { |
| 1176 | ITmfContext context1 = fTrace.seekEvent(0); |
| 1177 | fTrace.getNext(context1); |
| 1178 | ITmfLocation location = context1.getLocation().clone(); |
| 1179 | ITmfEvent event1 = fTrace.getNext(context1); |
| 1180 | ITmfContext context2 = fTrace.seekEvent(location); |
| 1181 | ITmfEvent event2 = fTrace.getNext(context2); |
| 1182 | assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); |
| 1183 | } |
| 1184 | |
| 1185 | public void testGetNextEndLocation() { |
| 1186 | ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); |
| 1187 | fTrace.getNext(context1); |
| 1188 | ITmfLocation location = context1.getLocation().clone(); |
| 1189 | ITmfContext context2 = fTrace.seekEvent(location); |
| 1190 | ITmfEvent event = fTrace.getNext(context2); |
| 1191 | assertNull("Event", event); |
| 1192 | } |
| 1193 | |
| 1194 | // ------------------------------------------------------------------------ |
| 1195 | // processRequest |
| 1196 | // ------------------------------------------------------------------------ |
| 1197 | |
| 1198 | @SuppressWarnings("hiding") |
| 1199 | public void testProcessEventRequestForAllEvents() throws InterruptedException { |
| 1200 | final int BLOCK_SIZE = 1; |
| 1201 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1202 | |
| 1203 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
| 1204 | final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
| 1205 | @Override |
| 1206 | public void handleData(final ITmfEvent event) { |
| 1207 | super.handleData(event); |
| 1208 | requestedEvents.add(event); |
| 1209 | } |
| 1210 | }; |
| 1211 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1212 | providers[0].sendRequest(request); |
| 1213 | request.waitForCompletion(); |
| 1214 | |
| 1215 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); |
| 1216 | assertTrue("isCompleted", request.isCompleted()); |
| 1217 | assertFalse("isCancelled", request.isCancelled()); |
| 1218 | |
| 1219 | // Ensure that we have distinct events. |
| 1220 | // Don't go overboard: we are not validating the stub! |
| 1221 | for (int i = 0; i < NB_EVENTS; i++) { |
| 1222 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | @SuppressWarnings("hiding") |
| 1227 | public void testProcessEventRequestForNbEvents() throws InterruptedException { |
| 1228 | final int BLOCK_SIZE = 100; |
| 1229 | final int NB_EVENTS = 1000; |
| 1230 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1231 | |
| 1232 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
| 1233 | final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
| 1234 | @Override |
| 1235 | public void handleData(final ITmfEvent event) { |
| 1236 | super.handleData(event); |
| 1237 | requestedEvents.add(event); |
| 1238 | } |
| 1239 | }; |
| 1240 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1241 | providers[0].sendRequest(request); |
| 1242 | request.waitForCompletion(); |
| 1243 | |
| 1244 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); |
| 1245 | assertTrue("isCompleted", request.isCompleted()); |
| 1246 | assertFalse("isCancelled", request.isCancelled()); |
| 1247 | |
| 1248 | // Ensure that we have distinct events. |
| 1249 | // Don't go overboard: we are not validating the stub! |
| 1250 | for (int i = 0; i < NB_EVENTS; i++) { |
| 1251 | assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | @SuppressWarnings("hiding") |
| 1256 | public void testProcessEventRequestForSomeEvents() throws InterruptedException { |
| 1257 | final int BLOCK_SIZE = 1; |
| 1258 | final long startTime = 100; |
| 1259 | final int NB_EVENTS = 1000; |
| 1260 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1261 | |
| 1262 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); |
| 1263 | final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
| 1264 | @Override |
| 1265 | public void handleData(final ITmfEvent event) { |
| 1266 | super.handleData(event); |
| 1267 | requestedEvents.add(event); |
| 1268 | } |
| 1269 | }; |
| 1270 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1271 | providers[0].sendRequest(request); |
| 1272 | request.waitForCompletion(); |
| 1273 | |
| 1274 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); |
| 1275 | assertTrue("isCompleted", request.isCompleted()); |
| 1276 | assertFalse("isCancelled", request.isCancelled()); |
| 1277 | |
| 1278 | // Ensure that we have distinct events. |
| 1279 | // Don't go overboard: we are not validating the stub! |
| 1280 | for (int i = 0; i < NB_EVENTS; i++) { |
| 1281 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | @SuppressWarnings("hiding") |
| 1286 | public void testProcessEventRequestForOtherEvents() throws InterruptedException { |
| 1287 | final int BLOCK_SIZE = 1; |
| 1288 | final int startIndex = 99; |
| 1289 | final long startTime = 100; |
| 1290 | final int NB_EVENTS = 1000; |
| 1291 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1292 | |
| 1293 | final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); |
| 1294 | final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, startIndex, NB_EVENTS, BLOCK_SIZE) { |
| 1295 | @Override |
| 1296 | public void handleData(final ITmfEvent event) { |
| 1297 | super.handleData(event); |
| 1298 | requestedEvents.add(event); |
| 1299 | } |
| 1300 | }; |
| 1301 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1302 | providers[0].sendRequest(request); |
| 1303 | request.waitForCompletion(); |
| 1304 | |
| 1305 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); |
| 1306 | assertTrue("isCompleted", request.isCompleted()); |
| 1307 | assertFalse("isCancelled", request.isCancelled()); |
| 1308 | |
| 1309 | // Ensure that we have distinct events. |
| 1310 | // Don't go overboard: we are not validating the stub! |
| 1311 | for (int i = 0; i < NB_EVENTS; i++) { |
| 1312 | assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | @SuppressWarnings("hiding") |
| 1317 | public void testProcessDataRequestForSomeEvents() throws InterruptedException { |
| 1318 | final int startIndex = 100; |
| 1319 | final int NB_EVENTS = 1000; |
| 1320 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1321 | |
| 1322 | final TmfDataRequest request = new TmfDataRequest(TmfEvent.class, startIndex, NB_EVENTS) { |
| 1323 | @Override |
| 1324 | public void handleData(final ITmfEvent event) { |
| 1325 | super.handleData(event); |
| 1326 | requestedEvents.add(event); |
| 1327 | } |
| 1328 | }; |
| 1329 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1330 | providers[0].sendRequest(request); |
| 1331 | request.waitForCompletion(); |
| 1332 | |
| 1333 | assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); |
| 1334 | assertTrue("isCompleted", request.isCompleted()); |
| 1335 | assertFalse("isCancelled", request.isCancelled()); |
| 1336 | |
| 1337 | // Ensure that we have distinct events. |
| 1338 | // Don't go overboard: we are not validating the stub! |
| 1339 | for (int i = 0; i < NB_EVENTS; i++) { |
| 1340 | assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue()); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | // ------------------------------------------------------------------------ |
| 1345 | // cancel |
| 1346 | // ------------------------------------------------------------------------ |
| 1347 | |
| 1348 | public void testCancel() throws InterruptedException { |
| 1349 | final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>(); |
| 1350 | |
| 1351 | final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); |
| 1352 | final TmfEventRequest request = new TmfEventRequest(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { |
| 1353 | int nbRead = 0; |
| 1354 | @Override |
| 1355 | public void handleData(final ITmfEvent event) { |
| 1356 | super.handleData(event); |
| 1357 | requestedEvents.add(event); |
| 1358 | if (++nbRead == BLOCK_SIZE) { |
| 1359 | cancel(); |
| 1360 | } |
| 1361 | } |
| 1362 | }; |
| 1363 | final ITmfDataProvider[] providers = TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class); |
| 1364 | providers[0].sendRequest(request); |
| 1365 | request.waitForCompletion(); |
| 1366 | |
| 1367 | assertEquals("nbEvents", BLOCK_SIZE, requestedEvents.size()); |
| 1368 | assertTrue("isCompleted", request.isCompleted()); |
| 1369 | assertTrue("isCancelled", request.isCancelled()); |
| 1370 | } |
| 1371 | |
| 1372 | // ------------------------------------------------------------------------ |
| 1373 | // toString |
| 1374 | // ------------------------------------------------------------------------ |
| 1375 | |
| 1376 | public void testDefaultTmfTraceStub() { |
| 1377 | assertFalse ("Open trace", fTrace == null); |
| 1378 | assertEquals("getType", TmfEvent.class, fTrace.getType()); |
| 1379 | assertNull ("getResource", fTrace.getResource()); |
| 1380 | assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); |
| 1381 | assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval()); |
| 1382 | assertEquals("getName", TEST_STREAM, fTrace.getName()); |
| 1383 | |
| 1384 | assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents()); |
| 1385 | assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue()); |
| 1386 | assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue()); |
| 1387 | assertEquals("getStartTime", 1, fTrace.getStartTime().getValue()); |
| 1388 | assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue()); |
| 1389 | |
| 1390 | String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() + |
| 1391 | ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() + |
| 1392 | ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() + |
| 1393 | "]"; |
| 1394 | assertEquals("toString", expected, fTrace.toString()); |
| 1395 | } |
| 1396 | |
| 1397 | } |