tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / PartialStateSystemTest.java
index 7627b08f42ca319507596da48907f21668bbf3f2..594756bb0a03d362fab105a2729d02f13fdac1c2 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 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
@@ -7,20 +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.CtfKernelStateProvider;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
-import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+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.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -31,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(CtfTmfTestTraces.tracesExist());
-        File stateFile = null;
+        assumeTrue(testTrace.exists());
+        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 CtfKernelStateProvider(CtfTmfTestTraces.getTestTrace(TRACE_INDEX));
-            ssq = StateSystemManager.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();
     }
 
     /**
@@ -112,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.027273 seconds and 5 git commands to generate.