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 c5303c17ec0205768015ecd29e22d4bab67953cc..acb1b1a4565c98714d12d5c52af498ca8561204a 100644 (file)
@@ -39,14 +39,15 @@ 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;
@@ -62,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;
 
@@ -77,7 +76,7 @@ public class TmfTraceTest {
 
     @Before
     public void setUp() {
-        fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+        fTrace = setupTrace(TEST_TRACE.getFullPath());
     }
 
     @After
@@ -95,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());
+                fTrace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
                 fTrace.indexTrace(true);
             } catch (final TmfTraceException e) {
                 e.printStackTrace();
@@ -113,182 +112,90 @@ public class TmfTraceTest {
     // ------------------------------------------------------------------------
 
     @Test
-    @SuppressWarnings("null")
-    public void testStandardConstructor() throws TmfTraceException {
-        TmfTraceStub trace = null;
-        File testfile = null;
+    public void testFullConstructor() throws TmfTraceException {
         try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath());
+            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(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
             trace.indexTrace(true);
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
 
-        assertFalse ("Open trace", trace == null);
-        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("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_TRACE.getPath(), 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());
-    }
+            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());
 
-    @Test
-    @SuppressWarnings("null")
-    public void testStandardConstructorCacheSize() throws TmfTraceException {
-        TmfTraceStub trace = null;
-        File testfile = null;
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath(), 0);
-            trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
         } catch (final IOException e) {
             fail("IOException");
         }
-
-        assertFalse ("Open trace", trace == null);
-        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());
-
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath());
-            trace.indexTrace(true);
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
-
-        assertEquals("getType",  ITmfEvent.class, trace.getType());
-        assertNull  ("getResource", trace.getResource());
-        assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-        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());
     }
 
     @Test
-    @SuppressWarnings("null")
-    public void testFullConstructor() throws TmfTraceException {
-        TmfTraceStub trace = null;
-        File testfile = null;
+    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);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, 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(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, interval);
             trace.indexTrace(true);
-        } catch (final URISyntaxException e) {
-            fail("URISyntaxException");
-        } catch (final IOException e) {
-            fail("IOException");
-        }
 
-        assertFalse ("Open trace", trace == null);
-        assertEquals("getType",  ITmfEvent.class, trace.getType());
-        assertNull  ("getResource", trace.getResource());
-        assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-        assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
-        assertEquals("getName", TEST_STREAM, trace.getName());
+            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", interval, trace.getStreamingInterval());
+            assertEquals("getName", TEST_TRACE.getPath(), 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());
-    }
+            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());
 
-    @Test
-    @SuppressWarnings("null")
-    public void testLiveTraceConstructor() throws TmfTraceException {
-        TmfTraceStub trace = null;
-        File testfile = null;
-        final long interval = 100;
-        try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, interval);
-            trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
         } catch (final IOException e) {
             fail("IOException");
         }
-
-        assertFalse ("Open trace", trace == null);
-        assertEquals("getType",  ITmfEvent.class, trace.getType());
-        assertNull  ("getResource", trace.getResource());
-        assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-        assertEquals("getStreamingInterval", interval, 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());
     }
 
     @Test
-    @SuppressWarnings("null")
     public void testCopyConstructor() throws TmfTraceException {
-        TmfTraceStub original = null;
-        TmfTraceStub trace = null;
-        File testfile = null;
         try {
-            final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
-            testfile = new File(FileLocator.toFileURL(location).toURI());
-            original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfCheckpointIndexer(null));
-            trace = new TmfTraceStub(original);
+            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(), 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", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, trace.getCacheSize());
+            assertEquals("getStreamingInterval", 0, trace.getStreamingInterval());
+            assertEquals("getName", TEST_TRACE.getPath(), 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");
         }
 
-        assertFalse ("Open trace", trace == null);
-        assertEquals("getType",  ITmfEvent.class, trace.getType());
-        assertNull  ("getResource", trace.getResource());
-        assertEquals("getPath", testfile.toURI().getPath(), trace.getPath());
-        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());
-
         // Test the copy of a null trace
         try {
             new TmfTraceStub((TmfTraceStub) null);
@@ -392,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());
 
@@ -412,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());
@@ -1388,7 +1295,7 @@ public class TmfTraceTest {
 
     @Test
     public void testCancel() throws InterruptedException {
-        final int limit = BLOCK_SIZE;
+        final int limit = 500;
         final Vector<ITmfEvent> requestedEvents = new Vector<ITmfEvent>();
 
         final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
@@ -1424,7 +1331,7 @@ public class TmfTraceTest {
         assertEquals("getType",  ITmfEvent.class, fTrace.getType());
         assertNull  ("getResource", fTrace.getResource());
         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());
@@ -1449,23 +1356,23 @@ 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());
     }
 
     /**
This page took 0.050618 seconds and 5 git commands to generate.