gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / StateSystemFullHistoryTest.java
index 2e8f5b9e9545248c8b5eb93207490539bf557857..a8a0f62db7a5805bd7fa397460588c19c3683ffa 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2012, 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
@@ -17,20 +17,21 @@ import static org.junit.Assert.assertEquals;
 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 org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 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.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
+import org.junit.After;
 import org.junit.Test;
 
 /**
@@ -41,22 +42,19 @@ import org.junit.Test;
  */
 public class StateSystemFullHistoryTest extends StateSystemTest {
 
-    private static File stateFile;
-    private static File stateFileBenchmark;
+    private static final @NonNull String TEST_FILE_NAME = "test.ht";
+    private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht";
 
-    private static final String TEST_FILE_NAME = "test.ht";
-    private static final String BENCHMARK_FILE_NAME = "test.benchmark.ht";
+    private File stateFile;
+    private File stateFileBenchmark;
+    private TestLttngKernelAnalysisModule module;
 
-    /**
-     * Initialize the test cases (build the history file once for all tests).
-     */
-    @BeforeClass
-    public static void initialize() {
-        assumeTrue(testTrace.exists());
+    @Override
+    protected ITmfStateSystem initialize() {
         stateFile = createStateFile(TEST_FILE_NAME);
         stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
 
-        TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
+        module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
         try {
             module.setTrace(testTrace.getTrace());
         } catch (TmfAnalysisException e) {
@@ -64,18 +62,23 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
         }
         module.schedule();
         assertTrue(module.waitForCompletion());
-        ssq = module.getStateSystem();
-
-        assertNotNull(ssq);
+        return module.getStateSystem();
     }
 
     /**
      * Clean-up
      */
-    @AfterClass
-    public static void tearDownClass() {
-        stateFile.delete();
-        stateFileBenchmark.delete();
+    @After
+    public void cleanup() {
+        if (module != null) {
+            module.close();
+        }
+        if (stateFile != null) {
+            stateFile.delete();
+        }
+        if (stateFileBenchmark != null) {
+            stateFileBenchmark.delete();
+        }
     }
 
     // ------------------------------------------------------------------------
@@ -88,19 +91,21 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
      */
     @Test
     public void testBuild() {
-        TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);
-        try {
-            module2.setTrace(testTrace.getTrace());
-        } catch (TmfAnalysisException e) {
-            fail();
-        }
-        module2.schedule();
-        assertTrue(module2.waitForCompletion());
-        ITmfStateSystem ssb2 = module2.getStateSystem();
+        try (TestLttngKernelAnalysisModule module2 =
+                new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);) {
+            try {
+                module2.setTrace(testTrace.getTrace());
+            } catch (TmfAnalysisException e) {
+                fail();
+            }
+            module2.schedule();
+            assertTrue(module2.waitForCompletion());
+            ITmfStateSystem ssb2 = module2.getStateSystem();
 
-        assertNotNull(ssb2);
-        assertEquals(startTime, ssb2.getStartTime());
-        assertEquals(endTime, ssb2.getCurrentEndTime());
+            assertNotNull(ssb2);
+            assertEquals(startTime, ssb2.getStartTime());
+            assertEquals(endTime, ssb2.getCurrentEndTime());
+        }
     }
 
     /**
@@ -109,21 +114,23 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
     @Test
     public void testOpenExistingStateFile() {
         /* 'newStateFile' should have already been created */
-        TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
-        try {
-            module2.setTrace(testTrace.getTrace());
-        } catch (TmfAnalysisException e) {
-            fail();
-        }
-        module2.schedule();
-        assertTrue(module2.waitForCompletion());
-        ITmfStateSystem ssb2 = module2.getStateSystem();
+        try (TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);) {
+            try {
+                module2.setTrace(testTrace.getTrace());
+            } catch (TmfAnalysisException e) {
+                fail();
+            }
+            module2.schedule();
+            assertTrue(module2.waitForCompletion());
+            ITmfStateSystem ssb2 = module2.getStateSystem();
 
-        assertNotNull(ssb2);
-        assertEquals(startTime, ssb2.getStartTime());
-        assertEquals(endTime, ssb2.getCurrentEndTime());
+            assertNotNull(ssb2);
+            assertEquals(startTime, ssb2.getStartTime());
+            assertEquals(endTime, ssb2.getCurrentEndTime());
+        }
     }
 
+    @NonNullByDefault
     private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
 
         private final String htFileName;
@@ -139,7 +146,7 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
         }
 
         @Override
-        public void setTrace(ITmfTrace trace) throws TmfAnalysisException {
+        public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
             if (!(trace instanceof CtfTmfTrace)) {
                 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
             }
@@ -148,7 +155,7 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
 
         @Override
         protected ITmfStateProvider createStateProvider() {
-            return new LttngKernelStateProvider((CtfTmfTrace) getTrace());
+            return new LttngKernelStateProvider(getTrace());
         }
 
         @Override
This page took 0.03262 seconds and 5 git commands to generate.