Remove context clone and add trace ranks to experiment location
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfExperimentTest.java
index 8a89d8e397fb977609a57bfaf9911907ed8fa399..8516300e127d6a2defe91893f3af7e852f995fc3 100644 (file)
@@ -1,50 +1,62 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010, 2012 Ericsson
- * 
+ * Copyright (c) 2009, 2010, 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
  *   Francois Chouinard - Adjusted for new Trace Model
+ *   Alexandre Montplaisir - Port to JUnit4
+ *   Patrick Tasse - Updated for rank in experiment location
  *******************************************************************************/
 
 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.assertNotNull;
+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.Collection;
 import java.util.Vector;
 
-import junit.framework.TestCase;
-
 import org.eclipse.core.resources.IFile;
 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.internal.tmf.core.trace.TmfExperimentLocation;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 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.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
 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 (single trace).
  */
-@SuppressWarnings({ "nls" })
-public class TmfExperimentTest extends TestCase {
+@SuppressWarnings({"nls","javadoc"})
+public class TmfExperimentTest {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -56,8 +68,10 @@ public class TmfExperimentTest extends TestCase {
     private static int          NB_EVENTS   = 10000;
     private static int          BLOCK_SIZE  = 1000;
 
-    private ITmfTrace<TmfEvent>[] fTestTraces;
-    private TmfExperimentStub<ITmfEvent> fExperiment;
+    private static final double DELTA = 1e-15;
+
+    private ITmfTrace[] fTestTraces;
+    private TmfExperimentStub fExperiment;
 
     private static byte SCALE = (byte) -3;
 
@@ -65,8 +79,7 @@ public class TmfExperimentTest extends TestCase {
     // Housekeeping
     // ------------------------------------------------------------------------
 
-    @SuppressWarnings("unchecked")
-    private synchronized ITmfTrace<?>[] setupTrace(final String path) {
+    private synchronized ITmfTrace[] setupTrace(final String path) {
         if (fTestTraces == null) {
             fTestTraces = new ITmfTrace[1];
             try {
@@ -87,44 +100,34 @@ public class TmfExperimentTest extends TestCase {
 
     private synchronized void setupExperiment() {
         if (fExperiment == null) {
-            fExperiment = new TmfExperimentStub<ITmfEvent>(EXPERIMENT, fTestTraces, BLOCK_SIZE);
+            fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE);
             fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
         }
     }
 
-    public TmfExperimentTest(final String name) throws Exception {
-        super(name);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() {
         setupTrace(DIRECTORY + File.separator + TEST_STREAM);
         setupExperiment();
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
 
+    @Test
     public void testSimpleTmfExperimentConstructor() {
-
-        TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTestTraces);
+        TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, fTestTraces);
         assertEquals("GetId", EXPERIMENT, experiment.getName());
         assertEquals("GetCacheSize", TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, experiment.getCacheSize());
         experiment.dispose();
 
-        experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null);
+        experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, null);
         experiment.dispose();
     }
 
+    @Test
     public void testNormalTmfExperimentConstructor() {
-
         assertEquals("GetId", EXPERIMENT, fExperiment.getName());
         assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
 
@@ -139,32 +142,20 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("getEndTime", NB_EVENTS, timeRange.getEndTime().getValue());
     }
 
-    @SuppressWarnings("static-access")
-    public void testSetCurrentExperiment() {
-
-        TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTestTraces);
-        experiment.setCurrentExperiment(experiment);
-        assertEquals("getCurrentExperiment", experiment, experiment.getCurrentExperiment());
-
-        TmfExperiment<TmfEvent> experiment2 = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null);
-        experiment.setCurrentExperiment(experiment2);
-        assertEquals("getCurrentExperiment", experiment2, experiment.getCurrentExperiment());
-
-        experiment.dispose();
-        experiment2.dispose();
-    }
-
     // ------------------------------------------------------------------------
     // getTimestamp
     // ------------------------------------------------------------------------
 
-    public void testGetTimestamp() throws Exception {
-        assertTrue("getTimestamp", fExperiment.getTimestamp(    0).equals(new TmfTimestamp(   1, (byte) -3)));
-        assertTrue("getTimestamp", fExperiment.getTimestamp(   10).equals(new TmfTimestamp(  11, (byte) -3)));
-        assertTrue("getTimestamp", fExperiment.getTimestamp(  100).equals(new TmfTimestamp( 101, (byte) -3)));
-        assertTrue("getTimestamp", fExperiment.getTimestamp( 1000).equals(new TmfTimestamp(1001, (byte) -3)));
-        assertTrue("getTimestamp", fExperiment.getTimestamp( 2000).equals(new TmfTimestamp(2001, (byte) -3)));
-        assertTrue("getTimestamp", fExperiment.getTimestamp( 2500).equals(new TmfTimestamp(2501, (byte) -3)));
+    @Test
+    public void testGetTimestamp() {
+        assertEquals("getTimestamp", new TmfTimestamp(    1, (byte) -3), fExperiment.getTimestamp(   0));
+        assertEquals("getTimestamp", new TmfTimestamp(    2, (byte) -3), fExperiment.getTimestamp(   1));
+        assertEquals("getTimestamp", new TmfTimestamp(   11, (byte) -3), fExperiment.getTimestamp(  10));
+        assertEquals("getTimestamp", new TmfTimestamp(  101, (byte) -3), fExperiment.getTimestamp( 100));
+        assertEquals("getTimestamp", new TmfTimestamp( 1001, (byte) -3), fExperiment.getTimestamp(1000));
+        assertEquals("getTimestamp", new TmfTimestamp( 2001, (byte) -3), fExperiment.getTimestamp(2000));
+        assertEquals("getTimestamp", new TmfTimestamp( 2501, (byte) -3), fExperiment.getTimestamp(2500));
+        assertEquals("getTimestamp", new TmfTimestamp(10000, (byte) -3), fExperiment.getTimestamp(9999));
         assertNull("getTimestamp", fExperiment.getTimestamp(10000));
     }
 
@@ -172,24 +163,52 @@ public class TmfExperimentTest extends TestCase {
     // Bookmarks file handling
     // ------------------------------------------------------------------------
 
-    public void testBookmarks() throws Exception {
+    @Test
+    public void testBookmarks() {
         assertNull("GetBookmarksFile", fExperiment.getBookmarksFile());
         IFile bookmarks = (IFile) fTestTraces[0].getResource();
         fExperiment.setBookmarksFile(bookmarks);
         assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile());
     }
 
+    // ------------------------------------------------------------------------
+    // State system and statistics methods
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testGetStatistics() {
+        /* There should not be any experiment-specific statistics */
+        ITmfStatistics stats = fExperiment.getStatistics();
+        assertNull(stats);
+    }
+
+    @Test
+    public void testGetStateSystem() {
+        /* There should not be any experiment-specific state system */
+        ITmfStateSystem ss = fExperiment.getStateSystem("something");
+        assertNull(ss);
+    }
+
+    @Test
+    public void testListStateSystem() {
+        Collection<String> sss = fExperiment.listStateSystems();
+        assertNotNull(sss);
+        assertEquals(0, sss.size());
+    }
+
     // ------------------------------------------------------------------------
     // seekEvent by location
     // ------------------------------------------------------------------------
 
-    public void testSeekBadLocation() throws Exception {
-        ITmfContext context = fExperiment.seekEvent((ITmfLocation<?>) new TmfLocation<Long>(0L));
+    @Test
+    public void testSeekBadLocation() {
+        ITmfContext context = fExperiment.seekEvent(new TmfLongLocation(0L));
         assertNull("seekEvent", context);
     }
 
-    public void testSeekNoTrace() throws Exception {
-        TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, null);
+    @Test
+    public void testSeekNoTrace() {
+        TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, null);
         ITmfContext context = experiment.seekEvent((TmfExperimentLocation) null);
         assertNull("seekEvent", context);
         experiment.dispose();
@@ -199,8 +218,8 @@ public class TmfExperimentTest extends TestCase {
     // seekEvent on ratio
     // ------------------------------------------------------------------------
 
-    public void testSeekEventOnRatio() throws Exception {
-
+    @Test
+    public void testSeekEventOnRatio() {
         // First event
         ITmfContext context = fExperiment.seekEvent(0.0);
         assertEquals("Context rank", 0, context.getRank());
@@ -215,21 +234,21 @@ public class TmfExperimentTest extends TestCase {
         event = fExperiment.parseEvent(context);
         assertEquals("Event timestamp", midTrace + 1, event.getTimestamp().getValue());
         assertEquals("Context rank", midTrace, context.getRank());
-        
+
         // Last event
         context = fExperiment.seekEvent(1.0);
         assertEquals("Context rank", NB_EVENTS, context.getRank());
         event = fExperiment.parseEvent(context);
         assertNull("Event timestamp", event);
         assertEquals("Context rank", NB_EVENTS, context.getRank());
-        
+
         // Beyond last event
         context = fExperiment.seekEvent(1.1);
         assertEquals("Context rank", NB_EVENTS, context.getRank());
         event = fExperiment.parseEvent(context);
         assertNull("Event timestamp", event);
         assertEquals("Context rank", NB_EVENTS, context.getRank());
-        
+
         // Negative ratio
         context = fExperiment.seekEvent(-0.5);
         assertEquals("Context rank", 0, context.getRank());
@@ -238,33 +257,26 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Context rank", 0, context.getRank());
     }
 
-    @SuppressWarnings("rawtypes")
-    public void testGetLocationRatio() throws Exception {
-
+    @Test
+    public void testGetLocationRatio() {
         // First event
         ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
         double ratio = fExperiment.getLocationRatio(context.getLocation());
-        context = fExperiment.seekEvent(ratio);
-        double ratio2 = fExperiment.getLocationRatio(context.getLocation());
-        assertEquals("getLocationRatio", ratio, ratio2);
+        assertEquals("getLocationRatio", 0.0, ratio, DELTA);
 
         // Middle event
         context = fExperiment.seekEvent(NB_EVENTS / 2);
         ratio = fExperiment.getLocationRatio(context.getLocation());
-        context = fExperiment.seekEvent(ratio);
-        ratio2 = fExperiment.getLocationRatio(context.getLocation());
-        assertEquals("getLocationRatio", ratio, ratio2);
+        assertEquals("getLocationRatio", (double) (NB_EVENTS / 2) / NB_EVENTS, ratio, DELTA);
 
         // Last event
         context = fExperiment.seekEvent(NB_EVENTS - 1);
         ratio = fExperiment.getLocationRatio(context.getLocation());
-        context = fExperiment.seekEvent(ratio);
-        ratio2 = fExperiment.getLocationRatio(context.getLocation());
-        assertEquals("getLocationRatio", ratio, ratio2);
+        assertEquals("getLocationRatio", (double) (NB_EVENTS - 1) / NB_EVENTS, ratio, DELTA);
     }
 
-//    @SuppressWarnings({ "unchecked", "rawtypes" })
-//    public void testGetCurrentLocation() throws Exception {
+//    @SuppressWarnings("rawtypes")
+//    public void testGetCurrentLocation() {
 //        ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
 //        ITmfLocation location = fExperiment.getCurrentLocation();
 //        assertEquals("getCurrentLocation", location, context.getLocation());
@@ -274,8 +286,8 @@ public class TmfExperimentTest extends TestCase {
     // seekEvent on rank
     // ------------------------------------------------------------------------
 
-    public void testSeekRankOnCacheBoundary() throws Exception {
-
+    @Test
+    public void testSeekRankOnCacheBoundary() {
         long cacheSize = fExperiment.getCacheSize();
 
         // On lower bound, returns the first event (TS = 1)
@@ -303,8 +315,8 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
     }
 
-    public void testSeekRankNotOnCacheBoundary() throws Exception {
-
+    @Test
+    public void testSeekRankNotOnCacheBoundary() {
         long cacheSize = fExperiment.getCacheSize();
 
         // Position trace at event rank 9
@@ -340,8 +352,8 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Context rank", 4501, context.getRank());
     }
 
-    public void testSeekRankOutOfScope() throws Exception {
-
+    @Test
+    public void testSeekRankOutOfScope() {
         // Position trace at beginning
         ITmfContext context = fExperiment.seekEvent(-1);
         assertEquals("Event rank", 0, context.getRank());
@@ -363,8 +375,8 @@ public class TmfExperimentTest extends TestCase {
     // seekEvent on timestamp
     // ------------------------------------------------------------------------
 
-    public void testSeekTimestampOnCacheBoundary() throws Exception {
-
+    @Test
+    public void testSeekTimestampOnCacheBoundary() {
         long cacheSize = fExperiment.getCacheSize();
 
         // Position trace at event rank 0
@@ -392,8 +404,8 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Context rank", 4 * cacheSize + 1, context.getRank());
     }
 
-    public void testSeekTimestampNotOnCacheBoundary() throws Exception {
-
+    @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());
@@ -435,8 +447,8 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Context rank", 4501, context.getRank());
     }
 
-    public void testSeekTimestampOutOfScope() throws Exception {
-
+    @Test
+    public void testSeekTimestampOutOfScope() {
         // Position trace at beginning
         ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0));
         assertEquals("Event rank", 0, context.getRank());
@@ -456,8 +468,8 @@ public class TmfExperimentTest extends TestCase {
     // seekEvent by location (context rank is undefined)
     // ------------------------------------------------------------------------
 
-    public void testSeekLocationOnCacheBoundary() throws Exception {
-        
+    @Test
+    public void testSeekLocationOnCacheBoundary() {
         long cacheSize = fExperiment.getCacheSize();
 
         // Position trace at event rank 0
@@ -491,8 +503,8 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue());
     }
 
-    public void testSeekLocationNotOnCacheBoundary() throws Exception {
-
+    @Test
+    public void testSeekLocationNotOnCacheBoundary() {
         long cacheSize = fExperiment.getCacheSize();
 
         // Position trace at event 'cacheSize' - 1
@@ -527,46 +539,308 @@ public class TmfExperimentTest extends TestCase {
         assertEquals("Event timestamp", 4502, event.getTimestamp().getValue());
     }
 
-    public void testSeekLocationOutOfScope() throws Exception {
-
+    @Test
+    public void testSeekLocationOutOfScope() {
         // Position trace at beginning
-        ITmfContext context = fExperiment.seekEvent((ITmfLocation<?>) null);
+        ITmfContext context = fExperiment.seekEvent((ITmfLocation) null);
 
         ITmfEvent event = fExperiment.getNext(context);
         assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
     }
 
     // ------------------------------------------------------------------------
-    // readtNextEvent - updates the context
+    // getNext - updates the context
     // ------------------------------------------------------------------------
 
-    public void testReadNextEvent() throws Exception {
+    private static void validateContextRanks(ITmfContext context) {
+        assertTrue("Experiment context type", context instanceof TmfExperimentContext);
+        TmfExperimentContext ctx = (TmfExperimentContext) context;
 
-        // On lower bound, returns the first event (ts = 0)
-        final ITmfContext context = fExperiment.seekEvent(0);
-        ITmfEvent event = fExperiment.getNext(context);
-        assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
+        int nbTraces = ctx.getContexts().length;
+
+        // expRank = sum(trace ranks) - nbTraces + 1 (if lastTraceRead != NO_TRACE)
+        long expRank = -nbTraces + ((ctx.getLastTrace() != TmfExperimentContext.NO_TRACE) ? 1 : 0);
+        for (int i = 0; i < nbTraces; i++) {
+            long rank = ctx.getContexts()[i].getRank();
+            if (rank == -1) {
+                expRank = -1;
+                break;
+            }
+            expRank += rank;
+        }
+        assertEquals("Experiment context rank", expRank, ctx.getRank());
+    }
+
+    @Test
+    public void testGetNextAfteSeekingOnTS_1() {
 
-        for (int i = 2; i < 20; i++) {
+        final long INITIAL_TS = 1;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (ts = 1)
+        final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0));
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
             event = fExperiment.getNext(context);
-            assertEquals("Event timestamp", i, event.getTimestamp().getValue());
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_TS + i, context.getRank());
         }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfteSeekingOnTS_2() {
+        final long INITIAL_TS = 2;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (ts = 2)
+        final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0));
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_TS + i, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfteSeekingOnTS_3() {
+
+        final long INITIAL_TS = 500;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (ts = 500)
+        final ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(INITIAL_TS, SCALE, 0));
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_TS + i, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfterSeekingOnRank_1() {
+        final long INITIAL_RANK = 0L;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (rank = 0)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfterSeekingOnRank_2() {
+        final long INITIAL_RANK = 1L;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (rank = 0)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfterSeekingOnRank_3() {
+        final long INITIAL_RANK = 500L;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (rank = 0)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_RANK);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_RANK + i + 1, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_RANK + i + 1, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_RANK + NB_READS + 1, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextAfterSeekingOnLocation_1() {
+        final ITmfLocation INITIAL_LOC = null;
+        final long INITIAL_TS = 1;
+        final int NB_READS = 20;
+
+        // On lower bound, returns the first event (ts = 1)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+            assertEquals("Event rank", INITIAL_TS + i, context.getRank());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+        assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank());
+
+        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;
+
+        // On lower bound, returns the first event (ts = 2)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+
+        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;
+
+        // On lower bound, returns the first event (ts = 501)
+        final ITmfContext context = fExperiment.seekEvent(INITIAL_LOC);
+
+        validateContextRanks(context);
+
+        // Read NB_EVENTS
+        ITmfEvent event;
+        for (int i = 0; i < NB_READS; i++) {
+            event = fExperiment.getNext(context);
+            assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
+        }
+
+        // Make sure we stay positioned
+        event = fExperiment.parseEvent(context);
+        assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
+
+        validateContextRanks(context);
+    }
+
+    @Test
+    public void testGetNextLocation() {
+        ITmfContext context1 = fExperiment.seekEvent(0);
+        fExperiment.getNext(context1);
+        ITmfLocation location = context1.getLocation();
+        ITmfEvent event1 = fExperiment.getNext(context1);
+        ITmfContext context2 = fExperiment.seekEvent(location);
+        ITmfEvent event2 = fExperiment.getNext(context2);
+        assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue());
+    }
+
+    @Test
+    public void testGetNextEndLocation() {
+        ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1);
+        fExperiment.getNext(context1);
+        ITmfLocation location = context1.getLocation();
+        ITmfContext context2 = fExperiment.seekEvent(location);
+        ITmfEvent event = fExperiment.getNext(context2);
+        assertNull("Event", event);
     }
 
     // ------------------------------------------------------------------------
     // processRequest
     // ------------------------------------------------------------------------
 
-    public void testProcessRequestForNbEvents() throws Exception {
-
+    @Test
+    public void testProcessRequestForNbEvents() throws InterruptedException {
         final int blockSize = 100;
         final int nbEvents  = 1000;
-        final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+        final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
             @Override
-            public void handleData(final TmfEvent event) {
+            public void handleData(final ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
             }
@@ -585,16 +859,16 @@ public class TmfExperimentTest extends TestCase {
         }
     }
 
-    public void testProcessRequestForNbEvents2() throws Exception {
-
+    @Test
+    public void testProcessRequestForNbEvents2() throws InterruptedException {
         final int blockSize = 2 * NB_EVENTS;
         final int nbEvents = 1000;
-        final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+        final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
             @Override
-            public void handleData(final TmfEvent event) {
+            public void handleData(final ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
             }
@@ -613,17 +887,17 @@ public class TmfExperimentTest extends TestCase {
         }
     }
 
-    public void testProcessRequestForAllEvents() throws Exception {
-
-        final int nbEvents  = TmfEventRequest.ALL_DATA;
+    @Test
+    public void testProcessRequestForAllEvents() throws InterruptedException {
+        final int nbEvents  = TmfDataRequest.ALL_DATA;
         final int blockSize =  1;
-        final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+        final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
         final long nbExpectedEvents = NB_EVENTS;
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
             @Override
-            public void handleData(final TmfEvent event) {
+            public void handleData(final ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
             }
@@ -646,17 +920,17 @@ public class TmfExperimentTest extends TestCase {
     // cancel
     // ------------------------------------------------------------------------
 
-    public void testCancel() throws Exception {
-
+    @Test
+    public void testCancel() throws InterruptedException {
         final int nbEvents  = NB_EVENTS;
         final int blockSize = BLOCK_SIZE;
-        final Vector<TmfEvent> requestedEvents = new Vector<TmfEvent>();
+        final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
             int nbRead = 0;
             @Override
-            public void handleData(final TmfEvent event) {
+            public void handleData(final ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
                 if (++nbRead == blockSize) {
@@ -678,4 +952,4 @@ public class TmfExperimentTest extends TestCase {
         assertTrue("isCancelled", request.isCancelled());
     }
 
-}
\ No newline at end of file
+}
This page took 0.032955 seconds and 5 git commands to generate.