2016-01-06 60 views
0

公共类CloudDeploymentOptionsCreationWizardPage3ACO扩展WizardPage {如何测试SWT GUI向导用JMeter

class MedianBestChart { 

    JFreeChart    chart; 
    ChartComposite   innerChartComposite; 
    java.awt.Color   awtRedColor; 
    Shape     downTriangleShap; 
    Shape     upTriangleShape; 
    XYPlot     plot; 
    XYLineAndShapeRenderer renderer; 
    XYSeries    bestValsSeries; 
    XYSeries    medianValsSeries; 
    XYSeries    diffValsSeries; 
    XYSeriesCollection  dataset; 

    MedianBestChart(String title, String yAxisText) { 

     this.bestValsSeries = new XYSeries("Best candidate"); 
     this.medianValsSeries = new XYSeries("Median"); 
     this.diffValsSeries = new XYSeries("Diff"); 

     this.dataset = new XYSeriesCollection(); 
     this.dataset.addSeries(this.bestValsSeries); 
     this.dataset.addSeries(this.medianValsSeries); 
     this.dataset.addSeries(this.diffValsSeries); 

     this.awtRedColor = SWTUtils.toAwtColor(SWTResourceManager 
       .getColor(SWT.COLOR_RED)); 
     this.downTriangleShap = ShapeUtilities.createDownTriangle(3); 
     this.upTriangleShape = ShapeUtilities.createUpTriangle(3); 

     this.chart = createChart(title, yAxisText); 

     this.innerChartComposite = new ChartComposite(
       CloudDeploymentOptionsCreationWizardPage3ACO.this.chartParentComposite, 
       SWT.FILL, this.chart, true); 

     // grid data for the composite; 
     final GridData chartCompositeGridData = new GridData(SWT.FILL, // horizontalAlignment; 
       SWT.FILL, // verticalAlignment; 
       true, // grabExcessHorizontalSpace; 
       true); // grabExcessVerticalSpace; 

     chartCompositeGridData.grabExcessHorizontalSpace = true; 
     chartCompositeGridData.grabExcessVerticalSpace = true; 

     this.innerChartComposite.setLayoutData(chartCompositeGridData); 
     this.innerChartComposite.setRangeZoomable(false); 
     this.innerChartComposite.setDomainZoomable(false); 
     this.innerChartComposite.setVisible(true); 

     this.chart.setBorderVisible(false); 

     CloudDeploymentOptionsCreationWizardPage3ACO.this.chartParentComposite 
     .layout(true); 
    } 

    JFreeChart createChart(String title, String yAxisText) { 

     // create the chart... 
     final JFreeChart chart = ChartFactory.createXYLineChart(title, 
       "Nr. candidates", // x 
       // axis 
       // label 
       yAxisText, // y axis label 
       this.dataset, // data 
       PlotOrientation.VERTICAL, true, // include legend 
       false, // tooltips 
       false // urls 
       ); 

     chart.setBackgroundPaint(SWTUtils.toAwtColor(Display.getDefault() 
       .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND))); 

     Font titleFontTmp = chart.getTitle().getFont(); 
     Font chartTitleFont = new Font("Plot title font", 
       titleFontTmp.getStyle(), titleFontTmp.getSize() - 6); 

     chart.getTitle().setFont(chartTitleFont); 

     this.plot = chart.getXYPlot(); 
     this.plot.setBackgroundPaint(java.awt.Color.white); 
     this.plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); 
     this.plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); 

     this.renderer = new XYLineAndShapeRenderer(true, true) { 

      private static final long serialVersionUID = 8963966491796723264L; 

      @Override 
      public LegendItem getLegendItem(int datasetIndex, int series) { 
       if (series != 2) { 
        return super.getLegendItem(datasetIndex, series); 
       } 
       else { 
        return null; 
       } 
      } 

     }; 

     this.renderer.setSeriesLinesVisible(0, true); 

     this.renderer.setSeriesShapesVisible(0, false); 
     this.renderer.setSeriesPaint(0, java.awt.Color.blue); 
     this.renderer.setSeriesLinesVisible(1, true); 

     this.renderer.setSeriesShapesVisible(1, false); 
     this.renderer.setSeriesPaint(1, new java.awt.Color(210, 105, 30)); 

     this.renderer.setSeriesStroke(2, new BasicStroke(3.0f, 
       BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, 
       new float[] { 2.0f, 6.0f }, 0.0f)); 

     this.plot.setRenderer(this.renderer); 

     final NumberAxis domainAxis = (NumberAxis) this.plot 
       .getDomainAxis(); 
     domainAxis 
     .setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 

     final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis(); 
     rangeAxis.setNumberFormatOverride(NumberFormat 
       .getInstance(Locale.US)); 

     return chart; 
    } 

    XYSeries getXYSeries(List<Double> vals, XYSeries series) { 

     series.clear(); 

     for (int i = 0; i < vals.size(); ++i) { 
      series.add(i + 1, vals.get(i)); 
     } 
     return series; 
    } 

    void updateChart(List<Double> bestVals, List<Double> medianVals) { 

     int size = bestVals.size(); 

     this.bestValsSeries = getXYSeries(bestVals, this.bestValsSeries); 
     this.medianValsSeries = getXYSeries(medianVals, 
       this.medianValsSeries); 
     this.diffValsSeries.clear(); 

     if (size > 1) { 
      this.diffValsSeries.add(size, bestVals.get(size - 1)); 
      this.diffValsSeries.add(size, medianVals.get(size - 1)); 
     } 

     this.renderer.setSeriesPaint(2, java.awt.Color.green); 
     this.renderer.setSeriesShape(2, this.upTriangleShape); 

     if (this.dataset.getItemCount(0) > 0) { 
      if (betterThanMedian(this.dataset.getSeries(0), 
        this.dataset.getSeries(1), false)) { 
       this.renderer.setSeriesPaint(2, java.awt.Color.red); 
       this.renderer.setSeriesShape(2, this.downTriangleShap); 
      } 
     } 

     // Refresh chart 
     this.plot.setDataset(this.dataset); 
    } 
} 

