db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1584636 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest: NsTest.java README.txt TimerThread.java
Date Fri, 04 Apr 2014 12:29:07 GMT
Author: rhillegas
Date: Fri Apr  4 12:29:06 2014
New Revision: 1584636

URL: http://svn.apache.org/r1584636
Log:
DERBY-6533: Add a knob to NsTest, allowing you to set a time limit for the test run; commit
derby-6533-03-timerThread.diff.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/TimerThread.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/README.txt

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=1584636&r1=1584635&r2=1584636&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 Fri
Apr  4 12:29:06 2014
@@ -65,6 +65,7 @@ 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   String  DURATION = "derby.nstest.durationInMinutes";
 
     private static  final   long    MILLIS_PER_MINUTE = 1000L * 60L;
     
@@ -81,7 +82,9 @@ public class NsTest extends Thread
         "\n" +
         "    -D" + OUTPUT_FILE + "=fileName    Redirects output and errors to a file.\n"
+
         "\n" +
-        "    -D" + JUST_COUNT_ERRORS + "=true    Makes the test run quietly at steady-state,
counting errors, and printing a summary at the end.\n";
+        "    -D" + JUST_COUNT_ERRORS + "=true    Makes the test run quietly at steady-state,
counting errors, and printing a summary at the end.\n" +
+        "\n" +
+        "    -D" + DURATION + "=$number    Run for this number of minutes.\n";
 
     private static  final   String  ERROR_BANNER1 = "//////////////////////////////////////////////////////////////\n";
     private static  final   String  ERROR_BANNER2 = "//    ";
@@ -225,6 +228,8 @@ public class NsTest extends Thread
     private static  boolean _justCountErrors;
     private static  HashMap<String,NsTestError> _errors = new HashMap<String,NsTestError>();
 
+    private static  long    _duration;
+    
     private static  boolean _statisticsAlreadyPrinted = false;
     private static  long        _maxSequenceCounter;
     private static  long        _startTimestamp;
@@ -350,6 +355,12 @@ public class NsTest extends Thread
             statisticsLogger = new PrintStream( outputFile );
         }
 
+		String duration = System.getProperty( DURATION );
+        if ( duration != null )
+        {
+            _duration = Long.parseLong( duration ) * MILLIS_PER_MINUTE;
+        }
+
         _justCountErrors = Boolean.getBoolean( JUST_COUNT_ERRORS );
 
         logger = new NsTestPrintStream( statisticsLogger, !_justCountErrors );
@@ -380,6 +391,13 @@ public class NsTest extends Thread
 			}    
 		}
         
+		TimerThread timerThread = null;
+        if ( _duration > 0L )
+        {
+            timerThread = new TimerThread( _duration );
+            timerThread.start();
+        }
+
 		// Load the driver and get a connection to the database
 		String jdbcUrl = "";
 		try {
@@ -571,8 +589,16 @@ public class NsTest extends Thread
 			testThreads[j].join();
 		}
 
+        if ( timerThread != null )
+        {
+            timerThread.stopNow();
+            timerThread.interrupt();
+            timerThread.join();
+        }
+
         // stop the sequence reader thread
 		sequenceReader.stopNow = true;
+		sequenceReader.interrupt();
 		sequenceReader.join();
 
 		// Print statistics

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt?rev=1584636&r1=1584635&r2=1584636&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt Fri
Apr  4 12:29:06 2014
@@ -79,6 +79,8 @@ The following flags can be set:
 
     -Dderby.nstest.justCountErrors=true    Makes the test run quietly at steady-state, counting
errors, and printing a summary at the end.
 
+    -Dderby.nstest.durationInMinutes=$number    Run for this number of minutes.
+
 The main class to invoke is org.apache.derbyTesting.system.nstest.NsTest. This class
 takes a String argument of "DerbyClient"/"Embedded", default is DerbyClient. The test requires
 the Network Server to be started on port 1900 to begin the run. 

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/TimerThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/TimerThread.java?rev=1584636&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/TimerThread.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/TimerThread.java
Fri Apr  4 12:29:06 2014
@@ -0,0 +1,111 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.TimerThread
+
+ 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;
+
+/**
+ * <p>
+ * A thread which sleeps for a specified time period, then wakes up
+ * and terminates the VM.
+ * </p>
+ */
+public class TimerThread extends Thread
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private long    _sleepTime;
+    private boolean _continueRunning = true;
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+	public TimerThread( long sleepTime )
+    {
+        _sleepTime = sleepTime;
+	}
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // Thread BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+	/*
+	 * Implementation of run() method to sleep, wake up, and kill the program.
+	 * 
+	 */
+	public void run() {
+
+        long    remainingTime = _sleepTime;
+        
+        while ( _continueRunning )
+        {
+            long    cycleStartTime = System.currentTimeMillis();
+            
+            try {
+                if ( remainingTime > 0L )
+                {
+                    NsTest.logger.println( "TimerThread sleeping for " + remainingTime +
" milliseconds." );
+                    sleep( remainingTime );
+                }
+
+                //
+                // End the program. This will fire the shutdown hook which
+                // prints the final statistics.
+                //
+                NsTest.logger.println( "TimerThread attempting to shut down the program."
);
+                NsTest.printStatistics();
+                Runtime.getRuntime().halt( 0 );
+                
+            } catch (java.lang.InterruptedException ie)
+            {
+                NsTest.printException( TimerThread.class.getName(), ie );
+            }
+            
+            long    elapsedTime = System.currentTimeMillis() - cycleStartTime;
+
+            remainingTime = remainingTime - elapsedTime;
+        }
+	}
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // OTHER BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** This method marks the thread for rundown */
+    public  void    stopNow() { _continueRunning = false; }
+
+}
+

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



Mime
View raw message