/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
- *
+ * Copyright (c) 2009, 2010, 20112 Ericsson
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Francois Chouinard - Adapted for TMF Trace Model 1.0
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.trace;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceIndexer;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
/**
private static final int NB_EVENTS = 10000;
private static TmfTraceStub fTrace = null;
- private static byte SCALE = (byte) -3;
+ private static int SCALE = -3;
// ------------------------------------------------------------------------
// Housekeeping
protected void setUp() throws Exception {
super.setUp();
fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
- // Dummy request to force the trace indexing
- final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class) {
- @Override
- public void handleData(final TmfEvent event) {
- super.handleData(event);
- }
- };
- fTrace.sendRequest(request);
- request.waitForCompletion();
}
@Override
// ------------------------------------------------------------------------
private TmfTraceStub setupTrace(final String path) {
- if (fTrace == null)
+ if (fTrace == null) {
try {
final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
final File test = new File(FileLocator.toFileURL(location).toURI());
- fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE, false);
+ fTrace = new TmfTraceStub(test.toURI().getPath(), BLOCK_SIZE);
+ fTrace.indexTrace();
} catch (final URISyntaxException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
+ }
return fTrace;
}
// Constructors
// ------------------------------------------------------------------------
- public void testTmfTraceDefault() throws Exception {
+ public void testStandardConstructor() throws Exception {
TmfTraceStub trace = null;
File testfile = null;
try {
final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
testfile = new File(FileLocator.toFileURL(location).toURI());
trace = new TmfTraceStub(testfile.toURI().getPath());
+ trace.indexTrace();
} catch (final URISyntaxException e) {
fail("URISyntaxException");
} catch (final IOException e) {
fail("IOException");
}
- assertTrue ("Open trace", trace != null);
- assertEquals("getType", TmfEvent.class, trace.getType());
- assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getName", TEST_STREAM, trace.getName());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getIndexPageSize());
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
}
- public void testTmfTraceDefaultCacheSize() throws Exception {
+ public void testStandardConstructorCacheSize() throws Exception {
TmfTraceStub trace = null;
File testfile = null;
try {
final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
testfile = new File(FileLocator.toFileURL(location).toURI());
trace = new TmfTraceStub(testfile.toURI().getPath(), 0);
+ trace.indexTrace();
+ } catch (final URISyntaxException e) {
+ fail("URISyntaxException");
+ } catch (final IOException e) {
+ fail("IOException");
+ }
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+
+ try {
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ testfile = new File(FileLocator.toFileURL(location).toURI());
+ trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE);
+ trace.indexTrace();
+ } catch (final URISyntaxException e) {
+ fail("URISyntaxException");
+ } catch (final IOException e) {
+ fail("IOException");
+ }
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
+ assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+ }
+
+ public void testFullConstructor() throws Exception {
+ TmfTraceStub trace = null;
+ File testfile = null;
+ try {
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ testfile = new File(FileLocator.toFileURL(location).toURI());
+ trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null);
+ trace.indexTrace();
+ } catch (final URISyntaxException e) {
+ fail("URISyntaxException");
+ } catch (final IOException e) {
+ fail("IOException");
+ }
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
+ assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void testCopyConstructor() throws Exception {
+ TmfTraceStub original = null;
+ TmfTraceStub trace = null;
+ File testfile = null;
+ try {
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ testfile = new File(FileLocator.toFileURL(location).toURI());
+ original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfTraceIndexer(null));
+ trace = new TmfTraceStub(original);
+ trace.indexTrace();
} catch (final URISyntaxException e) {
fail("URISyntaxException");
} catch (final IOException e) {
fail("IOException");
}
- assertTrue ("Open trace", trace != null);
- assertEquals("getType", TmfEvent.class, trace.getType());
- assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getName", TEST_STREAM, trace.getName());
- assertEquals("getCacheSize", TmfTrace.DEFAULT_INDEX_PAGE_SIZE, trace.getIndexPageSize());
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
+ assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+
+ // Test the copy of a null trace
+ try {
+ new TmfTraceStub((TmfTraceStub) null);
+ fail("Missing exception");
+ } catch (final IllegalArgumentException e) {
+ // test passed
+ } catch (final Exception e) {
+ fail("Unexpected exception");
+ }
}
- public void testTmfTrace() throws Exception {
- assertEquals("getType", TmfEvent.class, fTrace.getType());
- assertEquals("getName", TEST_STREAM, fTrace.getName());
- assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize());
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
+
+ public void testDefaultTmfTraceStub() throws Exception {
+ assertFalse ("Open trace", fTrace == null);
+ assertEquals("getType", TmfEvent.class, fTrace.getType());
+ assertNull ("getResource", fTrace.getResource());
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, fTrace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, fTrace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents());
+ assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
+
+ String expected = "TmfTrace [fPath=" + fTrace.getPath() + ", fCacheSize=" + fTrace.getCacheSize() +
+ ", fNbEvents=" + fTrace.getNbEvents() + ", fStartTime=" + fTrace.getStartTime() +
+ ", fEndTime=" + fTrace.getEndTime() + ", fStreamingInterval=" + fTrace.getStreamingInterval() +
+ "]";
+ assertEquals("toString", expected, fTrace.toString());
}
- // public void testClone() throws Exception {
- // TmfTraceStub trace = fTrace.clone();
- // assertEquals("getType", TmfEvent.class, trace.getType());
- // assertEquals("getPath", fTrace.getPath(), trace.getPath());
- // assertEquals("getName", TEST_STREAM, trace.getName());
- // assertEquals("getCacheSize", BLOCK_SIZE, trace.getIndexPageSize());
- // assertEquals("getTimeRange", fTrace.getTimeRange(), trace.getTimeRange());
- // }
+ // ------------------------------------------------------------------------
+ // Trace initialization
+ // ------------------------------------------------------------------------
+
+ public void testInitTrace() throws Exception {
+
+ // Instantiate an "empty" trace
+ final TmfTraceStub trace = new TmfTraceStub();
+
+ assertFalse ("Open trace", trace == null);
+ assertNull ("getType", trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", "", trace.getName());
+
+ assertEquals("getNbEvents", 0, trace.getNbEvents());
+ assertEquals("getRange-start", Long.MAX_VALUE, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", Long.MIN_VALUE, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", Long.MAX_VALUE, trace.getStartTime().getValue());
+ assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue());
+
+ // Validate
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ final File testfile = new File(FileLocator.toFileURL(location).toURI());
+ assertTrue("validate", trace.validate(null, testfile.getPath()));
+
+ // InitTrace and wait for indexing completion...
+ trace.initTrace(null, testfile.getPath(), TmfEvent.class);
+ int nbSecs = 0;
+ while (trace.getNbEvents() < NB_EVENTS && nbSecs < 10) {
+ Thread.sleep(1000);
+ nbSecs++;
+ }
+ if (trace.getNbEvents() < NB_EVENTS) {
+ fail("indexing");
+ }
+
+ assertFalse ("Open trace", trace == null);
+ assertEquals("getType", TmfEvent.class, trace.getType());
+ assertNull ("getResource", trace.getResource());
+ assertEquals("getCacheSize", TmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+ assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+ assertEquals("getName", TEST_STREAM, trace.getName());
+
+ assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
+ assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, trace.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue());
+ }
// ------------------------------------------------------------------------
// Get/Set time range
public void testSetTimeRange() throws Exception {
final TmfTraceStub trace = new TmfTraceStub(fTrace);
+ trace.indexTrace();
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
public void testSetStartTime() throws Exception {
final TmfTraceStub trace = new TmfTraceStub(fTrace);
+ trace.indexTrace();
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
public void testSetEndTime() throws Exception {
final TmfTraceStub trace = new TmfTraceStub(fTrace);
+ trace.indexTrace();
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
assertEquals("getRange-end", NB_EVENTS, trace.getTimeRange().getEndTime().getValue());
}
// ------------------------------------------------------------------------
- // Verify checkpoints
- // ------------------------------------------------------------------------
-
- public void testTmfTraceIndexing() throws Exception {
- assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize());
- assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
- assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
- assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
- assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
- assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
-
- final Vector<TmfCheckpoint> checkpoints = fTrace.getCheckpoints();
- final int pageSize = fTrace.getIndexPageSize();
- assertTrue("Checkpoints exist", checkpoints != null);
-
- // Validate that each checkpoint points to the right event
- for (int i = 0; i < checkpoints.size(); i++) {
- final TmfCheckpoint checkpoint = checkpoints.get(i);
- final TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
- final ITmfEvent event = fTrace.parseEvent(context);
- assertTrue(context.getRank() == i * pageSize);
- assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
- }
- }
-
- // ------------------------------------------------------------------------
- // parseEvent - make sure parseEvent doesn't update the context
- // ------------------------------------------------------------------------
-
- public void testParseEvent() throws Exception {
-
- final int NB_READS = 20;
-
- // On lower bound, returns the first event (ts = 0)
- final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
- TmfContext svContext = new TmfContext(context);
-
- ITmfEvent event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- assertTrue("parseEvent", context.equals(svContext));
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- assertTrue("parseEvent", context.equals(svContext));
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", 0, context.getRank());
- assertTrue("parseEvent", context.equals(svContext));
-
- // Position the trace at event NB_READS
- for (int i = 1; i < NB_READS; i++) {
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", i, event.getTimestamp().getValue());
- }
-
- svContext = new TmfContext(context);
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
- assertEquals("Event rank", NB_READS -1 , context.getRank());
- assertTrue("parseEvent", context.equals(svContext));
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
- assertEquals("Event rank", NB_READS - 1, context.getRank());
- assertTrue("parseEvent", context.equals(svContext));
- }
-
- // ------------------------------------------------------------------------
- // getNextEvent - updates the context
- // ------------------------------------------------------------------------
-
- public void testGetNextEvent() throws Exception {
-
- final int NB_READS = 20;
-
- // On lower bound, returns the first event (ts = 1)
- final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
-
- // Read NB_EVENTS
- ITmfEvent event;
- for (int i = 0; i < NB_READS; i++) {
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", i + 1, context.getRank());
- }
-
- // Make sure we stay positioned
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue());
- assertEquals("Event rank", NB_READS, context.getRank());
- }
-
- // ------------------------------------------------------------------------
- // seekLocation
- // Note: seekLocation() does not reliably set the rank
+ // seekEvent on timestamp
// ------------------------------------------------------------------------
- public void testSeekLocationOnCacheBoundary() throws Exception {
+ public void testSeekEventOnNullTimestamp() throws Exception {
// Position trace at event rank 0
- TmfContext context = fTrace.seekLocation(null);
- ITmfEvent event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ ITmfContext context = fTrace.seekEvent(null);
assertEquals("Event rank", 0, context.getRank());
- context = fTrace.seekLocation(context.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event rank 1000
- ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event rank 4000
- tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- }
-
- public void testSeekLocationNotOnCacheBoundary() throws Exception {
-
- // Position trace at event rank 9
- ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0));
- TmfContext context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- ITmfEvent event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event rank 999
- tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event rank 1001
- tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event rank 4500
- tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
- }
-
- public void testSeekLocationOutOfScope() throws Exception {
-
- // Position trace at beginning
- ITmfContext tmpContext = fTrace.seekLocation(null);
- ITmfContext context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
ITmfEvent event = fTrace.parseEvent(context);
assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- // Position trace at event passed the end
- tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
- context = fTrace.seekLocation(tmpContext.getLocation());
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.parseEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
-
- event = fTrace.getNextEvent(context);
- assertEquals("Event timestamp", null, event);
- assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+ assertEquals("Event rank", 0, context.getRank());
}
- // ------------------------------------------------------------------------
- // seekEvent on timestamp
- // ------------------------------------------------------------------------
-
public void testSeekEventOnTimestampOnCacheBoundary() throws Exception {
// Position trace at event rank 0
// seekEvent on rank
// ------------------------------------------------------------------------
+ public void testSeekEventOnNegativeRank() throws Exception {
+
+ // Position trace at event rank 0
+ ITmfContext context = fTrace.seekEvent(-1);
+ assertEquals("Event rank", 0, context.getRank());
+
+ ITmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ }
+
public void testSeekOnRankOnCacheBoundary() throws Exception {
// On lower bound, returns the first event (ts = 1)
assertEquals("Event rank", NB_EVENTS, context.getRank());
}
+ // ------------------------------------------------------------------------
+ // parseEvent - make sure parseEvent doesn't update the context
+ // ------------------------------------------------------------------------
+
+ public void testParseEvent() throws Exception {
+
+ final int NB_READS = 20;
+
+ // On lower bound, returns the first event (ts = 0)
+ final TmfContext context = (TmfContext) fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
+ TmfContext svContext = new TmfContext(context);
+
+ ITmfEvent event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", 0, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ // Position the trace at event NB_READS
+ for (int i = 1; i < NB_READS; i++) {
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", i, event.getTimestamp().getValue());
+ }
+
+ svContext = new TmfContext(context);
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS -1 , context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS - 1, context.getRank());
+ assertTrue("parseEvent", context.equals(svContext));
+ }
+
+ // ------------------------------------------------------------------------
+ // getNextEvent - updates the context
+ // ------------------------------------------------------------------------
+
+ public void testGetNextEvent() throws Exception {
+
+ final int NB_READS = 20;
+
+ // On lower bound, returns the first event (ts = 1)
+ final ITmfContext context = fTrace.seekEvent(new TmfTimestamp(0, SCALE, 0));
+
+ // Read NB_EVENTS
+ ITmfEvent event;
+ for (int i = 0; i < NB_READS; i++) {
+ event = fTrace.getNextEvent(context);
+ assertEquals("Event timestamp", i + 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", i + 1, context.getRank());
+ }
+
+ // Make sure we stay positioned
+ event = fTrace.parseEvent(context);
+ assertEquals("Event timestamp", NB_READS + 1, event.getTimestamp().getValue());
+ assertEquals("Event rank", NB_READS, context.getRank());
+ }
+
// ------------------------------------------------------------------------
// processRequest
// ------------------------------------------------------------------------
// Ensure that we have distinct events.
// Don't go overboard: we are not validating the stub!
- for (int i = 0; i < NB_EVENTS; i++)
+ for (int i = 0; i < NB_EVENTS; i++) {
assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
+ }
}
@SuppressWarnings("unchecked")
// Ensure that we have distinct events.
// Don't go overboard: we are not validating the stub!
- for (int i = 0; i < NB_EVENTS; i++)
+ for (int i = 0; i < NB_EVENTS; i++) {
assertEquals("Distinct events", i+1, requestedEvents.get(i).getTimestamp().getValue());
+ }
}
// ------------------------------------------------------------------------
public void handleData(final TmfEvent event) {
super.handleData(event);
requestedEvents.add(event);
- if (++nbRead == BLOCK_SIZE)
+ if (++nbRead == BLOCK_SIZE) {
cancel();
+ }
}
};
final ITmfDataProvider<TmfEvent>[] providers = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfTraceStub.class);
assertTrue("isCancelled", request.isCancelled());
}
+
+// // ------------------------------------------------------------------------
+// // seekLocation
+// // Note: seekLocation() does not reliably set the rank
+// // ------------------------------------------------------------------------
+//
+// public void testSeekLocationOnCacheBoundary() throws Exception {
+//
+// // Position trace at event rank 0
+// TmfContext context = fTrace.seekLocation(null);
+// ITmfEvent event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+// assertEquals("Event rank", 0, context.getRank());
+//
+// context = fTrace.seekLocation(context.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event rank 1000
+// ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(1001, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 1001, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event rank 4000
+// tmpContext = fTrace.seekEvent(new TmfTimestamp(4001, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 4001, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+// }
+//
+// public void testSeekLocationNotOnCacheBoundary() throws Exception {
+//
+// // Position trace at event rank 9
+// ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0));
+// TmfContext context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// ITmfEvent event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 10, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event rank 999
+// tmpContext = fTrace.seekEvent(new TmfTimestamp(1000, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 1000, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event rank 1001
+// tmpContext = fTrace.seekEvent(new TmfTimestamp(1002, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 1002, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event rank 4500
+// tmpContext = fTrace.seekEvent(new TmfTimestamp(4501, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 4501, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+// }
+//
+// public void testSeekLocationOutOfScope() throws Exception {
+//
+// // Position trace at beginning
+// ITmfContext tmpContext = fTrace.seekLocation(null);
+// ITmfContext context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// ITmfEvent event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// // Position trace at event passed the end
+// tmpContext = fTrace.seekEvent(new TmfTimestamp(NB_EVENTS + 1, SCALE, 0));
+// context = fTrace.seekLocation(tmpContext.getLocation());
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.parseEvent(context);
+// assertEquals("Event timestamp", null, event);
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+//
+// event = fTrace.getNextEvent(context);
+// assertEquals("Event timestamp", null, event);
+// assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank());
+// }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ // public void testTmfTraceIndexing() throws Exception {
+ // assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getIndexPageSize());
+ // assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
+ // assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
+ // assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
+ // assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
+ // assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
+ //
+ // final Vector<TmfCheckpoint> checkpoints = fTrace.getCheckpoints();
+ // final int pageSize = fTrace.getIndexPageSize();
+ // assertTrue("Checkpoints exist", checkpoints != null);
+ //
+ // // Validate that each checkpoint points to the right event
+ // for (int i = 0; i < checkpoints.size(); i++) {
+ // final TmfCheckpoint checkpoint = checkpoints.get(i);
+ // final TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+ // final ITmfEvent event = fTrace.parseEvent(context);
+ // assertTrue(context.getRank() == i * pageSize);
+ // assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ // }
+ // }
+
}
\ No newline at end of file