diff options
Diffstat (limited to 'java/perftests/src/test/java/org')
52 files changed, 643 insertions, 223 deletions
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java index a10b3b359e..629442d86c 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java @@ -39,14 +39,6 @@ public class ConfigFileHelperTest extends QpidTestCase _testDir = TestFileUtils.createTestDirectory(); } - public void testGenerateOutputCsvNameFrom() - { - String outputDir = "/tmp/outputDir"; - - assertEquals("/tmp/outputDir/my.json.file.csv", _configFileHelper.generateOutputCsvNameFrom("/tmp/my.json.file.json", outputDir)); - assertEquals("/tmp/outputDir/my.js.file.csv", _configFileHelper.generateOutputCsvNameFrom("/tmp/my.js.file.js", outputDir)); - } - public void testGetTestConfigFilesForDirectory() throws Exception { String jsFile = createFile("file1.js"); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java new file mode 100644 index 0000000000..ab55e8003d --- /dev/null +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.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; + +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/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java index 320e7d8c9d..09f7da4efb 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java @@ -19,12 +19,11 @@ */ package org.apache.qpid.disttest; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.Command; +import org.apache.qpid.test.utils.QpidTestCase; -public class VisitorTest extends TestCase +public class VisitorTest extends QpidTestCase { public void testStringVisited() throws Exception diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java index 4a82f6719f..2b29471558 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java @@ -21,7 +21,6 @@ package org.apache.qpid.disttest.client; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import junit.framework.TestCase; import org.apache.qpid.disttest.jms.ClientJmsDelegate; import org.apache.qpid.disttest.message.CreateConnectionCommand; @@ -32,8 +31,9 @@ import org.apache.qpid.disttest.message.CreateSessionCommand; import org.apache.qpid.disttest.message.StartTestCommand; import org.apache.qpid.disttest.message.StopClientCommand; import org.apache.qpid.disttest.message.TearDownTestCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class ClientCommandVisitorTest extends TestCase +public class ClientCommandVisitorTest extends QpidTestCase { private Client _client; private ClientCommandVisitor _visitor; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java index dd50766918..8139961fa4 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java @@ -29,17 +29,16 @@ import java.util.Collections; import java.util.Timer; import java.util.TimerTask; -import junit.framework.TestCase; - import org.apache.qpid.disttest.jms.ClientJmsDelegate; import org.apache.qpid.disttest.message.Command; import org.apache.qpid.disttest.message.ParticipantResult; import org.apache.qpid.disttest.message.Response; import org.apache.qpid.disttest.message.StopClientCommand; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.InOrder; import org.mockito.Mockito; -public class ClientTest extends TestCase +public class ClientTest extends QpidTestCase { private Client _client; private ClientJmsDelegate _delegate; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java index 58589d36f4..f75415a2bf 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java @@ -34,16 +34,15 @@ import java.util.Collection; import javax.jms.Message; import javax.jms.Session; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.jms.ClientJmsDelegate; import org.apache.qpid.disttest.message.ConsumerParticipantResult; import org.apache.qpid.disttest.message.CreateConsumerCommand; import org.apache.qpid.disttest.message.ParticipantResult; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.InOrder; -public class ConsumerParticipantTest extends TestCase +public class ConsumerParticipantTest extends QpidTestCase { private static final String SESSION_NAME1 = "SESSION1"; private static final String PARTICIPANT_NAME1 = "PARTICIPANT_NAME1"; @@ -114,7 +113,7 @@ public class ConsumerParticipantTest extends TestCase _inOrder.verify(_delegate).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT); _inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage); - _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + _inOrder.verify(_delegate).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage); } public void testReceiveMessagesForDurationSynch() throws Exception @@ -129,7 +128,7 @@ public class ConsumerParticipantTest extends TestCase verify(_delegate, atLeastOnce()).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT); verify(_delegate, atLeastOnce()).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage); } public void testReceiveMessagesBatchedSynch() throws Exception @@ -147,7 +146,7 @@ public class ConsumerParticipantTest extends TestCase verify(_delegate, times(numberOfMessages)).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT); verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, times(4)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, times(4)).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage); } public void testReceiveMessagesWithVaryingPayloadSize() throws Exception @@ -171,7 +170,7 @@ public class ConsumerParticipantTest extends TestCase verify(_delegate, times(numberOfMessages)).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT); verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage); } public void testReleaseResources() @@ -194,7 +193,7 @@ public class ConsumerParticipantTest extends TestCase _inOrder.verify(_delegate).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT); _inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage); - _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + _inOrder.verify(_delegate).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage); assertTrue("Unexpected consuemr results", result instanceof ConsumerParticipantResult); Collection<Long> latencies = ((ConsumerParticipantResult)result).getMessageLatencies(); assertNotNull("Message latency is not cllected", latencies); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java index 1ff8d3e5d7..8863e0f289 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java @@ -33,14 +33,13 @@ import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; -import junit.framework.TestCase; - import org.apache.qpid.disttest.client.property.ListPropertyValue; import org.apache.qpid.disttest.client.property.PropertyValue; import org.apache.qpid.disttest.client.property.SimplePropertyValue; import org.apache.qpid.disttest.message.CreateProducerCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class MessageProviderTest extends TestCase +public class MessageProviderTest extends QpidTestCase { private Session _session; private TextMessage _message; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java index f30e4664ff..6720047cd1 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java @@ -20,6 +20,7 @@ package org.apache.qpid.disttest.client; import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,14 +29,13 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.message.ParticipantResult; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.ArgumentMatcher; import org.mockito.InOrder; -public class ParticipantExecutorTest extends TestCase +public class ParticipantExecutorTest extends QpidTestCase { private static final ResultHasError HAS_ERROR = new ResultHasError(); private static final String CLIENT_NAME = "CLIENT_NAME"; @@ -69,8 +69,8 @@ public class ParticipantExecutorTest extends TestCase InOrder inOrder = inOrder(_participant, _client); inOrder.verify(_participant).doIt(CLIENT_NAME); - inOrder.verify(_client).sendResults(_mockResult); inOrder.verify(_participant).releaseResources(); + inOrder.verify(_client).sendResults(_mockResult); } public void testParticipantThrowsException() throws Exception @@ -82,13 +82,28 @@ public class ParticipantExecutorTest extends TestCase InOrder inOrder = inOrder(_participant, _client); inOrder.verify(_participant).doIt(CLIENT_NAME); + inOrder.verify(_participant).releaseResources(); inOrder.verify(_client).sendResults(argThat(HAS_ERROR)); + } + + public void testReleaseResourcesThrowsException() throws Exception + { + when(_participant.doIt(CLIENT_NAME)).thenReturn(_mockResult); + doThrow(DistributedTestException.class).when(_participant).releaseResources(); + + _participantExecutor.start(_client); + + InOrder inOrder = inOrder(_participant, _client); + + inOrder.verify(_participant).doIt(CLIENT_NAME); inOrder.verify(_participant).releaseResources(); + + // check that sendResults is called even though releaseResources threw an exception + inOrder.verify(_client).sendResults(_mockResult); } public void testThreadNameAndDaemonness() throws Exception { - ThreadPropertyReportingParticipant participant = new ThreadPropertyReportingParticipant(PARTICIPANT_NAME); _participantExecutor = new ParticipantExecutor(participant); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java index bd0d5a39c8..5cc8d2f30a 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java @@ -20,9 +20,10 @@ package org.apache.qpid.disttest.client; import static org.mockito.Mockito.mock; -import junit.framework.TestCase; -public class ParticipantRegistryTest extends TestCase +import org.apache.qpid.test.utils.QpidTestCase; + +public class ParticipantRegistryTest extends QpidTestCase { private ParticipantExecutorRegistry _participantRegistry = new ParticipantExecutorRegistry(); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java index 3b21834a5c..9eab459443 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java @@ -22,16 +22,15 @@ import java.util.Date; import javax.jms.DeliveryMode; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.ConsumerParticipantResult; import org.apache.qpid.disttest.message.CreateConsumerCommand; import org.apache.qpid.disttest.message.CreateParticpantCommand; import org.apache.qpid.disttest.message.CreateProducerCommand; import org.apache.qpid.disttest.message.ParticipantResult; import org.apache.qpid.disttest.message.ProducerParticipantResult; +import org.apache.qpid.test.utils.QpidTestCase; -public class ParticipantResultFactoryTest extends TestCase +public class ParticipantResultFactoryTest extends QpidTestCase { private static final String PARTICIPANT_NAME = "participantName"; private static final String REGISTERED_CLIENT_NAME = "registeredClientName"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java index a3ac11b756..08ee8715fd 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java @@ -31,15 +31,14 @@ import javax.jms.DeliveryMode; import javax.jms.Message; import javax.jms.Session; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.jms.ClientJmsDelegate; import org.apache.qpid.disttest.message.CreateProducerCommand; import org.apache.qpid.disttest.message.ParticipantResult; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.InOrder; -public class ProducerParticipantTest extends TestCase +public class ProducerParticipantTest extends QpidTestCase { private ProducerParticipant _producer; @@ -127,13 +126,13 @@ public class ProducerParticipantTest extends TestCase _inOrder.verify(_delegate).sendNextMessage(isA(CreateProducerCommand.class)); _inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage); - _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + _inOrder.verify(_delegate).commitIfNecessary(SESSION_NAME1); } public void testSendMessagesForDuration() throws Exception { - final long duration = 100; + final long duration = 1000; _command.setMaximumDuration(duration); ParticipantResult result = _producer.doIt(CLIENT_NAME); @@ -142,7 +141,24 @@ public class ProducerParticipantTest extends TestCase verify(_delegate, atLeastOnce()).sendNextMessage(isA(CreateProducerCommand.class)); verify(_delegate, atLeastOnce()).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, atLeastOnce()).commitIfNecessary(SESSION_NAME1); + } + + public void testSendMessagesForDurationWithDelayExceedingDuration() throws Exception + { + final long duration = 100; + _command.setMaximumDuration(duration); + _command.setStartDelay(150); + + try + { + _producer.doIt(CLIENT_NAME); + fail("Exception should be thrown indicating configuration error"); + } + catch(DistributedTestException e) + { + assertEquals("Start delay must be less than maximum test duration", e.getMessage()); + } } public void testSendMessageBatches() throws Exception @@ -161,7 +177,7 @@ public class ProducerParticipantTest extends TestCase verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class)); verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, times(expectedNumberOfCommits)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, times(expectedNumberOfCommits)).commitIfNecessary(SESSION_NAME1); } public void testSendMessageWithPublishInterval() throws Exception @@ -183,7 +199,7 @@ public class ProducerParticipantTest extends TestCase verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class)); verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, times(4)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, times(4)).commitIfNecessary(SESSION_NAME1); } public void testSendMessageWithVaryingPayloadSize() throws Exception @@ -208,7 +224,7 @@ public class ProducerParticipantTest extends TestCase verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class)); verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage); - verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1); + verify(_delegate, times(numberOfMessages)).commitIfNecessary(SESSION_NAME1); } public void testReleaseResources() diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java index c54355bc76..3172eb07ed 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java @@ -21,13 +21,9 @@ package org.apache.qpid.disttest.client.property; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.disttest.client.property.ListPropertyValue; -import org.apache.qpid.disttest.client.property.PropertyValue; -import org.apache.qpid.disttest.client.property.SimplePropertyValue; - -public class ListPropertyValueTest extends TestCase +public class ListPropertyValueTest extends QpidTestCase { private ListPropertyValue _generator; private List<PropertyValue> _items; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java index 17397db5b8..eba1bcc435 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java @@ -18,9 +18,9 @@ */ package org.apache.qpid.disttest.client.property; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class PropertyValueFactoryTest extends TestCase +public class PropertyValueFactoryTest extends QpidTestCase { private PropertyValueFactory _factory; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java index 878141895c..9651dd95ce 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java @@ -18,11 +18,9 @@ */ package org.apache.qpid.disttest.client.property; -import org.apache.qpid.disttest.client.property.RandomPropertyValue; +import org.apache.qpid.test.utils.QpidTestCase; -import junit.framework.TestCase; - -public class RandomPropertyValueTest extends TestCase +public class RandomPropertyValueTest extends QpidTestCase { private RandomPropertyValue _generator; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java index 6932919bed..b0649a49ae 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java @@ -18,11 +18,9 @@ */ package org.apache.qpid.disttest.client.property; -import org.apache.qpid.disttest.client.property.RangePropertyValue; +import org.apache.qpid.test.utils.QpidTestCase; -import junit.framework.TestCase; - -public class RangePropertyValueTest extends TestCase +public class RangePropertyValueTest extends QpidTestCase { private RangePropertyValue _generator; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java index a347d866c7..f1977015fe 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java @@ -18,9 +18,9 @@ */ package org.apache.qpid.disttest.client.property; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class SimplePropertyValueTest extends TestCase +public class SimplePropertyValueTest extends QpidTestCase { public void testGetValue() { diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java index 37820d2582..0880512333 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java @@ -25,9 +25,9 @@ import static org.mockito.Mockito.when; import java.util.concurrent.Callable; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ExecutorWithNoLimitsTest extends TestCase +public class ExecutorWithNoLimitsTest extends QpidTestCase { private final static Object RESULT = new Object(); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java index a201a7bacf..2abdba2446 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java @@ -20,16 +20,16 @@ package org.apache.qpid.disttest.client.utils; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.never; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ExecutorWithTimeLimitTest extends TestCase +public class ExecutorWithTimeLimitTest extends QpidTestCase { private static final int TIMEOUT = 500; private static final Object RESULT = new Object(); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java index cc969e1ef2..c07d9fcb81 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java @@ -21,14 +21,15 @@ package org.apache.qpid.disttest.controller; import java.util.Timer; import java.util.TimerTask; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; +import org.apache.qpid.test.utils.QpidTestCase; -public class ClientRegistryTest extends TestCase +public class ClientRegistryTest extends QpidTestCase { private static final String CLIENT1_REGISTERED_NAME = "CLIENT1_REGISTERED_NAME"; private static final String CLIENT2_REGISTERED_NAME = "CLIENT2_REGISTERED_NAME"; + private static final String CLIENT3_REGISTERED_NAME = "CLIENT3_REGISTERED_NAME"; + private static final int AWAIT_DELAY = 100; private ClientRegistry _clientRegistry = new ClientRegistry(); @@ -70,7 +71,7 @@ public class ClientRegistryTest extends TestCase assertEquals(0, numberOfClientsAbsent); } - public void testAwaitTwoClientWhenClientRegistersWhilstWaiting() + public void testAwaitTwoClientsWhenClientRegistersWhilstWaiting() { _clientRegistry.registerClient(CLIENT1_REGISTERED_NAME); registerClientLater(CLIENT2_REGISTERED_NAME, 50); @@ -79,6 +80,41 @@ public class ClientRegistryTest extends TestCase assertEquals(0, numberOfClientsAbsent); } + public void testAwaitTimeoutForPromptRegistrations() + { + registerClientsLaterAndAssertResult("Clients registering every 100ms should be within 600ms timeout", + new int[] {300, 400, 500}, + 600, + 0); + } + + public void testAwaitTimeoutForWhenThirdRegistrationIsLate() + { + registerClientsLaterAndAssertResult("Third client registering tardily should exceed timeout", + new int[] {300, 400, 1500}, + 600, + 1); + } + + public void testAwaitTimeoutWhenSecondAndThirdRegistrationsAreLate() + { + registerClientsLaterAndAssertResult("Second and third clients registering tardily should exceed timeout", + new int[] {300, 1500, 1500}, + 600, + 2); + } + + private void registerClientsLaterAndAssertResult(String message, int[] registrationDelays, int timeout, int expectedNumberOfAbsentees) + { + registerClientLater(CLIENT1_REGISTERED_NAME, registrationDelays[0]); + registerClientLater(CLIENT2_REGISTERED_NAME, registrationDelays[1]); + registerClientLater(CLIENT3_REGISTERED_NAME, registrationDelays[2]); + + int numberOfClientsAbsent = _clientRegistry.awaitClients(3, timeout); + + assertEquals(message, expectedNumberOfAbsentees, numberOfClientsAbsent); + } + private void registerClientLater(final String clientName, long delayInMillis) { doLater(new TimerTask() diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java index bc58ea41c5..f773c727a1 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java @@ -19,6 +19,8 @@ */ package org.apache.qpid.disttest.controller; +import static org.apache.qpid.systest.disttest.SystemTestConstants.COMMAND_RESPONSE_TIMEOUT; +import static org.apache.qpid.systest.disttest.SystemTestConstants.REGISTRATION_TIMEOUT; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -31,8 +33,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.controller.config.Config; import org.apache.qpid.disttest.controller.config.TestInstance; @@ -42,16 +42,14 @@ import org.apache.qpid.disttest.message.RegisterClientCommand; import org.apache.qpid.disttest.message.Response; import org.apache.qpid.disttest.message.StopClientCommand; import org.apache.qpid.disttest.results.aggregation.ITestResult; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -public class ControllerTest extends TestCase +public class ControllerTest extends QpidTestCase { private static final String CLIENT1_REGISTERED_NAME = "client-uid1"; - private static final long COMMAND_RESPONSE_TIMEOUT = 1000; - private static final long REGISTRATION_TIMEOUT = 1000; - private Controller _controller; private ControllerJmsDelegate _respondingJmsDelegate; private TestRunner _testRunner; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java index 284db38f44..da180f328f 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java @@ -25,9 +25,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ParticipatingClientsTest extends TestCase +public class ParticipatingClientsTest extends QpidTestCase { private static final String CLIENT1_CONFIGURED_NAME = "CLIENT1_CONFIGURED_NAME"; private static final String CLIENT2_CONFIGURED_NAME = "CLIENT2_CONFIGURED_NAME"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java index 983da299b9..d8b25e76fa 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java @@ -32,8 +32,6 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; -import junit.framework.TestCase; - import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.controller.config.QueueConfig; import org.apache.qpid.disttest.controller.config.TestInstance; @@ -45,10 +43,11 @@ import org.apache.qpid.disttest.message.ParticipantResult; import org.apache.qpid.disttest.message.Response; import org.apache.qpid.disttest.message.StartTestCommand; import org.apache.qpid.disttest.message.TearDownTestCommand; +import org.apache.qpid.test.utils.QpidTestCase; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -public class TestRunnerTest extends TestCase +public class TestRunnerTest extends QpidTestCase { private static final String TEST_NAME = "TEST_NAME"; private static final String PARTICIPANT_NAME = "TEST_PARTICIPANT_NAME"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java index d4af439dea..4bf4307eaf 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java @@ -29,16 +29,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.apache.qpid.disttest.client.property.PropertyValue; import org.apache.qpid.disttest.client.property.SimplePropertyValue; import org.apache.qpid.disttest.controller.CommandForClient; import org.apache.qpid.disttest.message.Command; import org.apache.qpid.disttest.message.CreateMessageProviderCommand; import org.apache.qpid.disttest.message.NoOpCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class ClientConfigTest extends TestCase +public class ClientConfigTest extends QpidTestCase { private static final String CLIENT1 = "client1"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js index 07f8bf9d92..527300eff4 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js @@ -1,3 +1,23 @@ +/* + * + * 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. + * + */ jsonObject = { "_tests": QPID.iterations( { "__ACK_MODE": [ 0, 1 ] }, @@ -31,4 +51,4 @@ jsonObject = { ) }) -}
\ No newline at end of file +} diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java index 257f139849..e208945901 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java @@ -23,12 +23,12 @@ import java.io.Reader; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.apache.qpid.disttest.ConfigFileTestHelper; import org.apache.qpid.disttest.client.property.PropertyValue; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; -public class ConfigReaderTest extends TestCase +public class ConfigReaderTest extends QpidTestCase { private Config _config; @@ -111,8 +111,9 @@ public class ConfigReaderTest extends TestCase public void testReadsJS() throws Exception { ConfigReader configReader = new ConfigReader(); - String path = getClass().getResource("ConfigReaderTest-test-config.js").toURI().getPath(); + String path = TestFileUtils.createTempFileFromResource(this, "ConfigReaderTest-test-config.js").getAbsolutePath(); _config = configReader.getConfigFromFile(path); + List<TestConfig> testConfigs = _config.getTestConfigs(); assertEquals("Unexpected number of tests", 2, testConfigs.size()); TestConfig testConfig1 = _config.getTestConfigs().get(0); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java index 88750b9737..291ce2af78 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java @@ -24,9 +24,9 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ConfigTest extends TestCase +public class ConfigTest extends QpidTestCase { public void testGetTestsForTestWithIteratingMessageSizes() { diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java index 7c839ed462..0eee80e425 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java @@ -27,13 +27,12 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.Command; import org.apache.qpid.disttest.message.CreateConnectionCommand; import org.apache.qpid.disttest.message.NoOpCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class ConnectionConfigTest extends TestCase +public class ConnectionConfigTest extends QpidTestCase { private static final String CONNECTION_FACTORY_NAME = "ConnectionFactoryName"; private static final String CONNECTION_NAME = "ConnectionName"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java index c011ff4711..0aa05a176e 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java @@ -19,11 +19,10 @@ */ package org.apache.qpid.disttest.controller.config; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.CreateConsumerCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class ConsumerConfigTest extends TestCase +public class ConsumerConfigTest extends QpidTestCase { public void testConsumerHasZeroArgConstructorForGson() { diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js index f64af82feb..eab98e8bd7 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js @@ -1,3 +1,23 @@ +/* + * + * 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. + * + */ jsonObject = { "_countries": QPID.iterations( { "__ITERATING_VALUE": [ 0, 1 ] }, @@ -20,4 +40,4 @@ jsonObject = { ) }) -}
\ No newline at end of file +} diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java index eb4063888b..55c1d4a7bd 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java @@ -25,15 +25,16 @@ import static org.apache.commons.beanutils.PropertyUtils.getProperty; import java.util.List; import java.util.TreeMap; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; import com.google.gson.Gson; -public class JavaScriptConfigEvaluatorTest extends TestCase +public class JavaScriptConfigEvaluatorTest extends QpidTestCase { public void testEvaluateJavaScript() throws Exception { - String jsFilePath = getClass().getResource("JavaScriptConfigEvaluatorTest-test-config.js").toURI().getPath(); + String jsFilePath = TestFileUtils.createTempFileFromResource(this, "JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath(); String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java index a3b367a4b4..148c07b1ca 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java @@ -21,13 +21,12 @@ package org.apache.qpid.disttest.controller.config; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; - import org.apache.qpid.disttest.client.property.PropertyValue; import org.apache.qpid.disttest.client.property.SimplePropertyValue; import org.apache.qpid.disttest.message.CreateMessageProviderCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class MessageProviderConfigTest extends TestCase +public class MessageProviderConfigTest extends QpidTestCase { public void testCreateCommandsForMessageProvider() { diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java index f58cc628a4..b6efd68cbd 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java @@ -32,7 +32,7 @@ public class ParticipantConfigTest extends QpidTestCase setTestSystemProperty(ParticipantConfig.DURATION_OVERRIDE_SYSTEM_PROPERTY, String.valueOf(overriddenDuration)); CreateParticpantCommand createParticipantCommand = mock(CreateParticpantCommand.class); - ParticipantConfig participantConfig = new ParticipantConfig("name", "destinationName", 1, 2, 5000) + ParticipantConfig participantConfig = new ParticipantConfig("name", "destinationName", false, 1, 2, 5000) { }; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java index b9e591f113..44fca4bb7c 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java @@ -22,11 +22,10 @@ package org.apache.qpid.disttest.controller.config; import javax.jms.DeliveryMode; import javax.jms.Message; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.CreateProducerCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class ProducerConfigTest extends TestCase +public class ProducerConfigTest extends QpidTestCase { public void testProducerHasZeroArgConstructorForGson() { diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java index 8775e4064d..02cdbb8fca 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java @@ -29,14 +29,13 @@ import java.util.List; import javax.jms.Session; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.Command; import org.apache.qpid.disttest.message.CreateConsumerCommand; import org.apache.qpid.disttest.message.CreateProducerCommand; import org.apache.qpid.disttest.message.CreateSessionCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class SessionConfigTest extends TestCase +public class SessionConfigTest extends QpidTestCase { private static final String CONNECTION_NAME = "conn1"; private static final String SESSION = "session1"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java index 1212a57606..be7c7a7c8c 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java @@ -26,12 +26,11 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.apache.qpid.disttest.controller.CommandForClient; import org.apache.qpid.disttest.message.NoOpCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class TestConfigTest extends TestCase +public class TestConfigTest extends QpidTestCase { private static final QueueConfig[] EMPTY_QUEUES_ARRAY = new QueueConfig[0]; private static final String CLIENT1 = "client1"; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java index 928fbe58cf..187b57c399 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java @@ -26,14 +26,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import junit.framework.TestCase; - import org.apache.qpid.disttest.controller.CommandForClient; import org.apache.qpid.disttest.message.CreateConsumerCommand; import org.apache.qpid.disttest.message.CreateProducerCommand; import org.apache.qpid.disttest.message.NoOpCommand; +import org.apache.qpid.test.utils.QpidTestCase; -public class TestInstanceTest extends TestCase +public class TestInstanceTest extends QpidTestCase { private static final String CLIENT_NAME = "CLIENT_NAME"; private static final int ITERATION_NUMBER = 0; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java new file mode 100644 index 0000000000..abc6b44493 --- /dev/null +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java @@ -0,0 +1,158 @@ +/* + * 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.db; + +import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER; +import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME; +import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME; +import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT; +import static org.apache.qpid.test.utils.TestFileUtils.createTestDirectory; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.Hashtable; +import java.util.TimeZone; + +import javax.naming.Context; +import javax.naming.NamingException; + +import org.apache.qpid.disttest.controller.ResultsForAllTests; +import org.apache.qpid.disttest.db.ResultsDbWriter.Clock; +import org.apache.qpid.disttest.message.ParticipantResult; +import org.apache.qpid.disttest.results.ResultsTestFixture; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.util.FileUtils; + +public class ResultsDbWriterTest extends QpidTestCase +{ + private static final long _dummyTimestamp = 1234; + + private File _tempDbDirectory; + private Clock _clock = mock(Clock.class); + private ResultsTestFixture _resultsTestFixture = new ResultsTestFixture(); + + @Override + protected void setUp() throws Exception + { + super.setUp(); + _tempDbDirectory = createTestDirectory(); + when(_clock.currentTimeMillis()).thenReturn(_dummyTimestamp); + } + + + @Override + protected void tearDown() throws Exception + { + try + { + FileUtils.deleteDirectory(_tempDbDirectory.getAbsolutePath()); + } + finally + { + super.tearDown(); + } + } + + + public void testWriteResults() throws Exception + { + Context context = getContext(); + ResultsForAllTests results = _resultsTestFixture.createResultsForAllTests(); + String runId = "myRunId"; + + ResultsDbWriter resultsDbWriter = new ResultsDbWriter(context, runId, _clock); + resultsDbWriter.createResultsTableIfNecessary(); + + resultsDbWriter.writeResults(results); + + ParticipantResult expectedResult = _resultsTestFixture.getFirstParticipantResult(results); + assertResultsAreInDb(context, expectedResult, runId); + } + + public void testDefaultRunId() throws Exception + { + TimeZone defaultTimeZone = TimeZone.getDefault(); + try + { + // set non-GMT timezone to make the test more rigorous. + TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00")); + ResultsDbWriter resultsDbWriter = new ResultsDbWriter(getContext(), null, _clock); + String runId = resultsDbWriter.getRunId(); + assertEquals( + "Default run id '" + runId + "' should correspond to dummy timestamp " + _clock.currentTimeMillis(), + "run 1970-01-01 00:00:01.234", + runId); + } + finally + { + TimeZone.setDefault(defaultTimeZone); + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private Context getContext() throws NamingException + { + Context context = mock(Context.class); + Hashtable environment = new Hashtable(); + + environment.put(ResultsDbWriter.DRIVER_NAME, "org.apache.derby.jdbc.EmbeddedDriver"); + environment.put(ResultsDbWriter.URL, "jdbc:derby:" + _tempDbDirectory + "perftestResultsDb;create=true"); + + when(context.getEnvironment()).thenReturn(environment); + return context; + } + + @SuppressWarnings("unchecked") + private void assertResultsAreInDb(Context context, ParticipantResult participantResult, String expectedRunId) throws Exception + { + String driverName = (String) context.getEnvironment().get(ResultsDbWriter.DRIVER_NAME); + Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(driverName); + driverClass.newInstance(); + String url = (String) context.getEnvironment().get(ResultsDbWriter.URL); + + Connection connection = DriverManager.getConnection(url); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery( + "SELECT * FROM results WHERE testName='" + participantResult.getTestName() + + "' AND runId='" + expectedRunId + "'"); + + try + { + rs.next(); + assertEquals(participantResult.getTestName(), rs.getString(TEST_NAME.getDisplayName())); + assertEquals(participantResult.getIterationNumber(), rs.getInt(ITERATION_NUMBER.getDisplayName())); + assertEquals(participantResult.getParticipantName(), rs.getString(PARTICIPANT_NAME.getDisplayName())); + assertEquals(participantResult.getThroughput(), rs.getDouble(THROUGHPUT.getDisplayName())); + assertEquals(expectedRunId, rs.getString(ResultsDbWriter.RUN_ID)); + assertEquals(new Timestamp(_dummyTimestamp), rs.getTimestamp(ResultsDbWriter.INSERTED_TIMESTAMP)); + } + finally + { + connection.close(); + } + } +} diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java index ab0f52263b..d4f0cb1f22 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java @@ -18,12 +18,11 @@ */ package org.apache.qpid.disttest.jms; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.Command; import org.apache.qpid.disttest.message.CommandType; +import org.apache.qpid.test.utils.QpidTestCase; -public class JmsMessageAdaptorTest extends TestCase +public class JmsMessageAdaptorTest extends QpidTestCase { public void testCheckAllCommandTypes() diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java index 4a56fff8fe..2e0c2e1ecd 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java @@ -24,14 +24,13 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.qpid.disttest.client.property.ListPropertyValue; import org.apache.qpid.disttest.client.property.PropertyValue; import org.apache.qpid.disttest.json.JsonHandler; +import org.apache.qpid.test.utils.QpidTestCase; -public class JsonHandlerTest extends TestCase +public class JsonHandlerTest extends QpidTestCase { private JsonHandler _jsonHandler = null; private SendChristmasCards _testCommand = null; diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java index 34727a7b8d..e9d444d59c 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java @@ -18,7 +18,8 @@ */ package org.apache.qpid.disttest.message; -import static org.apache.qpid.disttest.message.ParticipantAttribute.*; +import static org.apache.qpid.disttest.message.ParticipantAttribute.ACKNOWLEDGE_MODE; +import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE; import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME; import static org.apache.qpid.disttest.message.ParticipantAttribute.DELIVERY_MODE; import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE; @@ -30,23 +31,25 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONO import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC; import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER; import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION; -import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE; import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED; import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME; +import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE; import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY; import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL; import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY; import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME; import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN; import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE; +import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS; +import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS; import java.util.Date; import javax.jms.DeliveryMode; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class ParticipantResultTest extends TestCase +public class ParticipantResultTest extends QpidTestCase { public void testSharedParticipantResultAttributes() throws Exception diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.java index 565f59d25b..1edef031bf 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.java @@ -15,12 +15,15 @@ * 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.formatting; +package org.apache.qpid.disttest.results; +import static org.apache.qpid.disttest.message.ParticipantAttribute.ACKNOWLEDGE_MODE; +import static org.apache.qpid.disttest.message.ParticipantAttribute.AVERAGE_LATENCY; import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE; import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME; -import static org.apache.qpid.disttest.message.ParticipantAttribute.*; +import static org.apache.qpid.disttest.message.ParticipantAttribute.DELIVERY_MODE; import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE; import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_BROWSING_SUBSCRIPTION; import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_DURABLE_SUBSCRIPTION; @@ -29,7 +32,11 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SELECTOR; import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONOUS_CONSUMER; import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC; import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER; +import static org.apache.qpid.disttest.message.ParticipantAttribute.LATENCY_STANDARD_DEVIATION; import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION; +import static org.apache.qpid.disttest.message.ParticipantAttribute.MAX_LATENCY; +import static org.apache.qpid.disttest.message.ParticipantAttribute.MESSAGE_THROUGHPUT; +import static org.apache.qpid.disttest.message.ParticipantAttribute.MIN_LATENCY; import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED; import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME; import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE; @@ -46,46 +53,41 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_PAYLOA import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.HashMap; +import java.util.List; import java.util.Map; -import junit.framework.TestCase; - import org.apache.qpid.disttest.controller.ResultsForAllTests; import org.apache.qpid.disttest.controller.TestResult; import org.apache.qpid.disttest.message.ParticipantAttribute; import org.apache.qpid.disttest.message.ParticipantResult; +import org.apache.qpid.disttest.results.aggregation.ITestResult; -public class CSVFormaterTest extends TestCase +public class ResultsTestFixture { + public static final double THROUGHPUT_VALUE = 2048.49; + private static final String TEST1 = "TEST1"; private static final String PARTICIPANT = "PARTICIPANT"; private static final String CONFIGURED_CLIENT1 = "CONFIGURED_CLIENT1"; - private CSVFormater _formatter = new CSVFormater(); - - public void testResultsFileWithWithOneRow() throws Exception + public ResultsForAllTests createResultsForAllTests() { ParticipantResult participantResult = mock(ParticipantResult.class); Map<ParticipantAttribute, Object> participantAttributes = getParticipantAttributes(); when(participantResult.getAttributes()).thenReturn(participantAttributes); when(participantResult.getParticipantName()).thenReturn(PARTICIPANT); + when(participantResult.getTestName()).thenReturn(TEST1); + when(participantResult.getIterationNumber()).thenReturn(0); + when(participantResult.getThroughput()).thenReturn(THROUGHPUT_VALUE); TestResult testResult = new TestResult(TEST1); testResult.addParticipantResult(participantResult); ResultsForAllTests resultsForAllTests = new ResultsForAllTests(); resultsForAllTests.add(testResult); - - String output = _formatter.format(resultsForAllTests); - - String expectedOutput = readCsvOutputFileAsString("expectedOutput.csv"); - - assertEquals(expectedOutput, output); + return resultsForAllTests; } private Map<ParticipantAttribute, Object> getParticipantAttributes() @@ -96,7 +98,7 @@ public class CSVFormaterTest extends TestCase participantAttributes.put(ITERATION_NUMBER, 0); participantAttributes.put(CONFIGURED_CLIENT_NAME, CONFIGURED_CLIENT1); participantAttributes.put(PARTICIPANT_NAME, PARTICIPANT); - participantAttributes.put(NUMBER_OF_MESSAGES_PROCESSED, 0); + participantAttributes.put(NUMBER_OF_MESSAGES_PROCESSED, 2); participantAttributes.put(PAYLOAD_SIZE, 1); participantAttributes.put(PRIORITY, 2); participantAttributes.put(TIME_TO_LIVE, 3); @@ -115,32 +117,22 @@ public class CSVFormaterTest extends TestCase participantAttributes.put(TOTAL_NUMBER_OF_CONSUMERS, 1); participantAttributes.put(TOTAL_NUMBER_OF_PRODUCERS, 2); participantAttributes.put(TOTAL_PAYLOAD_PROCESSED, 1024); - participantAttributes.put(THROUGHPUT, 2048); + participantAttributes.put(THROUGHPUT, THROUGHPUT_VALUE); participantAttributes.put(TIME_TAKEN, 1000); participantAttributes.put(ERROR_MESSAGE, "error"); participantAttributes.put(MIN_LATENCY, 2l); participantAttributes.put(MAX_LATENCY, 9l); - participantAttributes.put(AVERAGE_LATENCY, 5.0f); + participantAttributes.put(AVERAGE_LATENCY, 4.6f); participantAttributes.put(LATENCY_STANDARD_DEVIATION, 2.0f); + participantAttributes.put(MESSAGE_THROUGHPUT, 2); return participantAttributes; } - private String readCsvOutputFileAsString(String filename) throws Exception + public ParticipantResult getFirstParticipantResult(ResultsForAllTests results) { - InputStream is = getClass().getResourceAsStream(filename); - assertNotNull(is); - - StringBuilder output = new StringBuilder(); - - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - String line = null; - while((line = br.readLine()) != null) - { - output.append(line); - output.append("\n"); - } - - return output.toString(); + List<ITestResult> testResults = results.getTestResults(); + ITestResult testResult = testResults.iterator().next(); + List<ParticipantResult> participantResults = testResult.getParticipantResults(); + return participantResults.iterator().next(); } - } diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java index 393837b4d5..011eb4e68b 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java @@ -24,11 +24,10 @@ import static org.mockito.Mockito.when; import java.util.Arrays; -import junit.framework.TestCase; - import org.apache.qpid.disttest.controller.ResultsForAllTests; +import org.apache.qpid.test.utils.QpidTestCase; -public class AggregatorTest extends TestCase +public class AggregatorTest extends QpidTestCase { private Aggregator _aggregator = new Aggregator(); private TestResultAggregator _testResultAggregator = mock(TestResultAggregator.class); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java index 72743be1d1..41da1edb33 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java @@ -24,11 +24,9 @@ import java.util.Date; import javax.jms.Session; import org.apache.qpid.disttest.message.ParticipantResult; -import org.apache.qpid.disttest.results.aggregation.ParticipantResultAggregator; +import org.apache.qpid.test.utils.QpidTestCase; -import junit.framework.TestCase; - -public class ParticipantResultAggregatorTest extends TestCase +public class ParticipantResultAggregatorTest extends QpidTestCase { private ParticipantResultAggregator _aggregator = new ParticipantResultAggregator(ParticipantResult.class, AGGREGATED_RESULT_NAME); @@ -39,15 +37,19 @@ public class ParticipantResultAggregatorTest extends TestCase private static final long PARTICIPANT1_STARTDATE = 50; private static final long PARTICIPANT1_ENDDATE = 20000; private static final long PARTICIPANT1_TOTAL_PROCESSED = 1024; + private static final int PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED = 20000; private static final long PARTICIPANT2_STARTDATE = 100; private static final long PARTICIPANT2_ENDDATE = 21000; private static final long PARTICIPANT2_TOTAL_PROCESSED = 2048; + private static final int PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED = 950; private static final long OVERALL_PROCESSED = PARTICIPANT1_TOTAL_PROCESSED + PARTICIPANT2_TOTAL_PROCESSED; private static final double OVERALL_TIMETAKEN = PARTICIPANT2_ENDDATE - PARTICIPANT1_STARTDATE; + private static final long OVERALL_NUMBER_OF_MESSAGES_PROCESSED = PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED + PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED; private static final double EXPECTED_AGGREGATED_ALL_THROUGHPUT = ((OVERALL_PROCESSED)/1024)/((OVERALL_TIMETAKEN)/1000); + private static final int EXPECTED_AGGREGATED_MESSAGE_THROUGHPUT = (int)(OVERALL_NUMBER_OF_MESSAGES_PROCESSED * 1000.0d/OVERALL_TIMETAKEN); public void testStartAndEndDateForOneParticipantResult() { @@ -128,6 +130,26 @@ public class ParticipantResultAggregatorTest extends TestCase assertEquals(EXPECTED_AGGREGATED_ALL_THROUGHPUT, aggregratedResult.getThroughput(), 0.1); } + public void testComputeMessageThroughput() + { + ParticipantResult result1 = new ParticipantResult(); + result1.setStartDate(new Date(PARTICIPANT1_STARTDATE)); + result1.setEndDate(new Date(PARTICIPANT1_ENDDATE)); + result1.setNumberOfMessagesProcessed(PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED); + + ParticipantResult result2 = new ParticipantResult(); + result2.setStartDate(new Date(PARTICIPANT2_STARTDATE)); + result2.setEndDate(new Date(PARTICIPANT2_ENDDATE)); + result2.setNumberOfMessagesProcessed(PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED); + + _aggregator.aggregate(result1); + _aggregator.aggregate(result2); + + ParticipantResult aggregratedResult = _aggregator.getAggregatedResult(); + assertEquals(EXPECTED_AGGREGATED_MESSAGE_THROUGHPUT, aggregratedResult.getMessageThroughput()); + + } + public void testConstantTestNameAndIterationNumberRolledUp() throws Exception { ParticipantResult result1 = new ParticipantResult(); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java index ec8da8418f..7417dddc4f 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java @@ -23,9 +23,9 @@ package org.apache.qpid.disttest.results.aggregation; import java.util.Arrays; import java.util.Collection; -import junit.framework.TestCase; +import org.apache.qpid.test.utils.QpidTestCase; -public class SeriesStatisticsTest extends TestCase +public class SeriesStatisticsTest extends QpidTestCase { public static Collection<Long> SERIES = Arrays.asList(new Long[] { 2l, 4l, 4l, 4l, 5l, 5l, 7l, 9l, 5l }); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java index 9c00e7cf1c..b254a0e3bf 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java @@ -18,29 +18,30 @@ */ package org.apache.qpid.disttest.results.aggregation; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; import java.util.Date; import java.util.List; -import junit.framework.TestCase; - +import org.apache.qpid.disttest.controller.ResultsForAllTests; import org.apache.qpid.disttest.controller.TestResult; import org.apache.qpid.disttest.message.ConsumerParticipantResult; import org.apache.qpid.disttest.message.ParticipantResult; import org.apache.qpid.disttest.message.ProducerParticipantResult; +import org.apache.qpid.test.utils.QpidTestCase; -public class TestResultAggregatorTest extends TestCase +public class TestResultAggregatorTest extends QpidTestCase { - private static final String TEST1_NAME = "TEST1_NAME"; private static final int TEST1_ITERATION_NUMBER = 1; - private static final String CONSUMER_PARTICIPANT_NAME1 = "CONSUMER_PARTICIPANT_NAME1"; private static final String CONSUMER_PARTICIPANT_NAME2 = "CONSUMER_PARTICIPANT_NAME2"; private static final String PRODUCER_PARTICIPANT_NAME = "PRODUCER_PARTICIPANT_NAME"; - private static final long CONSUMER1_STARTDATE = 50; private static final long CONSUMER1_ENDDATE = 20000; @@ -64,6 +65,33 @@ public class TestResultAggregatorTest extends TestCase private TestResultAggregator _aggregator = new TestResultAggregator(); + public void testAggregateTestResults() + { + ResultsForAllTests resultsForAllTests1 = mock(ResultsForAllTests.class); + ResultsForAllTests resultsForAllTests2 = mock(ResultsForAllTests.class); + + ResultsForAllTests summaryResult1 = mock(ResultsForAllTests.class); + ResultsForAllTests summaryResult2 = mock(ResultsForAllTests.class); + + when(resultsForAllTests1.getAllParticipantsResult()).thenReturn(summaryResult1); + when(resultsForAllTests2.getAllParticipantsResult()).thenReturn(summaryResult2); + + ITestResult testResult1 = mock(ITestResult.class); + ITestResult testResult2 = mock(ITestResult.class); + + when(summaryResult1.getTestResults()).thenReturn(Arrays.asList(testResult1)); + when(summaryResult2.getTestResults()).thenReturn(Arrays.asList(testResult2)); + + ResultsForAllTests actualSummaryResults = _aggregator.aggregateTestResults(Arrays.asList( + resultsForAllTests1, + resultsForAllTests2)); + + assertEquals( + "Summary results should contain the all the 'all participants' test results", + Arrays.asList(testResult1, testResult2), + actualSummaryResults.getTestResults()); + } + public void testAggregateResultsForTwoConsumerAndOneProducer() throws Exception { TestResult originalTestResult = createResultsFromTest(); @@ -141,6 +169,10 @@ public class TestResultAggregatorTest extends TestCase aggregatedTestResult.getAllParticipantResult(), TEST1_NAME, TEST1_ITERATION_NUMBER, BATCH_SIZE, NUMBER_OF_MESSAGES_CONSUMED_IN_TOTAL, 2, 1); + + int expectedThroughtput = (int)Math.round(NUMBER_OF_MESSAGES_PRODUCED * 1000.0d /(CONSUMER2_ENDDATE - PRODUCER_STARTDATE)); + ParticipantResult result = aggregatedTestResult.getAllParticipantResult(); + assertEquals("Unexpected message throughtput", expectedThroughtput, result.getMessageThroughput()); } private void assertLatencyAggregatedResults(ParticipantResult allConsumerParticipantResult) @@ -197,4 +229,5 @@ public class TestResultAggregatorTest extends TestCase participantResult.setEndDate(new Date(end)); participantResult.setBatchSize(batchSize); } + } diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java new file mode 100644 index 0000000000..bbf73b23d2 --- /dev/null +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java @@ -0,0 +1,62 @@ +/* + * 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.formatting; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.qpid.disttest.controller.ResultsForAllTests; +import org.apache.qpid.disttest.results.ResultsTestFixture; +import org.apache.qpid.test.utils.QpidTestCase; + +public class CSVFormatterTest extends QpidTestCase +{ + private CSVFormatter _formatter = new CSVFormatter(); + + public void testResultsFileWithWithOneRow() throws Exception + { + ResultsTestFixture resultsTestFixture = new ResultsTestFixture(); + ResultsForAllTests resultsForAllTests = resultsTestFixture.createResultsForAllTests(); + + String output = _formatter.format(resultsForAllTests); + + String expectedOutput = readCsvOutputFileAsString("expectedOutput.csv"); + + assertEquals(expectedOutput, output); + } + + private String readCsvOutputFileAsString(String filename) throws Exception + { + InputStream is = getClass().getResourceAsStream(filename); + assertNotNull(is); + + StringBuilder output = new StringBuilder(); + + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line = null; + while((line = br.readLine()) != null) + { + output.append(line); + output.append("\n"); + } + + return output.toString(); + } +} diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java index 6cec4b5245..ed109a2e27 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java @@ -19,15 +19,13 @@ package org.apache.qpid.disttest.results.formatting; -import junit.framework.TestCase; - import org.apache.qpid.disttest.message.ConsumerParticipantResult; import org.apache.qpid.disttest.message.ParticipantResult; import org.apache.qpid.disttest.message.ProducerParticipantResult; import org.apache.qpid.disttest.results.aggregation.TestResultAggregator; -import org.apache.qpid.disttest.results.formatting.CSVOrderParticipantResultComparator; +import org.apache.qpid.test.utils.QpidTestCase; -public class CSVOrderParticipantResultComparatorTest extends TestCase +public class CSVOrderParticipantResultComparatorTest extends QpidTestCase { CSVOrderParticipantResultComparator _comparator = new CSVOrderParticipantResultComparator(); diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv index ada2303d46..02ea67d56d 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv @@ -1,2 +1,2 @@ -testName,iterationNumber,clientName,participantName,numberOfMessages,payloadSizeB,priority,timeToLiveMs,acknowledgeMode,deliveryMode,batchSize,maximumDurationMs,producerStartDelayMs,producerIntervalMs,isTopic,isDurableSubscription,isBrowsingSubscription,isSelector,isNoLocal,isSynchronousConsumer,totalNumberOfConsumers,totalNumberOfProducers,totalPayloadProcessedB,throughputKbPerS,timeTakenMs,errorMessage,minLatency,maxLatency,averageLatency,latencyStandardDeviation -TEST1,0,CONFIGURED_CLIENT1,PARTICIPANT,0,1,2,3,4,5,6,7,8,9,true,false,true,false,true,false,1,2,1024,2048,1000,error,2,9,5.0,2.0 +testName,iterationNumber,throughputKbPerS,averageLatency,clientName,participantName,numberOfMessages,payloadSizeB,priority,timeToLiveMs,acknowledgeMode,deliveryMode,batchSize,maximumDurationMs,producerStartDelayMs,producerIntervalMs,isTopic,isDurableSubscription,isBrowsingSubscription,isSelector,isNoLocal,isSynchronousConsumer,totalNumberOfConsumers,totalNumberOfProducers,totalPayloadProcessedB,timeTakenMs,errorMessage,minLatency,maxLatency,latencyStandardDeviation,throughputMessagesPerS +TEST1,0,2048,5,CONFIGURED_CLIENT1,PARTICIPANT,2,1,2,3,4,5,6,7,8,9,true,false,true,false,true,false,1,2,1024,1000,error,2,9,2.0,2 diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java index 784e43469e..59396d46c0 100644 --- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java @@ -29,7 +29,6 @@ import javax.jms.Session; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; -import org.apache.qpid.disttest.DistributedTestException; import org.apache.qpid.disttest.controller.config.QueueConfig; import org.apache.qpid.disttest.jms.QpidQueueCreator; @@ -37,6 +36,9 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase { private static final Map<String, Object> EMPTY_ATTRIBUTES = Collections.emptyMap(); + private static final boolean QUEUE_DURABILITY = true; + + private Connection _connection; private QpidQueueCreator _creator; private Session _session; private List<QueueConfig> _configs; @@ -46,20 +48,20 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase public void setUp() throws Exception { super.setUp(); - Connection connection = getConnection(); - _session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + _connection = getConnection(); + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); _creator = new QpidQueueCreator(); _configs = new ArrayList<QueueConfig>(); - _queueName = "direct://amq.direct//" + getTestQueueName(); + _queueName = "direct://amq.direct//" + getTestQueueName() + "?durable='" + QUEUE_DURABILITY + "'"; } public void testCreateQueueWithoutAttributes() throws Exception { - _configs.add(new QueueConfig(_queueName, true, EMPTY_ATTRIBUTES)); + _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, EMPTY_ATTRIBUTES)); assertQueueBound(_queueName, false); - _creator.createQueues(_session, _configs); + _creator.createQueues(_connection, _session, _configs); assertQueueBound(_queueName, true); } @@ -68,46 +70,28 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("x-qpid-priorities", Integer.valueOf(5)); - _configs.add(new QueueConfig(_queueName, true, attributes)); + _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, attributes)); assertQueueBound(_queueName, false); - _creator.createQueues(_session, _configs); + _creator.createQueues(_connection, _session, _configs); assertQueueBound(_queueName, true); } public void testDeleteQueues() throws Exception { - _configs.add(new QueueConfig(_queueName, true, EMPTY_ATTRIBUTES)); + _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, EMPTY_ATTRIBUTES)); assertQueueBound(_queueName, false); - _creator.createQueues(_session, _configs); + _creator.createQueues(_connection, _session, _configs); assertQueueBound(_queueName, true); - _creator.deleteQueues(_session, _configs); + _creator.deleteQueues(_connection, _session, _configs); assertQueueBound(_queueName, false); } - public void testDeleteQueueThatDoesNotExist() throws Exception - { - String queueThatDoesNotExist = _queueName; - List<QueueConfig> configs = new ArrayList<QueueConfig>(); - Map<String, Object> attributes = Collections.emptyMap(); - configs.add(new QueueConfig(queueThatDoesNotExist, true, attributes)); - - try - { - _creator.deleteQueues(_session, configs); - fail("Exception not thrown"); - } - catch (DistributedTestException e) - { - // PASS - } - } - private void assertQueueBound(String queueName, boolean isBound) throws Exception { AMQDestination destination = (AMQDestination)_session.createQueue(queueName); diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java index 808b428bc9..b06ab0c735 100644 --- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java +++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java @@ -21,8 +21,8 @@ package org.apache.qpid.systest.disttest; public abstract class SystemTestConstants { - public static final long REGISTRATION_TIMEOUT = 5000; - public static final long COMMAND_RESPONSE_TIMEOUT = 10000; - public static final long TEST_RESULT_TIMEOUT = 5000; + public static final long REGISTRATION_TIMEOUT = 20000; + public static final long COMMAND_RESPONSE_TIMEOUT = 30000; + public static final long TEST_RESULT_TIMEOUT = 20000; } diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java index 7e58e1b5b1..a0c2a4b342 100644 --- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java @@ -20,7 +20,9 @@ package org.apache.qpid.systest.disttest.endtoend; import static org.apache.qpid.disttest.AbstractRunner.JNDI_CONFIG_PROP; import static org.apache.qpid.disttest.ControllerRunner.OUTPUT_DIR_PROP; +import static org.apache.qpid.disttest.ControllerRunner.RUN_ID; import static org.apache.qpid.disttest.ControllerRunner.TEST_CONFIG_PROP; +import static org.apache.qpid.disttest.ControllerRunner.WRITE_TO_DB; import java.io.File; import java.io.IOException; @@ -36,6 +38,7 @@ public class EndToEndTest extends QpidBrokerTestCase private ControllerRunner _runner; private static final String TEST_CONFIG = "perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/endtoend.json"; private static final String JNDI_CONFIG_FILE = "perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties"; + private static final String RUN1 = "run1"; public void testRunner() throws Exception { @@ -44,6 +47,8 @@ public class EndToEndTest extends QpidBrokerTestCase final String[] args = new String[] {TEST_CONFIG_PROP + "=" + TEST_CONFIG, JNDI_CONFIG_PROP + "=" + JNDI_CONFIG_FILE, + WRITE_TO_DB + "=true", + RUN_ID + "=" + RUN1, OUTPUT_DIR_PROP + "=" + csvOutputDir.getAbsolutePath()}; _runner = new ControllerRunner(); _runner.parseArgumentsIntoConfig(args); @@ -76,10 +81,10 @@ public class EndToEndTest extends QpidBrokerTestCase String[] cells = csvLine.split(",", DONT_STRIP_EMPTY_LAST_FIELD_FLAG); // All attributes become cells in the CSV, so this will be true assertEquals("Unexpected number of cells in CSV line " + csvLine, ParticipantAttribute.values().length, cells.length); - assertEquals("Unexpected test name in CSV line " + csvLine, testName, cells[0]); - assertEquals("Unexpected client name in CSV line " + csvLine, clientName, cells[2]); - assertEquals("Unexpected participant name in CSV line " + csvLine, participantName, cells[3]); - assertEquals("Unexpected number of messages processed in CSV line " + csvLine, String.valueOf(expectedNumberOfMessagesProcessed), cells[4]); + assertEquals("Unexpected test name in CSV line " + csvLine, testName, cells[ParticipantAttribute.TEST_NAME.ordinal()]); + assertEquals("Unexpected client name in CSV line " + csvLine, clientName, cells[ParticipantAttribute.CONFIGURED_CLIENT_NAME.ordinal()]); + assertEquals("Unexpected participant name in CSV line " + csvLine, participantName, cells[ParticipantAttribute.PARTICIPANT_NAME.ordinal()]); + assertEquals("Unexpected number of messages processed in CSV line " + csvLine, String.valueOf(expectedNumberOfMessagesProcessed), cells[ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED.ordinal()]); } diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties index b5d053227c..149e632048 100644 --- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties +++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties @@ -24,3 +24,6 @@ java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextF connectionfactory.connectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:15672' destination.controllerqueue = direct://amq.direct//controllerqueue + +jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver +jdbcUrl=jdbc:derby:/tmp/tempDbDirectory/perftestResultsDb;create=true |