tmf.core: Add unit tests for state system re-read
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 27 Oct 2016 16:28:02 +0000 (12:28 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 1 Dec 2016 14:50:19 +0000 (09:50 -0500)
This adds a unit test for a state system with full backend where the
results are re-read from a previously existing file.

Change-Id: Iab5fab6c6282f2411d2e4a0d3b0da3824653cb36
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/84036
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/statesystem/StateSystemAnalysisModuleTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/analysis/TestStateSystemModule.java
tmf/org.eclipse.tracecompass.tmf.core/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java

index bb6a25921f3b0d22494bc3c141f81daf10ac9546..98899b2e80448758ddef872c33fd8a1d2e57c32e 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.File;
 import java.util.Map;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.CyclicBarrier;
@@ -23,6 +24,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.tracecompass.tmf.core.statesystem.Messages;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
@@ -273,4 +275,34 @@ public class StateSystemAnalysisModuleTest {
         assertTrue(module.isQueryable(7));
         assertTrue(module.isQueryable(10));
     }
+
+    /**
+     * Test that an analysis with full backend is re-read correctly
+     * @throws TmfAnalysisException Propagates exceptions
+     */
+    @Test
+    public void testReReadFullAnalysis() throws TmfAnalysisException {
+        TestStateSystemModule module = new TestStateSystemModule(true);
+        TestStateSystemModule module2 = new TestStateSystemModule(true);
+        try {
+            ITmfTrace trace = fTrace;
+            assertNotNull(trace);
+            module.setTrace(trace);
+            module2.setTrace(trace);
+
+            // Execute the first module
+            module.schedule();
+            assertTrue(module.waitForCompletion());
+
+            // Execute the second module, it should read the state system file
+            File ssFile = module2.getSsFile();
+            assertNotNull(ssFile);
+            assertTrue(ssFile.exists());
+            module2.schedule();
+            assertTrue(module2.waitForCompletion());
+        } finally {
+            module.dispose();
+            module2.dispose();
+        }
+    }
 }
index fa265303d5efd46a2dea5599c88a3e0fd94f008b..e94d28a68fda3286302cb9f8d9ef154ec546e222 100644 (file)
@@ -14,6 +14,8 @@ package org.eclipse.tracecompass.tmf.tests.stubs.analysis;
 
 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 
+import java.io.File;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
@@ -29,6 +31,24 @@ public class TestStateSystemModule extends TmfStateSystemAnalysisModule {
 
     private @Nullable TestStateSystemProvider fProvider = null;
     private boolean fThrottleEvents = false;
+    private final boolean fOnDisk;
+
+    /**
+     * Constructor
+     */
+    public TestStateSystemModule() {
+        this(false);
+    }
+
+    /**
+     * Constructor specifying the backend type
+     *
+     * @param onDisk <code>true</code> if the state system should be built on disk
+     */
+    public TestStateSystemModule(boolean onDisk) {
+        super();
+        fOnDisk = onDisk;
+    }
 
     @Override
     protected ITmfStateProvider createStateProvider() {
@@ -42,7 +62,7 @@ public class TestStateSystemModule extends TmfStateSystemAnalysisModule {
 
     @Override
     protected StateSystemBackendType getBackendType() {
-        return StateSystemBackendType.INMEM;
+        return fOnDisk ? StateSystemBackendType.FULL : StateSystemBackendType.INMEM;
     }
 
     /**
@@ -78,4 +98,9 @@ public class TestStateSystemModule extends TmfStateSystemAnalysisModule {
         }
     }
 
+    @Override
+    public @Nullable File getSsFile() {
+        return super.getSsFile();
+    }
+
 }
index a7722916a2ac54baf80e3bddd7946c4cf00dbf0f..9d067230eb5bdd2e0afc34cd0c7edf017881d44f 100644 (file)
@@ -63,8 +63,9 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.core;x-friends:="org.eclip
  org.eclipse.tracecompass.tmf.core.trace.text,
  org.eclipse.tracecompass.tmf.core.uml2sd,
  org.eclipse.tracecompass.tmf.core.util
-Import-Package: com.google.common.base,
+Import-Package: com.google.common.annotations,
+ com.google.common.base,
  com.google.common.cache,
  com.google.common.collect,
- com.google.common.hash;version="15.0.0",
+ com.google.common.hash,
  org.apache.commons.io
index dfc25c7f94ee7048cf44740c39040c9f6d5b974f..711fe252a2d512847177a07d47c3124d4ad3f3bf 100644 (file)
@@ -47,6 +47,8 @@ import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
 
+import com.google.common.annotations.VisibleForTesting;
+
 /**
  * Abstract analysis module to generate a state system. It is a base class that
  * can be used as a shortcut by analysis who just need to build a single state
@@ -189,7 +191,14 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
     // TmfAbstractAnalysisModule
     // ------------------------------------------------------------------------
 
-    private @Nullable File getSsFile() {
+    /**
+     * Get the file where to save the results of the analysis
+     *
+     * @return The file to save the results in
+     * @since 2.2
+     */
+    @VisibleForTesting
+    protected @Nullable File getSsFile() {
         ITmfTrace trace = getTrace();
         if (trace == null) {
             return null;
This page took 0.026801 seconds and 5 git commands to generate.