tmf: Add a waitForCompletion() with no parameter to analysis modules
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / PartialStateSystemTest.java
index 4431d99bd18a723677ccd4703e917a8940660fd0..0c0d90a974623a94a373b194205eb671c2116c1e 100644 (file)
@@ -7,19 +7,27 @@
  *
  * Contributors:
  *   Alexandre Montplaisir - Initial API and implementation
+ *   Bernd Hufmann - Use state system analysis module instead of factory
  ******************************************************************************/
 
 package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
 
 import java.io.File;
-import java.io.IOException;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -30,24 +38,40 @@ import org.junit.Test;
  */
 public class PartialStateSystemTest extends StateSystemTest {
 
+    private static File stateFile;
+    private static final String TEST_FILE_NAME = "test-partial";
+
+
     /**
      * Initialization
      */
     @BeforeClass
     public static void initialize() {
         assumeTrue(testTrace.exists());
-        File stateFile = null;
+        stateFile = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + TEST_FILE_NAME);
+        if (stateFile.exists()) {
+            stateFile.delete();
+        }
+
+        TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
         try {
-            stateFile = File.createTempFile("test-partial", ".ht");
-            stateFile.deleteOnExit();
-
-            input = new LttngKernelStateProvider(testTrace.getTrace());
-            ssq = TmfStateSystemFactory.newPartialHistory(stateFile, input, true);
-        } catch (IOException e) {
-            e.printStackTrace();
-        } catch (TmfTraceException e) {
-            e.printStackTrace();
+            module.setTrace(testTrace.getTrace());
+        } catch (TmfAnalysisException e) {
+            fail();
         }
+        module.schedule();
+        assertTrue(module.waitForCompletion());
+        ssq = module.getStateSystem();
+
+        assertNotNull(ssq);
+    }
+
+    /**
+     * Class clean-up
+     */
+    @AfterClass
+    public static void tearDownClass() {
+        stateFile.delete();
     }
 
     /**
@@ -111,4 +135,43 @@ public class PartialStateSystemTest extends StateSystemTest {
     public void testRangeQueryInvalidTime2() throws TimeRangeException {
         super.testRangeQueryInvalidTime2();
     }
+
+    private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
+
+        private final String htFileName;
+
+        /**
+         * Constructor adding the views to the analysis
+         * @param htFileName
+         *      The History File Name
+         */
+        public TestLttngKernelAnalysisModule(String htFileName) {
+            super();
+            this.htFileName = htFileName;
+        }
+
+        @Override
+        public void setTrace(ITmfTrace trace) throws TmfAnalysisException {
+            if (!(trace instanceof CtfTmfTrace)) {
+                throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
+            }
+            super.setTrace(trace);
+        }
+
+        @Override
+        protected ITmfStateProvider createStateProvider() {
+            return new LttngKernelStateProvider((CtfTmfTrace) getTrace());
+        }
+
+        @Override
+        protected StateSystemBackendType getBackendType() {
+            return StateSystemBackendType.PARTIAL;
+        }
+
+        @Override
+        protected String getSsFileName() {
+            return htFileName;
+        }
+
+    }
 }
This page took 0.025278 seconds and 5 git commands to generate.