private Label        lblLcloudenvironmentval; 
private Label        lblVMsAtStartVal; 
private Label        reconfigRulesVal; 
private Label        lCostVal; 
private Label        lCostBetterThanVal; 
private Label        lMedianResponseTimesVal; 
private Label        lMedianResponseTimesBetterThanVal; 
private Label        lTimeoutsVal; 
private Label        lTimeoutsBetterThanVal; 
private ProgressBar       currentCDOprogressBar; 
private ProgressBar       overallProgressBar; 
private boolean        optimizationStarted; 
private CDOCreationOptimizedAutomaticMethod cdoCreationJob; 
private boolean        saveBestFoundCDO; 
private Label        lblRunning; 
private Label        lblSimulatedCandidates; 
private Label        lRunningVal; 
private Label        lSimulatedCandidatesVal; 
private Date        optimizationStartedDate; 
private Group        grpBestFoundCandidate; 
private Label        lblCurrentCloudDeployment; 
private Label        lblOverallProgress; 
private Button        btnDetailsBestCDO; 
private final Color       swtBlackColor; 
private final Color       swtGreenColor; 
private final Color       swtRedColor; 
private MedianBestChart      costChart; 
private MedianBestChart      responseTimeChart; 
private MedianBestChart      slaViolationsChart; 

