Class PerformanceTestCase


  • public class PerformanceTestCase
    extends Object
    A PerformanceTestCase is a convenience class that takes care of managing a PerformanceMeter.

    Here is an example:

     public class MyPerformanceTestCase extends PeformanceTestCase {
    
       public void testMyOperation() {
         for (int i= 0; i < 10; i++) {
           // preparation
           startMeasuring();
           // my operation
           stopMeasuring();
           // clean up
         }
         commitMeasurements();
         assertPerformance();
       }
     }
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.eclipse.test.performance.PerformanceMeter fPerformanceMeter  
      org.junit.rules.TestName name  
    • Constructor Summary

      Constructors 
      Constructor Description
      PerformanceTestCase()
      Constructs a performance test case.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void assertPerformance()
      Asserts default properties of the measurements captured for this test case.
      protected void assertPerformanceInRelativeBand​(org.eclipse.test.performance.Dimension dim, int lowerPercentage, int upperPercentage)
      Asserts that the measurement specified by the given dimension is within a certain range with respect to some reference value.
      protected void commitMeasurements()
      Called exactly once after repeated measurements are done and before their analysis.
      protected void finishMeasurements()
      Finishes measurements: stops measurements commits measurements assertPerformanceInRelativeBand(Dimension.ELAPSED_PROCESS, -100, +10);
      protected static org.eclipse.ui.IWorkbenchPage getActivePage()
      Returns active page.
      protected static org.eclipse.ui.IWorkbenchWindow getActiveWorkbenchWindow()
      Returns active workbench window.
      protected static void joinBackgroudActivities​(int timeOut)
      Waits until all active jobs stopped or fails on timeout
      protected static void runEventQueue()
      Reads an event from the operating system's event queue, dispatches it appropriately until there is potentially no more work to do
      protected static void runEventQueue​(org.eclipse.swt.widgets.Shell shell)  
      protected static void runEventQueue​(org.eclipse.ui.IWorkbenchPart part)
      Reads an event from the operating system's event queue, dispatches it appropriately until there is potentially no more work to do
      void setComment​(int commentKind, String commentText)
      Set a comment for the scenario represented by this TestCase.
      void setUp()
      Overridden to create a default performance meter for this test case.
      protected static void sleep​(int intervalTime)
      Causes the currently executing thread to sleep for the specified number of milliseconds
      protected void startMeasuring()
      Called from within a test case immediately before the code to measure is run.
      protected void stopMeasuring()
      Called from within a test case immediately after the operation to measure.
      void tagAsGlobalSummary​(String shortName, org.eclipse.test.performance.Dimension dimension)
      Mark the scenario of this test case to be included into the global and the component performance summary.
      void tagAsGlobalSummary​(String shortName, org.eclipse.test.performance.Dimension[] dimensions)
      Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance summary.
      void tagAsSummary​(String shortName, org.eclipse.test.performance.Dimension dimension)
      Mark the scenario of this test case to be included into the component performance summary.
      void tagAsSummary​(String shortName, org.eclipse.test.performance.Dimension[] dimensions)
      Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary.
      void tearDown()
      Overridden to dispose of the performance meter.
    • Field Detail

      • name

        public org.junit.rules.TestName name
      • fPerformanceMeter

        protected org.eclipse.test.performance.PerformanceMeter fPerformanceMeter
    • Constructor Detail

      • PerformanceTestCase

        public PerformanceTestCase()
        Constructs a performance test case.
    • Method Detail

      • setUp

        public void setUp()
                   throws Exception
        Overridden to create a default performance meter for this test case.
        Throws:
        Exception
      • tearDown

        public void tearDown()
                      throws Exception
        Overridden to dispose of the performance meter.
        Throws:
        Exception
      • tagAsGlobalSummary

        public void tagAsGlobalSummary​(String shortName,
                                       org.eclipse.test.performance.Dimension dimension)
        Mark the scenario of this test case to be included into the global and the component performance summary. The summary shows the given dimension of the scenario and labels the scenario with the short name.
        Parameters:
        shortName - a short (shorter than 40 characters) descritive name of the scenario
        dimension - the dimension to show in the summary
      • tagAsGlobalSummary

        public void tagAsGlobalSummary​(String shortName,
                                       org.eclipse.test.performance.Dimension[] dimensions)
        Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance summary. The summary shows the given dimensions of the scenario and labels the scenario with the short name.
        Parameters:
        shortName - a short (shorter than 40 characters) descritive name of the scenario
        dimensions - an array of dimensions to show in the summary
      • tagAsSummary

        public void tagAsSummary​(String shortName,
                                 org.eclipse.test.performance.Dimension dimension)
        Mark the scenario of this test case to be included into the component performance summary. The summary shows the given dimension of the scenario and labels the scenario with the short name.
        Parameters:
        shortName - a short (shorter than 40 characters) descritive name of the scenario
        dimension - the dimension to show in the summary
      • tagAsSummary

        public void tagAsSummary​(String shortName,
                                 org.eclipse.test.performance.Dimension[] dimensions)
        Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary. The summary shows the given dimensions of the scenario and labels the scenario with the short name.
        Parameters:
        shortName - a short (shorter than 40 characters) descritive name of the scenario
        dimensions - an array of dimensions to show in the summary
      • setComment

        public void setComment​(int commentKind,
                               String commentText)
        Set a comment for the scenario represented by this TestCase. Currently only comments with a commentKind of EXPLAINS_DEGRADATION_COMMENT are used. Their commentText is shown in a hover of the performance summaries graph if a performance degradation exists.
        Parameters:
        commentKind - kind of comment. Must be EXPLAINS_DEGRADATION_COMMENT to have an effect.
        commentText - the comment (shorter than 400 characters)
      • finishMeasurements

        protected void finishMeasurements()
        Finishes measurements:
        1. stops measurements
        2. commits measurements
        3. assertPerformanceInRelativeBand(Dimension.ELAPSED_PROCESS, -100, +10);
      • startMeasuring

        protected void startMeasuring()
        Called from within a test case immediately before the code to measure is run. It starts capturing of performance data. Must be followed by a call to stopMeasuring() before subsequent calls to this method or commitMeasurements().
        See Also:
        PerformanceMeter.start()
      • stopMeasuring

        protected void stopMeasuring()
        Called from within a test case immediately after the operation to measure. Must be preceded by a call to startMeasuring(), that follows any previous call to this method.
        See Also:
        PerformanceMeter.stop()
      • commitMeasurements

        protected void commitMeasurements()
        Called exactly once after repeated measurements are done and before their analysis. Afterwards startMeasuring() and stopMeasuring() must not be called.
        See Also:
        PerformanceMeter.commit()
      • assertPerformance

        protected void assertPerformance()
        Asserts default properties of the measurements captured for this test case.
        Throws:
        RuntimeException - if the properties do not hold
      • assertPerformanceInRelativeBand

        protected void assertPerformanceInRelativeBand​(org.eclipse.test.performance.Dimension dim,
                                                       int lowerPercentage,
                                                       int upperPercentage)
        Asserts that the measurement specified by the given dimension is within a certain range with respect to some reference value. If the specified dimension isn't available, the call has no effect.
        Parameters:
        dim - the Dimension to check
        lowerPercentage - a negative number indicating the percentage the measured value is allowed to be smaller than some reference value
        upperPercentage - a positive number indicating the percentage the measured value is allowed to be greater than some reference value
        Throws:
        RuntimeException - if the properties do not hold
      • joinBackgroudActivities

        protected static void joinBackgroudActivities​(int timeOut)
                                               throws org.eclipse.core.runtime.CoreException
        Waits until all active jobs stopped or fails on timeout
        Parameters:
        timeOut - wait timeout (minutes)
        Throws:
        org.eclipse.core.runtime.CoreException
      • runEventQueue

        protected static void runEventQueue()
        Reads an event from the operating system's event queue, dispatches it appropriately until there is potentially no more work to do

        NOTE: This method should be executed when workbench already started

      • runEventQueue

        protected static void runEventQueue​(org.eclipse.ui.IWorkbenchPart part)
        Reads an event from the operating system's event queue, dispatches it appropriately until there is potentially no more work to do
      • getActiveWorkbenchWindow

        protected static org.eclipse.ui.IWorkbenchWindow getActiveWorkbenchWindow()
        Returns active workbench window.

        NOTE: This method should be executed when workbench already started

        Returns:
        active workbench window
      • getActivePage

        protected static org.eclipse.ui.IWorkbenchPage getActivePage()
        Returns active page.

        NOTE: This method should be executed when workbench already started

        Returns:
        active workbench window page
      • sleep

        protected static void sleep​(int intervalTime)
        Causes the currently executing thread to sleep for the specified number of milliseconds
        Parameters:
        intervalTime - number of milliseconds to sleep
      • runEventQueue

        protected static void runEventQueue​(org.eclipse.swt.widgets.Shell shell)