diff options
| author | Phil Harvey <philharveyonline@apache.org> | 2013-02-23 15:17:42 +0000 |
|---|---|---|
| committer | Phil Harvey <philharveyonline@apache.org> | 2013-02-23 15:17:42 +0000 |
| commit | ee8380c8f9089e396c0fcaa12ebc3d16aab8f25e (patch) | |
| tree | 9f5500f581373c914a707aeafb8cf0c823d70cbb /qpid/java/perftests | |
| parent | 35a5dcbeab7bd020dad9ad22c893b799341c444c (diff) | |
| download | qpid-python-ee8380c8f9089e396c0fcaa12ebc3d16aab8f25e.tar.gz | |
QPID-4597: Java performance tests now support visualisation of timeseries data.
Refactored ChartBuilder hierarchy to reduce duplication, and renamed several classes to make them more intuitive.
Added timeseries chart definitions in perftests/etc/c/timeseries/.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1449342 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests')
32 files changed, 885 insertions, 215 deletions
diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef new file mode 100644 index 0000000000..e77f7b4eff --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Large transient messages +chartDescription=1P 1C, transient, auto-ack, with message payload 65536 bytes. + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Message Size - 1P-1C - TRANSIENT' and payloadSizeB = 65536 +series.1.colourName=red +series.1.legend=Throughput diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef new file mode 100644 index 0000000000..ffcf8c26b8 --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Large persistent messages +chartDescription=1P 1C, persistent, auto-ack, with message payload 65536 bytes. + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Message Size - 1P-1C - PERSISTENT' and payloadSizeB = 65536 +series.1.colourName=red +series.1.legend=Throughput diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef new file mode 100644 index 0000000000..ba01d4b7ad --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Multiple producers and consumers - auto ack +chartSubtitle=Persistent 1KB messages +chartDescription=10 P/Cs, persistent, auto-ack, with message payload 1KB. + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Varying number of participants: 10 consumers - 10 producers - PERSISTENT' +series.1.colourName=red +series.1.legend=Throughput
\ No newline at end of file diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef new file mode 100644 index 0000000000..f755bf4a5b --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Transactions +chartSubtitle=Persistent 1KB messages +chartDescription=1P 1C, persistent, transacted with message payload 1KB with batch size 1 for both P and C + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Batch Size 1-1 - PERSISTENT' +series.1.colourName=red +series.1.legend=Throughput
\ No newline at end of file diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef new file mode 100644 index 0000000000..ca390f8226 --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Transactions with large batches +chartSubtitle=Persistent 1KB messages +chartDescription=1P 1C, persistent, transacted with message payload 1KB with batch size 100 for both P and C + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Batch Size 100-100 - PERSISTENT' +series.1.colourName=red +series.1.legend=Throughput diff --git a/qpid/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef b/qpid/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef new file mode 100644 index 0000000000..6dce3a1a77 --- /dev/null +++ b/qpid/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +chartType=TIMELINE +chartTitle=Sorted queue +chartSubtitle=Persistent 1KB messages +chartDescription=1P 1C, persistent, auto-ack with message payload 1KB. Sorted queue with 160,000 random keys + +xAxisTitle=Date +yAxisTitle=Throughput (KB/s) + +series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'queue-type:sorted-queue' +series.1.colourName=red +series.1.legend=Throughput
\ No newline at end of file diff --git a/qpid/java/perftests/etc/visualisation-timeseries.sh b/qpid/java/perftests/etc/visualisation-timeseries.sh new file mode 100755 index 0000000000..32db2cb010 --- /dev/null +++ b/qpid/java/perftests/etc/visualisation-timeseries.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Runs the visualisation tool against perftest output assumed to be in a Derby database in the current directory + +BASE_DIR=`dirname $0` + +# Uncomment to read perftest data from a Derby database +JDBC_URL=jdbcUrl=jdbc:derby:perftestResultsDb +JDBC_DRIVER=jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver + +java -cp "${BASE_DIR}:${BASE_DIR}/../../build/lib/*" \ + -Djava.awt.headless=true -Dlog4j.configuration=file:log4j.properties \ + org.apache.qpid.disttest.charting.ChartingUtil \ + chart-defs=chartdefs/timeseries \ + ${JDBC_DRIVER} ${JDBC_URL} diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java index ed09f4a77e..5a77f22148 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java @@ -21,5 +21,5 @@ package org.apache.qpid.disttest.charting; public enum ChartType { - LINE, LINE3D, BAR, BAR3D, XYLINE, STATISTICAL_BAR + LINE, LINE3D, BAR, BAR3D, XYLINE, TIMELINE, STATISTICAL_BAR } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java index 491bb1c67d..b10fd477ed 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java @@ -36,7 +36,7 @@ public class BarChart3DBuilder extends CategoryDataSetBasedChartBuilder } @Override - public JFreeChart createChartImpl(String title, String xAxisTitle, + protected JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java index b5c6a38067..7705ef5d3a 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java @@ -35,7 +35,7 @@ public class BarChartBuilder extends CategoryDataSetBasedChartBuilder } @Override - public JFreeChart createChartImpl(String title, String xAxisTitle, + protected JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java index 700d7fa0ce..9cadf0ec3c 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java @@ -19,13 +19,13 @@ */ package org.apache.qpid.disttest.charting.chartbuilder; -import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; -import java.util.List; import org.apache.qpid.disttest.charting.definition.ChartingDefinition; -import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; +import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.title.ShortTextTitle; @@ -33,50 +33,67 @@ import org.jfree.data.general.Dataset; public abstract class BaseChartBuilder implements ChartBuilder { - private static final GradientPaint BLUE_GRADIENT = new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue); + static final GradientPaint BLUE_GRADIENT = new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue); - public void addCommonChartAttributes(JFreeChart chart, ChartingDefinition chartingDefinition) + private SeriesPainter _seriesPainter = new SeriesPainter(); + + private final SeriesBuilder _seriesBuilder; + + protected BaseChartBuilder(SeriesBuilder seriesBuilder) { - addSubtitle(chart, chartingDefinition); - setBackgroundColour(chart); + _seriesBuilder = seriesBuilder; } - protected void addSeriesAttributes(JFreeChart targetChart, List<SeriesDefinition> series, SeriesStrokeAndPaintApplier strokeAndPaintApplier) + @Override + public JFreeChart buildChart(ChartingDefinition chartingDefinition) { - for (int i = 0; i < series.size(); i++) - { - SeriesDefinition seriesDefinition = series.get(i); - if (seriesDefinition.getSeriesColourName() != null) - { - strokeAndPaintApplier.setSeriesPaint(i, ColorFactory.toColour(seriesDefinition.getSeriesColourName()), targetChart); - } - if (seriesDefinition.getStrokeWidth() != null) - { - // Negative width used to signify dashed - boolean dashed = seriesDefinition.getStrokeWidth() < 0; - float width = Math.abs(seriesDefinition.getStrokeWidth()); - BasicStroke stroke = buildStrokeOfWidth(width, dashed); - strokeAndPaintApplier.setSeriesStroke(i, stroke, targetChart); - } - } + _seriesBuilder.setDatasetHolder(newDatasetHolder()); + Dataset dataset = _seriesBuilder.build(chartingDefinition.getSeriesDefinitions()); + + JFreeChart chart = createChart(chartingDefinition, dataset); + return chart; } - public abstract JFreeChart createChartImpl(String title, String xAxisTitle, - String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, - boolean showUrls); - private BasicStroke buildStrokeOfWidth(float width, boolean dashed) + /** + * return a holder of an empty dataset suitable for use with the chart type + * returned by {@link #createChartImpl(String, String, String, Dataset, PlotOrientation, boolean, boolean, boolean)}. + */ + protected abstract DatasetHolder newDatasetHolder(); + + /** + * Create a chart with the supplied parameters. + * + * For ease of implementation, the signature is intentionally similar + * to {@link ChartFactory}'s factory methods. + */ + protected abstract JFreeChart createChartImpl( + String title, String xAxisTitle, String yAxisTitle, + final Dataset dataset, + PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls); + + /** + * Create a {@link SeriesStrokeAndPaintApplier} that will be used to format a chart + */ + protected abstract SeriesStrokeAndPaintApplier newStrokeAndPaintApplier(); + + + private JFreeChart createChart(ChartingDefinition chartingDefinition, final Dataset dataset) { - final BasicStroke stroke; - if (dashed) - { - stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {5.0f, 3.0f}, 0.0f); - } - else - { - stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); - } - return stroke; + String title = chartingDefinition.getChartTitle(); + String xAxisTitle = chartingDefinition.getXAxisTitle(); + String yAxisTitle = chartingDefinition.getYAxisTitle(); + + final JFreeChart chart = createChartImpl( + title, xAxisTitle, yAxisTitle, + dataset, + PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS); + + addSubtitle(chart, chartingDefinition); + chart.setBackgroundPaint(BLUE_GRADIENT); + _seriesPainter.applySeriesAppearance(chart, chartingDefinition.getSeriesDefinitions(), newStrokeAndPaintApplier()); + + return chart; } private void addSubtitle(JFreeChart chart, ChartingDefinition chartingDefinition) @@ -87,9 +104,9 @@ public abstract class BaseChartBuilder implements ChartBuilder } } - private void setBackgroundColour(JFreeChart chart) + void setSeriesPainter(SeriesPainter seriesPainter) { - chart.setBackgroundPaint(BLUE_GRADIENT); + _seriesPainter = seriesPainter; } } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java index ffa85d5c50..0d08fd8ad1 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java @@ -20,44 +20,36 @@ package org.apache.qpid.disttest.charting.chartbuilder; -import java.awt.Color; -import java.awt.Stroke; - -import org.apache.qpid.disttest.charting.definition.ChartingDefinition; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; -import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.data.general.Dataset; public abstract class CategoryDataSetBasedChartBuilder extends BaseChartBuilder { - private final SeriesBuilder _seriesBuilder; - public CategoryDataSetBasedChartBuilder(SeriesBuilder seriesBuilder) { - _seriesBuilder = seriesBuilder; + super(seriesBuilder); } @Override - public JFreeChart buildChart(ChartingDefinition chartingDefinition) + protected DatasetHolder newDatasetHolder() { - String title = chartingDefinition.getChartTitle(); - String xAxisTitle = chartingDefinition.getXAxisTitle(); - String yAxisTitle = chartingDefinition.getYAxisTitle(); - - final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - - _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback() + return new DatasetHolder() { + final private DefaultCategoryDataset _dataset = new DefaultCategoryDataset(); + @Override public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row) { String x = row.dimensionAsString(0); double y = row.dimensionAsDouble(1); - dataset.addValue(y, seriesDefinition.getSeriesLegend(), x); + _dataset.addValue(y, seriesDefinition.getSeriesLegend(), x); } @Override @@ -78,31 +70,27 @@ public abstract class CategoryDataSetBasedChartBuilder extends BaseChartBuilder return 2; } - }); - - _seriesBuilder.build(chartingDefinition.getSeries()); - - final JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle, - dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS); - - chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); - - addCommonChartAttributes(chart, chartingDefinition); - addSeriesAttributes(chart, chartingDefinition.getSeries(), new SeriesStrokeAndPaintApplier() - { @Override - public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart) + public Dataset getPopulatedDataset() { - targetChart.getCategoryPlot().getRenderer().setSeriesStroke(seriesIndex, stroke); + return _dataset; } + }; + } - @Override - public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart) - { - targetChart.getCategoryPlot().getRenderer().setSeriesPaint(seriesIndex, colour); - } - }); + @Override + protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier() + { + return new CategoryStrokeAndPaintApplier(); + } + @Override + protected final JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) + { + JFreeChart chart = createCategoryChart(title, xAxisTitle, yAxisTitle, dataset, plotOrientation, showLegend, showToolTips, showUrls); + chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); return chart; } + + protected abstract JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls); } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java new file mode 100644 index 0000000000..cbf5cbe515 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java @@ -0,0 +1,41 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.disttest.charting.chartbuilder; + +import java.awt.Color; +import java.awt.Stroke; + +import org.jfree.chart.JFreeChart; + +class CategoryStrokeAndPaintApplier implements SeriesStrokeAndPaintApplier +{ + @Override + public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart) + { + targetChart.getCategoryPlot().getRenderer().setSeriesStroke(seriesIndex, stroke); + } + + @Override + public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart) + { + targetChart.getCategoryPlot().getRenderer().setSeriesPaint(seriesIndex, colour); + } +}
\ No newline at end of file diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java index f4e11a2c4d..63a0573676 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java @@ -39,8 +39,10 @@ public class ChartBuilderFactory return new BarChart3DBuilder(seriesBuilder); case XYLINE: return new XYLineChartBuilder(seriesBuilder); + case TIMELINE: + return new TimeSeriesLineChartBuilder(seriesBuilder); case STATISTICAL_BAR: - return new StatisticalBarCharBuilder(seriesBuilder); + return new StatisticalBarChartBuilder(seriesBuilder); default: throw new IllegalArgumentException("Unknown chart type " + chartType); } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java index 27fff12da0..b92a25f5ac 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java @@ -34,7 +34,7 @@ public class LineChart3DBuilder extends CategoryDataSetBasedChartBuilder } @Override - public JFreeChart createChartImpl(String title, String xAxisTitle, + protected JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java index 40f3a09b6b..3f5b18acda 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java @@ -35,7 +35,7 @@ public class LineChartBuilder extends CategoryDataSetBasedChartBuilder } @Override - public JFreeChart createChartImpl(String title, String xAxisTitle, + protected JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java new file mode 100644 index 0000000000..854635dc87 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.disttest.charting.chartbuilder; + +import java.awt.BasicStroke; +import java.util.List; + +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.jfree.chart.JFreeChart; + +public class SeriesPainter +{ + public void applySeriesAppearance(JFreeChart chart, List<SeriesDefinition> seriesDefinitions, SeriesStrokeAndPaintApplier strokeAndPaintApplier) + { + for (int i = 0; i < seriesDefinitions.size(); i++) + { + SeriesDefinition seriesDefinition = seriesDefinitions.get(i); + if (seriesDefinition.getSeriesColourName() != null) + { + strokeAndPaintApplier.setSeriesPaint(i, ColorFactory.toColour(seriesDefinition.getSeriesColourName()), chart); + } + if (seriesDefinition.getStrokeWidth() != null) + { + // Negative width used to signify dashed + boolean dashed = seriesDefinition.getStrokeWidth() < 0; + float width = Math.abs(seriesDefinition.getStrokeWidth()); + BasicStroke stroke = buildStrokeOfWidth(width, dashed); + strokeAndPaintApplier.setSeriesStroke(i, stroke, chart); + } + } + } + + private BasicStroke buildStrokeOfWidth(float width, boolean dashed) + { + final BasicStroke stroke; + if (dashed) + { + stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {5.0f, 3.0f}, 0.0f); + } + else + { + stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + } + return stroke; + } +} diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java index 61acc8cfdf..c5ad2d7dad 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java @@ -20,14 +20,11 @@ */ package org.apache.qpid.disttest.charting.chartbuilder; -import java.awt.Color; import java.awt.Font; -import java.awt.Stroke; -import org.apache.qpid.disttest.charting.definition.ChartingDefinition; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; -import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; @@ -42,33 +39,27 @@ import org.jfree.data.general.Dataset; import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; import org.jfree.data.statistics.StatisticalCategoryDataset; -public class StatisticalBarCharBuilder extends BaseChartBuilder +public class StatisticalBarChartBuilder extends BaseChartBuilder { - private final SeriesBuilder _seriesBuilder; - - public StatisticalBarCharBuilder(SeriesBuilder seriesBuilder) + public StatisticalBarChartBuilder(SeriesBuilder seriesBuilder) { - _seriesBuilder = seriesBuilder; + super(seriesBuilder); } @Override - public JFreeChart buildChart(ChartingDefinition chartingDefinition) + protected DatasetHolder newDatasetHolder() { - String title = chartingDefinition.getChartTitle(); - String xAxisTitle = chartingDefinition.getXAxisTitle(); - String yAxisTitle = chartingDefinition.getYAxisTitle(); - - final DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); - - _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback() + return new DatasetHolder() { + private final DefaultStatisticalCategoryDataset _dataset = new DefaultStatisticalCategoryDataset(); + @Override public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row) { String x = row.dimensionAsString(0); double mean = row.dimensionAsDouble(1); double stdDev = row.dimensionAsDouble(2); - dataset.add(mean, stdDev, seriesDefinition.getSeriesLegend(), x); + _dataset.add(mean, stdDev, seriesDefinition.getSeriesLegend(), x); } @Override @@ -89,32 +80,18 @@ public class StatisticalBarCharBuilder extends BaseChartBuilder return 3; } - }); - - _seriesBuilder.build(chartingDefinition.getSeries()); - - final JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle, dataset, PLOT_ORIENTATION, SHOW_LEGEND, - SHOW_TOOL_TIPS, SHOW_URLS); - - chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); - - addCommonChartAttributes(chart, chartingDefinition); - addSeriesAttributes(chart, chartingDefinition.getSeries(), new SeriesStrokeAndPaintApplier() - { @Override - public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart) + public Dataset getPopulatedDataset() { - targetChart.getCategoryPlot().getRenderer().setSeriesStroke(seriesIndex, stroke); + return _dataset; } + }; + } - @Override - public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart) - { - targetChart.getCategoryPlot().getRenderer().setSeriesPaint(seriesIndex, colour); - } - }); - - return chart; + @Override + protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier() + { + return new CategoryStrokeAndPaintApplier(); } @Override @@ -128,6 +105,9 @@ public class StatisticalBarCharBuilder extends BaseChartBuilder CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true); + + chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); + return chart; } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java new file mode 100644 index 0000000000..803a098dfa --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.disttest.charting.chartbuilder; + +import java.util.Date; + +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; +import org.jfree.data.general.Dataset; +import org.jfree.data.time.Millisecond; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + +class TimeSeriesHolder implements DatasetHolder +{ + private final TimeSeriesCollection _timeSeriesCollection = new TimeSeriesCollection(); + private TimeSeries _timeSeries; + + @Override + public void beginSeries(SeriesDefinition seriesDefinition) + { + _timeSeries = new TimeSeries(seriesDefinition.getSeriesLegend()); + } + + @Override + public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row) + { + Date x = row.dimensionAsDate(0); + double y = row.dimensionAsDouble(1); + RegularTimePeriod jfreeChartDate = new Millisecond(x); + _timeSeries.add(jfreeChartDate, y); + } + + @Override + public void endSeries(SeriesDefinition seriesDefinition) + { + _timeSeriesCollection.addSeries(_timeSeries); + } + + @Override + public int getNumberOfDimensions() + { + return 2; + } + + @Override + public Dataset getPopulatedDataset() + { + return _timeSeriesCollection; + } +}
\ No newline at end of file diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java new file mode 100644 index 0000000000..7249ae6332 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.disttest.charting.chartbuilder; + +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.general.Dataset; +import org.jfree.data.xy.XYDataset; + +public class TimeSeriesLineChartBuilder extends XYDataSetBasedChartBuilder +{ + public TimeSeriesLineChartBuilder(SeriesBuilder seriesBuilder) + { + super(seriesBuilder); + } + + @Override + protected DatasetHolder newDatasetHolder() + { + return new TimeSeriesHolder(); + } + + @Override + public JFreeChart createChartImpl(String title, String xAxisTitle, + String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, + boolean showLegend, boolean showToolTips, boolean showUrls) + { + JFreeChart chart = ChartFactory.createTimeSeriesChart( + title, + xAxisTitle, + yAxisTitle, + (XYDataset)dataset, + showLegend, + showToolTips, + showUrls); + + return chart; + } +} diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java index 46b6ac6fab..575712f06c 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java @@ -25,34 +25,28 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.apache.qpid.disttest.charting.definition.ChartingDefinition; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; -import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; import org.jfree.chart.JFreeChart; +import org.jfree.data.general.Dataset; import org.jfree.data.xy.DefaultXYDataset; public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder { - private final SeriesBuilder _seriesBuilder; - public XYDataSetBasedChartBuilder(SeriesBuilder seriesBuilder) { - this._seriesBuilder = seriesBuilder; + super(seriesBuilder); } @Override - public JFreeChart buildChart(ChartingDefinition chartingDefinition) + protected DatasetHolder newDatasetHolder() { - String title = chartingDefinition.getChartTitle(); - String xAxisTitle = chartingDefinition.getXAxisTitle(); - String yAxisTitle = chartingDefinition.getYAxisTitle(); - - final DefaultXYDataset dataset = new DefaultXYDataset(); - _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback() + return new DatasetHolder() { + private final DefaultXYDataset _dataset = new DefaultXYDataset(); private List<Double[]> _xyPairs = null; @Override @@ -69,12 +63,11 @@ public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder _xyPairs.add(new Double[] {x, y}); } - @Override public void endSeries(SeriesDefinition seriesDefinition) { double[][] seriesData = listToSeriesDataArray(); - dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData); + _dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData); } @Override @@ -93,18 +86,22 @@ public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder seriesData[0][i] = xyPair[0]; seriesData[1][i] = xyPair[1]; i++; - } + } return seriesData; } - }); - _seriesBuilder.build(chartingDefinition.getSeries()); - - final JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle, - dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS); + @Override + public Dataset getPopulatedDataset() + { + return _dataset; + } + }; + } - addCommonChartAttributes(chart, chartingDefinition); - addSeriesAttributes(chart, chartingDefinition.getSeries(), new SeriesStrokeAndPaintApplier() + @Override + protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier() + { + return new SeriesStrokeAndPaintApplier() { @Override public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart) @@ -117,8 +114,6 @@ public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder { targetChart.getXYPlot().getRenderer().setSeriesPaint(seriesIndex, colour); } - }); - - return chart; + }; } } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java index 6bef7c313e..bfe47e598e 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java @@ -89,7 +89,7 @@ public class ChartingDefinition return _chartType; } - public List<SeriesDefinition> getSeries() + public List<SeriesDefinition> getSeriesDefinitions() { return Collections.unmodifiableList(_seriesDefinitions); } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java index c9c35d26b4..14fd50facc 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java @@ -20,12 +20,18 @@ package org.apache.qpid.disttest.charting.seriesbuilder; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.jfree.data.general.Dataset; -public interface SeriesBuilderCallback +/** + * Accepts data in the form of {@link SeriesDefinition}s and {@link SeriesRow}s, + * and returns it as a {@link Dataset} for use by a JFreeChart chart. + */ +public interface DatasetHolder { - public void beginSeries(SeriesDefinition seriesDefinition); + int getNumberOfDimensions(); + void beginSeries(SeriesDefinition seriesDefinition); + void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row); + void endSeries(SeriesDefinition seriesDefinition); - public int getNumberOfDimensions(); - public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row); - public void endSeries(SeriesDefinition seriesDefinition); + Dataset getPopulatedDataset(); } diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java index 525d29151a..180aa54c6d 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java @@ -31,6 +31,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.apache.qpid.disttest.charting.ChartingException; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.jfree.data.general.Dataset; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +43,7 @@ public class JdbcSeriesBuilder implements SeriesBuilder { private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSeriesBuilder.class); - private SeriesBuilderCallback _callback; + private DatasetHolder _datasetHolder; private final JdbcUrlGenerator _jdbcUrlGenerator; @@ -58,19 +59,20 @@ public class JdbcSeriesBuilder implements SeriesBuilder } @Override - public void setSeriesBuilderCallback(SeriesBuilderCallback callback) + public void setDatasetHolder(DatasetHolder callback) { - this._callback = callback; + _datasetHolder = callback; } @Override - public void build(List<SeriesDefinition> seriesDefinitions) + public Dataset build(List<SeriesDefinition> seriesDefinitions) { for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();) { SeriesDefinition series = iterator.next(); buildDataSetForSingleSeries(series); } + return _datasetHolder.getPopulatedDataset(); } private void buildDataSetForSingleSeries(SeriesDefinition seriesDefinition) @@ -87,7 +89,7 @@ public class JdbcSeriesBuilder implements SeriesBuilder stmt = conn.createStatement(); ResultSet results = stmt.executeQuery(seriesStatement); int columnCount = results.getMetaData().getColumnCount(); - _callback.beginSeries(seriesDefinition); + _datasetHolder.beginSeries(seriesDefinition); while (results.next()) { Object[] row = new Object[columnCount]; @@ -96,10 +98,10 @@ public class JdbcSeriesBuilder implements SeriesBuilder row[i] = results.getObject(i+1); } - SeriesRow seriesRow = SeriesRow.createValidSeriesRow(_callback.getNumberOfDimensions(), row); - _callback.addDataPointToSeries(seriesDefinition, seriesRow); + SeriesRow seriesRow = SeriesRow.createValidSeriesRow(_datasetHolder.getNumberOfDimensions(), row); + _datasetHolder.addDataPointToSeries(seriesDefinition, seriesRow); } - _callback.endSeries(seriesDefinition); + _datasetHolder.endSeries(seriesDefinition); } catch (SQLException e) { diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java index 0dfba304a9..a865c838c6 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java @@ -22,18 +22,20 @@ package org.apache.qpid.disttest.charting.seriesbuilder; import java.util.List; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.jfree.data.general.Dataset; public interface SeriesBuilder { /** * Uses the supplied {@link SeriesDefinition}s to read the series data - * and pass it to the callback set up in {@link #setSeriesBuilderCallback(SeriesBuilderCallback)}. + * and pass it to the dataset holder set up in {@link #setDatasetHolder(DatasetHolder)}. + * + * @return the populated dataset */ - void build(List<SeriesDefinition> seriesDefinitions); + Dataset build(List<SeriesDefinition> seriesDefinitions); /** - * Stores the supplied callback so it can be used in {@link #build(List)}. + * Stores the supplied dataset holder so it can be populated in {@link #build(List)}. */ - void setSeriesBuilderCallback(SeriesBuilderCallback seriesBuilderCallback); - + void setDatasetHolder(DatasetHolder datasetHolder); }
\ No newline at end of file diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java index 6c87b88c45..9c16866939 100644 --- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java +++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java @@ -19,6 +19,7 @@ package org.apache.qpid.disttest.charting.seriesbuilder; import java.util.Arrays; +import java.util.Date; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -63,6 +64,11 @@ public class SeriesRow return Double.parseDouble(dimensionAsString(dimension)); } + public Date dimensionAsDate(int dimension) + { + return (Date) dimension(dimension); + } + @Override public int hashCode() { diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java new file mode 100644 index 0000000000..85ba84fd5e --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.disttest.charting.chartbuilder; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.*; + +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.qpid.disttest.charting.definition.ChartingDefinition; +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.Plot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.title.TextTitle; +import org.jfree.data.general.Dataset; + +public class BaseChartBuilderTest extends TestCase +{ + private static final String CHART_TITLE = "CHART_TITLE"; + private static final String CHART_SUB_TITLE = "CHART_SUB_TITLE"; + private static final String X_TITLE = "X_TITLE"; + private static final String Y_TITLE = "Y_TITLE"; + + @SuppressWarnings("unchecked") + private List<SeriesDefinition> _seriesDefinitions = mock(List.class); + + private ChartingDefinition _chartingDefinition = mock(ChartingDefinition.class); + private SeriesStrokeAndPaintApplier _strokeAndPaintApplier = mock(SeriesStrokeAndPaintApplier.class); + private DatasetHolder _datasetHolder = mock(DatasetHolder.class); + private SeriesPainter _seriesPainter = mock(SeriesPainter.class); + + private SeriesBuilder _seriesBuilder = mock(SeriesBuilder.class); + + private JFreeChart _jFreeChart; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + Plot plot = new CategoryPlot(); + _jFreeChart = new JFreeChart(plot); + + when(_chartingDefinition.getChartTitle()).thenReturn(CHART_TITLE); + when(_chartingDefinition.getChartSubtitle()).thenReturn(CHART_SUB_TITLE); + when(_chartingDefinition.getXAxisTitle()).thenReturn(X_TITLE); + when(_chartingDefinition.getYAxisTitle()).thenReturn(Y_TITLE); + when(_chartingDefinition.getSeriesDefinitions()).thenReturn(_seriesDefinitions ); + } + + public void testBuildChart() + { + BaseChartBuilder chartBuilder = new ChartBuilder(_seriesBuilder, _strokeAndPaintApplier, _datasetHolder) + { + @Override + protected JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) + { + assertEquals(CHART_TITLE, title); + assertEquals(X_TITLE, xAxisTitle); + assertEquals(Y_TITLE, yAxisTitle); + + return _jFreeChart; + } + }; + + JFreeChart chart = chartBuilder.buildChart(_chartingDefinition); + + assertEquals(BaseChartBuilder.BLUE_GRADIENT, chart.getBackgroundPaint()); + assertEquals("The *second* subtitle of the generated chart should have the text from the chart definition", + CHART_SUB_TITLE, ((TextTitle)chart.getSubtitle(1)).getText()); + verify(_seriesPainter).applySeriesAppearance(_jFreeChart, _seriesDefinitions, _strokeAndPaintApplier); + } + + /** + * Extends BaseChartBuilder to allow us to plug in in mock dependencies + */ + private abstract class ChartBuilder extends BaseChartBuilder + { + private SeriesStrokeAndPaintApplier _seriesStrokeAndPaintApplier; + private DatasetHolder _datasetHolder; + + private ChartBuilder(SeriesBuilder seriesBuilder, SeriesStrokeAndPaintApplier seriesStrokeAndPaintApplier, DatasetHolder datasetHolder) + { + super(seriesBuilder); + _seriesStrokeAndPaintApplier = seriesStrokeAndPaintApplier; + _datasetHolder = datasetHolder; + setSeriesPainter(_seriesPainter); + } + + @Override + protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier() + { + return _seriesStrokeAndPaintApplier; + } + + @Override + protected DatasetHolder newDatasetHolder() + { + return _datasetHolder; + } + } +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java index e735fb58c6..dcd9f93830 100644 --- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java @@ -59,4 +59,10 @@ public class ChartBuilderFactoryTest extends TestCase ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.XYLINE, _seriesBuilder); assertTrue(builder instanceof XYLineChartBuilder); } + + public void testTimeSeriesLineChart() + { + ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.TIMELINE, _seriesBuilder); + assertTrue(builder instanceof TimeSeriesLineChartBuilder); + } } diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java index fe9cb2aefe..6d80a55770 100644 --- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java @@ -19,17 +19,21 @@ */ package org.apache.qpid.disttest.charting.chartbuilder; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.File; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.List; +import junit.framework.TestCase; + import org.apache.qpid.disttest.charting.ChartType; import org.apache.qpid.disttest.charting.definition.ChartingDefinition; import org.apache.qpid.disttest.charting.definition.SeriesDefinition; -import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; +import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; import org.apache.qpid.disttest.charting.writer.ChartWriter; @@ -37,14 +41,12 @@ import org.apache.qpid.test.utils.TestFileUtils; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.ShortTextTitle; - -import junit.framework.TestCase; +import org.jfree.data.general.Dataset; /** * Tests the production of the different chart types. To manually * verify the generated output, set the system property {@link #RETAIN_TEST_CHARTS} * to prevent the automatic deletion of the test chart directory. - * */ public class ChartProductionTest extends TestCase { @@ -55,6 +57,16 @@ public class ChartProductionTest extends TestCase private static final String TEST_SERIESLEGEND = "TEST_SERIESLEGEND"; + private static final SeriesRow[] SIMPLE_SERIES_ROWS = new SeriesRow[] + { + new SeriesRow(1d, 1d), + new SeriesRow(2d, 2d), + new SeriesRow(3d, 3d), + new SeriesRow(4d, 4d), + new SeriesRow(5d, 5d), + new SeriesRow(6d, 6d), + }; + private static final String RETAIN_TEST_CHARTS = "retainTestCharts"; private SeriesDefinition _seriesDefinition = mock(SeriesDefinition.class); @@ -75,7 +87,7 @@ public class ChartProductionTest extends TestCase when(_chartingDefinition.getChartSubtitle()).thenReturn(TEST_CHARTSUBTITLE); when(_chartingDefinition.getXAxisTitle()).thenReturn(TEST_XAXIS); when(_chartingDefinition.getYAxisTitle()).thenReturn(TEST_YAXIS); - when(_chartingDefinition.getSeries()).thenReturn(Collections.singletonList(_seriesDefinition)); + when(_chartingDefinition.getSeriesDefinitions()).thenReturn(Collections.singletonList(_seriesDefinition)); File chartDir = TestFileUtils.createTestDirectory("charts", false); if (!System.getProperties().containsKey(RETAIN_TEST_CHARTS)) @@ -92,7 +104,7 @@ public class ChartProductionTest extends TestCase public void testBarChart() throws Exception { - ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, new SampleSeriesBuilder()); + ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, new SampleSeriesBuilder(SIMPLE_SERIES_ROWS)); assertChartTitlesAndWriteToFile(builder); } @@ -129,36 +141,38 @@ public class ChartProductionTest extends TestCase assertChartTitlesAndWriteToFile(builder); } - public void testStatiscticalBarChart() throws Exception + public void testTimeSeriesLineChart() throws Exception + { + SeriesRow[] timelineSeriesRows = new SeriesRow[] + { + new SeriesRow(new Date(1), 1d), + new SeriesRow(new Date(2), 2d), + new SeriesRow(new Date(3), 3d), + new SeriesRow(new Date(4), 4d), + new SeriesRow(new Date(5), 5d), + new SeriesRow(new Date(6), 6d), + }; + ChartBuilder builder = ChartBuilderFactory.createChartBuilder( + ChartType.TIMELINE, + new SampleSeriesBuilder(timelineSeriesRows)); + + assertChartTitlesAndWriteToFile(builder); + } + + public void testStatisticalBarChart() throws Exception { + SeriesRow[] statisticalSeriesRows = new SeriesRow[] + { + new SeriesRow(1d, 1d, 0.5d), + new SeriesRow(2d, 2d, 0.4d), + new SeriesRow(4d, 4d, 0.3d), + new SeriesRow(5d, 5d, 0.2d), + new SeriesRow(6d, 6d, 0.1d) + }; + ChartBuilder builder = ChartBuilderFactory.createChartBuilder( ChartType.STATISTICAL_BAR, - new SeriesBuilder() - { - private SeriesBuilderCallback _dataPointCallback; - - @Override - public void build(List<SeriesDefinition> seriesDefinitions) - { - for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();) - { - SeriesDefinition seriesDefinition = iterator.next(); - _dataPointCallback.beginSeries(seriesDefinition); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(1d, 1d, 0.5d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(2d, 2d, 0.4d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(4d, 4d, 0.3d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(5d, 5d, 0.2d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(6d, 3d, 0.1d)); - _dataPointCallback.endSeries(seriesDefinition); - } - } - - @Override - public void setSeriesBuilderCallback(SeriesBuilderCallback dataPointCallback) - { - _dataPointCallback = dataPointCallback; - } - }); + new SampleSeriesBuilder(statisticalSeriesRows)); assertChartTitlesAndWriteToFile(builder); } @@ -184,28 +198,38 @@ public class ChartProductionTest extends TestCase private class SampleSeriesBuilder implements SeriesBuilder { - private SeriesBuilderCallback _dataPointCallback; + private DatasetHolder _datasetHolder; + private SeriesRow[] _sampleSeriesRows = SIMPLE_SERIES_ROWS; + + public SampleSeriesBuilder() + { + } + + public SampleSeriesBuilder(SeriesRow[] sampleSeriesRows) + { + _sampleSeriesRows = sampleSeriesRows; + } @Override - public void build(List<SeriesDefinition> seriesDefinitions) + public Dataset build(List<SeriesDefinition> seriesDefinitions) { for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();) { SeriesDefinition seriesDefinition = iterator.next(); - _dataPointCallback.beginSeries(seriesDefinition); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(1d, 1d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(2d, 2d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(4d, 4d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(5d, 5d)); - _dataPointCallback.addDataPointToSeries(seriesDefinition, new SeriesRow(6d, 3d)); - _dataPointCallback.endSeries(seriesDefinition); + _datasetHolder.beginSeries(seriesDefinition); + for(SeriesRow seriesRow : _sampleSeriesRows) + { + _datasetHolder.addDataPointToSeries(seriesDefinition, seriesRow); + } + _datasetHolder.endSeries(seriesDefinition); } + return _datasetHolder.getPopulatedDataset(); } @Override - public void setSeriesBuilderCallback(SeriesBuilderCallback dataPointCallback) + public void setDatasetHolder(DatasetHolder dataPointCallback) { - _dataPointCallback = dataPointCallback; + _datasetHolder = dataPointCallback; } } } diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java new file mode 100644 index 0000000000..e1ee9510b4 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java @@ -0,0 +1,73 @@ +package org.apache.qpid.disttest.charting.chartbuilder; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import junit.framework.TestCase; + +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; +import org.jfree.data.time.TimeSeriesDataItem; + +public class TimeSeriesBuilderCallbackTest extends TestCase +{ + private static final String SERIES_LEGEND = "mySeriesLegend"; + + private static final int NUMBER_OF_DATA_POINTS = 3; + + private Date[] _dates; + private double[] _values; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00")); + + calendar.set(2013, Calendar.JANUARY, 1); + Date jan1 = calendar.getTime(); + + calendar.set(2013, Calendar.JANUARY, 2); + Date jan2 = calendar.getTime(); + + calendar.set(2013, Calendar.JANUARY, 3); + Date jan3 = calendar.getTime(); + + _dates = new Date[] {jan1, jan2, jan3}; + _values = new double[] {2.0, 4.0, 8.0}; + } + + + public void testAddPointToSeries() + { + TimeSeriesHolder timeSeriesHolder = new TimeSeriesHolder(); + + SeriesDefinition seriesDefinition = mock(SeriesDefinition.class); + when(seriesDefinition.getSeriesLegend()).thenReturn(SERIES_LEGEND); + + timeSeriesHolder.beginSeries(seriesDefinition); + + timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[0], _values[0])); + timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[1], _values[1])); + timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[2], _values[2])); + + timeSeriesHolder.endSeries(seriesDefinition); + + TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) timeSeriesHolder.getPopulatedDataset(); + + TimeSeries actualTimeSeries = timeSeriesCollection.getSeries(SERIES_LEGEND); + for(int i = 0; i < NUMBER_OF_DATA_POINTS; i++) + { + TimeSeriesDataItem dataItem0 = actualTimeSeries.getDataItem(i); + assertEquals(_dates[i].getTime(), dataItem0.getPeriod().getMiddleMillisecond()); + assertEquals(_values[i], dataItem0.getValue()); + } + } + +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java index a626ad9466..e300e00478 100644 --- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java @@ -96,7 +96,7 @@ public class ChartingDefinitionCreatorTest extends TestCase String stemOnly = testDefFile.getName().replaceFirst("\\.chartdef", ""); assertEquals(stemOnly, definition1.getChartStemName()); - final List<SeriesDefinition> seriesDefinitions = definition1.getSeries(); + final List<SeriesDefinition> seriesDefinitions = definition1.getSeriesDefinitions(); assertEquals(1, seriesDefinitions.size()); SeriesDefinition seriesDefinition = seriesDefinitions.get(0); assertEquals(TEST_SERIES_SELECT_STATEMENT, seriesDefinition.getSeriesStatement()); diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java index 20d5082448..a5e697b3f4 100644 --- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java @@ -41,7 +41,7 @@ public class JdbcSeriesBuilderTest extends TestCase private static final String TEST_SERIES1_COLOUR_NAME = "blue"; private static final Integer TEST_SERIES1_STROKE_WIDTH = 3; - private SeriesBuilderCallback _seriesWalkerCallback = mock(SeriesBuilderCallback.class); + private DatasetHolder _seriesWalkerCallback = mock(DatasetHolder.class); private File _testTempDir; @@ -60,7 +60,7 @@ public class JdbcSeriesBuilderTest extends TestCase JdbcSeriesBuilder seriesBuilder = new JdbcSeriesBuilder("org.relique.jdbc.csv.CsvDriver", null); - seriesBuilder.setSeriesBuilderCallback(_seriesWalkerCallback); + seriesBuilder.setDatasetHolder(_seriesWalkerCallback); seriesBuilder.build(Collections.singletonList(seriesDefinition)); |
