diff options
| author | Phil Harvey <philharveyonline@apache.org> | 2013-02-09 06:41:36 +0000 |
|---|---|---|
| committer | Phil Harvey <philharveyonline@apache.org> | 2013-02-09 06:41:36 +0000 |
| commit | 4ce88b3efeeaf02b7f3ca0c342b981dcdccde377 (patch) | |
| tree | c36ff4f9cac39d1dcd8de3f1efe247b449ca7cd3 /java/perftests | |
| parent | f16b26d2da1a828f443dea2a2e57c02248927f25 (diff) | |
| download | qpid-python-4ce88b3efeeaf02b7f3ca0c342b981dcdccde377.tar.gz | |
QPID-4533: Java Performance Tests - addressed bug in JdbcSeriesBuilder that caused it to ignore the CSV series directory.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1444335 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/perftests')
8 files changed, 203 insertions, 19 deletions
diff --git a/java/perftests/etc/visualisation.sh b/java/perftests/etc/visualisation.sh index 6d4719db16..53a3f94f9c 100755 --- a/java/perftests/etc/visualisation.sh +++ b/java/perftests/etc/visualisation.sh @@ -28,6 +28,8 @@ BASE_DIR=`dirname $0` java -cp "${BASE_DIR}:${BASE_DIR}/../../build/lib/*" \ -Djava.awt.headless=true -Dlog4j.configuration=file:log4j.properties \ + -DcsvCurrentDir=. \ + -DcsvBaselineDir=. \ org.apache.qpid.disttest.charting.ChartingUtil \ chart-defs=chartdefs \ ${JDBC_DRIVER} ${JDBC_URL} diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java b/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java index 549f37c2da..456c13a2b9 100644 --- a/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java +++ b/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java @@ -25,7 +25,6 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME; import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT; import java.sql.Connection; -import java.sql.Driver; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -203,8 +202,7 @@ public class ResultsDbWriter + " missing from context environment: " + environment); } - @SuppressWarnings("unchecked") - Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(driverName); + Class.forName(driverName); Object url = environment.get(URL); if(url == null) @@ -411,6 +409,10 @@ public class ResultsDbWriter statement.execute(); connection.commit(); } + catch(SQLException e) + { + _logger.error("Couldn't write " + participantResult, e); + } finally { if (statement != null) diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java index e1403be397..91eafe324b 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java @@ -31,6 +31,7 @@ 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.apache.qpid.disttest.charting.seriesbuilder.JdbcSeriesBuilder; +import org.apache.qpid.disttest.charting.seriesbuilder.JdbcUrlGenerator; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; import org.apache.qpid.disttest.charting.writer.ChartWriter; import org.jfree.chart.JFreeChart; @@ -69,11 +70,11 @@ public class ChartingUtil /** the class name of the JDBC driver to use for reading the chart data */ public static final String JDBC_DRIVER_NAME_PROP = "jdbcDriverClass"; - public static final String JDBC_DRIVER_NAME_DEFAULT = JdbcSeriesBuilder.DEFAULT_JDBC_DRIVER_NAME; + public static final String JDBC_DRIVER_NAME_DEFAULT = JdbcUrlGenerator.DEFAULT_JDBC_DRIVER_NAME; /** the JDBC URL of the data to be charted */ public static final String JDBC_URL_PROP = "jdbcUrl"; - public static final String JDBC_URL_DEFAULT = JdbcSeriesBuilder.DEFAULT_JDBC_URL; + public static final String JDBC_URL_DEFAULT = null; private Map<String,String> _cliOptions = new HashMap<String, String>(); diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java index 61373e0ebb..d89ff855e2 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java @@ -19,6 +19,9 @@ */ package org.apache.qpid.disttest.charting.definition; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + public class SeriesDefinition { private final String _seriesStatement; @@ -60,4 +63,13 @@ public class SeriesDefinition { return _seriesStrokeWidth; } + + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("seriesLegend", _seriesLegend) + .append("seriesStatement", _seriesStatement) + .append("seriesDirectory", _seriesDirectory).toString(); + } } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java index 2cd8d9951f..525d29151a 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java @@ -35,24 +35,25 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * A {@link SeriesBuilder} that uses JDBC to read series data + * A {@link SeriesBuilder} that uses JDBC to read series data. + * The actual JDBC URL used is determined by my {@link JdbcUrlGenerator}. */ public class JdbcSeriesBuilder implements SeriesBuilder { private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSeriesBuilder.class); - public static final String DEFAULT_JDBC_DRIVER_NAME = "org.relique.jdbc.csv.CsvDriver"; - - /** the dot at the end denotes the current directory */ - public static final String DEFAULT_JDBC_URL = "jdbc:relique:csv:."; - - private final String _jdbcUrl; private SeriesBuilderCallback _callback; - public JdbcSeriesBuilder(String jdbcDriverClass, String jdbcUrl) + private final JdbcUrlGenerator _jdbcUrlGenerator; + + /** + * @param providedJdbcUrl the JDBC URL. Provide null if the value should be + * inferred by {@link #_jdbcUrlGenerator}. + */ + public JdbcSeriesBuilder(String jdbcDriverClass, String providedJdbcUrl) { registerDriver(jdbcDriverClass); - _jdbcUrl = jdbcUrl; + _jdbcUrlGenerator = new JdbcUrlGenerator(providedJdbcUrl); LOGGER.info("Created: " + this); } @@ -78,7 +79,8 @@ public class JdbcSeriesBuilder implements SeriesBuilder Statement stmt = null; try { - conn = DriverManager.getConnection(_jdbcUrl); + String jdbcUrl = _jdbcUrlGenerator.getJdbcUrl(seriesDefinition); + conn = DriverManager.getConnection(jdbcUrl); final String seriesStatement = seriesDefinition.getSeriesStatement(); @@ -146,6 +148,8 @@ public class JdbcSeriesBuilder implements SeriesBuilder @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("jdbcUrl", _jdbcUrl).toString(); + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("jdbcUrlGenerator", _jdbcUrlGenerator) + .toString(); } } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java new file mode 100644 index 0000000000..77f367b0f1 --- /dev/null +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java @@ -0,0 +1,81 @@ +/* + * 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.seriesbuilder; + +import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang.StringUtils.isNotBlank; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; + +public class JdbcUrlGenerator +{ + private String _providedJdbdUrl; + + public static final String DEFAULT_JDBC_DRIVER_NAME = "org.relique.jdbc.csv.CsvDriver"; + + /** + * Used to create the JDBC URL if one has not been passed in. + */ + private static final String CSV_JDBC_URL_BASE = "jdbc:relique:csv:"; + + /** + * @param providedJdbcUrl the JDBC URL. Provide null if the value should be + * inferred. + */ + public JdbcUrlGenerator(String providedJdbcUrl) + { + _providedJdbdUrl = providedJdbcUrl; + } + + /** + * Returns either the provided value ({@link #_providedJdbdUrl}) + * or a CSV JDBC URL pointing at {@link SeriesDefinition#getSeriesDirectory()} value. + */ + public String getJdbcUrl(SeriesDefinition seriesDefinition) + { + String seriesDir = seriesDefinition.getSeriesDirectory(); + + if(_providedJdbdUrl == null) + { + if(isBlank(seriesDir)) + { + throw new IllegalArgumentException("Neither a series directory nor a JDBC url have been specified. Series definition: " + seriesDefinition); + } + return CSV_JDBC_URL_BASE + seriesDir; + } + else + { + if(isNotBlank(seriesDir)) + { + throw new IllegalArgumentException("Both a series directory '" + seriesDir + "' and a JDBC url have been specified. Series definition: " + seriesDefinition); + } + return _providedJdbdUrl; + } + } + + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("providedJdbdUrl", _providedJdbdUrl) + .toString(); + } +}
\ No newline at end of file diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java index bd66e8e888..20d5082448 100644 --- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java +++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java @@ -58,9 +58,7 @@ public class JdbcSeriesBuilderTest extends TestCase { SeriesDefinition seriesDefinition = createTestSeriesDefinition(); - JdbcSeriesBuilder seriesBuilder = new JdbcSeriesBuilder( - "org.relique.jdbc.csv.CsvDriver", - "jdbc:relique:csv:" + _testTempDir.getAbsolutePath()); + JdbcSeriesBuilder seriesBuilder = new JdbcSeriesBuilder("org.relique.jdbc.csv.CsvDriver", null); seriesBuilder.setSeriesBuilderCallback(_seriesWalkerCallback); diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java new file mode 100644 index 0000000000..353fc718d3 --- /dev/null +++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java @@ -0,0 +1,84 @@ +/* + * 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.seriesbuilder; + +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import static org.mockito.Mockito.*; + +import junit.framework.TestCase; + +public class JdbcUrlGeneratorTest extends TestCase +{ + public void testGetJdbcUrlWithoutProvidingAUrlReturnsCsvUrlWithCorrectDirectory() + { + JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(null); + SeriesDefinition seriesDefinition = mock(SeriesDefinition.class); + when(seriesDefinition.getSeriesDirectory()).thenReturn("mydir"); + + String jdbcUrl = jdbcUrlGenerator.getJdbcUrl(seriesDefinition); + + assertEquals("jdbc:relique:csv:mydir", jdbcUrl); + } + + public void testGetJdbcUrlReturnsProvidedUrl() + { + String urlTemplate = "urlTemplate"; + JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(urlTemplate); + SeriesDefinition seriesDefinition = mock(SeriesDefinition.class); + + String jdbcUrl = jdbcUrlGenerator.getJdbcUrl(seriesDefinition); + + assertEquals(urlTemplate, jdbcUrl); + } + + public void testGetJdbcUrlThrowsExceptionIfUrlProvidedAndSeriesDirectorySpecified() + { + String urlTemplate = "urlTemplate"; + JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(urlTemplate); + SeriesDefinition seriesDefinition = mock(SeriesDefinition.class); + when(seriesDefinition.getSeriesDirectory()).thenReturn("mydir"); + + try + { + jdbcUrlGenerator.getJdbcUrl(seriesDefinition); + fail("Expected exception not thrown"); + } + catch (IllegalArgumentException e) + { + // pass + } + } + + public void testGetJdbcUrlThrowsExceptionWithoutAProvidedUrlOrSeriesDirectory() + { + JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(null); + SeriesDefinition seriesDefinition = mock(SeriesDefinition.class); + when(seriesDefinition.getSeriesDirectory()).thenReturn(null); + + try + { + jdbcUrlGenerator.getJdbcUrl(seriesDefinition); + fail("Expected exception not thrown"); + } + catch (IllegalArgumentException e) + { + // pass + } + } +} |
