db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1583749 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest: NsTest.java init/DbSetup.java tester/TesterObject.java utils/DbUtil.java utils/SequenceReader.java
Date Tue, 01 Apr 2014 18:38:32 GMT
Author: rhillegas
Date: Tue Apr  1 18:38:32 2014
New Revision: 1583749

URL: http://svn.apache.org/r1583749
Log:
DERBY-6533: Add a sequence generator to NsTest along with start and end timestamps; commit
derby-6533-02-aa-sequencesAndMoreStats.diff.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java?rev=1583749&r1=1583748&r2=1583749&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java Tue
Apr  1 18:38:32 2014
@@ -29,6 +29,7 @@ import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.sql.Connection;
+import java.sql.Timestamp;
 
 import org.apache.derbyTesting.system.nstest.init.DbSetup;
 import org.apache.derbyTesting.system.nstest.init.Initializer;
@@ -38,6 +39,7 @@ import org.apache.derbyTesting.system.ns
 import org.apache.derbyTesting.system.nstest.tester.Tester2;
 import org.apache.derbyTesting.system.nstest.tester.Tester3;
 import org.apache.derbyTesting.system.nstest.utils.MemCheck;
+import org.apache.derbyTesting.system.nstest.utils.SequenceReader;
 
 /**
  * NsTest - the main class to start the tests The main test settings are as
@@ -63,6 +65,8 @@ public class NsTest extends Thread
     private static  final   String  OUTPUT_FILE = "derby.nstest.outputFile";
     private static  final   String  JUST_COUNT_ERRORS = "derby.nstest.justCountErrors";
     private static  final   String  QUIET = "derby.nstest.quiet";
+
+    private static  final   long    MILLIS_PER_MINUTE = 1000L * 60L;
     
     private static  final   String  USAGE =
         "Usage:\n" +
@@ -222,6 +226,9 @@ public class NsTest extends Thread
     private static  HashMap<String,NsTestError> _errors = new HashMap<String,NsTestError>();
 
     private static  boolean _statisticsAlreadyPrinted = false;
+    private static  long        _maxSequenceCounter;
+    private static  long        _startTimestamp;
+    private static  long        _endTimestamp;
 
 	public static int numActiveTestThreads() {
 		int activeThreadCount=0;
@@ -238,6 +245,11 @@ public class NsTest extends Thread
 		return activeThreadCount;
 	}
 
+    public  static  void    updateSequenceTracker( long newValue )
+    {
+        _maxSequenceCounter = newValue;
+    }
+
     public  static  boolean justCountErrors() { return _justCountErrors; }
 
 	public static synchronized void addError( Throwable t )
@@ -329,6 +341,8 @@ public class NsTest extends Thread
 	public static void main(String[] args) throws SQLException, IOException,
 	InterruptedException, Exception, Throwable
     {
+        _startTimestamp = System.currentTimeMillis();
+
 		String outputFile = System.getProperty( OUTPUT_FILE );
         statisticsLogger = System.out;
         if ( outputFile != null )
@@ -483,7 +497,7 @@ public class NsTest extends Thread
 		if (CREATE_DATABASE_ONLY) {
 			logger
 			.println("Finished creating the database, TEST THREADS WILL NOT RUN!!");
-			// Finally also stop the memory checker thread, else the test will
+			// Finally also stop the memory checker and sequence threads, else the test will
 			// remain hung!
 			mc.stopNow = true;
 			mc.join();
@@ -544,6 +558,12 @@ public class NsTest extends Thread
 
 		}
 
+		// check sequence value thread
+		// 60,000 msec = 1 minute delay between checks
+		logger.println("Starting sequence reader thread");
+		SequenceReader  sequenceReader = new SequenceReader( DriverManager.getConnection( jdbcUrl,
prop ), 60000 );
+		sequenceReader.start();
+
 		// Wait for the test threads to finish and join back
 		for (int j = 0; j < maxTestThreads; j++)
         {
@@ -551,6 +571,10 @@ public class NsTest extends Thread
 			testThreads[j].join();
 		}
 
+        // stop the sequence reader thread
+		sequenceReader.stopNow = true;
+		sequenceReader.join();
+
 		// Print statistics
         printStatistics();
 
@@ -568,10 +592,16 @@ public class NsTest extends Thread
         if ( _statisticsAlreadyPrinted ) { return; }
         else { _statisticsAlreadyPrinted = true; }
 
+        _endTimestamp = System.currentTimeMillis();
+
 		statisticsLogger.println("");
 		statisticsLogger.println("STATISTICS OF OPERATIONS DONE");
 		statisticsLogger.println("-----------------------------");
-		statisticsLogger.println("");
+		statisticsLogger.println("\n\n");
+		statisticsLogger.println( "Start time = " + (new Timestamp( _startTimestamp )).toString()
);
+		statisticsLogger.println( "End time = " + (new Timestamp( _endTimestamp )).toString() );
+		statisticsLogger.println( "Duration = " + ( (_endTimestamp - _startTimestamp) / MILLIS_PER_MINUTE
) + " minutes" );
+		statisticsLogger.println("\n\n");
 		statisticsLogger.println("SUCCESSFUL: ");
 		statisticsLogger.println("	Number of INSERTS = " + numInserts);
 		statisticsLogger.println("	Number of UPDATES = " + numUpdates);
@@ -591,6 +621,8 @@ public class NsTest extends Thread
 		.println("NOTE: Failing operations could be because of locking issue that are\n"
 				+ "directly related to the application logic.  They are not necessarily bugs.");
 
+        statisticsLogger.println( "\nMax sequence counter peeked at = " + _maxSequenceCounter
+ "\n" );
+        
         if ( _errors.size() > 0 )
         {
             countAndPrintSQLStates();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java?rev=1583749&r1=1583748&r2=1583749&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java
Tue Apr  1 18:38:32 2014
@@ -86,6 +86,7 @@ public class DbSetup {
 						+ "t_timestamp timestamp," + "t_varchar varchar(100),"
 						+ "t_clob clob(1K)," + "t_blob blob(10K),"
 						+ "serialkey bigint generated always as identity, "
+						+ "sequenceColumn bigint, "
 						+ "unique (serialkey)) ");
 
 				s.execute("create index t_char_ind on nstesttab ( t_char)");
@@ -112,6 +113,9 @@ public class DbSetup {
 				s
 				.execute("create index t_serialkey_ind on nstesttab (serialkey)");
 
+                NsTest.logger.println( "Creating nstesttab_seq sequence" );
+                s.execute( "create sequence nstesttab_seq as bigint start with 0" );
+
 				NsTest.logger
 				.println("creating table 'NSTRIGTAB' and corresponding indices");
 				s.execute("create table NSTRIGTAB (" + "id int,"
@@ -123,7 +127,8 @@ public class DbSetup {
 						+ "t_smallint smallint," + "t_time time,"
 						+ "t_timestamp timestamp," + "t_varchar varchar(100),"
 						+ "t_clob clob(1K)," + "t_blob blob(10K),"
-						+ "serialkey bigint )");
+						+ "serialkey bigint, "
+						+ "sequenceColumn bigint )");
 				// create trigger
 				s.execute("CREATE TRIGGER NSTEST_TRIG AFTER DELETE ON nstesttab "
 						+ "REFERENCING OLD AS OLDROW FOR EACH ROW MODE DB2SQL "
@@ -133,7 +138,8 @@ public class DbSetup {
 						+ "OLDROW.T_FLOAT, OLDROW.T_INT,OLDROW.T_LONGINT, OLDROW.T_numeric_large,"
 						+ "OLDROW.T_real,OLDROW.T_smallint,OLDROW.T_time,OLDROW.T_timestamp,OLDROW.T_varchar,"
 						+ "OLDROW.T_clob,OLDROW.T_blob, "
-						+ "OLDROW.serialkey)");
+						+ "OLDROW.serialkey, "
+						+ "OLDROW.sequenceColumn )");
 			} catch (Exception e) {
                 if ( NsTest.justCountErrors() ) { NsTest.printException( DbSetup.class.getName(),
e ); }
 				else { e.printStackTrace( NsTest.logger ); }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java?rev=1583749&r1=1583748&r2=1583749&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java
Tue Apr  1 18:38:32 2014
@@ -216,7 +216,7 @@ public class TesterObject {
 					+ " t_date, t_decimal, t_decimal_nn, t_double, "
 					+ " t_float, t_int, t_longint, t_numeric_large,"
 					+ " t_real, t_smallint, t_time, t_timestamp,"
-					+ " t_varchar, serialkey from nstesttab where serialkey <= "
+					+ " t_varchar, serialkey, sequenceColumn from nstesttab where serialkey <= "
 					+ numRowsToSelect);
 		} catch (Exception e) {
 			NsTest.logger
@@ -282,6 +282,9 @@ public class TesterObject {
 		            // get value of column serialkey
 		            long lg2 = rSet.getLong(16);
 
+		            // get value of sequence column
+		            long lg3 = rSet.getLong(17);
+
 		            numRowsSelected++;
 		        }
 		        NsTest.addStats(NsTest.SELECT, 1);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java?rev=1583749&r1=1583748&r2=1583749&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java
Tue Apr  1 18:38:32 2014
@@ -96,8 +96,8 @@ public class DbUtil {
 					+ " t_date, t_decimal, t_decimal_nn, t_double, "
 					+ " t_float, t_int, t_longint, t_numeric_large,"
 					+ " t_real, t_smallint, t_time, t_timestamp,"
-					+ " t_varchar,t_clob,t_blob) values ("
-					+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,cast('00000000000000000000000000000000031'
as clob(1K)),cast(X'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031'
as blob(10K)))");
+					+ " t_varchar,t_clob,t_blob,sequenceColumn) values ("
+					+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,cast('00000000000000000000000000000000031'
as clob(1K)),cast(X'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031'
as blob(10K)), next value for nstesttab_seq)");
 			
 			Random rand = new Random();
 			
@@ -195,19 +195,26 @@ public class DbUtil {
 			try {
 				rowsAdded = ps.executeUpdate();
 			} catch (SQLException sqe) {
-				if (sqe.getSQLState().equalsIgnoreCase("40XL1")) {
-					NsTest.logger
-					.println("LOCK TIMEOUT obtained during insert - add_one_row() "
-							+ sqe.getSQLState());
-				}
-				else if (sqe.getSQLState().equalsIgnoreCase("23505")) {
-				    NsTest.logger
-				    .println("prevented duplicate row - add_one_row(): "
-				            + sqe.getSQLState() + "; " + sqe.getMessage());
+                if ( NsTest.justCountErrors() )
+                {
+                    NsTest.addError( sqe );
+                }
+                else
+                {
+                    if (sqe.getSQLState().equalsIgnoreCase("40XL1")) {
+                        NsTest.logger
+                            .println("LOCK TIMEOUT obtained during insert - add_one_row()
"
+                                     + sqe.getSQLState());
+                    }
+                    else if (sqe.getSQLState().equalsIgnoreCase("23505")) {
+                        NsTest.logger
+                            .println("prevented duplicate row - add_one_row(): "
+                                     + sqe.getSQLState() + "; " + sqe.getMessage());
 
-				} else {
-					throw sqe;
-				}
+                    } else {
+                        throw sqe;
+                    }
+                }
 				
 			}
 			if (rowsAdded == 1) {

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java?rev=1583749&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java
Tue Apr  1 18:38:32 2014
@@ -0,0 +1,100 @@
+/*
+ 
+ Derby - Class org.apache.derbyTesting.system.nstest.utils.SequenceReader
+ 
+ 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.system.nstest.utils;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Date;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * SequenceReader - a background thread that checks the state of the sequence counter.
+ */
+public class SequenceReader extends Thread
+{
+    private Connection  conn;
+	private int delay = 60000;
+    
+
+	public boolean stopNow = false;
+
+	public SequenceReader( Connection connection, int num )
+    {
+        conn = connection;
+		delay = num;
+	}
+
+	/*
+	 * Implementation of run() method to check the sequence counter.
+	 * 
+	 */
+	public void run() {
+        NsTest.logger.println( "Starting the sequence reader thread with delay = " + delay
);
+		while (stopNow == false)
+        {
+			try {
+				readSequenceValue();
+				sleep( delay );
+                
+				// first check if there are still active tester threads.
+				if (NsTest.numActiveTestThreads() != 0 && NsTest.numActiveTestThreads() >
1)
+				{
+					continue;
+				}
+				else
+				{
+					NsTest.logger.println("no more test threads, finishing SequenceReader thread also");
+                    readSequenceValue();
+					stopNow=true;
+				}
+			} catch (java.lang.InterruptedException ie) {
+				NsTest.logger.println("SequenceReader: unexpected error in sleep");
+			}
+		}
+	}
+
+	/*
+	 * Print the current memory status
+	 */
+	private void readSequenceValue()
+    {
+        try {
+            PreparedStatement   ps = conn.prepareStatement
+                ( "values syscs_util.syscs_peek_at_sequence( 'NSTEST', 'NSTESTTAB_SEQ' )"
);
+            ResultSet       rs = ps.executeQuery();
+            rs.next();
+            long    nextSequenceValue = rs.getLong( 1 );
+            NsTest.logger.println( "Next sequence number = " + nextSequenceValue );
+            NsTest.updateSequenceTracker( nextSequenceValue );
+            rs.close();
+            ps.close();
+        }
+        catch (Exception e)
+        {
+            NsTest.printException( SequenceReader.class.getName(), e );
+        }
+	}
+
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/SequenceReader.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message