db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1162832 - in /db/derby/code/branches/10.8/java: engine/org/apache/derby/diag/ErrorLogReader.java engine/org/apache/derby/diag/StatementDuration.java testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
Date Mon, 29 Aug 2011 14:31:24 GMT
Author: rhillegas
Date: Mon Aug 29 14:31:24 2011
New Revision: 1162832

URL: http://svn.apache.org/viewvc?rev=1162832&view=rev
Log:
DERBY-5391: Port 1162827 from trunk to 10.8 branch.

Modified:
    db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/ErrorLogReader.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/StatementDuration.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/ErrorLogReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/ErrorLogReader.java?rev=1162832&r1=1162831&r2=1162832&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/ErrorLogReader.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/ErrorLogReader.java Mon
Aug 29 14:31:24 2011
@@ -89,7 +89,7 @@ public class ErrorLogReader extends VTIT
 
 	// Variables for current row
 	private String line;
-	private int gmtIndex;
+	private int endTimestampIndex;
 	private int threadIndex;
 	private int xidIndex;
 	private int lccidIndex;
@@ -97,7 +97,7 @@ public class ErrorLogReader extends VTIT
 	private int drdaidIndex;
 
 
-	private static final String GMT_STRING = " GMT";
+	private static final String END_TIMESTAMP = " Thread";
 	private static final String PARAMETERS_STRING = "Parameters:";
 	private static final String BEGIN_THREAD_STRING = "[";
 	private static final String END_THREAD_STRING = "]";
@@ -178,7 +178,7 @@ public class ErrorLogReader extends VTIT
 				return false;
 			}
 
-			gmtIndex = line.indexOf(GMT_STRING);
+            endTimestampIndex = line.indexOf( END_TIMESTAMP );
 			threadIndex = line.indexOf(BEGIN_THREAD_STRING);
 			xidIndex = line.indexOf(BEGIN_XID_STRING);
 			lccidIndex = line.indexOf(BEGIN_XID_STRING, xidIndex + 1);
@@ -191,7 +191,7 @@ public class ErrorLogReader extends VTIT
 				continue;
 			}
 
