2016-01-06 62 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的等