summaryrefslogtreecommitdiff
path: root/qpid/java/perftests/src/test
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-07-04 15:06:05 +0000
committerKeith Wall <kwall@apache.org>2012-07-04 15:06:05 +0000
commite40eb10fcbde6c1227d523befec06a64c4727f5f (patch)
tree26365896e4b12928c17c35f3d0339909027c81ae /qpid/java/perftests/src/test
parent021cb0af0cef02fbdd8132ce598f8663954dbdfc (diff)
downloadqpid-python-e40eb10fcbde6c1227d523befec06a64c4727f5f.tar.gz
QPID-4103: [Java Performance Tests] Allow specifying of test configuration with javascript
Applied patch from Oleksandr Rudyy <orudyy@gmail.com> and Philip Harvey <phil@philharveyonline.com>. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1357294 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests/src/test')
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java79
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileTestHelper.java (renamed from qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelper.java)2
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java38
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java48
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js34
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controllerandclient/ControllerAndClientTest.java6
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controlleronly/DistributedControllerTest.java4
7 files changed, 203 insertions, 8 deletions
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java
new file mode 100644
index 0000000000..a10b3b359e
--- /dev/null
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class ConfigFileHelperTest extends QpidTestCase
+{
+ private File _testDir;
+ private ConfigFileHelper _configFileHelper = new ConfigFileHelper();
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ _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");
+ String jsonFile = createFile("file2.json");
+ createFile("file.txt");
+ createDir("dir.js");
+
+ String testConfigPath = _testDir.getAbsolutePath();
+
+ List<String> configFiles = _configFileHelper.getTestConfigFiles(testConfigPath);
+
+ Set<String> expectedFiles = new HashSet<String>(Arrays.asList(jsFile, jsonFile));
+ Set<String> actualFiles = new HashSet<String>(configFiles);
+
+ assertEquals(expectedFiles, actualFiles);
+ }
+
+ private void createDir(String dirName)
+ {
+ File dir = new File(_testDir, dirName);
+ dir.mkdir();
+ }
+
+ private String createFile(String fileName) throws IOException
+ {
+ File file = new File(_testDir, fileName);
+ file.createNewFile();
+ return file.getAbsolutePath();
+ }
+}
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelper.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileTestHelper.java
index 12ba3b56ad..71cd61db82 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelper.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileTestHelper.java
@@ -26,7 +26,7 @@ import java.io.Reader;
import org.apache.qpid.disttest.controller.config.Config;
import org.apache.qpid.disttest.controller.config.ConfigReader;
-public class ConfigFileHelper
+public class ConfigFileTestHelper
{
public static Reader getConfigFileReader(Class<?> testClass, String resourceName)
{
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
index 91b219585a..21981c93dd 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
@@ -25,7 +25,7 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.apache.qpid.disttest.ConfigFileHelper;
+import org.apache.qpid.disttest.ConfigFileTestHelper;
import org.apache.qpid.disttest.client.property.PropertyValue;
public class ConfigReaderTest extends TestCase
@@ -36,7 +36,7 @@ public class ConfigReaderTest extends TestCase
protected void setUp()
{
ConfigReader configReader = new ConfigReader();
- Reader reader = ConfigFileHelper.getConfigFileReader(getClass(), "sampleConfig.json");
+ Reader reader = ConfigFileTestHelper.getConfigFileReader(getClass(), "sampleConfig.json");
_config = configReader.readConfig(reader);
}
@@ -108,4 +108,38 @@ public class ConfigReaderTest extends TestCase
assertNotNull("id property is not found", properties.get("id"));
}
+ public void testReadsJS() throws Exception
+ {
+ ConfigReader configReader = new ConfigReader();
+ String path = getClass().getClassLoader().getResource("org/apache/qpid/disttest/controller/config/test-config.js").toURI().getPath();
+ _config = configReader.getConfigFromFile(path);
+ List<TestConfig> testConfigs = _config.getTestConfigs();
+ assertEquals("Unexpected number of tests", 2, testConfigs.size());
+ TestConfig testConfig1 = _config.getTestConfigs().get(0);
+ List<ClientConfig> cleintConfigs = testConfig1.getClients();
+ assertEquals("Unexpected number of test 1 clients", 2, cleintConfigs.size());
+ List<QueueConfig> queueConfigs = testConfig1.getQueues();
+ assertEquals("Unexpected number of test 1 queue", 1, queueConfigs.size());
+ assertEquals("Unexpected queue name", "Json-Queue-Name", queueConfigs.get(0).getName());
+ ClientConfig cleintConfig = cleintConfigs.get(0);
+ List<ConnectionConfig> connectionConfigs = cleintConfig.getConnections();
+ assertEquals("Unexpected number of connections", 1, connectionConfigs.size());
+ List<SessionConfig> sessionConfigs = connectionConfigs.get(0).getSessions();
+ assertEquals("Unexpected number of sessions", 1, sessionConfigs.size());
+ assertEquals("Unexpected ack mode", 0, sessionConfigs.get(0).getAcknowledgeMode());
+
+ TestConfig testConfig2 = _config.getTestConfigs().get(1);
+ List<ClientConfig> cleintConfigs2 = testConfig2.getClients();
+ assertEquals("Unexpected number of test 1 clients", 2, cleintConfigs2.size());
+ List<QueueConfig> queueConfigs2 = testConfig2.getQueues();
+ assertEquals("Unexpected number of test 1 queue", 1, queueConfigs2.size());
+ assertEquals("Unexpected queue name", "Json-Queue-Name", queueConfigs2.get(0).getName());
+ ClientConfig cleintConfig2 = cleintConfigs2.get(0);
+ List<ConnectionConfig> connectionConfigs2 = cleintConfig2.getConnections();
+ assertEquals("Unexpected number of connections", 1, connectionConfigs2.size());
+ List<SessionConfig> sessionConfigs2 = connectionConfigs2.get(0).getSessions();
+ assertEquals("Unexpected number of sessions", 1, sessionConfigs2.size());
+ assertEquals("Unexpected ack mode", 1, sessionConfigs2.get(0).getAcknowledgeMode());
+ }
+
}
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
new file mode 100644
index 0000000000..e797ce4c06
--- /dev/null
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.controller.config;
+
+import junit.framework.TestCase;
+
+public class JavaScriptConfigEvaluatorTest extends TestCase
+{
+ public void testEvaluateJavaScript() throws Exception
+ {
+ String path = getClass().getClassLoader().getResource("org/apache/qpid/disttest/controller/config/test-config.js")
+ .toURI().getPath();
+
+ String config = new JavaScriptConfigEvaluator().evaluateJavaScript(path);
+
+ String expected = "{\"_tests\":[{\"_queues\":[{\"_name\":\"Json-Queue-Name\"}],\"_clients\":"
+ + "[{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":[{\"_acknowledgeMode\":\"0\","
+ + "\"_sessionName\":\"session1\",\"_consumers\":[]}]}],\"_name\":\"repeatingClient0\"},"
+ + "{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":[{\"_acknowledgeMode\":\"0\","
+ + "\"_sessionName\":\"session1\",\"_consumers\":[]}]}],\"_name\":\"repeatingClient1\"}]"
+ + ",\"_iterationNumber\":0,\"_name\":\"Test 1\"},{\"_queues\":[{\"_name\":\"Json-Queue-Name\"}],"
+ + "\"_clients\":[{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":"
+ + "[{\"_acknowledgeMode\":\"1\",\"_sessionName\":\"session1\",\"_consumers\":[]}]}],"
+ + "\"_name\":\"repeatingClient0\"},{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":"
+ + "[{\"_acknowledgeMode\":\"1\",\"_sessionName\":\"session1\",\"_consumers\":[]}]}],"
+ + "\"_name\":\"repeatingClient1\"}],\"_iterationNumber\":1,\"_name\":\"Test 1\"}]}";
+
+ assertEquals("Unexpected configuration", expected, config);
+ }
+}
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js
new file mode 100644
index 0000000000..07f8bf9d92
--- /dev/null
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js
@@ -0,0 +1,34 @@
+jsonObject = {
+ "_tests":
+ QPID.iterations( { "__ACK_MODE": [ 0, 1 ] },
+ {
+ // this is a comment - it wouldn't be allowed if this were pure JSON
+
+ "_name": "Test 1",
+ "_queues": [
+ {
+ "_name": "Json-Queue-Name"
+ }
+ ],
+
+ "_clients": QPID.times(2,
+ {
+ "_name": "repeatingClient__CLIENT_INDEX",
+ "_connections": [
+ {
+ "_name": "connection1",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": "__ACK_MODE",
+ "_consumers": []
+ }
+ ]
+ }
+ ]
+ },
+ "__CLIENT_INDEX"
+ )
+ })
+
+} \ No newline at end of file
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controllerandclient/ControllerAndClientTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controllerandclient/ControllerAndClientTest.java
index c103af501c..ddb4cb7e51 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controllerandclient/ControllerAndClientTest.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controllerandclient/ControllerAndClientTest.java
@@ -32,7 +32,7 @@ import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.NamingException;
-import org.apache.qpid.disttest.ConfigFileHelper;
+import org.apache.qpid.disttest.ConfigFileTestHelper;
import org.apache.qpid.disttest.client.Client;
import org.apache.qpid.disttest.client.ClientState;
import org.apache.qpid.disttest.controller.Controller;
@@ -100,7 +100,7 @@ public class ControllerAndClientTest extends DistributedTestSystemTestBase
// cleaning manually
while(consumer.receive(1000l) != null);
- final Config config = ConfigFileHelper.getConfigFromResource(getClass(), "produceClient.json");
+ final Config config = ConfigFileTestHelper.getConfigFromResource(getClass(), "produceClient.json");
_controller.setConfig(config);
final Client client1 = new Client(new ClientJmsDelegate(_context));
final Thread client1Thread = createBackgroundClientThread(client1);
@@ -181,7 +181,7 @@ public class ControllerAndClientTest extends DistributedTestSystemTestBase
private List<TestResult> runTestsForTwoClients(String jsonConfigFile, int expectedNumberOfTests) throws NamingException, InterruptedException
{
- final Config config = ConfigFileHelper.getConfigFromResource(getClass(), jsonConfigFile);
+ final Config config = ConfigFileTestHelper.getConfigFromResource(getClass(), jsonConfigFile);
_controller.setConfig(config);
final Client client1 = new Client(new ClientJmsDelegate(_context));
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controlleronly/DistributedControllerTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controlleronly/DistributedControllerTest.java
index ad7f0e0682..74c4724901 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controlleronly/DistributedControllerTest.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/systest/disttest/controlleronly/DistributedControllerTest.java
@@ -38,7 +38,7 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TemporaryQueue;
-import org.apache.qpid.disttest.ConfigFileHelper;
+import org.apache.qpid.disttest.ConfigFileTestHelper;
import org.apache.qpid.disttest.controller.Controller;
import org.apache.qpid.disttest.controller.config.Config;
import org.apache.qpid.disttest.jms.ControllerJmsDelegate;
@@ -96,7 +96,7 @@ public class DistributedControllerTest extends DistributedTestSystemTestBase
public void testControllerSendsOneCommandToSingleClient() throws Exception
{
- Config config = ConfigFileHelper.getConfigFromResource(getClass(), "distributedControllerTest.json");
+ Config config = ConfigFileTestHelper.getConfigFromResource(getClass(), "distributedControllerTest.json");
_controller.setConfig(config);
sendRegistration(CLIENT1);