--- /dev/null
+/*******************************************************************************
+ * 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 java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+
+/**
+ * <b><u>TmfTraceTest</u></b>
+ * <p>
+ * Test suite for the TmfTrace class.
+ */
+@SuppressWarnings("nls")
+public class TmfCheckpointIndexTest extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
+ private static final String DIRECTORY = "testfiles";
+ private static final String TEST_STREAM = "A-Test-10K";
+ private static final int BLOCK_SIZE = 500;
+ private static final int NB_EVENTS = 10000;
+ private static TestTrace fTrace = null;
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ public TmfCheckpointIndexTest(final String name) throws Exception {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ fTrace.dispose();
+ fTrace = null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper classes
+ // ------------------------------------------------------------------------
+
+ private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public TestIndexer(TestTrace testTrace) {
+ super((ITmfTrace) testTrace);
+ }
+ public Vector<TmfCheckpoint> getCheckpoints() {
+ return fTraceIndex;
+ }
+ }
+
+ private class TestTrace extends TmfTraceStub {
+ public TestTrace(String path, int blockSize) throws FileNotFoundException {
+ super(path, blockSize);
+ fIndexer = new TestIndexer(this);
+ }
+ public TestIndexer getIndexer() {
+ return (TestIndexer) fIndexer;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper functions
+ // ------------------------------------------------------------------------
+
+ private TestTrace setupTrace(final String path) {
+ 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 TestTrace(test.toURI().getPath(), BLOCK_SIZE);
+ fTrace.indexTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return fTrace;
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ public void testTmfTraceIndexing() throws Exception {
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ 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());
+
+ Vector<TmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+ int pageSize = fTrace.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ TmfCheckpoint checkpoint = checkpoints.get(i);
+ TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+ ITmfEvent event = fTrace.parseEvent(context);
+ assertTrue(context.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ }
+ }
+
+}
\ No newline at end of file
* <p>
* Abstract implementation of ITmfTrace.
* <p>
- * Document me...
+ * Since the concept of 'location' is trace specific, the concrete classes have
+ * to provide the related methods, namely:
+ * <ul>
+ * <li> public ITmfLocation<?> getCurrentLocation()
+ * <li> public double getLocationRatio(ITmfLocation<?> location)
+ * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
+ * <li> public ITmfContext seekEvent(double ratio)
+ * </ul>
+ * A concrete trace must provide its corresponding parser. A common way to
+ * accomplish this is by making the concrete class extend TmfTrace and
+ * implement ITmfEventParser.
+ * <p>
+ * The concrete class can either specify its own indexer or use the provided
+ * TmfCheckpointIndexer (default). In this case, the trace cache size will be
+ * used as checkpoint interval.
*/
public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
}
/**
- * The standard constructor (non-live trace)
+ * The standard constructor (non-live trace). Applicable when the trace
+ * implements its own parser and if at checkpoint-based index is OK.
*
* @param resource the resource associated to the trace
* @param type the trace event type
}
/**
- * The standard constructor (live trace)
+ * The standard constructor (live trace). Applicable when the trace
+ * implements its own parser and if at checkpoint-based index is OK.
*
* @param resource the resource associated to the trace
* @param type the trace event type
}
/**
- * The full constructor
+ * The 'non-default indexer' constructor. Allows to provide a trace
+ * specific indexer.
*
* @param resource the resource associated to the trace
* @param type the trace event type
* @param indexer the trace indexer
* @throws FileNotFoundException
*/
- @SuppressWarnings({ "unchecked", "rawtypes" })
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
final long interval, final ITmfTraceIndexer<?> indexer) throws FileNotFoundException {
+ this(resource, type, path, cacheSize, interval, null, null);
+ }
+
+ /**
+ * The full constructor where trace specific indexer/parser are provided.
+ *
+ * @param resource the resource associated to the trace
+ * @param type the trace event type
+ * @param path the trace path
+ * @param cacheSize the trace cache size
+ * @param indexer the trace indexer
+ * @param parser the trace event parser
+ * @throws FileNotFoundException
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
+ final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<ITmfEvent> parser) throws FileNotFoundException {
super();
fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE;
fStreamingInterval = interval;
fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
+ fParser = parser;
initialize(resource, path, type);
}
fCacheSize = trace.getCacheSize();
fStreamingInterval = trace.getStreamingInterval();
fIndexer = new TmfCheckpointIndexer(this);
- initialize(trace.getResource(), trace.getPath(), trace.getType());
+ fParser = trace.fParser;
+ initialize(trace.getResource(), trace.getPath(), trace.getEventType());
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getType()
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
*/
@Override
@SuppressWarnings("unchecked")
- public Class<T> getType() {
+ public Class<T> getEventType() {
return (Class<T>) super.getType();
}