private final Job       elapsedTimeUpdaterJob = new Job(
     "Elapsed Time Updater Job") { 
    private volatile boolean cancel = false; 

    @Override 
    protected void canceling() { 
     this.cancel = true; 
    } 

    @Override 
    protected IStatus run(
      IProgressMonitor arg0) { 

     while (true) { 

      Display.getDefault() 
      .asyncExec(
        new Runnable() { 

         @Override 
         public void run() { 

          CloudDeploymentOptionsCreationWizardPage3ACO.this.lRunningVal 
          .setText(Utilities 
            .getElapsedTime(CloudDeploymentOptionsCreationWizardPage3ACO.this.optimizationStartedDate)); 

         } 
        }); 

      try { 
       getThread(); 
       Thread.sleep(1000); 

       if (this.cancel) { 
        return Status.OK_STATUS; 
       } 
      } 
      catch (InterruptedException e) { 
       Utilities 
       .logError(e 
         .getMessage()); 
      } 
     } 
    } 
}; 
private Composite       chartParentComposite; 
private final AbstractHandler    updateChartsHandler = new AbstractHandler() { 

    @Override 
    public Object execute(
      ExecutionEvent ee) 
        throws ExecutionException { 

     Map<String, Pair<List<Double>, List<Double>>> applicationContext = (Map<String, Pair<List<Double>, List<Double>>>) ee 
       .getApplicationContext(); 

     final Pair<List<Double>, List<Double>> costsBestAndMedianVals = applicationContext 
       .get(org.cloudmig.cloudmigxpress.activity.generation.transformation.ga.Messages.CDOEvaluator_lowCostObjective); 
     final Pair<List<Double>, List<Double>> responseTimesBestAndMedianVals = applicationContext 
       .get(org.cloudmig.cloudmigxpress.activity.generation.transformation.ga.Messages.CDOEvaluator_lowResponseTimesObjective); 
     final Pair<List<Double>, List<Double>> nrTimeoutsBestAndMedianVals = applicationContext 
       .get(org.cloudmig.cloudmigxpress.activity.generation.transformation.ga.Messages.CDOEvaluator_lowNrSLAViolationsObjective); 

     Display.getDefault() 
     .asyncExec(
       new Runnable() { 

        @Override 
        public void run() { 
         updateCharts(
           costsBestAndMedianVals, 
           responseTimesBestAndMedianVals, 
           nrTimeoutsBestAndMedianVals); 

        } 
       }); 
     return null; 
    } 
}; 

/** 
* Create the wizard. 
*/ 
public CloudDeploymentOptionsCreationWizardPage3ACO() { 
    super("wizardPage"); 
    setImageDescriptor(ResourceManager 
      .getPluginImageDescriptor("org.cloudmig.cloudmigxpress", 
        "icons/iconfinder_com_1327065738_question-type-one-correct.png")); 
    setTitle("Compute Best Suited Cloud Deployment Option"); 
    setDescription("Step 3 of 3 - Run the cloud deployment optimization process"); 
    this.optimizationStarted = false; 
    this.saveBestFoundCDO = true; 

    this.swtBlackColor = SWTResourceManager.getColor(SWT.COLOR_BLACK); 
    this.swtGreenColor = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN); 
    this.swtRedColor = SWTResourceManager.getColor(SWT.COLOR_RED); 
} 

我已经SWT这是我在这里。提到在我的代码组件是从哪儿用户SWT GUI可以从GUI中选择输入并执行作业。我想单元测试那个作业并测量性能。但是我不知道如何从GUI输入并将其提供给jmeter。或者我们可以在不写jmetersmpler的情况下将jmeter代码绑定到现有的API中。

我在我的两个问题,我想与大家分享: 1)能的JMeter支持SWT GUI测试如果有比你能提供简单的演示 2)如何实现的JMeter在SWT GUI与现有代码以及如何测试它们。

+0

你可能会更好看[SWTBot](http://eclipse.org/swtbot/) –

回答

0

JMeter无法独立测试独立的桌面应用程序。通常,不需要对桌面应用程序进行加载测试,因为它们只能由单个人使用,并且如果应用程序响应时间正常 - 您无需执行任何额外步骤。

但是,如果您的应用程序与后端服务器通信 - 您可能需要测试服务器以检查它是如何处理来自多个并发应用程序实例的负载的。在这种情况下,这里的选项:

  • 如果应用程序使用HTTP或HTTPS与后端服务器进行通信 - 你可以捕获通过JMeter的HTTP(S) Test Script Recorder的请求,然后重播它们
  • 如果正在使用其它协议 - 你可以检查可用JMeter SamplersJMeter Plugins,看是否被支持的协议,并使用相关采样
  • 还有几个选项,通过下面的测试元素做一些编码:

    • 如果你有JUnit测试 - 你可以重复使用,并在多线程的方式通过JUnit Request Sampler
    • 运行它们也有可能使用脚本语言之一,其符合JSR-223规格如JavaScript,JEXL,BeanShell的等