Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfTraceTest.java
index e3b027792bc9bf170cee09c2f9f883a9281d9a08..acb1b1a4565c98714d12d5c52af498ca8561204a 100644 (file)
@@ -35,17 +35,19 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 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.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 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;
 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.TmfCheckpointIndexer;
 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.location.ITmfLocation;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.junit.After;
 import org.junit.Before;
@@ -61,10 +63,8 @@ public class TmfTraceTest {
     // 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;
 
@@ -76,7 +76,7 @@ public class TmfTraceTest {
 
     @Before
     public void setUp() {
-        fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+        fTrace = setupTrace(TEST_TRACE.getFullPath());
     }
 
     @After
@@ -94,7 +94,7 @@ public class TmfTraceTest {
             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);
+                fTrace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
                 fTrace.indexTrace(true);
             } catch (final TmfTraceException e) {
                 e.printStackTrace();
@@ -111,101 +111,20 @@ public class TmfTraceTest {
     // Constructors
     // ------------------------------------------------------------------------
 
-    @Test
-    public void testStandardConstructor() throws TmfTraceException {
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            File testfile = new File(FileLocator.toFileURL(location).toURI());
-            TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath());
-            trace.indexTrace(true);
-
-            assertEquals("getType", ITmfEvent.class, trace.getType());
-            assertNull("getResource", trace.getResource());
-            assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-            assertEquals("getCacheSize", ITmfTrace.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());
-
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
-    }
-
-    @Test
-    public void testStandardConstructorCacheSize() throws TmfTraceException {
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            File testfile = new File(FileLocator.toFileURL(location).toURI());
-            TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), 0);
-            trace.indexTrace(true);
-
-            assertEquals("getType", ITmfEvent.class, trace.getType());
-            assertNull("getResource", trace.getResource());
-            assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-            assertEquals("getCacheSize", ITmfTrace.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());
-
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
-
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            File testfile = new File(FileLocator.toFileURL(location).toURI());
-            TmfTraceStub trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE);
-            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("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());
-
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
-    }
-
     @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());
@@ -224,17 +143,17 @@ public class TmfTraceTest {
     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());
@@ -252,18 +171,18 @@ public class TmfTraceTest {
     @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());
@@ -380,7 +299,7 @@ public class TmfTraceTest {
         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 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
         final File testfile = new File(FileLocator.toFileURL(location).toURI());
         assertTrue("validate", trace.validate(null, testfile.getPath()).isOK());
 
@@ -400,7 +319,7 @@ public class TmfTraceTest {
         assertNull  ("getResource", trace.getResource());
         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());
@@ -1223,11 +1142,11 @@ public class TmfTraceTest {
 
     @Test
     public void testProcessEventRequestForAllEvents() throws InterruptedException {
-        final int blockSize = 1;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class,
+                range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
@@ -1251,12 +1170,12 @@ public class TmfTraceTest {
 
     @Test
     public void testProcessEventRequestForNbEvents() throws InterruptedException {
-        final int blockSize = 100;
         final int nbEvents  = 1000;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class,
+                range, 0, nbEvents, ExecutionType.FOREGROUND) {
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
@@ -1280,13 +1199,13 @@ public class TmfTraceTest {
 
     @Test
     public void testProcessEventRequestForSomeEvents() throws InterruptedException {
-        final int blockSize = 1;
         final long startTime = 100;
         final int nbEvents  = 1000;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class,
+                range, 0, nbEvents, ExecutionType.FOREGROUND) {
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
@@ -1310,14 +1229,14 @@ public class TmfTraceTest {
 
     @Test
     public void testProcessEventRequestForOtherEvents() throws InterruptedException {
-        final int blockSize =  1;
         final int startIndex = 99;
         final long startTime = 100;
         final int nbEvents  = 1000;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, nbEvents, blockSize) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class,
+                range, startIndex, nbEvents, ExecutionType.FOREGROUND) {
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
@@ -1345,7 +1264,10 @@ public class TmfTraceTest {
         final int nbEvents  = 1000;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
-        final TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbEvents) {
+        final TmfDataRequest request = new TmfDataRequest(ITmfEvent.class,
+                startIndex,
+                nbEvents,
+                TmfDataRequest.ExecutionType.FOREGROUND) {
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
@@ -1373,16 +1295,19 @@ public class TmfTraceTest {
 
     @Test
     public void testCancel() throws InterruptedException {
+        final int limit = 500;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
-        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) {
+        final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class,
+                range, 0, NB_EVENTS, ExecutionType.FOREGROUND) {
             int nbRead = 0;
+
             @Override
             public void handleData(final ITmfEvent event) {
                 super.handleData(event);
                 requestedEvents.add(event);
-                if (++nbRead == BLOCK_SIZE) {
+                if (++nbRead == limit) {
                     cancel();
                 }
             }
@@ -1391,7 +1316,7 @@ public class TmfTraceTest {
         providers[0].sendRequest(request);
         request.waitForCompletion();
 
-        assertEquals("nbEvents",  BLOCK_SIZE, requestedEvents.size());
+        assertEquals("nbEvents",  limit, requestedEvents.size());
         assertTrue("isCompleted", request.isCompleted());
         assertTrue("isCancelled", request.isCancelled());
     }
@@ -1405,9 +1330,8 @@ public class TmfTraceTest {
         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());
@@ -1432,22 +1356,31 @@ public class TmfTraceTest {
         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());
             trace.setInitialRangeOffset(new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE));
             trace.indexTrace(true);
+
+            TmfTimestamp initRange = new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE);
+            assertEquals("getInitialRangeOffset", initRange, trace.getInitialRangeOffset());
+
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
         } catch (final IOException e) {
             fail("IOException");
         }
-        assertFalse ("Open trace", trace == null);
+    }
 
-        TmfTimestamp initRange = new TmfTimestamp(5, ITmfTimestamp.MILLISECOND_SCALE);
-        assertEquals("getInitialRangeOffset", initRange, trace.getInitialRangeOffset());
+    /**
+     * Run the String getHostId() method test
+     */
+    @Test
+    public void testTraceHostId() {
+        String a = fTrace.getHostId();
+        assertEquals("A-Test-10K", a);
     }
 }
This page took 0.034772 seconds and 5 git commands to generate.