/** ID of the test state system analysis module */
public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.analysis.sstest";
- private TmfTraceStub fTrace;
+ private TmfStateSystemAnalysisModule module;
/**
* Setup test trace
*/
@Before
public void setupTraces() {
- fTrace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace();
+ TmfTraceStub trace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace();
+ TmfSignalManager.deregister(trace);
+ trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null));
+
+ module = (TmfStateSystemAnalysisModule) trace.getAnalysisModule(MODULE_SS);
}
/**
*/
@Test
public void testSsModule() {
- TmfSignalManager.deregister(fTrace);
- fTrace.traceOpened(new TmfTraceOpenedSignal(this, fTrace, null));
-
- TmfStateSystemAnalysisModule module = (TmfStateSystemAnalysisModule) fTrace.getAnalysisModule(MODULE_SS);
- ITmfStateSystem ss = null;
- ss = module.getStateSystem();
+ ITmfStateSystem ss = module.getStateSystem();
assertNull(ss);
module.schedule();
if (module.waitForCompletion(new NullProgressMonitor())) {
}
}
+ /**
+ * Make sure that the state system is initialized after callingĀ
+ * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
+ */
+ @Test
+ public void testInitialization() {
+ assertNull(module.getStateSystem());
+ module.schedule();
+
+ module.waitForInitialization();
+ assertNotNull(module.getStateSystem());
+ }
+
}
import java.io.File;
import java.io.IOException;
import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
private static final String EXTENSION = ".ht"; //$NON-NLS-1$
+ private final CountDownLatch fInitialized = new CountDownLatch(1);
+
@Nullable private ITmfStateSystemBuilder fStateSystem;
@Nullable private ITmfStateProvider fStateProvider;
@Nullable private IStateHistoryBackend fHtBackend;
return fStateSystem;
}
+ /**
+ * Block the calling thread until the analysis module has been initialized.
+ * After this method returns, {@link #getStateSystem()} should not return
+ * null anymore.
+ */
+ public void waitForInitialization() {
+ try {
+ fInitialized.await();
+ } catch (InterruptedException e) {}
+ }
+
// ------------------------------------------------------------------------
// TmfAbstractAnalysisModule
// ------------------------------------------------------------------------
try {
fHtBackend = new HistoryTreeBackend(htFile, version);
fStateSystem = new StateSystem(fHtBackend, false);
+ fInitialized.countDown();
return;
} catch (IOException e) {
/*
fStateProvider = provider;
fRequest = request;
+ /*
+ * The state system object is now created, we can consider this module
+ * "initialized" (components can retrieve it and start doing queries).
+ */
+ fInitialized.countDown();
+
+ /*
+ * Block the executeAnalysis() construction is complete (so that the
+ * progress monitor displays that it is running).
+ */
try {
- fRequest.waitForCompletion();
+ request.waitForCompletion();
} catch (InterruptedException e) {
e.printStackTrace();
}