From 9bcbad89194862ef37832b9936ba8fc5fa58c47b Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Fri, 7 Mar 2014 17:24:48 +0000 Subject: QPID-5612: JMS benchmarking tool [Part of the existing Java Broker Performance Test suite] Simple tool that uses the existing performance test suite to give a message throughput statistics (msg/s) and (Kbytes/s) for a use case involving a producer/consumer (on separate connections) with persistent messages on transactional sessions. The test scales the number of connections through 1, 2, 5 and 10 and reports separate statistics for each. The duration of the test and message size can be overridden from the command line via system properties -Dqpid.disttest.duration and -Dqpid.disttest.messageSize respectively. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1575336 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/disttest/ResultsFileWriterTest.java | 85 --------------------- .../config/JavaScriptConfigEvaluatorTest.java | 29 ++++++++ .../controller/config/ProducerConfigTest.java | 15 ++++ .../disttest/results/ResultsFileWriterTest.java | 86 ++++++++++++++++++++++ 4 files changed, 130 insertions(+), 85 deletions(-) delete mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java create mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsFileWriterTest.java (limited to 'qpid/java/perftests/src/test') diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java deleted file mode 100644 index ab55e8003d..0000000000 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.util.Arrays; - -import org.apache.qpid.disttest.controller.ResultsForAllTests; -import org.apache.qpid.disttest.results.aggregation.TestResultAggregator; -import org.apache.qpid.disttest.results.formatting.CSVFormatter; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.test.utils.TestFileUtils; -import org.apache.qpid.util.FileUtils; - -public class ResultsFileWriterTest extends QpidTestCase -{ - private CSVFormatter _csvFormater = mock(CSVFormatter.class); - private TestResultAggregator _testResultAggregator = mock(TestResultAggregator.class); - - private File _outputDir = TestFileUtils.createTestDirectory(); - - private ResultsFileWriter _resultsFileWriter = new ResultsFileWriter(_outputDir); - - @Override - public void setUp() - { - _resultsFileWriter.setCsvFormater(_csvFormater); - _resultsFileWriter.setTestResultAggregator(_testResultAggregator); - } - - public void testWriteResultsToFile() - { - ResultsForAllTests resultsForAllTests = mock(ResultsForAllTests.class); - - String expectedCsvContents = "expected-csv-contents"; - when(_csvFormater.format(resultsForAllTests)).thenReturn(expectedCsvContents); - - _resultsFileWriter.writeResultsToFile(resultsForAllTests, "config.json"); - - File resultsFile = new File(_outputDir, "config.csv"); - - assertEquals(expectedCsvContents, FileUtils.readFileAsString(resultsFile)); - } - - public void testWriteResultsSummary() - { - ResultsForAllTests results1 = mock(ResultsForAllTests.class); - ResultsForAllTests results2 = mock(ResultsForAllTests.class); - ResultsForAllTests summaryResults = mock(ResultsForAllTests.class); - - when(_testResultAggregator.aggregateTestResults(Arrays.asList(results1, results2))) - .thenReturn(summaryResults); - - String expectedSummaryFileContents = "expected-summary-file"; - - when(_csvFormater.format(summaryResults)) - .thenReturn(expectedSummaryFileContents); - - _resultsFileWriter.writeResultsSummary(Arrays.asList(results1, results2)); - - File summaryFile = new File(_outputDir, ResultsFileWriter.TEST_SUMMARY_FILE_NAME); - - assertEquals(expectedSummaryFileContents, FileUtils.readFileAsString(summaryFile)); - } - -} diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java index 55c1d4a7bd..174bd8092c 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java @@ -22,6 +22,7 @@ package org.apache.qpid.disttest.controller.config; import static org.apache.commons.beanutils.PropertyUtils.getProperty; +import java.io.FileReader; import java.util.List; import java.util.TreeMap; @@ -59,6 +60,34 @@ public class JavaScriptConfigEvaluatorTest extends QpidTestCase assertEquals("Unexpected iterating attribute", "1", getProperty(country1, "_regions.[0]._towns.[0]._iteratingAttribute")); } + public void testEvaluateJavaScriptWithReader() throws Exception + { + String jsFilePath = TestFileUtils.createTempFileFromResource(this, "JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath(); + + FileReader fileReader = new FileReader(jsFilePath); + String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(fileReader); + + Object configAsObject = getObject(rawConfig); + + // Tests are produced by the QPID.iterations js function + assertEquals("Unexpected number of countries", 2, getPropertyAsList(configAsObject, "_countries").size()); + + Object country0 = getProperty(configAsObject, "_countries.[0]"); + assertEquals("Unexpected country name", "Country", getProperty(country0, "_name")); + assertEquals("Unexpected country iteration number", 0, getPropertyAsInt(country0, "_iterationNumber")); + + assertEquals("Unexpected number of regions", 2, getPropertyAsList(country0, "_regions").size()); + // Region names are produced by the QPID.times js function + assertEquals("Unexpected region name", "repeatingRegion0", getProperty(country0, "_regions.[0]._name")); + assertEquals("Unexpected region name", "repeatingRegion1", getProperty(country0, "_regions.[1]._name")); + // Iterating attribute are produced by the QPID.iterations js function + assertEquals("Unexpected iterating attribute", "0", getProperty(country0, "_regions.[0]._towns.[0]._iteratingAttribute")); + + Object country1 = getProperty(configAsObject, "_countries.[1]"); + assertEquals("Unexpected country iteration number", 1, getPropertyAsInt(country1, "_iterationNumber")); + assertEquals("Unexpected iterating attribute", "1", getProperty(country1, "_regions.[0]._towns.[0]._iteratingAttribute")); + } + private int getPropertyAsInt(Object configAsObject, String property) throws Exception { Number propertyValue = (Number) getProperty(configAsObject, property); diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java index 44fca4bb7c..ea9a406b1d 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java @@ -41,6 +41,21 @@ public class ProducerConfigTest extends QpidTestCase assertEquals(Message.DEFAULT_TIME_TO_LIVE, p.getTimeToLive()); } + public void testMessageSizeDefault() + { + CreateProducerCommand producer = new ProducerConfig().createCommand("session1"); + assertEquals("Unexpected default message size", 1024, producer.getMessageSize()); + } + + public void testMessageSizeDefaultOverride() + { + final long overriddenMessageSize = 4096; + setTestSystemProperty(ProducerConfig.MESSAGE_SIZE_OVERRIDE_SYSTEM_PROPERTY, String.valueOf(overriddenMessageSize)); + + CreateProducerCommand producer2 = new ProducerConfig().createCommand("session1"); + assertEquals("Unexpected message size", overriddenMessageSize, producer2.getMessageSize()); + } + public void testCreateProducerCommand() { String destination = "url:/destination"; diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsFileWriterTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsFileWriterTest.java new file mode 100644 index 0000000000..db306ea1a4 --- /dev/null +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsFileWriterTest.java @@ -0,0 +1,86 @@ +/* + * 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.results; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.Arrays; + +import org.apache.qpid.disttest.controller.ResultsForAllTests; +import org.apache.qpid.disttest.results.ResultsCsvWriter; +import org.apache.qpid.disttest.results.aggregation.TestResultAggregator; +import org.apache.qpid.disttest.results.formatting.CSVFormatter; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; + +public class ResultsFileWriterTest extends QpidTestCase +{ + private CSVFormatter _csvFormater = mock(CSVFormatter.class); + private TestResultAggregator _testResultAggregator = mock(TestResultAggregator.class); + + private File _outputDir = TestFileUtils.createTestDirectory(); + + private ResultsCsvWriter _resultsFileWriter = new ResultsCsvWriter(_outputDir); + + @Override + public void setUp() + { + _resultsFileWriter.setCsvFormater(_csvFormater); + _resultsFileWriter.setTestResultAggregator(_testResultAggregator); + } + + public void testWriteResultsToFile() + { + ResultsForAllTests resultsForAllTests = mock(ResultsForAllTests.class); + + String expectedCsvContents = "expected-csv-contents"; + when(_csvFormater.format(resultsForAllTests)).thenReturn(expectedCsvContents); + + _resultsFileWriter.writeResults(resultsForAllTests, "config.json"); + + File resultsFile = new File(_outputDir, "config.csv"); + + assertEquals(expectedCsvContents, FileUtils.readFileAsString(resultsFile)); + } + + public void testWriteResultsSummary() + { + ResultsForAllTests results1 = mock(ResultsForAllTests.class); + ResultsForAllTests results2 = mock(ResultsForAllTests.class); + ResultsForAllTests summaryResults = mock(ResultsForAllTests.class); + + when(_testResultAggregator.aggregateTestResults(Arrays.asList(results1, results2))) + .thenReturn(summaryResults); + + String expectedSummaryFileContents = "expected-summary-file"; + + when(_csvFormater.format(summaryResults)) + .thenReturn(expectedSummaryFileContents); + + _resultsFileWriter.writeResultsSummary(Arrays.asList(results1, results2)); + + File summaryFile = new File(_outputDir, ResultsCsvWriter.TEST_SUMMARY_FILE_NAME); + + assertEquals(expectedSummaryFileContents, FileUtils.readFileAsString(summaryFile)); + } + +} -- cgit v1.2.1