db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r588800 - /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
Date Fri, 26 Oct 2007 23:33:11 GMT
Author: kmarsden
Date: Fri Oct 26 16:33:10 2007
New Revision: 588800

URL: http://svn.apache.org/viewvc?rev=588800&view=rev
Log:
DERBY-176 (partial) Improved version of the largeCodeGen test with looping based upon query
element count and a test for a large IN clause.

Still does not run as part of suite.
merged 354826 from trunk.


Modified:
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java?rev=588800&r1=588799&r2=588800&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
Fri Oct 26 16:33:10 2007
@@ -1,27 +1,155 @@
+
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.largeCodeGen
+
+   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.sql.DriverManager;
 import java.sql.Connection;
 import java.sql.*;
 
-import java.util.Properties;
 import org.apache.derby.tools.ij;
 
 
 // This test tries to push byte code generation to the limit.
-// the variable numUnions can be changed to push up the byte code generated
-// It has to be run with a large amount of memory. if numUnions is set high e.g.
-//  java -Djvmflags=-Xmx512M org.apache.derbyTesting.harness.RunTest lang/largeCodeGen
-// This is but one code path other areas need to be tested such as large in clauses, etc.
+// It has to be run with a large amount of memory which is set with jvmflags in 
+// largeCodeGen_app.properties
+// There are only a few types of cases now. Other areas need to be tested such as large in
clauses, etc.
+// 
 
 public class largeCodeGen
 {
 
+	
     public static void main(String argv[]) 
        throws Exception
     {
-        Statement stmt = null;
+    	ij.getPropertyArg(argv); 
+        Connection con = ij.startJBMS();
+        con.setAutoCommit(false);
+        createTestTable(con);
+        testParamsInWhereClause(con);
+        testInClause(con);
+        testUnions(con);
+        con.commit();
+        con.close();
+    }
+    
+    private static void createTestTable(Connection con) throws SQLException
+    {
+    	 Statement stmt = null;		
+    	 stmt = con.createStatement();
+    	 try {
+			stmt.executeUpdate("drop table t0 ");
+		}catch (SQLException se)
+		{
+			// drop error ok.
+			if (!se.getSQLState().equals("42Y55"))
+				throw se;
+		}	
+		
+		String createSQL = 	"create table t0 " +
+		"(si smallint,i int, bi bigint, r real, f float, d double precision, n5_2 numeric(5,2),
dec10_3 decimal(10,3), ch20 char(3),vc varchar(20), lvc long varchar)";
+		stmt.executeUpdate(createSQL);	
+		stmt.executeUpdate("insert into t0 values(2,3,4,5.3,5.3,5.3,31.13,123456.123, 'one','one','one')");
+    }
+    
+    /**
+     * Test many parameters in the where clause
+     * e.g. 
+	 * @param con  
+	 */
+	private static void testParamsInWhereClause(Connection con)  throws SQLException {
+		 
+		 for (int count = 200; count <= 10000 ; count += 100)
+		 {
+			 // keep testing until it fails.
+			 if (testWhereParams(con, count))
+				 break;
+		 }
+	}
+
+	
+	/**
+	 * Tests numParam parameter markers in a where clause
+	 * 
+	 * @param con          
+	 * @param  numparams  
+	 */
+	private static boolean testWhereParams(Connection con, int numParams) throws SQLException
{
+		String pred = "(si = ? AND i = ? )";
+		String testName = "WHERE clause with " + numParams + " parameters";
+		StringBuffer sqlBuffer = new StringBuffer((numParams * 20) + 512);
+		sqlBuffer.append("DELETE FROM T0 WHERE " + pred );
+		for (int i = 2; i < numParams; i+=2)
+		{
+			sqlBuffer.append(" OR (si = ? AND i = ? ) ");
+		}
+		try {
+			PreparedStatement ps = con.prepareStatement(sqlBuffer.toString());
+			System.out.println("PASS: " + testName);
+			ps.close();
+			return false;
+		 
+		}catch (Exception e)
+		{
+			reportFailure(testName, e);
+			return true;
+			
+		}
+	}
+	private static void testInClause(Connection con)  throws SQLException {
+		 for (int count = 2500; count <= 10000 ; count += 100)
+		 {
+			 // keep testing until it fails.
+			 if (testInClause(con, count))
+				 break;
+		 }
+	}	
+	private static boolean testInClause(Connection con, int numParams) throws SQLException {
+		String testName = "IN clause with " + numParams + " parameters";
+		StringBuffer sqlBuffer = new StringBuffer((numParams * 20) + 512);
+		sqlBuffer.append("SELECT * FROM T0 WHERE I IN ("  );
+		for (int i = 1; i < numParams; i++)
+		{
+			sqlBuffer.append("?, ");
+		}
+		sqlBuffer.append("?)");
+		try {
+			PreparedStatement ps = con.prepareStatement(sqlBuffer.toString());
+			System.out.println("PASS: " + testName);
+			ps.close();
+			return false;
+		 
+		}catch (Exception e)
+		{
+			reportFailure(testName, e);
+			return true;
+			
+		}
+	}
+	private static void testUnions(Connection con) throws Exception
+	{
+		Statement stmt = null;
         PreparedStatement pstmt = null; 
+        createTestTable(con);
 		//int numUnions = 4000;
 		//int numUnions = 2000;
 		/*
@@ -31,24 +159,11 @@
 		  (class: db2j/exe/ac601a400fx0102xc673xe3e9x000000163ac04, method: 
 		  execute signature: ()Lcom/ibm/db2j/protocol/Database/Language/Interface/ResultSet;) Illegal
target of jump or branch". My fix affects generated method "fillResultSet". With size 10000
largeCodeGen gets Java exception: 'java.io.IOException: constant_pool(70796 > 65535)'.
 		*/
-
-		String tableName = "t0";		
+		
 		String viewName = "v0";		
-
-		ij.getPropertyArg(argv); 
-	        Connection con = ij.startJBMS();        
-
-		con.setAutoCommit(false);
 		stmt = con.createStatement();
- 	       System.out.println("connected");
 
-		// Create table
-		try {
-			stmt.executeUpdate("drop table " + tableName);
-		}catch (SQLException se)
-		{
-			// drop error ok.
-		}
+		
 		try {
 			stmt.executeUpdate("drop view " + viewName);
 		}catch (SQLException se)
@@ -56,46 +171,51 @@
 			// drop error ok.
 		}
 
