db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r550544 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: suites/ tests/lang/
Date Mon, 25 Jun 2007 16:50:03 GMT
Author: kmarsden
Date: Mon Jun 25 09:50:02 2007
New Revision: 550544

URL: http://svn.apache.org/viewvc?view=rev&rev=550544
Log:
DERBY-2727  convert lang/AggregateClassLoading to JUnit.

Contributed by Ugo Matrangolo


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoading_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?view=diff&rev=550544&r1=550543&r2=550544
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
Mon Jun 25 09:50:02 2007
@@ -1,7 +1,6 @@
 jdbcapi/metadata.java
 jdbcapi/metadataMultiConn.java
 jdbcapi/odbc_metadata.java
-lang/AggregateClassLoading.java
 lang/DB2IsolationLevels.sql
 lang/LOBDB2compatibility.sql
 lang/aggregateOptimization.sql

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java?view=auto&rev=550544
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
Mon Jun 25 09:50:02 2007
@@ -0,0 +1,161 @@
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.AggregateClassLoadingTest
+ *  
+ * 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.derbyTesting.functionTests.tests.lang;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+
+/**
+ * Test for ensuring the aggregate implementation classes are loaded correctly,
+ * even when the context class loader loads Derby engine classes as well. This
+ * is a typical situation we have seen with J2EE servers where Derby may be in
+ * the application WAR and provided as a system service by the container. <BR>
+ * Jira issue DERBY-997 <BR>
+ * Assumes embedded and only needs to be run in embedded, since all class
+ * loading happens on the engine side.
+ */
+public class AggregateClassLoadingTest extends BaseJDBCTestCase {
+
+	private static URL derbyURL;
+	private static URLClassLoader cl;
+	
+	/**
+	 * Basic constructor.
+	 */	
+	public AggregateClassLoadingTest(String name) {
+		super(name);
+	}
+	
+	/**
+	 * Sets the auto commit to false.
+	 */
+	protected void initializeConnection(Connection conn) throws SQLException {
+		conn.setAutoCommit(false);
+	}
+	
+	/**
+	 * Returns the implemented tests.
+	 * 
+	 * @return An instance of <code>Test</code> with the implemented tests to
+	 *         run.
+	 */
+	public static Test suite() {
+		
+		
+		/* this test creates a class loader, adding that permission to
+		 * derbyTesting.jar would mean that permission was granted all
+		 * the way up the stack to the derby engine. Thus increasing
+		 * the chance that incorrectly a privileged block could be dropped
+		 * but the tests continue to pass. 
+		 */		
+		return SecurityManagerSetup.noSecurityManager(
+						new CleanDatabaseTestSetup(
+								new TestSuite(AggregateClassLoadingTest.class,
+										"AggregateClassLoadingTest")) {
+							protected void tearDown() throws Exception {
+								Thread.currentThread().setContextClassLoader(null);
+								super.tearDown();
+							}
+
+							/**
+							 * @see org.apache.derbyTesting.junit.CleanDatabaseTestSetup#decorateSQL(java.sql.Statement)
+							 */
+							protected void decorateSQL(Statement s)
+									throws SQLException {
+								s.execute("create table t (i int)");
+								s.execute("insert into t values 1,2,3,4,5,6,null,4,5,456,2,4,6,7,2144,44,2,-2,4");
+
+								/*
+								 * Find the location of the code for the Derby
+								 * connection. The rest of the engine will be at
+								 * the same location!
+								 */
+								derbyURL = s.getConnection().getClass().getProtectionDomain().getCodeSource()
+										.getLocation();
+
+								/*
+								 * Create a new loader that loads from the same
+								 * location as the engine. Create it without a
+								 * parent, otherwise the parent will be the
+								 * class loader of this class which is most
+								 * likely the same as the engine. Since the
+								 * class loader delegates to its parent first
+								 * the bug would not show, as all the derby
+								 * engine classes would be from a single loader.
+								 */
+								cl = new URLClassLoader(new URL[] { derbyURL }, null);
+								Thread.currentThread().setContextClassLoader(cl);
+
+								super.decorateSQL(s);
+							}
+						});
+		
+	}		
+		
+	public void testAggregateMAX() throws SQLException {
+		testAggregate("select MAX(i) from t");
+	}
+	
+	public void testAggregateMIN() throws SQLException {
+		testAggregate("select MIN(i) from t");
+	}
+	
+	public void testAggregateAVG() throws SQLException {
+		testAggregate("select AVG(i) from t");
+	}
+		
+	public void testAggregateCOUNT() throws SQLException {
+		testAggregate("select COUNT(i) from t");
+	}
+	
+	public void testAggregateCOUNT2() throws SQLException {
+		testAggregate("select COUNT(*) from t");
+	}
+	
+    /**
+     * Just run and display the aggregates result.
+     * 
+     * Test some aggregates, their generated class will attempt
+	 * to load the internal aggregate through the context loader
+	 * first, and then any remaining loader.
+     */
+    private void testAggregate(String query) throws SQLException {
+		Statement s = createStatement();
+		ResultSet rs = s.executeQuery(query);
+			
+		rs.next();
+		rs.close();
+   }	
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggregateClassLoadingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?view=diff&rev=550544&r1=550543&r2=550544
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Mon Jun 25 09:50:02 2007
@@ -109,6 +109,7 @@
         suite.addTest(TimestampArithTest.suite());
         suite.addTest(SpillHashTest.suite());
         suite.addTest(CaseExpressionTest.suite());
+        suite.addTest(AggregateClassLoadingTest.suite());
 
         // Add the XML tests, which exist as a separate suite
         // so that users can "run all XML tests" easily.



Mime
View raw message