* Contributors:
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Adjusted for new Trace Model
+ * Alexandre Montplaisir - Port to JUnit4
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.trace;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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.Vector;
-import junit.framework.TestCase;
-
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test suite for the TmfExperiment class (multiple traces).
*/
@SuppressWarnings({"nls","javadoc"})
-public class TmfMultiTraceExperimentTest extends TestCase {
+public class TmfMultiTraceExperimentTest {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
+
private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
private static final String DIRECTORY = "testfiles";
private static final String TEST_STREAM1 = "O-Test-10K";
// Housekeeping
// ------------------------------------------------------------------------
+ @Before
+ public void setUp() {
+ setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
+ if (fExperiment == null) {
+ fExperiment = new TmfExperimentStub(EXPERIMENT, fTraces, BLOCK_SIZE);
+ fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
+ }
+ }
+
private synchronized static ITmfTrace[] setupTrace(final String path1, final String path2) {
if (fTraces == null) {
fTraces = new ITmfTrace[2];
return fTraces;
}
- /**
- * @param name the test name
- */
- public TmfMultiTraceExperimentTest(final String name) {
- super(name);
- }
-
- @Override
- protected synchronized void setUp() throws Exception {
- super.setUp();
- setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
- if (fExperiment == null) {
- fExperiment = new TmfExperimentStub(EXPERIMENT, fTraces, BLOCK_SIZE);
- fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
+ @Test
public void testBasicTmfExperimentConstructor() {
-
assertEquals("GetId", EXPERIMENT, fExperiment.getName());
assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
// seekEvent on rank
// ------------------------------------------------------------------------
+ @Test
public void testSeekRankOnCacheBoundary() {
-
long cacheSize = fExperiment.getCacheSize();
// On lower bound, returns the first event (TS = 1)
assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
+ @Test
public void testSeekRankNotOnCacheBoundary() {
-
long cacheSize = fExperiment.getCacheSize();
// Position trace at event rank 9
assertEquals("Context rank", 4501, context.getRank());
}
+ @Test
public void testSeekRankOutOfScope() {
-
// Position trace at beginning
ITmfContext context = fExperiment.seekEvent(-1);
assertEquals("Event rank", 0, context.getRank());
// seekEvent on timestamp
// ------------------------------------------------------------------------
+ @Test
public void testSeekTimestampOnCacheBoundary() {
-
long cacheSize = fExperiment.getCacheSize();
// Position trace at event rank 0
assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
}
+ @Test
public void testSeekTimestampNotOnCacheBoundary() {
-
// Position trace at event rank 1 (TS = 2)
ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0));
assertEquals("Context rank", 1, context.getRank());
assertEquals("Context rank", 4501, context.getRank());
}
+ @Test
public void testSeekTimestampOutOfScope() {
-
// Position trace at beginning
ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
assertEquals("Event rank", 0, context.getRank());
// seekEvent by location (context rank is undefined)
// ------------------------------------------------------------------------
+ @Test
public void testSeekLocationOnCacheBoundary() {
-
long cacheSize = fExperiment.getCacheSize();
// Position trace at event rank 0
assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue());
}
+ @Test
public void testSeekLocationNotOnCacheBoundary() {
-
long cacheSize = fExperiment.getCacheSize();
// Position trace at event 'cacheSize' - 1
assertEquals("Event timestamp", 4502, event.getTimestamp().getValue());
}
+ @Test
public void testSeekLocationOutOfScope() {
-
// Position trace at beginning
ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
assertEquals("Experiment context rank", expRank, ctx.getRank());
}
+ @Test
public void testGetNextAfteSeekingOnTS_1() {
-
final long INITIAL_TS = 1;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfteSeekingOnTS_2() {
-
final long INITIAL_TS = 2;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfteSeekingOnTS_3() {
-
final long INITIAL_TS = 500;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnRank_1() {
-
final long INITIAL_RANK = 0L;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnRank_2() {
-
final long INITIAL_RANK = 1L;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnRank_3() {
-
final long INITIAL_RANK = 500L;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnLocation_1() {
-
final ITmfLocation INITIAL_LOC = null;
final long INITIAL_TS = 1;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnLocation_2() {
-
final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(1L).getLocation();
final long INITIAL_TS = 2;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextAfterSeekingOnLocation_3() {
-
final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(500L).getLocation();
final long INITIAL_TS = 501;
final int NB_READS = 20;
validateContextRanks(context);
}
+ @Test
public void testGetNextLocation() {
ITmfContext context1 = fExperiment.seekEvent(0);
fExperiment.getNext(context1);
assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue());
}
+ @Test
public void testGetNextEndLocation() {
ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1);
fExperiment.getNext(context1);
// processRequest
// ------------------------------------------------------------------------
+ @Test
public void testProcessRequestForNbEvents() throws InterruptedException {
-
final int blockSize = 100;
final int nbEvents = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
}
}
+ @Test
public void testProcessRequestForNbEvents2() throws InterruptedException {
-
final int blockSize = 2 * NB_EVENTS;
final int nbEvents = 1000;
final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
}
}
+ @Test
public void testProcessRequestForAllEvents() throws InterruptedException {
-
final int nbEvents = TmfDataRequest.ALL_DATA;
final int blockSize = 1;
final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
// cancel
// ------------------------------------------------------------------------
+ @Test
public void testCancel() throws InterruptedException {
-
final int nbEvents = NB_EVENTS;
final int blockSize = BLOCK_SIZE;
final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
// getTimestamp
// ------------------------------------------------------------------------
+ @Test
public void testGetTimestamp() {
assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0));
assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1));
// getInitialRangeOffset, getCurrentRange, getCurrentTime
// ------------------------------------------------------------------------
+ @Test
public void testDefaultCurrentTimeValues() {
// reset to default initial range offset
((TmfTraceStub)fTraces[0]).setInitialRangeOffset(null);
assertEquals("getInitialRangeOffset", initRange, exp.getInitialRangeOffset());
assertEquals("getCurrentTime", TmfTimestamp.ZERO, exp.getCurrentTime());
assertEquals("getCurrentRange", TmfTimeRange.NULL_RANGE, exp.getCurrentRange());
-
}
+
}