import java.io.File;
import java.lang.reflect.InvocationTargetException;
-import java.util.concurrent.TimeoutException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
*/
public class ProjectModelTestData {
- /* Maximum number of thread delays the main thread will do before timing out */
- private static final int DELAY_COUNTER = 1000;
- /* Default delay time when having the main thread sleep. */
- private static final long DEFAULT_DELAY = 500;
-
/** Default test project name */
public static final String PROJECT_NAME = "Test_Project";
* longer delays in those cases, it is preferable to use the
* {@link ProjectModelTestData#delayThread(long)} instead.
*
- * Timeout is DELAY_COUNTER * DEFAULT_DELAY ms
- *
* @param projectElement
* The trace element we are waiting for. If the element if not of
* type TmfTraceElement, the thread is delayed only once.
- * @throws TimeoutException
+ * @throws WaitTimeoutException
* If after the maximum number of delays the trace is still
* null, we throw a timeout exception, the trace has not opened.
*/
- public static void delayUntilTraceOpened(final ITmfProjectModelElement projectElement) throws TimeoutException {
+ public static void delayUntilTraceOpened(final ITmfProjectModelElement projectElement) throws WaitTimeoutException {
if (projectElement instanceof TmfCommonProjectElement) {
TmfCommonProjectElement traceElement = (TmfCommonProjectElement) projectElement;
- final long deadline = System.nanoTime() + (DELAY_COUNTER * DEFAULT_DELAY * 1000000L);
- do {
- delayThread(DEFAULT_DELAY);
- if (traceElement.getTrace() != null) {
- return;
+ WaitUtils.waitUntil(new IWaitCondition() {
+ @Override
+ public boolean test() throws Exception {
+ return traceElement.getTrace() != null;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Timeout while waiting for " + traceElement;
}
- } while (System.nanoTime() < deadline);
- throw new TimeoutException("Timeout while waiting for " + traceElement);
+ });
}
- delayThread(DEFAULT_DELAY);
- }
+ }
}
import java.util.List;
import java.util.Optional;
-import java.util.concurrent.TimeoutException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfViewsElement;
import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
import org.junit.After;
import org.junit.Before;
try {
ProjectModelTestData.delayUntilTraceOpened(traceElement);
- } catch (TimeoutException e) {
+ } catch (WaitTimeoutException e) {
fail("The analysis parent did not open in a reasonable time");
}
ITmfTrace trace = traceElement.getTrace();
import static org.junit.Assert.fail;
import java.util.List;
-import java.util.concurrent.TimeoutException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.IWaitCondition;
import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbench;
analysis.activateParentTrace();
try {
ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
- } catch (TimeoutException e) {
+ } catch (WaitTimeoutException e) {
fail("The analysis parent did not open in a reasonable time");
}
/* Make sure the output list is not empty */
+ WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1));
List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
assertFalse(outputList.isEmpty());
boolean found = false;
analysis.activateParentTrace();
try {
ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
- } catch (TimeoutException e) {
+ } catch (WaitTimeoutException e) {
fail("The analysis parent did not open in a reasonable time");
}
+ WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1));
List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
assertFalse(outputList.isEmpty());
view = activePage.findView(TestAnalysisUi.VIEW_ID);
assertNotNull(view);
}
+
+ private static final class ConditionTraceChildrenElements implements IWaitCondition {
+ private final ITmfProjectModelElement fProjectElement;
+ private int fCurNumChildren;
+ private int fExpectedChildNum;
+
+ private ConditionTraceChildrenElements(ITmfProjectModelElement projectElement, int childNum) {
+ fProjectElement = projectElement;
+ fExpectedChildNum = childNum;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ fCurNumChildren = fProjectElement.getChildren().size();
+ return fCurNumChildren == fExpectedChildNum;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Timeout while waiting for " + fProjectElement + " to have number of children. Expected: " + fExpectedChildNum + " Actual: " + fCurNumChildren;
+ }
+ }
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.concurrent.TimeoutException;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
+import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/* Give the trace a chance to open */
try {
ProjectModelTestData.delayUntilTraceOpened(traceElement);
- } catch (TimeoutException e) {
+ } catch (WaitTimeoutException e) {
fail("The trace did not open in a reasonable delay");
}
TmfOpenTraceHelper.openTraceFromElement(traceElement);
try {
ProjectModelTestData.delayUntilTraceOpened(traceElement);
- } catch (TimeoutException e) {
+ } catch (WaitTimeoutException e) {
fail("The trace did not open in a reasonable delay");
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.concurrent.TimeoutException;
-
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
}
TmfOpenTraceHelper.openTraceFromElement(fExperiment);
- try {
- ProjectModelTestData.delayUntilTraceOpened(fExperiment);
- } catch (TimeoutException e1) {
- fail (e1.getMessage());
- }
+ ProjectModelTestData.delayUntilTraceOpened(fExperiment);
ITmfTrace trace = fExperiment.getTrace();
assertTrue(trace instanceof TmfExperimentStub);
public void testNoExperimentTypeChildren() {
TmfOpenTraceHelper.openTraceFromElement(fExperiment);
- try {
- ProjectModelTestData.delayUntilTraceOpened(fExperiment);
- } catch (TimeoutException e1) {
- fail (e1.getMessage());
- }
+ ProjectModelTestData.delayUntilTraceOpened(fExperiment);
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();