/*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
- *
+ * Copyright (c) 2011, 2013 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
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Bernd Hufmann - Initial API and implementation
*******************************************************************************/
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
import org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
/**
* Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
* utility methods for interacting with the loader/view.
+ *
+ * @author Bernd Hufmann
*/
public class Uml2SDTestFacility {
private SDView fSdView;
private TmfTraceStub fTrace = null;
private TmfUml2SDTestTrace fParser = null;
- private TmfExperiment<TmfEvent> fExperiment = null;
+ private TmfExperiment fExperiment = null;
- private boolean fIsInitialized = false;
+ private volatile boolean fIsInitialized = false;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @return the singleton instance.
+ */
public synchronized static Uml2SDTestFacility getInstance() {
if (fInstance == null) {
fInstance = new Uml2SDTestFacility();
view = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
- .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
+ .findView("org.eclipse.ui.internal.introview");
if (view != null) {
PlatformUI.getWorkbench()
view = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
- .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
+ .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView");
} catch (final PartInitException e) {
throw new RuntimeException(e);
fSdView = (SDView) view;
fLoader = (TmfUml2SDSyncLoader)LoadersManager.getInstance().createLoader(
- "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView); //$NON-NLS-1$
+ "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView);
delay(3000);
fIsInitialized = true;
}
- private TmfTraceStub setupTrace(final ITmfEventParser<TmfEvent> parser) {
+ private TmfTraceStub setupTrace(final ITmfEventParser parser) {
try {
// Create test trace object
- final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
+ final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null);
final File test = new File(FileLocator.toFileURL(location).toURI());
- return new TmfTraceStub(test.getPath(), 500, true, parser, null);
+ return new TmfTraceStub(test.getPath(), 500, true, parser);
} catch (final TmfTraceException e) {
e.printStackTrace();
throw new RuntimeException(e);
*/
public void dispose() {
if (fIsInitialized) {
- fExperiment.dispose();
+ ITmfTrace trace = fTrace;
+ TmfExperiment experiment = fExperiment;
+ if (trace == null || experiment == null) {
+ throw new IllegalStateException();
+ }
+
+ trace.broadcast(new TmfTraceClosedSignal(this, experiment));
+ experiment.dispose();
// Wait for all Eclipse jobs to finish
waitForJobs();
/**
* Sleeps current thread or GUI thread for a given time.
- * @param waitTimeMillis
+ * @param waitTimeMillis time in milliseconds to wait
*/
public void delay(final long waitTimeMillis) {
final Display display = Display.getCurrent();
final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
while(System.currentTimeMillis() < endTimeMillis) {
if (!display.readAndDispatch()) {
- display.sleep();
+ // We do not use Display.sleep because it might never wake up
+ // if there is no user interaction
+ try {
+ Thread.sleep(Math.min(waitTimeMillis, 10));
+ } catch (final InterruptedException e) {
+ // Ignored
+ }
}
display.update();
}
/**
* @return current experiment.
*/
- public TmfExperiment<TmfEvent> getExperiment() {
+ public TmfExperiment getExperiment() {
return fExperiment;
}
}
/**
- * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
+ * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader.Uml2SDTestFacility#selectExperiment(boolean)
*/
public void selectExperiment() {
this.selectExperiment(true);
* Selects the experiment.
* @param wait true to wait for indexing to finish else false
*/
- @SuppressWarnings({ "rawtypes", "unchecked" })
public void selectExperiment(final boolean wait) {
fParser = new TmfUml2SDTestTrace();
fTrace = setupTrace(fParser);
fParser.setTrace(fTrace);
-// fTrace = setupTrace(fParser);
-
final ITmfTrace traces[] = new ITmfTrace[1];
traces[0] = fTrace;
- fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, "TestExperiment", traces); //$NON-NLS-1$
- fTrace.broadcast(new TmfExperimentSelectedSignal<TmfEvent>(this, fExperiment));
+ fExperiment = new TmfExperiment(ITmfEvent.class, "TestExperiment", traces) {
+ @Override
+ protected ITmfTraceIndexer createIndexer(int interval) {
+ return new TmfCheckpointIndexer(this, interval);
+ }
+ };
+ fTrace.broadcast(new TmfTraceOpenedSignal(this, fExperiment, null));
+ fTrace.broadcast(new TmfTraceSelectedSignal(this, fExperiment));
if (wait) {
while (fExperiment.getNbEvents() == 0) {
delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
* Disposes the experiment.
*/
public void disposeExperiment() {
- fExperiment.dispose();
+ ITmfTrace trace = fTrace;
+ TmfExperiment experiment = fExperiment;
+ if (trace == null || experiment == null) {
+ throw new IllegalStateException();
+ }
+ trace.broadcast(new TmfTraceClosedSignal(this, experiment));
+ experiment.dispose();
delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
}
*/
public void createFilterCriteria() {
// Create Filter Criteria and save tme
- final List<FilterCriteria> filterToSave = new ArrayList<FilterCriteria>();
+ final List<FilterCriteria> filterToSave = new ArrayList<>();
Criteria criteria = new Criteria();
criteria.setLifeLineSelected(true);
criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
criteria = new Criteria();
criteria.setSyncMessageSelected(true);
- criteria.setExpression("BALL_.*"); //$NON-NLS-1$
+ criteria.setExpression("BALL_.*");
filterToSave.add(new FilterCriteria(criteria, true, false));
FilterListDialog.saveFiltersCriteria(filterToSave);
}