From derby-commits-return-14037-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Wed Mar 16 17:24:05 2011 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 31819 invoked from network); 16 Mar 2011 17:24:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Mar 2011 17:24:05 -0000 Received: (qmail 17111 invoked by uid 500); 16 Mar 2011 17:24:05 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 17085 invoked by uid 500); 16 Mar 2011 17:24:05 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 17078 invoked by uid 99); 16 Mar 2011 17:24:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Mar 2011 17:24:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Mar 2011 17:24:04 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8F27023888EA; Wed, 16 Mar 2011 17:23:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1082226 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/derbynet/GetCurrentPropertiesTest.java junit/TestConfiguration.java Date: Wed, 16 Mar 2011 17:23:41 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110316172341.8F27023888EA@eris.apache.org> Author: kahatlen Date: Wed Mar 16 17:23:41 2011 New Revision: 1082226 URL: http://svn.apache.org/viewvc?rev=1082226&view=rev Log: DERBY-5100: GetCurrentPropertiesTest depends on implicit ordering of test cases Made the test ordering explicit. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java?rev=1082226&r1=1082225&r2=1082226&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java Wed Mar 16 17:23:41 2011 @@ -25,7 +25,6 @@ import java.util.Properties; import java.util.Enumeration; import org.apache.derbyTesting.junit.BaseJDBCTestCase; import junit.framework.Test; -import junit.framework.TestSuite; import org.apache.derby.drda.NetworkServerControl; import org.apache.derbyTesting.junit.NetworkServerTestSetup; import org.apache.derbyTesting.junit.TestConfiguration; @@ -52,15 +51,20 @@ public class GetCurrentPropertiesTest ex public static Test suite() { - TestSuite suite = new TestSuite("GetCurrentPropertiesTest"); - Test test = TestConfiguration - .clientServerSuite(GetCurrentPropertiesTest.class); + // Use a fixed order for the test cases so that we know the exact + // order in which they run. Some of them depend on the connection + // number having a specific value, which can only be guaranteed if + // we know exactly how many connections have been opened, hence the + // need for a fixed order. Some also depend on seeing property values + // set by the previous test case. + Test test = + TestConfiguration.orderedSuite(GetCurrentPropertiesTest.class); + test = TestConfiguration.clientServerDecorator(test); // Install a security manager using the special policy file. test = decorateWithPolicy(test); - suite.addTest(test); // return suite; to ensure that nothing interferes with setting of // properties, wrap in singleUseDatabaseDecorator - return TestConfiguration.singleUseDatabaseDecorator(suite); + return TestConfiguration.singleUseDatabaseDecorator(test); } /** * Construct the name of the server policy file. @@ -104,7 +108,7 @@ public class GetCurrentPropertiesTest ex * * @throws Exception */ - public void testPropertiesBeforeConnection() throws Exception { + public void test_01_propertiesBeforeConnection() throws Exception { Properties p = null; String userDir = getSystemProperty( "user.dir" ); String traceDir = userDir + File.separator + "system"; @@ -138,7 +142,7 @@ public class GetCurrentPropertiesTest ex * * @throws Exception */ - public void testPropertiesAfterConnection() throws Exception { + public void test_02_propertiesAfterConnection() throws Exception { Properties p = null; String userDir = getSystemProperty( "user.dir" ); String traceDir = userDir + File.separator + "system"; @@ -176,7 +180,7 @@ public class GetCurrentPropertiesTest ex * * @throws Exception */ - public void testPropertiesTraceOn() throws Exception { + public void test_03_propertiesTraceOn() throws Exception { Properties p = null; NetworkServerControl nsctrl = NetworkServerTestSetup.getNetworkServerControl(); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1082226&r1=1082225&r2=1082226&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Wed Mar 16 17:23:41 2011 @@ -28,8 +28,11 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; import junit.extensions.TestSetup; import junit.framework.Assert; @@ -413,6 +416,39 @@ public final class TestConfiguration { return suiteName; } + + /** + * A comparator that orders {@code TestCase}s lexicographically by + * their names. + */ + private static final Comparator TEST_ORDERER = new Comparator() { + public int compare(Object o1, Object o2) { + TestCase t1 = (TestCase) o1; + TestCase t2 = (TestCase) o2; + return t1.getName().compareTo(t2.getName()); + } + }; + + /** + * Create a test suite with all the test cases in the specified class. The + * test cases should be ordered lexicographically by their names. + * + * @param testClass the class with the test cases + * @return a lexicographically ordered test suite + */ + public static Test orderedSuite(Class testClass) { + // Extract all tests from the test class and order them. + ArrayList tests = Collections.list(new TestSuite(testClass).tests()); + Collections.sort(tests, TEST_ORDERER); + + // Build a new test suite with the tests in lexicographic order. + TestSuite suite = new TestSuite(suiteName(testClass)); + for (Iterator it = tests.iterator(); it.hasNext(); ) { + suite.addTest((Test) it.next()); + } + + return suite; + } /** * Create a suite for the passed test class that includes