You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2007/03/20 22:52:21 UTC
svn commit: r520613 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
functionTests/tests/lang/NullIfTest.java junit/JDBC.java
junit/RuntimeStatisticsParser.java junit/SQLUtilities.java
Author: kmarsden
Date: Tue Mar 20 14:52:20 2007
New Revision: 520613
URL: http://svn.apache.org/viewvc?view=rev&rev=520613
Log:
DERBY-2463 Create runtime statistics parser for JUnit tests
Create SQLUtilities.getRuntimeStatisticsParser and
executeAndGetRuntimeStatisticsParser for use by tests.
Also move createAndPoplulateAllDatatypesTable to SQLUtilities
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java (with props)
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java?view=diff&rev=520613&r1=520612&r2=520613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java Tue Mar 20 14:52:20 2007
@@ -30,6 +30,7 @@
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SQLUtilities;
import org.apache.derbyTesting.junit.TestConfiguration;
public class PrepStmtMetaDataTest extends BaseJDBCTestCase {
@@ -179,7 +180,7 @@
{
Connection conn = getConnection();
Statement s = conn.createStatement();
- JDBC.createAndPopulateAllDataTypesTable(s);
+ SQLUtilities.createAndPopulateAllDataTypesTable(s);
PreparedStatement ps = conn.prepareStatement("SELECT * from AllDataTypesTable");
ResultSetMetaData rsmd = ps.getMetaData();
int colCount = rsmd.getColumnCount();
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java?view=diff&rev=520613&r1=520612&r2=520613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java Tue Mar 20 14:52:20 2007
@@ -36,6 +36,7 @@
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SQLUtilities;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derbyTesting.functionTests.tests.lang.CastingTest;
@@ -143,14 +144,14 @@
for (int firstColumnType = 0; firstColumnType < CastingTest.SQLTypes.length; firstColumnType++) {
StringBuffer nullIfString = new StringBuffer("SELECT NULLIF("
- + JDBC.allDataTypesColumnNames[firstColumnType]);
+ + SQLUtilities.allDataTypesColumnNames[firstColumnType]);
for (int secondColumnType = 0; secondColumnType < CastingTest.SQLTypes.length; secondColumnType++) {
int row = 0;
try {
StringBuffer completeNullIfString = new StringBuffer(
nullIfString.toString() + ","
- + JDBC.allDataTypesColumnNames[secondColumnType]);
+ + SQLUtilities.allDataTypesColumnNames[secondColumnType]);
ResultSet rs = s.executeQuery(completeNullIfString
+ ") from AllDataTypesTable");
while (rs.next()) {
@@ -201,7 +202,7 @@
for (int secondColumnType = 0; secondColumnType < CastingTest.SQLTypes.length; secondColumnType++) {
String nullIfString = new String("SELECT NULLIF(?,"
- + JDBC.allDataTypesColumnNames[secondColumnType]
+ + SQLUtilities.allDataTypesColumnNames[secondColumnType]
+ ") from AllDataTypesTable");
int row = 0;
try {
@@ -303,7 +304,7 @@
*
*/
protected void decorateSQL(Statement s) throws SQLException {
- JDBC.createAndPopulateAllDataTypesTable(s);
+ SQLUtilities.createAndPopulateAllDataTypesTable(s);
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=520613&r1=520612&r2=520613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Tue Mar 20 14:52:20 2007
@@ -883,86 +883,5 @@
}
}
- public static String VALID_DATE_STRING = "'2000-01-01'";
- public static String VALID_TIME_STRING = "'15:30:20'";
- public static String VALID_TIMESTAMP_STRING = "'2000-01-01 15:30:20'";
- public static String NULL_VALUE="NULL";
-
- public static String[] allDataTypesColumnNames =
- {
- "SMALLINTCOL",
- "INTEGERCOL",
- "BIGINTCOL",
- "DECIMALCOL",
- "REALCOL",
- "DOUBLECOL",
- "CHARCOL",
- "VARCHARCOL",
- "LONGVARCHARCOL",
- "CHARFORBITCOL",
- "VARCHARFORBITCOL",
- "LVARCHARFORBITCOL",
- "CLOBCOL",
- "DATECOL",
- "TIMECOL",
- "TIMESTAMPCOL",
- "BLOBCOL",
-
- };
-
- private static String[][]allDataTypesSQLData =
- {
- {NULL_VALUE, "0","1","2"}, // SMALLINT
- {NULL_VALUE,"0","1","21"}, // INTEGER
- {NULL_VALUE,"0","1","22"}, // BIGINT
- {NULL_VALUE,"0.0","1.0","23.0"}, // DECIMAL(10,5)
- {NULL_VALUE,"0.0","1.0","24.0"}, // REAL,
- {NULL_VALUE,"0.0","1.0","25.0"}, // DOUBLE
- {NULL_VALUE,"'0'","'aa'","'2.0'"}, // CHAR(60)
- {NULL_VALUE,"'0'","'aa'",VALID_TIME_STRING}, //VARCHAR(60)",
- {NULL_VALUE,"'0'","'aa'",VALID_TIMESTAMP_STRING}, // LONG VARCHAR
- {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaaa'"}, // CHAR(60) FOR BIT DATA
- {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaba'"}, // VARCHAR(60) FOR BIT DATA
- {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaca'"}, //LONG VARCHAR FOR BIT DATA
- {NULL_VALUE,"'13'","'14'",NULL_VALUE}, //CLOB(1k)
- {NULL_VALUE,VALID_DATE_STRING,VALID_DATE_STRING,NULL_VALUE}, // DATE
- {NULL_VALUE,VALID_TIME_STRING,VALID_TIME_STRING,VALID_TIME_STRING}, // TIME
- {NULL_VALUE,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING}, // TIMESTAMP
- {NULL_VALUE,NULL_VALUE,NULL_VALUE,NULL_VALUE} // BLOB
- };
-
- /**
- * Create a table AllDataTypesTable and populate with data
- * @param s
- * @throws SQLException
- */
- public static void createAndPopulateAllDataTypesTable(Statement s) throws SQLException {
- try {
- s.executeUpdate("DROP TABLE AllDataTypesTable");
- } catch (SQLException se) {
- }
-
- StringBuffer createSQL = new StringBuffer(
- "create table AllDataTypesTable (");
- for (int type = 0; type < CastingTest.SQLTypes.length - 1; type++) {
- createSQL.append(allDataTypesColumnNames[type] + " " + CastingTest.SQLTypes[type]
- + ",");
- }
- createSQL.append(allDataTypesColumnNames[CastingTest.SQLTypes.length - 1] + " "
- + CastingTest.SQLTypes[CastingTest.SQLTypes.length - 1] + ")");
- s.executeUpdate(createSQL.toString());
-
- for (int row = 0; row < allDataTypesSQLData[0].length; row++) {
- createSQL = new StringBuffer(
- "insert into AllDataTypesTable values(");
- for (int type = 0; type < CastingTest.SQLTypes.length - 1; type++) {
- createSQL.append(allDataTypesSQLData[type][row] + ",");
- }
- createSQL.append(allDataTypesSQLData[CastingTest.SQLTypes.length - 1][row] + ")");
-
- s.executeUpdate(createSQL.toString());
- }
-
- s.close();
- }
+
}
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java?view=auto&rev=520613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java Tue Mar 20 14:52:20 2007
@@ -0,0 +1,55 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.functionTests.util.RunTimeStatisticsParser
+ *
+ * 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.junit;
+
+import java.sql.Connection;
+
+public class RuntimeStatisticsParser {
+
+ private int isolationLevel = Connection.TRANSACTION_NONE;
+
+ /**
+ * Create a RuntimeStatistics object to parse the text and extract
+ * information. Currently only isolation level is the only thing extracted.
+ *
+ * @param rts
+ * Runtime Statistics string
+ *
+ */
+ public RuntimeStatisticsParser(String rts) {
+ if (rts.indexOf(" at serializable isolation level ") != -1)
+ isolationLevel = Connection.TRANSACTION_SERIALIZABLE;
+ else if (rts.indexOf("at read uncommitted isolation level") != -1)
+ isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
+ else if (rts.indexOf("at read committed isolation level") != -1)
+ isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
+ else if (rts.indexOf("at repeatable read isolation level") != -1)
+ isolationLevel = Connection.TRANSACTION_REPEATABLE_READ;
+
+ }
+
+ /**
+ * @return Isolation level from parsed RuntimeStatistics
+ */
+ public int getIsolationLevel() {
+ return isolationLevel;
+ }
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java?view=auto&rev=520613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java Tue Mar 20 14:52:20 2007
@@ -0,0 +1,126 @@
+package org.apache.derbyTesting.junit;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.derbyTesting.functionTests.tests.lang.CastingTest;
+
+public class SQLUtilities {
+
+ public static String VALID_DATE_STRING = "'2000-01-01'";
+ public static String VALID_TIME_STRING = "'15:30:20'";
+ public static String VALID_TIMESTAMP_STRING = "'2000-01-01 15:30:20'";
+ public static String NULL_VALUE="NULL";
+
+ public static String[] allDataTypesColumnNames =
+ {
+ "SMALLINTCOL",
+ "INTEGERCOL",
+ "BIGINTCOL",
+ "DECIMALCOL",
+ "REALCOL",
+ "DOUBLECOL",
+ "CHARCOL",
+ "VARCHARCOL",
+ "LONGVARCHARCOL",
+ "CHARFORBITCOL",
+ "VARCHARFORBITCOL",
+ "LVARCHARFORBITCOL",
+ "CLOBCOL",
+ "DATECOL",
+ "TIMECOL",
+ "TIMESTAMPCOL",
+ "BLOBCOL",
+
+ };
+
+ private static String[][]allDataTypesSQLData =
+ {
+ {NULL_VALUE, "0","1","2"}, // SMALLINT
+ {NULL_VALUE,"0","1","21"}, // INTEGER
+ {NULL_VALUE,"0","1","22"}, // BIGINT
+ {NULL_VALUE,"0.0","1.0","23.0"}, // DECIMAL(10,5)
+ {NULL_VALUE,"0.0","1.0","24.0"}, // REAL,
+ {NULL_VALUE,"0.0","1.0","25.0"}, // DOUBLE
+ {NULL_VALUE,"'0'","'aa'","'2.0'"}, // CHAR(60)
+ {NULL_VALUE,"'0'","'aa'",VALID_TIME_STRING}, //VARCHAR(60)",
+ {NULL_VALUE,"'0'","'aa'",VALID_TIMESTAMP_STRING}, // LONG VARCHAR
+ {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaaa'"}, // CHAR(60) FOR BIT DATA
+ {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaba'"}, // VARCHAR(60) FOR BIT DATA
+ {NULL_VALUE,"X'10aa'",NULL_VALUE,"X'10aaca'"}, //LONG VARCHAR FOR BIT DATA
+ {NULL_VALUE,"'13'","'14'",NULL_VALUE}, //CLOB(1k)
+ {NULL_VALUE,SQLUtilities.VALID_DATE_STRING,SQLUtilities.VALID_DATE_STRING,NULL_VALUE}, // DATE
+ {NULL_VALUE,VALID_TIME_STRING,VALID_TIME_STRING,VALID_TIME_STRING}, // TIME
+ {NULL_VALUE,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING,VALID_TIMESTAMP_STRING}, // TIMESTAMP
+ {NULL_VALUE,NULL_VALUE,NULL_VALUE,NULL_VALUE} // BLOB
+ };
+
+ /**
+ * Create a table AllDataTypesTable and populate with data
+ * @param s
+ * @throws SQLException
+ */
+ public static void createAndPopulateAllDataTypesTable(Statement s) throws SQLException {
+ try {
+ s.executeUpdate("DROP TABLE AllDataTypesTable");
+ } catch (SQLException se) {
+ }
+
+ StringBuffer createSQL = new StringBuffer(
+ "create table AllDataTypesTable (");
+ for (int type = 0; type < CastingTest.SQLTypes.length - 1; type++) {
+ createSQL.append(allDataTypesColumnNames[type] + " " + CastingTest.SQLTypes[type]
+ + ",");
+ }
+ createSQL.append(allDataTypesColumnNames[CastingTest.SQLTypes.length - 1] + " "
+ + CastingTest.SQLTypes[CastingTest.SQLTypes.length - 1] + ")");
+ s.executeUpdate(createSQL.toString());
+
+ for (int row = 0; row < allDataTypesSQLData[0].length; row++) {
+ createSQL = new StringBuffer(
+ "insert into AllDataTypesTable values(");
+ for (int type = 0; type < CastingTest.SQLTypes.length - 1; type++) {
+ createSQL.append(allDataTypesSQLData[type][row] + ",");
+ }
+ createSQL.append(allDataTypesSQLData[CastingTest.SQLTypes.length - 1][row] + ")");
+
+ s.executeUpdate(createSQL.toString());
+ }
+
+ s.close();
+ }
+
+ /**
+ *
+ * Assumes user previously executed
+ * "call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)";
+ * @param s Statement to use for calling runtime statistics function
+ * @return a runtime statistics parser
+ * @throws SQLException
+ */
+ public static RuntimeStatisticsParser getRuntimeStatisticsParser(Statement s) throws SQLException
+ {
+ ResultSet rs = s.executeQuery("values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()");
+ rs.next();
+ String rts = rs.getString(1);
+ return new RuntimeStatisticsParser(rts);
+ }
+
+ public static RuntimeStatisticsParser executeAndGetRuntimeStatistics(Connection conn, String sql ) throws SQLException
+ {
+ Statement s = conn.createStatement();
+ Statement s2 = conn.createStatement();
+ CallableStatement cs = conn.prepareCall("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
+ cs.execute();
+ cs.close();
+ s.execute(sql);
+ ResultSet rs = s.getResultSet();
+ if (rs != null)
+ JDBC.assertDrainResults(rs);
+ return SQLUtilities.getRuntimeStatisticsParser(s2);
+ }
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SQLUtilities.java
------------------------------------------------------------------------------
svn:eol-style = native