-			if (gmtIndex != -1 && threadIndex != -1  && xidIndex != -1 &&

+			if (endTimestampIndex != -1 && threadIndex != -1  && xidIndex != -1 &&

 				databaseIndex != -1)
 			{
 				return true;
@@ -234,7 +234,7 @@ public class ErrorLogReader extends VTIT
 		switch (columnNumber)
 		{
 			case 1:
-				return line.substring(0, gmtIndex);
+				return line.substring(0, endTimestampIndex);
 
 			case 2:
 				return line.substring(threadIndex + 1, line.indexOf(END_THREAD_STRING));
@@ -314,7 +314,7 @@ public class ErrorLogReader extends VTIT
 	/* MetaData
 	 */
 	
-	// column1: TS varchar(26) not null
+	// column1: TS varchar(29) not null
 	// column2: THREADID varchar(40) not null
 	// column3: XID  varchar(15) not null
 	// column4: LCCID  varchar(15) not null
@@ -322,7 +322,7 @@ public class ErrorLogReader extends VTIT
 	// column6: DRDAID varchar(50) nullable
 	// column5: LOGTEXT VARCHAR(max) not null
 	private static final ResultColumnDescriptor[] columnInfo = {
-		EmbedResultSetMetaData.getResultColumnDescriptor("TS", Types.VARCHAR, false, 26),
+		EmbedResultSetMetaData.getResultColumnDescriptor("TS", Types.VARCHAR, false, 29),
 		EmbedResultSetMetaData.getResultColumnDescriptor("THREADID", Types.VARCHAR, false, 40),
 		EmbedResultSetMetaData.getResultColumnDescriptor("XID", Types.VARCHAR, false, 15),
 		EmbedResultSetMetaData.getResultColumnDescriptor("LCCID", Types.VARCHAR, false, 15),

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/StatementDuration.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/StatementDuration.java?rev=1162832&r1=1162831&r2=1162832&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/StatementDuration.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/diag/StatementDuration.java Mon
Aug 29 14:31:24 2011
@@ -26,7 +26,7 @@ import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.FileInputStream;
-
+import java.text.SimpleDateFormat;
 import java.util.Hashtable;
 import java.util.Enumeration;
 import java.util.Properties;
@@ -86,13 +86,13 @@ public class StatementDuration extends V
 
 	// Variables for current row
 	private String line;
-	private int gmtIndex;
+	private int endTimestampIndex;
 	private int threadIndex;
 	private int xidIndex;
 	private int lccidIndex;
 	private String[] currentRow;
 
-	private static final String GMT_STRING = " GMT";
+	private static final String END_TIMESTAMP = " Thread";
 	private static final String BEGIN_THREAD_STRING = "[";
 	private static final String END_THREAD_STRING = "]";
 	private static final String BEGIN_XID_STRING = "= ";
@@ -170,12 +170,12 @@ public class StatementDuration extends V
 				return false;
 			}
 
-			gmtIndex = line.indexOf(GMT_STRING);
+            endTimestampIndex = line.indexOf( END_TIMESTAMP );
 			threadIndex = line.indexOf(BEGIN_THREAD_STRING);
 			xidIndex = line.indexOf(BEGIN_XID_STRING);
 			lccidIndex = line.indexOf(BEGIN_XID_STRING, xidIndex + 1);
 
-			if (gmtIndex != -1 && threadIndex != -1)
+			if (endTimestampIndex != -1 && threadIndex != -1 && xidIndex != -1)
 			{
 				/* Build a row */
 				String[] newRow = new String[6];
@@ -198,9 +198,9 @@ public class StatementDuration extends V
 				currentRow = (String[]) previousRow;
 				
 				/* Figure out the duration. */
-				Timestamp endTs = Timestamp.valueOf(newRow[0]);
+				Timestamp endTs = stringToTimestamp( newRow[0] );
 				long end = endTs.getTime() + endTs.getNanos() / 1000000;
-				Timestamp startTs = Timestamp.valueOf(currentRow[0]);
+				Timestamp startTs = stringToTimestamp( currentRow[0] );
 				long start = startTs.getTime() + startTs.getNanos() / 1000000;
 				currentRow[5] = Long.toString(end - start);
 
@@ -208,6 +208,47 @@ public class StatementDuration extends V
 			}
 		}
 	}
+    // Turn a string into a Timestamp
+    private Timestamp   stringToTimestamp( String raw ) throws SQLException
+    {
+        //
+        // We have to handle two timestamp formats.
+        //
+        // 1) Logged timestamps look like this before 10.7 and the fix introduced by DERBY-4752:
+        //
+        //     2006-12-15 16:14:58.280 GMT
+        //
+        // 2) From 10.7 onward, logged timestamps look like this:
+        //
+        //     Fri Aug 26 09:28:00 PDT 2011
+        //
+        String  trimmed = raw.trim();
+
+        // if we're dealing with a pre-10.7 timestamp
+        if ( !Character.isDigit( trimmed.charAt( trimmed.length() -1 ) ) )
+        {
+            // strip off the trailing timezone, which Timestamp does not expect
+
+            trimmed = trimmed.substring( 0, trimmed.length() - 4 );
+            
+            return Timestamp.valueOf( trimmed );
+        }
+        else
+        {
+            //
+            // From 10.7 onward, the logged timestamp was formatted by Date.toString().
+            //
+            SimpleDateFormat    sdf = new SimpleDateFormat( "EEE MMM dd HH:mm:ss zzz yyyy"
);
+
+            try {
+                return new Timestamp( sdf.parse( trimmed ).getTime() );
+            }
+            catch (Exception e)
+            {
+                throw new SQLException( e.getMessage() );
+            }
+        }
+    }
 
 	/**
 		@see java.sql.ResultSet#close
@@ -250,7 +291,7 @@ public class StatementDuration extends V
 		switch (columnNumber)
 		{
 			case 1:
-				return line.substring(0, gmtIndex);
+				return line.substring(0, endTimestampIndex);
 
 			case 2:
 				return line.substring(threadIndex + 1, line.indexOf(END_THREAD_STRING));
@@ -328,7 +369,7 @@ public class StatementDuration extends V
 	*/
 	private static final ResultColumnDescriptor[] columnInfo = {
 
-		EmbedResultSetMetaData.getResultColumnDescriptor("TS",        Types.VARCHAR, false, 26),
+		EmbedResultSetMetaData.getResultColumnDescriptor("TS",        Types.VARCHAR, false, 29),
 		EmbedResultSetMetaData.getResultColumnDescriptor("THREADID",  Types.VARCHAR, false, 80),
 		EmbedResultSetMetaData.getResultColumnDescriptor("XID",       Types.VARCHAR, false, 15),
 		EmbedResultSetMetaData.getResultColumnDescriptor("LCCID",     Types.VARCHAR, false, 10),

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java?rev=1162832&r1=1162831&r2=1162832&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
Mon Aug 29 14:31:24 2011
@@ -26,6 +26,7 @@ import org.apache.derbyTesting.junit.JDB
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 import java.sql.ResultSet;
@@ -33,6 +34,9 @@ import java.sql.Statement;
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Properties;
 
 public final class SysDiagVTIMappingTest extends BaseJDBCTestCase {
 
@@ -50,10 +54,18 @@ public final class SysDiagVTIMappingTest
     public static Test suite()
     {
         TestSuite suite = new TestSuite("Diagnostic VTI Table Mappings");
-        suite.addTest(TestConfiguration.
-            defaultSuite(SysDiagVTIMappingTest.class));
 
-        /* Some of the VTIs that are tested in this class require a derby.log
+        Test    defaultSetup = TestConfiguration.defaultSuite( SysDiagVTIMappingTest.class
);
+
+        // turn on statement logging so there will be something in the error log
+        // to run these vtis against
+        Properties sysprops = new Properties();
+        sysprops.put( "derby.language.logStatementText", "true" );
+        Test    verboseTest = new SystemPropertyTestSetup ( defaultSetup, sysprops );
+
+        suite.addTest( verboseTest );
+
+         /* Some of the VTIs that are tested in this class require a derby.log
          * file.  We have a test log file stored in the tests/lang directory,
          * and since the VTIs are going to try to read it, the test log file
          * must be in a directory for which Derby has read access.  By
@@ -393,7 +405,7 @@ public final class SysDiagVTIMappingTest
         JDBC.assertColumnNames(rs, expColNames);
         String [][] expRS = new String [][]
         {
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0",
                 "(DATABASE = ugh), (DRDAID = null), Cleanup action starting",
                 "0"}
         };
@@ -413,7 +425,7 @@ public final class SysDiagVTIMappingTest
         JDBC.assertColumnNames(rs, expColNames);
         expRS = new String [][]
         {
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0",
                 "(DATABASE = ugh), (DRDAID = null), Cleanup action starting",
                 "0"}
         };
@@ -450,9 +462,9 @@ public final class SysDiagVTIMappingTest
         JDBC.assertColumnNames(rs, expColNames);
         String [][] expRS = new String [][]
         {
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0", "ugh",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0", "ugh",
                 "null", "Cleanup action starting"},
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0", "ugh",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0", "ugh",
                 "null", "Failed Statement is: select * from oops"}
         };
         
@@ -471,9 +483,9 @@ public final class SysDiagVTIMappingTest
         JDBC.assertColumnNames(rs, expColNames);
         expRS = new String [][]
         {
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0", "ugh",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0", "ugh",
                 "null", "Cleanup action starting"},
-            {"2006-12-15 16:14:58.280", "main,5,main", "1111", "0", "ugh",
+            {"2006-12-15 16:14:58.280 GMT", "main,5,main", "1111", "0", "ugh",
                 "null", "Failed Statement is: select * from oops"}
         };
 
@@ -703,6 +715,37 @@ public final class SysDiagVTIMappingTest
         st.close();
     }
 
+    /**
+     * Test date formatting in the vtis which read the error log. This attempts
+     * to keep us from breaking these vtis if the format of logged timestamps
+     * changes. See DERBY-5391.
+     */
+    public  void    test_5391() throws Exception
+    {
+        Statement   st = createStatement();
+
+        ResultSet   rs1 = st.executeQuery( "select * from table (syscs_diag.error_log_reader(
)) as t1" );
+        vetTimestamp( rs1 );
+        rs1.close();
+
+        ResultSet   rs2 = st.executeQuery( "select * from table (syscs_diag.statement_duration())
as t1" );
+        vetTimestamp( rs2 );
+        rs2.close();
+
+        st.close();
+    }
+    private void    vetTimestamp( ResultSet rs ) throws Exception
+    {
+        assertTrue( rs.next() );
+
+        String  timestampString = rs.getString( 1 ).trim();
+
+        SimpleDateFormat    sdf = new SimpleDateFormat( "EEE MMM dd HH:mm:ss zzz yyyy" );
+        Timestamp   timestamp = new Timestamp( sdf.parse( timestampString ).getTime() );
+
+        println( timestamp.toString() );
+    }
+
     /* All statements in this method should fail because a VTI table-
      * mapping that takes arguments can only be used as part of the TABLE 
      * constructor.  Any other uses of, or attempts to modify, such a



Mime
View raw message