summaryrefslogtreecommitdiff
path: root/qpid/java/perftests/visualisation-jfc
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-04-30 07:43:38 +0000
committerKeith Wall <kwall@apache.org>2012-04-30 07:43:38 +0000
commit615e748200fe647f24394f4c15f334a7ed816b81 (patch)
treec9c913ddc25e7d743a4c77b17561cd2029bcb636 /qpid/java/perftests/visualisation-jfc
parent0792d245a58c68fbd5313ef698609443e9ad9ec3 (diff)
downloadqpid-python-615e748200fe647f24394f4c15f334a7ed816b81.tar.gz
QPID-3977: Add charting framework for new distributed test tool.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1332087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests/visualisation-jfc')
-rw-r--r--qpid/java/perftests/visualisation-jfc/build.xml142
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java26
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingException.java46
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java135
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java47
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java30
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java40
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java27
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java68
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java45
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java133
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java85
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java140
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java50
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java60
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java40
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java90
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java149
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java113
19 files changed, 1466 insertions, 0 deletions
diff --git a/qpid/java/perftests/visualisation-jfc/build.xml b/qpid/java/perftests/visualisation-jfc/build.xml
new file mode 100644
index 0000000000..b838855e8b
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/build.xml
@@ -0,0 +1,142 @@
+<!--
+ - 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.
+ -->
+<project name="visualisation-jfc" default="build">
+ <property name="module.depends" value="common perftests" />
+ <property name="module.test.depends" value="test" />
+
+ <import file="../../module.xml" />
+
+
+ <!-- JFreeChart and JFreeCommon -->
+
+ <property name="jfree.lib.dir" value="${project.root}/lib/jfree" />
+ <property name="jfreechart.version" value="1.0.13" />
+ <property name="jfreecommon.version" value="1.0.16" />
+ <property name="jfreechart.download.url" value="http://repo1.maven.org/maven2/jfree/jfreechart/${jfreechart.version}/jfreechart-${jfreechart.version}.jar" />
+ <property name="jfreecommon.download.url" value="http://repo1.maven.org/maven2/jfree/jcommon/${jfreecommon.version}/jcommon-${jfreecommon.version}.jar" />
+ <property name="jfreechart.jar.file" value="${jfree.lib.dir}/jfreechart-${jfreechart.version}.jar" />
+ <property name="jfreecommon.jar.file" value="${jfree.lib.dir}/jfreecommon-${jfreecommon.version}.jar" />
+
+ <!-- CSVJDBC -->
+
+ <property name="csvjdbc.lib.dir" value="${project.root}/lib/csvjdbc" />
+ <property name="csvjdbc.version" value="1.0.8" />
+ <property name="csvjdbc.download.url" value="http://csvjdbc.sourceforge.net/maven2/net/sourceforge/csvjdbc/csvjdbc/${csvjdbc.version}/csvjdbc-${csvjdbc.version}.jar" />
+
+ <property name="csvjdbc.jar.file" value="${csvjdbc.lib.dir}/csvjdbc-${csvjdbc.version}.jar" />
+
+ <!--check whether the JFree jar is present, possibly after download-->
+ <target name="check-jfree-jars">
+ <condition property="jfree.available">
+ <and>
+ <available file="${jfreechart.jar.file}"/>
+ <available file="${jfreecommon.jar.file}"/>
+ </and>
+ </condition>
+ </target>
+
+ <!--echo that BDB is required if it isnt present, with associated licencing note-->
+ <target name="jfree-jar-required" depends="jfree-licence-note-optional" unless="jfree.available">
+ <echo>The JFreeChart library is required to use this optional module.
+
+The jar file may be downloaded by either:
+
+ Seperately running the following command from the qpid/java/perftests/visualisation-jfc dir: ant download-jfree
+
+ OR
+
+ Adding -Ddownload-jfree=true to your regular build command.</echo>
+ <fail>The JFreechart JARs were not found</fail>
+ </target>
+
+ <!--issue JFree licencing note if JFree isnt already present-->
+ <target name="jfree-licence-note-optional" depends="check-jfree-jars" unless="jfree.available">
+ <antcall target="jfree-licence-note"/>
+ </target>
+
+ <!--issue JFree licencing note-->
+ <target name="jfree-licence-note">
+ <echo>*NOTE* The JFreeChart and JFreeCommon libraries required by this optional module are licensed under the LGPL Licence, which is not compatible with the Apache Licence v2.0.
+
+For a copy of the LGPL Licence, please see:
+http://www.gnu.org/licenses/lgpl.html
+ </echo>
+ </target>
+
+ <target name="check-csvjdbc-jars">
+ <condition property="csvjdbc.available">
+ <available file="${csvjdbc.jar.file}"/>
+ </condition>
+ </target>
+
+ <!--check if an inline JFree download was requested with the build-->
+ <target name="checkjfree-request-props" if="download-jfree">
+ <antcall target="download-jfree"/>
+ </target>
+
+ <!--echo that CSVJDBC is required if it isnt present, with associated licencing note-->
+ <target name="csvjdbc-jar-required" depends="csvjdbc-licence-note-optional" unless="csvjdbc.available">
+ <echo>The CSVJDBC library is required to use this optional module.
+
+The jar file may be downloaded by either:
+
+ Seperately running the following command from the qpid/java/perftests/visualisation-jfc dir: ant download-csvjdbc
+
+ OR
+
+ Adding -Ddownload-csvjdbc=true to your regular build command.</echo>
+ <fail>The CSVJDBC JAR was not found</fail>
+ </target>
+
+ <!--issue CSVJDBC licencing note-->
+ <target name="csvjdbc-licence-note">
+ <echo>*NOTE* The CSVJDBC library required by this optional module is licensed under the LGPL Licence, which is not compatible with the Apache Licence v2.0.
+
+For a copy of the LGPL Licence, please see:
+http://www.gnu.org/licenses/lgpl.html
+ </echo>
+ </target>
+
+ <!--issue CSVJDBC licencing note if CSVJDBC isnt already present-->
+ <target name="csvjdbc-licence-note-optional" depends="check-csvjdbc-jars" unless="csvjdbc.available">
+ <antcall target="csvjdbc-licence-note"/>
+ </target>
+
+ <!--download JFree, with licencing note-->
+ <target name="download-jfree" depends="jfree-licence-note">
+ <mkdir dir="${jfree.lib.dir}"/>
+ <echo>Downloading JFreeChart</echo>
+ <get src="${jfreechart.download.url}" dest="${jfreechart.jar.file}" usetimestamp="true" />
+ <get src="${jfreecommon.download.url}" dest="${jfreecommon.jar.file}" usetimestamp="true" />
+ </target>
+
+ <target name="checkcsvjdbc-request-props" if="download-csvjdbc">
+ <antcall target="download-csvjdbc"/>
+ </target>
+
+ <target name="download-csvjdbc" depends="csvjdbc-licence-note">
+ <mkdir dir="${csvjdbc.lib.dir}"/>
+ <echo>Downloading csvjdbc</echo>
+ <get src="${csvjdbc.download.url}" dest="${csvjdbc.jar.file}" usetimestamp="true" />
+ </target>
+
+ <target name="build" depends="checkjfree-request-props, jfree-jar-required, checkcsvjdbc-request-props, csvjdbc-jar-required, module.build" />
+
+
+</project>
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
new file mode 100644
index 0000000000..2803f2d767
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+public enum ChartType
+{
+ LINE, BAR
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingException.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingException.java
new file mode 100644
index 0000000000..120a4dc750
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingException.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+public class ChartingException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ public ChartingException()
+ {
+ super();
+ }
+
+ public ChartingException(String message)
+ {
+ super(message);
+ }
+
+ public ChartingException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public ChartingException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
new file mode 100644
index 0000000000..a149d1a097
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
@@ -0,0 +1,135 @@
+/*
+ *
+ * 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;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.disttest.ArgumentParser;
+import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilder;
+import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilderFactory;
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ChartingUtil
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(ChartingUtil.class);
+
+ public static final String OUTPUT_DIR_PROP = "outputdir";
+ public static final String OUTPUT_DIR_DEFAULT = ".";
+
+ public static final String CHART_DEFINITIONS_PROP = "chart-defs";
+ public static final String CHART_DEFINITIONS_DEFAULT = ".";
+
+ private Map<String,String> _cliOptions = new HashMap<String, String>();
+ {
+ _cliOptions.put(OUTPUT_DIR_PROP, OUTPUT_DIR_DEFAULT);
+ _cliOptions.put(CHART_DEFINITIONS_PROP, CHART_DEFINITIONS_DEFAULT);
+ }
+
+ public static void main(String[] args) throws Exception
+ {
+ try
+ {
+ LOGGER.debug("Starting charting");
+
+ ChartingUtil chartingUtil = new ChartingUtil();
+ chartingUtil.parseArgumentsIntoConfig(args);
+ chartingUtil.produceAllCharts();
+ }
+ finally
+ {
+ LOGGER.debug("Charting complete");
+ }
+ }
+
+ private void produceAllCharts()
+ {
+ final String chartingDefsDir = _cliOptions.get(CHART_DEFINITIONS_PROP);
+ List<ChartingDefinition> definitions = loadChartDefinitions(chartingDefsDir);
+
+ LOGGER.debug("There are {} chart(s) to produce", definitions.size());
+
+ for (ChartingDefinition chartingDefinition : definitions)
+ {
+ ChartBuilder chartBuilder = ChartBuilderFactory.createChartBuilder(chartingDefinition.getChartType());
+ JFreeChart chart = chartBuilder.buildChart(chartingDefinition);
+ writeChartToFileSystem(chart, chartingDefinition.getChartStemName());
+ }
+ }
+
+ private void writeChartToFileSystem(JFreeChart chart, String chartStemName)
+ {
+ OutputStream pngOutputStream = null;
+ try
+ {
+
+ File pngFile = new File(chartStemName + ".png");
+ pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile));
+ ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0);
+ pngOutputStream.close();
+
+ LOGGER.debug("Written {} chart", pngFile);
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException("Failed to create chart", e);
+ }
+ finally
+ {
+ if (pngOutputStream != null)
+ {
+ try
+ {
+ pngOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException("Failed to create chart", e);
+ }
+ }
+ }
+ }
+
+ private List<ChartingDefinition> loadChartDefinitions(String chartingDefsDir)
+ {
+ ChartingDefinitionCreator chartingDefinitionLoader = new ChartingDefinitionCreator();
+ return chartingDefinitionLoader.createFromFileOrDirectory(chartingDefsDir);
+ }
+
+ private void parseArgumentsIntoConfig(String[] args)
+ {
+ ArgumentParser argumentParser = new ArgumentParser();
+ argumentParser.parseArgumentsIntoConfig(_cliOptions, args);
+ }
+
+
+}
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
new file mode 100644
index 0000000000..302263a604
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
@@ -0,0 +1,47 @@
+/*
+ * 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.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+public class BarChartBuilder extends DataSetBasedChartBuilder
+{
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final DefaultCategoryDataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createBarChart(title,
+ xAxisTitle,
+ yAxisTitle,
+ dataset,
+ plotOrientation,
+ showLegend,
+ showToolTips,
+ showUrls);
+ return chart;
+ }
+
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java
new file mode 100644
index 0000000000..c6f5ecc175
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java
@@ -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.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.jfree.chart.JFreeChart;
+
+public interface ChartBuilder
+{
+
+ public JFreeChart buildChart(ChartingDefinition chartingDefinition);
+
+}
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
new file mode 100644
index 0000000000..4c5d4fa09f
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
@@ -0,0 +1,40 @@
+/*
+ * 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.ChartType;
+
+public class ChartBuilderFactory
+{
+
+ public static ChartBuilder createChartBuilder(ChartType chartType)
+ {
+ switch (chartType)
+ {
+ case LINE:
+ return new LineChartBuilder();
+ case BAR:
+ return new BarChartBuilder();
+ 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/DataPointCallback.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java
new file mode 100644
index 0000000000..a47df0e8af
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java
@@ -0,0 +1,27 @@
+/*
+ * 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.definition.SeriesDefinition;
+
+public interface DataPointCallback
+{
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object xValue, Object yValue);
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java
new file mode 100644
index 0000000000..6e2491c883
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java
@@ -0,0 +1,68 @@
+/*
+ * 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.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.CategoryLabelPositions;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+public abstract class DataSetBasedChartBuilder implements ChartBuilder
+{
+ private static final CategoryLabelPositions LABEL_POSITION = CategoryLabelPositions.UP_45;
+ private static final PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL;
+
+ @Override
+ public JFreeChart buildChart(ChartingDefinition chartingDefinition)
+ {
+ String title = chartingDefinition.getChartTitle();
+ String xAxisTitle = chartingDefinition.getXAxisTitle();
+ String yAxisTitle = chartingDefinition.getYAxisTitle();
+
+ final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
+
+ SeriesBuilder seriesBuilder = new SeriesBuilder(new DataPointCallback()
+ {
+ @Override
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition,
+ Object xValue, Object yValue)
+ {
+ String x = (String) xValue;
+ double y = (Double) yValue;
+ dataset.addValue( y, seriesDefinition.getSeriesLegend(), x);
+ }
+ });
+
+ seriesBuilder.build(chartingDefinition.getSeries());
+
+ JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle,
+ dataset, PLOT_ORIENTATION, true, false, false);
+
+ chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(LABEL_POSITION);
+
+ return chart;
+ }
+
+ public abstract JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final DefaultCategoryDataset 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
new file mode 100644
index 0000000000..697dfdcf3e
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
@@ -0,0 +1,45 @@
+/*
+ * 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.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+public class LineChartBuilder extends DataSetBasedChartBuilder
+{
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final DefaultCategoryDataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createLineChart(title,
+ xAxisTitle,
+ yAxisTitle,
+ dataset,
+ plotOrientation,
+ showLegend,
+ showToolTips,
+ showUrls);
+ return chart;
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java
new file mode 100644
index 0000000000..de717792db
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java
@@ -0,0 +1,133 @@
+/*
+ * 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.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.ChartingException;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+
+public class SeriesBuilder
+{
+ static
+ {
+ registerCsvDriver();
+ }
+
+ private final DataPointCallback _dataPointCallback;
+
+ public SeriesBuilder(DataPointCallback dataPointCallback)
+ {
+ _dataPointCallback = dataPointCallback;
+ }
+
+ public void build(List<SeriesDefinition> seriesDefinitions)
+ {
+ for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
+ {
+ SeriesDefinition series = iterator.next();
+ buildDataSetForSingleSeries(series);
+ }
+ }
+
+ private void buildDataSetForSingleSeries(SeriesDefinition seriesDefinition)
+ {
+ Connection conn = null;
+ Statement stmt = null;
+ try
+ {
+ File seriesDir = getValidatedSeriesDirectory(seriesDefinition);
+
+ conn = DriverManager.getConnection("jdbc:relique:csv:" + seriesDir.getAbsolutePath());
+
+ final String seriesStatement = seriesDefinition.getSeriesStatement();
+
+ stmt = conn.createStatement();
+ ResultSet results = stmt.executeQuery(seriesStatement);
+
+ while (results.next())
+ {
+ Object xValue = results.getString(1);
+ Object yValue = results.getDouble(2);
+
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, xValue, yValue);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new ChartingException("Failed to create chart dataset", e);
+ }
+ finally
+ {
+ if (stmt != null)
+ {
+ try
+ {
+ stmt.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Failed to close statement", e);
+ }
+ }
+ if (conn != null)
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Failed to close connection", e);
+ }
+ }
+ }
+ }
+
+ private File getValidatedSeriesDirectory(SeriesDefinition series)
+ {
+ File seriesDir = new File(series.getSeriesDirectory());
+ if (!seriesDir.isDirectory())
+ {
+ throw new ChartingException("seriesDirectory must be a directory : " + seriesDir);
+ }
+ return seriesDir;
+ }
+
+ private static void registerCsvDriver() throws ExceptionInInitializerError
+ {
+ try
+ {
+ Class.forName("org.relique.jdbc.csv.CsvDriver");
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Could not load CSV/JDBC driver", e);
+ }
+ }
+
+}
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
new file mode 100644
index 0000000000..82b59b6d6e
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
@@ -0,0 +1,85 @@
+/*
+ * 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.definition;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.ChartType;
+
+public class ChartingDefinition
+{
+ private final String _chartStemName;
+ private final ChartType _chartType;
+ private final String _chartTitle;
+ private final String _xaxisTitle;
+ private final String _yaxisTitle;
+ private final List<SeriesDefinition> _seriesDefinitions;
+
+
+ public ChartingDefinition(final String chartStemName,
+ final ChartType chartType,
+ final String chartTitle,
+ final String xaxisTitle,
+ final String yaxisTitle, List<SeriesDefinition> seriesDefinitions)
+ {
+ _chartStemName = chartStemName;
+ _chartType = chartType;
+ _chartTitle = chartTitle;
+ _xaxisTitle = xaxisTitle;
+ _yaxisTitle = yaxisTitle;
+ _seriesDefinitions = seriesDefinitions;
+ }
+
+ public String getChartStemName()
+ {
+ return _chartStemName;
+ }
+
+ public String getChartTitle()
+ {
+ return _chartTitle;
+ }
+
+
+ public String getXAxisTitle()
+ {
+ return _xaxisTitle;
+ }
+
+
+ public String getYAxisTitle()
+ {
+ return _yaxisTitle;
+ }
+
+
+
+ public ChartType getChartType()
+ {
+ return _chartType;
+ }
+
+ public List<SeriesDefinition> getSeries()
+ {
+ return Collections.unmodifiableList(_seriesDefinitions);
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
new file mode 100644
index 0000000000..8a3d313519
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
@@ -0,0 +1,140 @@
+/*
+ * 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.definition;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.qpid.disttest.charting.ChartType;
+import org.apache.qpid.disttest.charting.ChartingException;
+
+public class ChartingDefinitionCreator
+{
+ public static final String CHARTDEF_FILE_EXTENSION = ".chartdef";
+
+ public static final String CHART_TYPE_KEY = "chartType";
+ public static final String CHART_TITLE_KEY = "chartTitle";
+ public static final String XAXIS_TITLE_KEY = "xAxisTitle";
+ public static final String YAXIS_TITLE_KEY = "yAxisTitle";
+
+ private SeriesDefinitionCreator _seriesDefinitionCreator = new SeriesDefinitionCreator();
+
+ public List<ChartingDefinition> createFromFileOrDirectory(String chartingDefinitionFileOrDirectory)
+ {
+ List<ChartingDefinition> definitions = new ArrayList<ChartingDefinition>();
+
+ File fileOrDirectory = new File(chartingDefinitionFileOrDirectory);
+ if (fileOrDirectory.isDirectory())
+ {
+ File[] matchingFiles = fileOrDirectory.listFiles(new CHARTDEF_FILE_FILTER());
+
+ for (File file : matchingFiles)
+ {
+ final ChartingDefinition chartDefinition = createChartDefinition(file);
+ definitions.add(chartDefinition);
+ }
+ }
+ else
+ {
+ final ChartingDefinition chartDefinition = createChartDefinition(fileOrDirectory);
+ definitions.add(chartDefinition);
+ }
+
+ return definitions;
+ }
+
+ private ChartingDefinition createChartDefinition(File file)
+ {
+ Reader reader = null;
+ try
+ {
+ reader = new BufferedReader(new FileReader(file));
+ Properties props = new Properties();
+ props.load(reader);
+
+ final String chartStemName = getStemNameFrom(file);
+
+ final ChartType chartType = ChartType.valueOf(props.getProperty(CHART_TYPE_KEY));
+ final String chartTitle = props.getProperty(CHART_TITLE_KEY);
+ final String xAxisTitle = props.getProperty(XAXIS_TITLE_KEY);
+ final String yAxisTitle = props.getProperty(YAXIS_TITLE_KEY);
+
+ final List<SeriesDefinition> seriesDefinitions = createSeriesDefinitions(props);
+
+ final ChartingDefinition chartDefinition = new ChartingDefinition(chartStemName,
+ chartType,
+ chartTitle,
+ xAxisTitle,
+ yAxisTitle,
+ seriesDefinitions);
+ return chartDefinition;
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException("Unable to open file " + file, e);
+ }
+ finally
+ {
+ if (reader != null)
+ {
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException(e);
+ }
+ }
+ }
+
+ }
+
+ private String getStemNameFrom(File file)
+ {
+ final String nameWithExtension = file.getName();
+ final String nameWithoutExtensionPart = nameWithExtension.replaceAll("\\.[^\\.]*$", "");
+ return nameWithoutExtensionPart;
+ }
+
+ private List<SeriesDefinition> createSeriesDefinitions(Properties props)
+ {
+ return _seriesDefinitionCreator.createFromProperties(props);
+ }
+
+ private final class CHARTDEF_FILE_FILTER implements FileFilter
+ {
+ @Override
+ public boolean accept(File pathname)
+ {
+ return pathname.isFile() && pathname.getName().endsWith(CHARTDEF_FILE_EXTENSION);
+ }
+ }
+
+
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java
new file mode 100644
index 0000000000..a39e906957
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java
@@ -0,0 +1,50 @@
+/*
+ * 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.definition;
+
+public class SeriesDefinition
+{
+ private final String _seriesStatement;
+ private final String _seriesLegend;
+ private final String _seriesDirectory;
+
+ public SeriesDefinition(String seriesStatement, String seriesLegend, String seriesDirectory)
+ {
+ _seriesStatement = seriesStatement;
+ _seriesLegend = seriesLegend;
+ _seriesDirectory = seriesDirectory;
+ }
+
+ public String getSeriesStatement()
+ {
+ return _seriesStatement;
+ }
+
+ public String getSeriesLegend()
+ {
+ return _seriesLegend;
+ }
+
+ public String getSeriesDirectory()
+ {
+ return _seriesDirectory;
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java
new file mode 100644
index 0000000000..fcc11807c8
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java
@@ -0,0 +1,60 @@
+/*
+ * 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.definition;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.lang.text.StrSubstitutor;
+
+public class SeriesDefinitionCreator
+{
+ public static final String SERIES_STATEMENT_KEY_FORMAT = "series.%d.statement";
+ public static final String SERIES_LEGEND_KEY_FORMAT = "series.%d.legend";
+ public static final String SERIES_DIRECTORY_KEY_FORMAT = "series.%d.dir";
+
+ public List<SeriesDefinition> createFromProperties(Properties properties)
+ {
+ final List<SeriesDefinition> seriesDefinitions = new ArrayList<SeriesDefinition>();
+
+ int index = 1;
+ boolean moreSeriesDefinitions = true;
+ while(moreSeriesDefinitions)
+ {
+ String seriesStatement = properties.getProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, index));
+ String seriesLegend = properties.getProperty(String.format(SERIES_LEGEND_KEY_FORMAT, index));
+ String seriesDir = StrSubstitutor.replaceSystemProperties(properties.getProperty(String.format(SERIES_DIRECTORY_KEY_FORMAT, index)));
+
+ if (seriesStatement != null)
+ {
+ final SeriesDefinition seriesDefinition = new SeriesDefinition(seriesStatement, seriesLegend, seriesDir);
+ seriesDefinitions.add(seriesDefinition);
+ }
+ else
+ {
+ moreSeriesDefinitions = false;
+ }
+ index++;
+ }
+ return seriesDefinitions;
+ }
+
+}
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
new file mode 100644
index 0000000000..bdbbc4a585
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.ChartType;
+
+import junit.framework.TestCase;
+
+public class ChartBuilderFactoryTest extends TestCase
+{
+ public void testLineChart()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE);
+ assertTrue(builder instanceof LineChartBuilder);
+ }
+
+ public void testBarChart()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR);
+ assertTrue(builder instanceof BarChartBuilder);
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java
new file mode 100644
index 0000000000..1b1c9969b3
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.verify;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+
+public class SeriesBuilderTest extends TestCase
+{
+ private static final String TEST_SERIES_1_SELECT_STATEMENT = "SELECT A, B FROM test";
+ private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
+
+ private DataPointCallback _dataPointCallback = mock(DataPointCallback.class);
+ private SeriesBuilder _seriesBuilder = new SeriesBuilder(_dataPointCallback);
+
+ private File _testTempDir;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _testTempDir = createTestTemporaryDirectory();
+ }
+
+ public void testBuildOneSeries() throws Exception
+ {
+ createTestCsvIn(_testTempDir);
+ SeriesDefinition seriesDefinition = createTestSeriesDefinition();
+
+ _seriesBuilder.build(Collections.singletonList(seriesDefinition));
+
+ verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"elephant", (Object)2.0);
+ verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"lion", (Object)3.0);
+ verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"tiger", (Object)4.0);
+ }
+
+ private void createTestCsvIn(File testDir) throws Exception
+ {
+ File csv = new File(_testTempDir, "test.csv");
+
+ PrintWriter csvWriter = new PrintWriter(new BufferedWriter(new FileWriter(csv)));
+ csvWriter.println("A,B");
+ csvWriter.println("elephant,2");
+ csvWriter.println("lion,3");
+ csvWriter.println("tiger,4");
+ csvWriter.close();
+ }
+
+ private SeriesDefinition createTestSeriesDefinition()
+ {
+ SeriesDefinition definition = new SeriesDefinition(TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, _testTempDir.getAbsolutePath());
+ return definition;
+ }
+
+ private File createTestTemporaryDirectory() throws Exception
+ {
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime());
+ tmpDir.mkdirs();
+ tmpDir.deleteOnExit();
+ return tmpDir;
+ }
+
+}
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
new file mode 100644
index 0000000000..80d1cc3d21
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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.definition;
+
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TYPE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.XAXIS_TITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.YAXIS_TITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STATEMENT_KEY_FORMAT;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.disttest.charting.ChartType;
+import org.apache.qpid.disttest.charting.ChartingException;
+
+public class ChartingDefinitionCreatorTest extends TestCase
+{
+ private static final String TEST_CHART_TITLE = "CHART_TITLE";
+ private static final String TEST_XAXIS_TITLE = "XAXIS_TITLE";
+ private static final String TEST_YAXIS_TITLE = "YAXIS_TITLE";
+ private static final ChartType TEST_CHART_TYPE = ChartType.LINE;
+
+ private static final String TEST_SERIES_SELECT_STATEMENT = "SERIES_SELECT_STATEMENT";
+
+ private ChartingDefinitionCreator _chartingDefinitionLoader = new ChartingDefinitionCreator();
+ private File _testTempDir;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _testTempDir = createTestTemporaryDirectory();
+ }
+
+ public void testLoadTwoDefinitionsFromDirectory() throws Exception
+ {
+ createTestDefinitionWithin(_testTempDir);
+ createTestDefinitionWithin(_testTempDir);
+
+ List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(_testTempDir.getAbsolutePath());
+ assertEquals(2, definitions.size());
+ }
+
+ public void testLoadOneDefinitionFromFile() throws Exception
+ {
+ File testDefFile = createTestDefinitionWithin(_testTempDir);
+
+ List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(testDefFile.getAbsolutePath());
+ assertEquals(1, definitions.size());
+
+ ChartingDefinition definition1 = definitions.get(0);
+ assertEquals(TEST_CHART_TITLE, definition1.getChartTitle());
+ }
+
+ public void testDefinitionsProperties() throws Exception
+ {
+ File testDefFile = createTestDefinitionWithin(_testTempDir);
+
+ List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(testDefFile.getAbsolutePath());
+ assertEquals(1, definitions.size());
+
+ ChartingDefinition definition1 = definitions.get(0);
+ assertEquals(TEST_CHART_TITLE, definition1.getChartTitle());
+ assertEquals(TEST_XAXIS_TITLE, definition1.getXAxisTitle());
+ assertEquals(TEST_YAXIS_TITLE, definition1.getYAxisTitle());
+ assertEquals(TEST_CHART_TYPE, definition1.getChartType());
+
+ String stemOnly = testDefFile.getName().replaceFirst("\\.chartdef", "");
+ assertEquals(stemOnly, definition1.getChartStemName());
+
+ final List<SeriesDefinition> seriesDefinitions = definition1.getSeries();
+ assertEquals(1, seriesDefinitions.size());
+ SeriesDefinition seriesDefinition = seriesDefinitions.get(0);
+ assertEquals(TEST_SERIES_SELECT_STATEMENT, seriesDefinition.getSeriesStatement());
+ }
+
+ public void testDefinitionFileNotFound() throws Exception
+ {
+ File notFound = new File(_testTempDir,"notfound.chartdef");
+ assertFalse(notFound.exists());
+
+ try
+ {
+ _chartingDefinitionLoader.createFromFileOrDirectory(notFound.getAbsolutePath());
+ fail("Exception not thrown");
+ }
+ catch(ChartingException ce)
+ {
+ // PASS
+ }
+ }
+
+ private File createTestDefinitionWithin(File _testTempDir) throws Exception
+ {
+ final String testDefFileName = "test." + System.nanoTime() + ".chartdef";
+ File chartDef = new File(_testTempDir, testDefFileName);
+ chartDef.createNewFile();
+
+ Properties props = new Properties();
+ props.setProperty(CHART_TYPE_KEY, TEST_CHART_TYPE.name());
+ props.setProperty(CHART_TITLE_KEY, TEST_CHART_TITLE);
+ props.setProperty(XAXIS_TITLE_KEY, TEST_XAXIS_TITLE);
+ props.setProperty(YAXIS_TITLE_KEY, TEST_YAXIS_TITLE);
+
+ props.setProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, 1), TEST_SERIES_SELECT_STATEMENT);
+
+ final FileWriter writer = new FileWriter(chartDef);
+ try
+ {
+ props.store(writer, "Test chart definition file");
+ }
+ finally
+ {
+ writer.close();
+ }
+
+ return chartDef;
+ }
+
+ private File createTestTemporaryDirectory() throws Exception
+ {
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime());
+ tmpDir.mkdirs();
+ tmpDir.deleteOnExit();
+ return tmpDir;
+ }
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java
new file mode 100644
index 0000000000..2187793c53
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.definition;
+
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_DIRECTORY_KEY_FORMAT;
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_LEGEND_KEY_FORMAT;
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STATEMENT_KEY_FORMAT;
+
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+public class SeriesDefinitionCreatorTest extends TestCase
+{
+ private static final String TEST_SERIES_1_SELECT_STATEMENT = "SERIES_1_SELECT_STATEMENT";
+ private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
+ private static final String TEST_SERIES_1_DIR = "SERIES_1_DIR";
+
+ private static final String TEST_SERIES_1_DIR_WITH_SYSPROP = "${java.io.tmpdir}/mydir";
+
+ private static final String TEST_SERIES_2_SELECT_STATEMENT = "SERIES_2_SELECT_STATEMENT";
+ private static final String TEST_SERIES_2_LEGEND = "SERIES_2_LEGEND";
+ private static final String TEST_SERIES_2_DIR = "SERIES_2_DIR";
+
+ private Properties _properties = new Properties();
+
+ private SeriesDefinitionCreator _seriesDefinitionLoader = new SeriesDefinitionCreator();
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void testOneSeriesDefinition() throws Exception
+ {
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
+
+ List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
+ assertEquals(1, definitions.size());
+
+ SeriesDefinition definition = definitions.get(0);
+ assertEquals(TEST_SERIES_1_SELECT_STATEMENT, definition.getSeriesStatement());
+ assertEquals(TEST_SERIES_1_LEGEND, definition.getSeriesLegend());
+ assertEquals(TEST_SERIES_1_DIR, definition.getSeriesDirectory());
+ }
+
+ public void testTwoSeriesDefinitions() throws Exception
+ {
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
+ createTestProperties(2, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR);
+
+ List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
+ assertEquals(2, definitions.size());
+
+ SeriesDefinition seriesDefinition1 = definitions.get(0);
+ assertEquals(TEST_SERIES_1_SELECT_STATEMENT, seriesDefinition1.getSeriesStatement());
+ assertEquals(TEST_SERIES_1_LEGEND, seriesDefinition1.getSeriesLegend());
+ assertEquals(TEST_SERIES_1_DIR, seriesDefinition1.getSeriesDirectory());
+
+ SeriesDefinition seriesDefinition2 = definitions.get(1);
+ assertEquals(TEST_SERIES_2_SELECT_STATEMENT, seriesDefinition2.getSeriesStatement());
+ assertEquals(TEST_SERIES_2_LEGEND, seriesDefinition2.getSeriesLegend());
+ assertEquals(TEST_SERIES_2_DIR, seriesDefinition2.getSeriesDirectory());
+ }
+
+ public void testNonSequentialSeriesDefinitionsIgnored() throws Exception
+ {
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
+ createTestProperties(3, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR);
+
+ List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
+ assertEquals(1, definitions.size());
+ }
+
+ public void testSeriesDirectorySubstitution() throws Exception
+ {
+ final String tmpDir = System.getProperty("java.io.tmpdir");
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR_WITH_SYSPROP);
+
+ List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
+ assertEquals(1, definitions.size());
+
+ SeriesDefinition seriesDefinition1 = definitions.get(0);
+ assertTrue(seriesDefinition1.getSeriesDirectory().startsWith(tmpDir));
+ }
+
+ private void createTestProperties(int index, String selectStatement, String seriesLegend, String seriesDir) throws Exception
+ {
+ _properties.setProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, index), selectStatement);
+ _properties.setProperty(String.format(SERIES_LEGEND_KEY_FORMAT, index), seriesLegend);
+ _properties.setProperty(String.format(SERIES_DIRECTORY_KEY_FORMAT, index), seriesDir);
+ }
+
+}