tmf.ui: Add a SWTbot condition for XY charts ready
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 20 Oct 2016 14:03:37 +0000 (10:03 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 26 Oct 2016 15:12:56 +0000 (11:12 -0400)
bug 500770

Change-Id: If70437ab08871962415a2b954307b58f24460331
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/83595
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java

index 5559e6db044c5d1b1f2a0d949d8d563d245e493c..c1ecf95e428ac0d1ad9223fae29aea72e4ca820d 100644 (file)
@@ -45,6 +45,7 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.ui.IEditorReference;
 import org.hamcrest.Matcher;
@@ -572,6 +573,44 @@ public final class ConditionHelpers {
         return new TimeGraphIsReadyCondition(view, selectionRange, visibleTime);
     }
 
+    private static class XYViewerIsReadyCondition extends DefaultCondition  {
+
+        private TmfXYChartViewer fViewer;
+        private String fFailureMessage;
+
+        private XYViewerIsReadyCondition(TmfXYChartViewer view) {
+            fViewer = view;
+        }
+
+        @Override
+        public boolean test() throws Exception {
+
+            if (fViewer.isDirty()) {
+                fFailureMessage = "Time graph is dirty";
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String getFailureMessage() {
+            return fFailureMessage;
+        }
+    }
+
+    /**
+     *
+     * Wait until the XY chart viewer is ready. The XY chart viewer is
+     * considered ready when it is not updating.
+     *
+     * @param viewer
+     *            the XY chart viewer
+     * @return ICondition for verification
+     */
+    public static ICondition xyViewerIsReadyCondition(TmfXYChartViewer viewer) {
+        return new XYViewerIsReadyCondition(viewer);
+    }
+
     private static class NumberOfEventsCondition extends DefaultCondition {
 
         private ITmfTrace fTrace;
index 29ca3f9809084fde4b5975eb8e9c384ec9c76860..9511a29d4141df8e475a54e59340c411540757fb 100644 (file)
@@ -24,6 +24,8 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.viewers.TmfTimeViewer;
 import org.swtchart.Chart;
 import org.swtchart.IAxis;
@@ -31,6 +33,8 @@ import org.swtchart.ISeries;
 import org.swtchart.ISeriesSet;
 import org.swtchart.Range;
 
+import com.google.common.annotations.VisibleForTesting;
+
 /**
  * Base class for a XY-Chart based on SWT chart. It provides a methods to define
  * zoom, selection and tool tip providers. It also provides call backs to be
@@ -305,6 +309,32 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
      */
     protected abstract void updateContent();
 
+    /**
+     * Returns whether or not this chart viewer is dirty. The viewer is
+     * considered dirty if it has yet to completely update its model.
+     *
+     * This method is meant to be used by tests in order to know when it is safe
+     * to proceed.
+     *
+     * @return true if the time graph view has yet to completely update its
+     *         model, false otherwise
+     * @since 2.2
+     */
+    @VisibleForTesting
+    public boolean isDirty() {
+        if (getTrace() == null) {
+            return false;
+        }
+
+        TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
+        long startTime = ctx.getWindowRange().getStartTime().toNanos();
+        long endTime = ctx.getWindowRange().getEndTime().toNanos();
+
+        // If the chart viewer hasn't updated all the way to the end of
+        // the window range then it's dirty. A refresh should happen later.
+        return (getWindowStartTime() != startTime || getWindowEndTime() != endTime);
+    }
+
     // ------------------------------------------------------------------------
     // Signal Handler
     // ------------------------------------------------------------------------
index 10db54ba7168a57a9393ef71852f2867650080c9..3030b00e4d384bab7b648c3162259e424caca967 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.logging.Logger;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -72,6 +73,8 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     private UpdateThread fUpdateThread;
 
+    private volatile AtomicInteger fDirty = new AtomicInteger();
+
     /**
      * Constructor
      *
@@ -134,6 +137,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
      */
     protected void reinitialize() {
         fSeriesValues.clear();
+        fDirty.incrementAndGet();
         Thread thread = new Thread() {
             // Don't use TmfUiRefreshHandler (bug 467751)
             @Override
@@ -148,6 +152,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                                 /* Delete the old series */
                                 clearContent();
                                 createSeries();
+                                fDirty.decrementAndGet();
                             }
                         }
                     });
@@ -185,6 +190,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                 public void run() {
                     LOGGER.info(() -> getLogMessage("UpdateDataStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
                     updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+                    fDirty.decrementAndGet();
                     LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             });
@@ -227,6 +233,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     @Override
     protected void updateContent() {
+        fDirty.incrementAndGet();
         getDisplay().asyncExec(new Runnable() {
             @Override
             public void run() {
@@ -438,4 +445,16 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
         super.clearContent();
     }
 
+    @Override
+    public boolean isDirty() {
+        boolean dirty = super.isDirty();
+
+        if (dirty) {
+            return dirty;
+        }
+
+        // Check the specific dirtiness of this view
+        return fDirty.get() != 0;
+    }
+
 }
This page took 0.027686 seconds and 5 git commands to generate.