-		String createSQL = 	"create table " +
-			tableName +
-			"(si smallint,i int, bi bigint, r real, f float, d double precision, n5_2 numeric(5,2),
dec10_3 decimal(10,3), ch20 char(3),vc varchar(20), lvc long varchar)";
-		stmt.executeUpdate(createSQL);
-		stmt.executeUpdate("insert into " + tableName + " values(2,3,4,5.3,5.3,5.3,31.13,123456.123,
'one','one','one')");
-		
-		System.out.println("Building view 100 unions");  
+				  
 		StringBuffer createView = new StringBuffer("create view " + viewName + 
-												   " as select * from " + 
-												   tableName);
+												   " as select * from t0 " );
 		for (int i = 1; i < 100; i ++)
 		{
-			createView.append(" UNION ALL (SELECT * FROM " + tableName + ")");
+			createView.append(" UNION ALL (SELECT * FROM t0 )");
 		}
 		String createViewString = createView.toString();
 		//System.out.println(createViewString);
 		stmt.executeUpdate(createView.toString());
 		
 		// 2000 unions caused method too big error in verifier
-		largeUnionSelect(con, viewName, 2000);
-
 		// 10000 unions overflows the number of constant pool entries
-		largeUnionSelect(con, viewName, 10000);		
+		
+		for (int count = 800; count <= 10000; count += 100)
+		{
+			// keep testing until it fails
+			if (largeUnionSelect(con, viewName, count))
+				break;
+		}
     }
     
-    private static void largeUnionSelect(Connection con, String viewName,
+    private static boolean largeUnionSelect(Connection con, String viewName,
     		int numUnions) throws Exception
 	{
 
-		StringBuffer selectSQLBuffer  = new StringBuffer("select * from t0 ") ;
+    	// There are 100 unions in each view so round to the nearest 100
+    	String testName = "SELECT with " + numUnions/100 * 100 + " unions";
+		
+		String unionClause = " UNION ALL (SELECT * FROM " + viewName + ")";
+
+		StringBuffer selectSQLBuffer  =
+			new StringBuffer(((numUnions/100) * unionClause.length()) + 512);
+		
+		selectSQLBuffer.append("select * from t0 ");
+		
 		for (int i = 1; i < numUnions/100;i++)
 		{
-			selectSQLBuffer.append(" UNION ALL (SELECT * FROM " + viewName + ")");
+			selectSQLBuffer.append(unionClause);
 		}	
 		
 		try {
 		// Ready to execute the problematic query 
 		String selectSQL = selectSQLBuffer.toString();
 		//System.out.println(selectSQL);
-		System.out.println("SELECT with " + numUnions/100 * 100 + " unions");
         PreparedStatement pstmt = con.prepareStatement(selectSQL);
         ResultSet rs = pstmt.executeQuery();
 		int numRowsExpected = (numUnions/100 * 100);
@@ -106,17 +226,16 @@
 			if ((numRows % 100) == 0)
 			checkRowData(rs);
 		}
-		System.out.println("PASS: Row data check ok");
+		System.out.println("PASS: " + testName + " Row data check ok");
         con.commit();
         pstmt.close();
-        con.close();
+        return false;
+     
 		} catch (SQLException sqle)
 		{
-			System.out.println("FAILED QUERY");
-			do {
-				System.out.println(sqle.getSQLState() + ":" + sqle.getMessage());
-				sqle = sqle.getNextException();
-			} while (sqle != null);
+			reportFailure(testName, sqle);
+			return true;
+			
 		}
 
       }
@@ -138,6 +257,26 @@
 		}
 	}
 
+	/**
+	 * Show failure message and exception stack trace
+	 * @param testName
+	 * @param e
+	 */
+	private static void reportFailure(String testName, Exception e)
+	{
+		System.out.print("FAILED QUERY: " + testName +". ");
+		if (e instanceof SQLException)
+		{
+			SQLException se = (SQLException) e;
+			while (se != null)
+			{
+				se.printStackTrace(System.out);
+				se = se.getNextException();
+			}
+		}	
+		else e.printStackTrace();
+	
+	}
+	
 }
-
 



Mime
View raw message