Author: kwall Date: Tue Jul 17 14:09:54 2012 New Revision: 1362503 URL: http://svn.apache.org/viewvc?rev=1362503&view=rev Log: 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 <[email protected]>. Added: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js - copied, changed from r1362502, qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js - copied, changed from r1362502, qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js Removed: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js Modified: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java Copied: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js (from r1362502, qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js) URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js?p2=qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js&p1=qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js&r1=1362502&r2=1362503&rev=1362503&view=diff ============================================================================== (empty) Modified: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java?rev=1362503&r1=1362502&r2=1362503&view=diff ============================================================================== --- qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java (original) +++ qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java Tue Jul 17 14:09:54 2012 @@ -111,7 +111,7 @@ public class ConfigReaderTest extends Te 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<TestConfig> testConfigs = _config.getTestConfigs(); assertEquals("Unexpected number of tests", 2, testConfigs.size()); Added: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json?rev=1362503&view=auto ============================================================================== --- qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json (added) +++ qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json Tue Jul 17 14:09:54 2012 @@ -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 Copied: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js (from r1362502, qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js) URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js?p2=qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js&p1=qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js&r1=1362502&r2=1362503&rev=1362503&view=diff ============================================================================== (empty) Modified: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java?rev=1362503&r1=1362502&r2=1362503&view=diff ============================================================================== --- qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java (original) +++ qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java Tue Jul 17 14:09:54 2012 @@ -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 jsFilePath = getClass().getResource("JavaScriptConfigEvaluatorTest-test-config.js").getPath(); + + String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath); + + String config = formatForComparison(rawConfig); + assertTrue(config.contains("\"_iterationNumber\":1")); - String config = new JavaScriptConfigEvaluator().evaluateJavaScript(path); + File expectedJsonFile = new File(getClass().getResource("JavaScriptConfigEvaluatorTest-expected-json.json").getPath()); + String rawExpected = FileUtils.readFileAsString(expectedJsonFile); - 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 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; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
