// ------------------------------------------------------------------------
private static TmfTraceStub openTrace() {
- final String DIRECTORY = "testfiles";
- final String TEST_STREAM = "A-Test-10K";
- final String path = DIRECTORY + File.separator + TEST_STREAM;
-
TmfTraceStub trace = null;
try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TmfTestTrace.A_TEST_10K.getFullPath()), null);
final File test = new File(FileLocator.toFileURL(location).toURI());
- trace = new TmfTraceStub(test.toURI().getPath(), 500, false);
+ trace = new TmfTraceStub(test.toURI().getPath(), 500, false, null, null);
} catch (final TmfTraceException e) {
e.printStackTrace();
} catch (final URISyntaxException e) {
// Coalescing
// ------------------------------------------------------------------------
- private static final String DIRECTORY = "testfiles";
- private static final String TEST_STREAM = "A-Test-10K";
+ private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K;
private static final int NB_EVENTS = 5000;
- private static final int BLOCK_SIZE = 100;
// Initialize the test trace
private TmfTraceStub fTrace = null;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+ import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
try {
ITmfTrace[] traces = new ITmfTrace[2];
- URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
+ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TmfTestTrace.O_TEST_10K.getFullPath()), null);
File test = new File(FileLocator.toFileURL(location).toURI());
- final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
+ final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null, null);
traces[0] = trace1;
- location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
+ location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TmfTestTrace.E_TEST_10K.getFullPath()), null);
test = new File(FileLocator.toFileURL(location).toURI());
- final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
+ final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null, null);
traces[1] = trace2;
return traces;
// Variables
// ------------------------------------------------------------------------
+ private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K;
private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
- 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 TmfTraceStub fTrace = null;
@Test
public void testFullConstructor() throws TmfTraceException {
try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
File testfile = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null);
+ TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
trace.indexTrace(true);
assertEquals("getType", ITmfEvent.class, trace.getType());
assertNull("getResource", trace.getResource());
assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
- assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getName", TEST_TRACE.getPath(), trace.getName());
assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
public void testLiveTraceConstructor() throws TmfTraceException {
final long interval = 100;
try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
File testfile = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, interval);
+ TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, interval);
trace.indexTrace(true);
assertEquals("getType", ITmfEvent.class, trace.getType());
assertNull("getResource", trace.getResource());
assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", interval, trace.getStreamingInterval());
- assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getName", TEST_TRACE.getPath(), trace.getName());
assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
@Test
public void testCopyConstructor() throws TmfTraceException {
try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
File testfile = new File(FileLocator.toFileURL(location).toURI());
- TmfTraceStub original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfCheckpointIndexer(null));
+ TmfTraceStub original = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, new TmfCheckpointIndexer(null), null);
TmfTraceStub trace = new TmfTraceStub(original);
trace.indexTrace(true);
assertEquals("getType", ITmfEvent.class, trace.getType());
assertNull("getResource", trace.getResource());
assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
- assertEquals("getCacheSize", BLOCK_SIZE, trace.getCacheSize());
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
- assertEquals("getName", TEST_STREAM, trace.getName());
+ assertEquals("getName", TEST_TRACE.getPath(), trace.getName());
assertEquals("getNbEvents", NB_EVENTS, trace.getNbEvents());
assertEquals("getRange-start", 1, trace.getTimeRange().getStartTime().getValue());
assertFalse ("Open trace", fTrace == null);
assertEquals("getType", ITmfEvent.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("getName", TEST_TRACE.getPath(), fTrace.getName());
assertEquals("getNbEvents", NB_EVENTS, fTrace.getNbEvents());
assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
TmfTraceStub trace = null;
File testfile = null;
try {
- final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
+ final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
testfile = new File(FileLocator.toFileURL(location).toURI());
- trace = new TmfTraceStub(testfile.toURI().getPath());
+ trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
// verify initial values
TmfTimestamp defaultInitRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
assertEquals("getInitialRangeOffset", defaultInitRange, trace.getInitialRangeOffset());
--- /dev/null
- private static final String DIRECTORY = "testfiles";
- private static final String TEST_STREAM = "A-Test-10K";
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 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
+ * Alexandre Montplaisir - Port to JUnit4
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+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.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
++import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfCheckpointIndexTest {
+
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
- setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ private static final int BLOCK_SIZE = 100;
+ private static final int NB_EVENTS = 10000;
+ private static TestTrace fTrace = null;
+ private static EmptyTestTrace fEmptyTrace = null;
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ @Before
+ public void setUp() {
++ setupTrace(TmfTestTrace.A_TEST_10K.getFullPath());
+ }
+
+ @After
+ public void tearDown() {
+ fTrace.dispose();
+ fTrace = null;
+ fEmptyTrace.dispose();
+ fEmptyTrace = null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper classes
+ // ------------------------------------------------------------------------
+
+ private static class TestIndexer extends TmfCheckpointIndexer {
+ @SuppressWarnings({ })
+ public TestIndexer(TestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ @SuppressWarnings({ })
+ public TestIndexer(EmptyTestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ public List<ITmfCheckpoint> getCheckpoints() {
+ return getTraceIndex();
+ }
+ }
+
+ private class TestTrace extends TmfTraceStub {
+ public TestTrace(String path, int blockSize) throws TmfTraceException {
+ super(path, blockSize, false, null, null);
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ private class EmptyTestTrace extends TmfEmptyTraceStub {
+ public EmptyTestTrace() {
+ super();
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper functions
+ // ------------------------------------------------------------------------
+
+ private synchronized void 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(true);
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (fEmptyTrace == null) {
+ fEmptyTrace = new EmptyTestTrace();
+ fEmptyTrace.indexTrace(true);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testTmfTraceIndexing() {
+ 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());
+
+ List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+ int pageSize = fTrace.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ ITmfCheckpoint 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));
+ }
+ }
+
+ @Test
+ public void testEmptyTmfTraceIndexing() {
+ assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, fEmptyTrace.getCacheSize());
+ assertEquals("getTraceSize", 0, fEmptyTrace.getNbEvents());
+ assertEquals("getRange-start", TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getStartTime());
+ assertEquals("getRange-end", TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getEndTime());
+ assertEquals("getStartTime", TmfTimestamp.BIG_BANG, fEmptyTrace.getStartTime());
+ assertEquals("getEndTime", TmfTimestamp.BIG_BANG, fEmptyTrace.getEndTime());
+
+ List<ITmfCheckpoint> checkpoints = fEmptyTrace.getIndexer().getCheckpoints();
+ int pageSize = fEmptyTrace.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", 0, checkpoints.size());
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ ITmfCheckpoint checkpoint = checkpoints.get(i);
+ TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+ ITmfEvent event = fEmptyTrace.parseEvent(context);
+ assertTrue(context.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ }
+ }
+
+}
--- /dev/null
- private static final String DIRECTORY = "testfiles";
- // Trace has 3 events at t=101 at rank 99, 100, 101
- // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
- private static final String TEST_STREAM = "A-Test-10K-2";
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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:
+ * Bernd Hufmann - Initial API and implementation
+ * Alexandre Montplaisir - Port to JUnit4
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+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.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
++import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexer class (events with same
+ * timestamp around checkpoint).
+ */
+@SuppressWarnings("javadoc")
+public class TmfCheckpointIndexTest2 {
+
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
- setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+ private static final int BLOCK_SIZE = 100;
+ private static final int NB_EVENTS = 702;
+ private static TestTrace fTrace = null;
+ private static EmptyTestTrace fEmptyTrace = null;
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ @Before
+ public void setUp() {
++ // Trace has 3 events at t=101 at rank 99, 100, 101
++ // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
++ setupTrace(TmfTestTrace.A_TEST_10K2.getFullPath());
+ }
+
+ @After
+ public void tearDown() {
+ fTrace.dispose();
+ fTrace = null;
+ fEmptyTrace.dispose();
+ fEmptyTrace = null;
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper classes
+ // ------------------------------------------------------------------------
+
+ private static class TestIndexer extends TmfCheckpointIndexer {
+ @SuppressWarnings({ })
+ public TestIndexer(TestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ @SuppressWarnings({ })
+ public TestIndexer(EmptyTestTrace testTrace) {
+ super(testTrace, BLOCK_SIZE);
+ }
+ public List<ITmfCheckpoint> getCheckpoints() {
+ return getTraceIndex();
+ }
+ }
+
+ private class TestTrace extends TmfTraceStub {
+ public TestTrace(String path, int blockSize) throws TmfTraceException {
+ super(path, blockSize, false, null, null);
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ private class EmptyTestTrace extends TmfEmptyTraceStub {
+ public EmptyTestTrace() {
+ super();
+ setIndexer(new TestIndexer(this));
+ }
+ @Override
+ public TestIndexer getIndexer() {
+ return (TestIndexer) super.getIndexer();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper functions
+ // ------------------------------------------------------------------------
+
+ private synchronized void 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(true);
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (fEmptyTrace == null) {
+ fEmptyTrace = new EmptyTestTrace();
+ fEmptyTrace.indexTrace(true);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testTmfTraceMultiTimestamps() {
+ assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
+ assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", 102, fTrace.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
+ assertEquals("getEndTime", 102, fTrace.getEndTime().getValue());
+
+ List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE + 1, checkpoints.size());
+
+ // Trace has 3 events with same timestamp (ts=101) at rank 99, 100, 101
+
+ // Verify that the event at rank=99 is returned when seeking to ts=101 (first event with this timestamp)
+ // and not the event at checkpoint boundary
+ TmfTimestamp seekTs = new TmfTimestamp(101, -3, 0);
+ ITmfContext ctx = fTrace.seekEvent(seekTs);
+ ITmfEvent event = fTrace.getNext(ctx);
+
+ assertEquals(99, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ event = fTrace.getNext(ctx);
+
+ assertEquals(100, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ event = fTrace.getNext(ctx);
+
+ assertEquals(101, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
+ // Verify that the event at rank=102 is returned when seeking to ts=102 (first event with this timestamp)
+ // and not the event at checkpoint boundary
+ seekTs = new TmfTimestamp(102, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(102, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to first checkpoint
+ seekTs = new TmfTimestamp(1, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(1, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp before first event
+ seekTs = new TmfTimestamp(0, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(1, ctx.getRank());
+ assertEquals(0, new TmfTimestamp(1, -3, 0).compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp between first and second checkpoint
+ seekTs = new TmfTimestamp(50, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(50, ctx.getRank());
+ assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+ // Verify seek to timestamp after last event in trace
+ seekTs = new TmfTimestamp(103, -3, 0);
+ ctx = fTrace.seekEvent(seekTs);
+ event = fTrace.getNext(ctx);
+
+ assertEquals(-1, ctx.getRank());
+ assertNull(event);
+ }
+}
--- /dev/null
- private static final String DIRECTORY = "testfiles";
- private static final String TEST_STREAM1 = "O-Test-10K";
- private static final String TEST_STREAM2 = "E-Test-10K";
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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
+ * Alexandre Montplaisir - Port to JUnit4
+ * Patrick Tasse - Updated for ranks in experiment location
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+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.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
++import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfExperimentCheckpointIndexTest {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
- final String path1 = DIRECTORY + File.separator + TEST_STREAM1;
- final String path2 = DIRECTORY + File.separator + TEST_STREAM2;
+ private static final String EXPERIMENT = "MyExperiment";
++ private static final TmfTestTrace TEST_TRACE1 = TmfTestTrace.O_TEST_10K;
++ private static final TmfTestTrace TEST_TRACE2 = TmfTestTrace.E_TEST_10K;
+ private static int NB_EVENTS = 20000;
+ private static int BLOCK_SIZE = 1000;
+
+ private static ITmfTrace[] fTestTraces;
+ private static TmfExperimentStub fExperiment;
+
+ // ------------------------------------------------------------------------
+ // Housekeeping
+ // ------------------------------------------------------------------------
+
+ @Before
+ public void setUp() {
+ setupTraces();
+ fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE);
+ fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
+ }
+
+ @After
+ public void tearDown() {
+ fExperiment.dispose();
+ fExperiment = null;
+ for (ITmfTrace trace : fTestTraces) {
+ trace.dispose();
+ }
+ fTestTraces = null;
+ }
+
+ private static void setupTraces() {
- URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
+
+ fTestTraces = new ITmfTrace[2];
+ try {
- location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
++ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE1.getFullPath()), null);
+ File test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null, null);
+ fTestTraces[0] = trace1;
- URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM1), null);
++ location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE2.getFullPath()), null);
+ test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null, null);
+ fTestTraces[1] = trace2;
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Verify checkpoints
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testTmfTraceIndexing() {
+ assertEquals("getCacheSize", BLOCK_SIZE, fExperiment.getCacheSize());
+ assertEquals("getTraceSize", NB_EVENTS, fExperiment.getNbEvents());
+ assertEquals("getRange-start", 1, fExperiment.getTimeRange().getStartTime().getValue());
+ assertEquals("getRange-end", NB_EVENTS, fExperiment.getTimeRange().getEndTime().getValue());
+ assertEquals("getStartTime", 1, fExperiment.getStartTime().getValue());
+ assertEquals("getEndTime", NB_EVENTS, fExperiment.getEndTime().getValue());
+
+ List<ITmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
+ int pageSize = fExperiment.getCacheSize();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+ // Validate that each checkpoint points to the right event
+ for (int i = 0; i < checkpoints.size(); i++) {
+ ITmfCheckpoint checkpoint = checkpoints.get(i);
+ ITmfLocation location = checkpoint.getLocation();
+ ITmfContext context = fExperiment.seekEvent(location);
+ ITmfEvent event = fExperiment.parseEvent(context);
+ assertTrue(context.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Streaming
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testGrowingIndex() {
+ ITmfTrace[] testTraces = new TmfTraceStub[2];
+ try {
- location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM2), null);
++ URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE1.getFullPath()), null);
+ File test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false, null, null);
+ testTraces[0] = trace1;
++ location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE2.getFullPath()), null);
+ test = new File(FileLocator.toFileURL(location).toURI());
+ final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false, null, null);
+ testTraces[1] = trace2;
+ } catch (final TmfTraceException e) {
+ e.printStackTrace();
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+ TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, testTraces, BLOCK_SIZE);
+ int pageSize = experiment.getCacheSize();
+
+ // Build the first half of the index
+ TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3));
+ experiment.getIndexer().buildIndex(0, range, true);
+
+ // Validate that each checkpoint points to the right event
+ List<ITmfCheckpoint> checkpoints = experiment.getIndexer().getCheckpoints();
+ assertTrue("Checkpoints exist", checkpoints != null);
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE / 2, checkpoints.size());
+
+ // Build the second half of the index
+ experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true);
+
+ // Validate that each checkpoint points to the right event
+ assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+ for (int i = 0; i < checkpoints.size(); i++) {
+ ITmfCheckpoint checkpoint = checkpoints.get(i);
+ ITmfLocation location = checkpoint.getLocation();
+ ITmfContext context = experiment.seekEvent(location);
+ ITmfEvent event = experiment.parseEvent(context);
+ assertTrue(context.getRank() == i * pageSize);
+ assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+ assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue());
+ }
+
+ /* Clean up (since we didn't use the class-specific fixtures) */
+ experiment.dispose();
+ for (ITmfTrace trace : testTraces) {
+ trace.dispose();
+ }
+ }
+
+}