From 0241c3b71364bcf0087bdbda1d2cd97805309fcd Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Tue, 17 Jul 2012 14:09:54 +0000 Subject: QPID-4103: [Java Performance Tests] modified test so that its success is no longer dependent on the order of the attributes in json2.js's JSON strings (this order varies between JDK 1.6 and 1.7, which caused a Jenkins test failure). Applied patch from Philip Harvey . git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1362503 13f79535-47bb-0310-9956-ffa450edef68 --- .../config/ConfigReaderTest-test-config.js | 34 ++++++++ .../controller/config/ConfigReaderTest.java | 2 +- ...avaScriptConfigEvaluatorTest-expected-json.json | 94 ++++++++++++++++++++++ .../JavaScriptConfigEvaluatorTest-test-config.js | 34 ++++++++ .../config/JavaScriptConfigEvaluatorTest.java | 50 ++++++++---- .../qpid/disttest/controller/config/test-config.js | 34 -------- 6 files changed, 197 insertions(+), 51 deletions(-) create mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js create mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json create mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js delete mode 100644 qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js (limited to 'qpid/java') diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-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/ConfigReaderTest-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/disttest/controller/config/ConfigReaderTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java index 21981c93dd..e7b6cdd3c6 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 @@ -111,7 +111,7 @@ public class ConfigReaderTest extends TestCase 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(); + String path = getClass().getResource("ConfigReaderTest-test-config.js").getPath(); _config = configReader.getConfigFromFile(path); List testConfigs = _config.getTestConfigs(); assertEquals("Unexpected number of tests", 2, testConfigs.size()); diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json new file mode 100644 index 0000000000..d56def5699 --- /dev/null +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json @@ -0,0 +1,94 @@ +{ + "_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" + } + ] +} \ No newline at end of file diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-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/JavaScriptConfigEvaluatorTest-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/disttest/controller/config/JavaScriptConfigEvaluatorTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java index e797ce4c06..6d4b3f6290 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java @@ -20,29 +20,47 @@ */ package org.apache.qpid.disttest.controller.config; +import java.io.File; +import java.util.TreeMap; + +import org.apache.qpid.util.FileUtils; + import junit.framework.TestCase; +import com.google.gson.Gson; + 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\"}]}"; + String jsFilePath = getClass().getResource("JavaScriptConfigEvaluatorTest-test-config.js").getPath(); + + String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath); + + String config = formatForComparison(rawConfig); + assertTrue(config.contains("\"_iterationNumber\":1")); + + File expectedJsonFile = new File(getClass().getResource("JavaScriptConfigEvaluatorTest-expected-json.json").getPath()); + String rawExpected = FileUtils.readFileAsString(expectedJsonFile); + + String expected = formatForComparison(rawExpected); assertEquals("Unexpected configuration", expected, config); } + + /** + * Does an unmarshall-then-marshall on the supplied JSON string so that + * we can compare the output when testing for equivalent JSON strings, + * ignoring ordering of attributes. + */ + private String formatForComparison(String jsonStringIn) + { + Gson gson = new Gson(); + + @SuppressWarnings("rawtypes") + TreeMap configObj = gson.fromJson(jsonStringIn, TreeMap.class); + + String jsonStringOut = gson.toJson(configObj); + return jsonStringOut; + } } 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 deleted file mode 100644 index 07f8bf9d92..0000000000 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js +++ /dev/null @@ -1,34 +0,0 @@ -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 -- cgit v1.2.1