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 fu...@apache.org on 2007/03/05 23:01:25 UTC
svn commit: r514882 [1/2] - in /db/derby/code/trunk/java/testing: ./
org/apache/derbyTesting/system/nstest/
org/apache/derbyTesting/system/nstest/init/
org/apache/derbyTesting/system/nstest/tester/
org/apache/derbyTesting/system/nstest/utils/
Author: fuzzylogic
Date: Mon Mar 5 14:01:23 2007
New Revision: 514882
URL: http://svn.apache.org/viewvc?view=rev&rev=514882
Log:
DERBY-2248: Add Network Server system test.
Committed for Manjula Kutty <ma...@gmail.com>
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/TesterObject.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/DbUtil.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/utils/MemCheck.java (with props)
Modified:
db/derby/code/trunk/java/testing/build.xml
Modified: db/derby/code/trunk/java/testing/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/build.xml?view=diff&rev=514882&r1=514881&r2=514882
==============================================================================
--- db/derby/code/trunk/java/testing/build.xml (original)
+++ db/derby/code/trunk/java/testing/build.xml Mon Mar 5 14:01:23 2007
@@ -81,6 +81,7 @@
<ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/master"/>
<ant dir="${derby.testing.src.dir}/${derby.testing.suites.dir}"/>
<ant dir="${derby.testing.src.dir}/${derby.testing.system.dir}/mailjdbc"/>
+ <ant dir="${derby.testing.src.dir}/${derby.testing.system.dir}/nstest"/>
<ant dir="${derby.testing.src.dir}/${derby.testing.system.dir}/oe"/>
<ant dir="${derby.testing.src.dir}/${derby.testing.system.dir}/optimizer"/>
<ant dir="${derby.testing.src.dir}/${derby.testing.system.dir}/sttest"/>
Added: 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?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,646 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.NsTest
+
+ 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;
+
+import java.util.Properties;
+import java.sql.SQLException;
+import java.sql.DriverManager;
+import java.io.IOException;
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.nstest.init.DbSetup;
+import org.apache.derbyTesting.system.nstest.init.Initializer;
+import org.apache.derbyTesting.system.nstest.init.NWServerThread;
+import org.apache.derbyTesting.system.nstest.tester.BackupRestoreReEncryptTester;
+import org.apache.derbyTesting.system.nstest.tester.Tester1;
+import org.apache.derbyTesting.system.nstest.tester.Tester2;
+import org.apache.derbyTesting.system.nstest.tester.Tester3;
+import org.apache.derbyTesting.system.nstest.utils.MemCheck;
+
+/**
+ * NsTest - the main class to start the tests The main test settings are as
+ * follows: INIT_THREADS = Initializer threads MAX_INITIAL_ROWS = Initial set of
+ * rows inserted before test begins MAX_ITERATIONS = Each client does these many
+ * transactions in the test MAX_LOW_STRESS_ROWS = Num of rows worked over in a
+ * transaction MAX_OPERATIONS_PER_CONN = Num of transaction batches made by a
+ * client before closing the connection NUMTESTER1 = Number of Tester1 testers
+ * NUMTESTER2 = Number of Tester2 testers NUMTESTER3 = Number of Tester3 testers
+ * NUM_HIGH_STRESS_ROWS = Maximum rows to be selected NUM_UNTOUCHED_ROWS =
+ * Number of rows on which Update/Delete operations are not performed
+ *
+ * START_SERVER_IN_SAME_VM= Set to true/false to start Network Server in the
+ * same VM.
+ *
+ * The System property 'derby.nstest.backupRestore' can be set to false for
+ * turning off Backup/Restore/Re-Encryption.
+ */
+
+public class NsTest extends Thread {
+
+ public static final String dbName = "nstestdb";
+
+ public static final String user = "nstest";
+
+ public static final String password = "nstest";
+
+ public static final String clientURL = "jdbc:derby://localhost:1900/";
+
+ public static final String embedURL = "jdbc:derby:";
+
+ public static final String dataEncypt = "dataEncryption=true";
+
+ public static final String bootPwd = "bootPassword=12345678";
+
+ public static final String clientDbURL = new String(clientURL + dbName
+ + ";create=true");
+
+ public static final String retrieveMessagePart = "retrieveMessagesFromServerOnGetMessage=true;";
+
+ public static final String embedDbURL = new String(embedURL + dbName
+ + ";create=true");
+
+ public static boolean embeddedMode = false; // true is to run the test in
+
+ // embedded mode
+
+ public static final String driver = new String(
+ "org.apache.derby.jdbc.ClientDriver");
+
+ public static final String embedDriver = new String(
+ "org.apache.derby.jdbc.EmbeddedDriver");
+
+ public static Properties prop = new Properties();
+
+ public static int INIT = 0;
+
+ public static int TESTER1 = 1;
+
+ public static int TESTER2 = 2;
+
+ public static int TESTER3 = 3;
+
+ public static int BACKUP = 4;
+
+ public static String BACKUPDIR = "backupdir";
+
+ public static String RESTOREDIR = "restoredir";
+
+ public static boolean START_SERVER_IN_SAME_VM = false;// If the server
+
+ // also needs to be
+ // started as a
+ // thread
+
+ public static boolean AUTO_COMMIT_OFF = false; // true is autocommit off
+
+ public static boolean CREATE_DATABASE_ONLY = false;
+
+ public static boolean schemaCreated = false; // initially schema is
+
+ // assumed to not exist
+
+ // *********Uncomment this block for a small test scenario, comment it for
+ // full testing
+ /*
+ * public static int INIT_THREADS = 3; //keep this low to avoid deadlocks
+ * public static int MAX_INITIAL_ROWS = 150; //for a small test public
+ * static int MAX_ITERATIONS = 50; //for a small test public static int
+ * MAX_LOW_STRESS_ROWS = 10; //for a small test public static int
+ * MAX_OPERATIONS_PER_CONN = 10; //for a small test public static int
+ * NUMTESTER1 = 3; //for a small test public static int NUMTESTER2 = 4;
+ * //for a small test public static int NUMTESTER3 = 3; //for a small test
+ * public static int NUM_HIGH_STRESS_ROWS = 20; //for a small test public
+ * static int NUM_UNTOUCHED_ROWS = 50; //for a small test
+ */
+ // ***End of small test scenario block
+ // ****Comment this block for a small test scenario, uncomment it for full
+ // testing
+ public static int INIT_THREADS = 6; // keep this low to avoid deadlocks
+
+ // public static int MAX_INITIAL_ROWS = 60000; //for network server mode
+ public static int MAX_INITIAL_ROWS = 6000; // for network server mode
+
+ public static int MAX_ITERATIONS = 2000; // Each client does these many
+
+ // transactions in the test.
+
+ // for network server mode
+ public static int MAX_LOW_STRESS_ROWS = 30; // num of rows worked over in a
+
+ // transaction
+
+ // for network server mode
+ public static int MAX_OPERATIONS_PER_CONN = 25; // num of transaction
+
+ // batches made by a client
+
+ // before closing the connection
+ // for network server mode
+ public static int NUMTESTER1 = 15; // for network server mode
+
+ // ***public static int NUMTESTER1 = 45; //for embedded mode
+ public static int NUMTESTER2 = 45; // for network server mode
+
+ // ***public static int NUMTESTER2 = 135; //for embedded server mode
+ public static int NUMTESTER3 = 10; // for network server mode
+
+ // ***public static int NUMTESTER3 = 30; //for network server mode
+ public static int NUM_HIGH_STRESS_ROWS = 25000; // for network server mode
+
+ public static int NUM_UNTOUCHED_ROWS = 6000; // for network server mode
+
+ // ***End of full test block
+
+ // The following are to keep statistics of the number of
+ // Insert/Updates/Deletes & Selects
+ public static int numInserts = 0;
+
+ public static int numUpdates = 0;
+
+ public static int numDeletes = 0;
+
+ public static int numSelects = 0;
+
+ public static int numFailedInserts = 0;
+
+ public static int numFailedUpdates = 0;
+
+ public static int numFailedDeletes = 0;
+
+ public static int numFailedSelects = 0;
+
+ public static int numConnections = 0;
+
+ public static int INSERT = 0;
+
+ public static int UPDATE = 1;
+
+ public static int DELETE = 2;
+
+ public static int SELECT = 3;
+
+ public static int FAILED_INSERT = 4;
+
+ public static int FAILED_UPDATE = 5;
+
+ public static int FAILED_DELETE = 6;
+
+ public static int FAILED_SELECT = 7;
+
+ public static int CONNECTIONS_MADE = 8;
+
+ public static final String SUCCESS = " *** SUCCESS *** ";
+
+ public static String driver_type = null;
+
+ private int type;
+
+ public static synchronized void addStats(int type, int addValue) {
+ switch (type) {
+ case 0:
+ numInserts += addValue;
+ break;
+ case 1:
+ numUpdates += addValue;
+ break;
+ case 2:
+ numDeletes += addValue;
+ break;
+ case 3:
+ numSelects += addValue;
+ break;
+ case 4:
+ numFailedInserts += addValue;
+ break;
+ case 5:
+ numFailedUpdates += addValue;
+ break;
+ case 6:
+ numFailedDeletes += addValue;
+ break;
+ case 7:
+ numFailedSelects += addValue;
+ break;
+ case 8:
+ numConnections += addValue;
+ break;
+ }
+ }
+
+ NsTest(int ttype, int k) throws Exception {
+ this.type = ttype; // INIT or TESTER1/2/3
+
+ if (ttype == INIT)
+ this.setName("InitThread " + k);
+ else if ((ttype == TESTER1) || (ttype == TESTER2) || (ttype == TESTER3))
+ this.setName("Thread " + k);
+ }
+
+ // ****************************************************************************
+ //
+ // main - will load the Derby embedded or client, invoke the
+ // database setup, initialize the
+ // tables and then kick off the test threads.
+ //
+ // ****************************************************************************
+ public static void main(String[] args) throws SQLException, IOException,
+ InterruptedException, Exception, Throwable {
+
+ Connection conn = null;
+ if (args.length == 1) {
+ driver_type = args[0];
+ if (!((driver_type.equalsIgnoreCase("DerbyClient"))
+ || (driver_type
+ .equalsIgnoreCase("Embedded")))) {
+ printUsage();
+ return;
+ }
+ System.out.println("Test nstest starting....., using driver: "
+ + driver_type);
+ } else {
+ driver_type = "DerbyClient";
+ }
+
+ // Load the driver and get a connection to the database
+ String jdbcUrl = "";
+ try {
+ if (driver_type.equalsIgnoreCase("Embedded")) {
+ // System.out.println("Driver embedd : " + driver_type);
+ System.out.println("Loading the embedded driver...");
+ Class.forName(embedDriver).newInstance();
+ jdbcUrl = embedDbURL + ";" + dataEncypt + ";" + bootPwd;
+ embeddedMode = true;
+ } else {
+ System.out.println("Driver type : " + driver_type);
+ System.out.println("Loading the Derby Client driver..."
+ + driver);
+ Class.forName(driver).newInstance();
+ System.out.println("Client Driver loaded");
+ jdbcUrl = clientDbURL + ";" + dataEncypt + ";" + bootPwd;
+ }
+ if ((!embeddedMode) && START_SERVER_IN_SAME_VM) {
+ startNetworkServer();
+ }
+ prop.setProperty("user", user);
+ prop.setProperty("password", password);
+ System.out
+ .println("Getting a connection using the url: " + jdbcUrl);
+ System.out.println("JDBC url= " + jdbcUrl);
+ conn = DriverManager.getConnection(jdbcUrl, prop);
+
+ } catch (SQLException sqe) {
+
+ System.out.println("\n\n " + sqe + sqe.getErrorCode() + " "
+ + sqe.getSQLState());
+ if ((sqe.getErrorCode() == -4499)
+ || sqe.getSQLState().equalsIgnoreCase("08001")) {
+ System.out
+ .println("\n Unable to connect, test cannot proceed. Please verify if the Network Server is started on port 1900.");
+ // sqe.printStackTrace();
+ return;
+ }
+
+ } catch (ClassNotFoundException cnfe) {
+ System.out.println("Driver not found: " + cnfe.getMessage());
+ cnfe.printStackTrace();
+ return;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Unexpected Failure");
+ printException("nstest.main() method ==> ", e);
+ }
+
+ // create test schema if it does not already exist
+ if (DbSetup.doIt(conn) == false) {
+ System.out.println("Error in dbSetup, test will exit");
+ System.exit(1);
+ }
+
+ // Note that the connection is still open, we can safely close it now
+ try {
+ conn.close();
+ } catch (Exception e) {
+ System.out
+ .println("FAIL - Error closing the connection in nstest.main():");
+ printException("Closing connection in nstest.main()", e);
+ }
+
+ // check memory in separate thread-- allows us to monitor usage during
+ // database calls
+ // 200,000 msec = 3min, 20 sec delay between checks
+ System.out.println("Starting memory checker thread");
+ MemCheck mc = new MemCheck(200000);
+ mc.start();
+
+ // Now populate the tables using INIT_THREADS number of threads only if
+ // the schemaCreated
+ // flag has not been set. If so, then we assume that some other thread
+ // from possibly
+ // another jvm reached here and has already created the schema and
+ // loaded the tables.
+ // Note that we kick off threads of this object type (nstest) and use
+ // the run method to
+ // do the work. The key to starting the init threads is the use of the
+ // constructor
+ // to indicate to the thread that it is an init thread. In this case, we
+ // pass the
+ // value INIT to the constructor and in the run method we go to the
+ // right section of the
+ // code based on what value is passed in. The other possible value that
+ // a thread can get
+ // is TESTER which indicates that these are the main test threads.
+
+ if (NsTest.schemaCreated == false) {
+ // Table was created by this object, so we need to load it
+ System.out
+ .println("Kicking off initialization threads that will populate the test table");
+ NsTest initThreads[] = new NsTest[INIT_THREADS];
+
+ for (int i = 0; i < INIT_THREADS; i++) {
+ initThreads[i] = new NsTest(INIT, i);
+ initThreads[i].start();
+ sleep(3000);
+ }
+
+ // Wait for the init threads to finish and join back
+ for (int i = 0; i < INIT_THREADS; i++) {
+ initThreads[i].join();
+ }
+ }// end of if(nstest.schemaCreated==false)
+
+ // For informational/debug purposes, print out whether this process
+ // created the schema
+ if (NsTest.schemaCreated) // true means that the schema was created by
+ // another jvm
+ System.out
+ .println("Schema has already been created by another process!");
+
+ // The following 2 lines are used when you want to only create the test
+ // database that can be
+ // used as a reference so that subsequent tests do not need to create
+ // one of their own.
+ // The CREATE_DATABASE_ONLY FLAG is set with the rest of the flags
+ if (CREATE_DATABASE_ONLY) {
+ System.out
+ .println("Finished creating the database, TEST THREADS WILL NOT RUN!!");
+ // Finally also stop the memory checker thread, else the test will
+ // remain hung!
+ mc.stopNow = true;
+ mc.join();
+ return;
+ }
+
+ // Table was created by some other object, so we assume it is already
+ // loaded
+ // Now kick off the actual test threads that will do the work for us.
+ // Note that we use
+ // the value TESTER when initializing the threads.
+ // The total number of threads is NUMTESTER1+NUMTESTER2+NUMTESTER3
+ System.out
+ .println("Kicking off test threads that will work over the test table");
+
+ int numTestThread = 0;
+ int maxTestThreads = 1 + NUMTESTER1 + NUMTESTER2 + NUMTESTER3;
+ NsTest testThreads[] = new NsTest[maxTestThreads];
+
+ // This loop is made of 3 subloops that will initialize the required
+ // amount of tester threads
+ // It uses the numTestThread variable as the array index which gets
+ // incremented in each subloop
+ while (numTestThread < maxTestThreads) {
+ String runBackup = System.getProperty("derby.nstest.backupRestore");
+ // Check for property setting to decide the need for starting
+ // BackupRestore thread
+ if ((runBackup != null) && (runBackup.equalsIgnoreCase("false"))) {
+ System.out.println("BackupRestore Thread not started...");
+ } else {
+ // Otherwise, start the BackupRestore Thread by default
+ testThreads[numTestThread] = new NsTest(BACKUP, numTestThread);
+ testThreads[numTestThread].start();
+ numTestThread++;
+ }
+
+ for (int j = 0; j < NUMTESTER1; j++) {
+ testThreads[numTestThread] = new NsTest(TESTER1, numTestThread);
+ testThreads[numTestThread].start();
+ sleep(3000);
+ numTestThread++;
+ }
+ for (int j = 0; j < NUMTESTER2; j++) {
+ testThreads[numTestThread] = new NsTest(TESTER2, numTestThread);
+ testThreads[numTestThread].start();
+ sleep(3000);
+ numTestThread++;
+ }
+ for (int j = 0; j < NUMTESTER3; j++) {
+ testThreads[numTestThread] = new NsTest(TESTER3, numTestThread);
+ testThreads[numTestThread].start();
+ sleep(3000);
+ numTestThread++;
+ }
+
+ }
+
+ // Wait for the init threads to finish and join back
+ for (int j = 0; j < maxTestThreads; j++) {
+ System.out.println("Waiting for thread " + j
+ + " to join back/finish");
+ testThreads[j].join();
+ }
+
+ // Print statistics
+ System.out.println("");
+ System.out.println("STATISTICS OF OPERATIONS DONE");
+ System.out.println("-----------------------------");
+ System.out.println("");
+ System.out.println("SUCCESSFUL: ");
+ System.out.println(" Number of INSERTS = " + numInserts);
+ System.out.println(" Number of UPDATES = " + numUpdates);
+ System.out.println(" Number of DELETES = " + numDeletes);
+ System.out.println(" Number of SELECTS = " + numSelects);
+ System.out.println("");
+ System.out.println("FAILED: ");
+ System.out.println(" Number of failed INSERTS = " + numFailedInserts);
+ System.out.println(" Number of failed UPDATES = " + numFailedUpdates);
+ System.out.println(" Number of failed DELETES = " + numFailedDeletes);
+ System.out.println(" Number of failed SELECTS = " + numFailedSelects);
+ System.out.println("");
+ System.out.println(" Note that this may not be the same as the server side connections made "
+ + " to the database especially if connection pooling is employed");
+ System.out.println("");
+ System.out
+ .println("NOTE: Failing operations could be because of locking issue that are "
+ + "directly related to the application logic. They are not necessarily bugs.");
+
+ // Finally also stop the memory checker thread
+ mc.stopNow = true;
+ mc.join();
+
+ System.out
+ .println("End of test nstest! Look for 'FAIL' messages in the output and derby.log");
+
+ }// end of main
+
+ // ****************************************************************************
+ //
+ // run() - the main workhorse method of the threads that will either
+ // initialize
+ // the table data or work over it as part of the test process.
+ // Table data initialization threads are of the following type
+ // Initializer -
+ // Bulk Insert client type that deals with a large(stress)
+ // number of rows with the connection being closed after the insert.
+ // Max rows inserted is based on the parameter MAX_INITIAL_ROWS
+ // Note that the run method will also instantiate tester objects of
+ // different
+ // types based on the following criteria
+ // Tester1 -
+ // The connection to the database is open forever. This client
+ // will do Insert/Update/Delete and simple Select queries over
+ // a small to medium set of data determined randomly as 1 row to
+ // MAX_LOW_STRESS_ROWS. Autocommit is left on.
+ // Tester2 -
+ // The connection is frequently opened and closed based on
+ // a random choice between 1 and MAX_OPERATIONS_PER_CONN number of
+ // transaction batches committed by this client type. This client will
+ // do Insert/Update/Delete and simple Select queries over a
+ // small to medium set of data determined randomly as 1 row to
+ // MAX_LOW_STRESS_ROWS.
+ // Tester3 -
+ // Query only kind of client that deals with a large result
+ // set based on a select query that returns a large number of
+ // rows (stress condition). Connection is closed after each
+ // query. The query will need to run in a DIRTY_READ mode, i.e.
+ // READ UNCOMMITTED isolation level. We work over the untouched
+ // portion of rows in the table (i.e. serialkey 1 to NUM_UNTOUCHED_ROWS)
+ //
+ // The mix of the tester types is based on the parameters NUMTESTER1,
+ // NUMTESTER2, NUMTESTER3.
+ //
+ //
+ // ****************************************************************************
+ public void run() {
+
+ System.out.println(this.getName() + " is now running");
+
+ if (this.type == INIT) {
+ Initializer Init = new Initializer(this.getName());
+ Init.startInserts(); // this method only returns when the thread
+ // is done
+ } else if (this.type == TESTER1) {
+ Tester1 Tstr1 = new Tester1("Tester1" + this.getName());
+ Tstr1.startTesting(); // this method only returns when the thread
+ // is done
+ } else if (this.type == TESTER2) {
+ Tester2 Tstr2 = new Tester2("Tester2" + this.getName());
+ Tstr2.startTesting(); // this method only returns when the thread
+ // is done
+ } else if (this.type == TESTER3) {
+ Tester3 Tstr3 = new Tester3("Tester3" + this.getName());
+ Tstr3.startTesting(); // this method only returns when the thread
+ // is done
+ } else if (this.type == BACKUP) {
+ BackupRestoreReEncryptTester Tstr4 = null;
+ try {
+ Tstr4 = new BackupRestoreReEncryptTester(
+ "BackupRestoreReEncrypt" + this.getName());
+ } catch (IOException ioe) {
+ System.out
+ .println(ioe
+ + "=====> Unable to create backup log file, test cannot proceed ");
+ ioe.printStackTrace();
+ return;
+ }
+ Tstr4.startTesting();
+
+ } else {
+ System.out
+ .println("FAIL: Invalid thread type, should be INIT or TESTERx or BACKUP");
+ System.out.println("You should check the code and restart");
+ return;
+ }
+
+ System.out.println(this.getName() + " finished and is now exiting");
+
+ }// end of run()
+
+ // ** This method abstracts exception message printing for all exception
+ // messages. You may want to change
+ // ****it if more detailed exception messages are desired.
+ // ***Method is synchronized so that the output file will contain sensible
+ // stack traces that are not
+ // ****mixed but rather one exception printed at a time
+ public static synchronized void printException(String where, Exception e) {
+ if (e instanceof SQLException) {
+ SQLException se = (SQLException) e;
+ if (se.getSQLState() != null) { // SQLSTATE is NULL for a
+ if (se.getSQLState().equals("40001"))
+ System.out.println("deadlocked detected");
+ if (se.getSQLState().equals("40XL1"))
+ System.out.println(" lock timeout exception");
+ if (se.getSQLState().equals("23500"))
+ System.out.println(" duplicate key violation");
+ }
+ if (se.getNextException() != null) {
+ String m = se.getNextException().getSQLState();
+ System.out.println(se.getNextException().getMessage()
+ + " SQLSTATE: " + m);
+ }
+ }
+ if (e.getMessage().equals(null)) {
+ System.out.println("NULL error message detected");
+ System.out.println("Here is the NULL exection - " + e.toString());
+ System.out.println("Stack trace of the NULL exception - ");
+ e.printStackTrace(System.out);
+ }
+ System.out.println("At this point - " + where
+ + ", exception thrown was : " + e.getMessage());
+
+ }
+
+ public static String getDriverURL() {
+ if (driver_type.equalsIgnoreCase("DerbyClient")) {
+ return clientURL;
+ } else {
+ return embedURL;
+ }
+ }
+
+ public static void startNetworkServer() throws Exception {
+ try {
+ NWServerThread nsw = new NWServerThread("localhost", 1900);
+ nsw.start();
+ Thread.sleep(10000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+
+ }
+
+ public static void printUsage() {
+ System.out.println("Usage:");
+ System.out
+ .println("java org.apache.derbyTesting.system.nstest.NsTest DerbyClient|Embedded");
+ System.out.println("\nNo argument/Default value is 'DerbyClient'");
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/NsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt Mon Mar 5 14:01:23 2007
@@ -0,0 +1,108 @@
+
+ Network Server System Test Readme
+
+1) Description
+2) Packaging
+3) How to run
+4) Settings
+5) Known issues
+6) Future work
+
+DESCRIPTION:
+============
+The Network Server System Test (NsTest) is a configurable long running system test for
+various Derby features running under the network server(or embedded) mode. The test uses
+a single table having all the supported data types as columns with multiple clients
+performing Insert/Update/Delete and Select operations. The table has a delete trigger
+which populates a similar table when fired. On regular intervals the test also performs
+back-up/restore and re-encryption. The test follows the suggested usage of JDBC with
+liberal use of PreparedStatements and closing of respective objects when not in use.
+The test starts off by using preset number of Initialzer threads (INIT_THREADS=6) to begin
+loading the tables. Once loaded, each invocation of the test uses 71 clients with the following
+distribution to peform various operations on the database:
+
+1 - A single back-up/restore/re-encrypt thread
+15 - Tester1 threads keeps the connection to the database open forever
+45 - Tester2 threads frequently opens and closed based on a random choice
+10 - Tester3 threads opens/closes the connection to the database after each query
+
+To increase the number of client either:
+(a) Update the above settings to teh desired number
+(b) Invoke multiple instances of the test in separate VMs with the System property
+ 'derby.nstest.backupRestore' set to 'false' for all the instances except one. This
+ will set the Backup/Restore/Re-Encryption thread to be started only once.
+
+Option (b) works best to avoid any single point of test failure and losing the entire test
+run artifacts.
+
+The test has been particularly useful in detecting increased memory usage, locking etc. and
+also verifies the expected behaviour when all the different Derby features are used in conjunction.
+
+PACKAGING:
+==========
+The test resides under the org.apache.derbyTesting.systen.nstest package. The main
+class to invoke is org.apache.derbyTesting.system.nstest.NsTest. Currently all the
+variable settings used in the test are set in this class. The user threads reside in the
+'tester' package while some initializer and generic utility classes belong to
+'init' and 'utils' package.
+
+HOW TO RUN:
+===========
+Usage:
+java org.apache.derbyTesting.system.nstest.NsTest DerbyClient|Embedded
+
+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.
+
+To start the NW Server as a thread in the same VM, set the START_SERVER_IN_SAME_VM to true,
+useful for a small test setup.
+
+To turn off Backup/Restore/Re-Encryption, set the System property 'derby.nstest.backupRestore'
+to 'false', default is 'true'.
+
+EXIT CRITERIA
+=============
+
+1. There should not be any fatal failures
+2. No unwanted lock time outs or deadlocks
+
+SETTINGS:
+=========
+Almost all the variable settings for this test reside in the org.apache.derbyTesting.system.nstest.NsTest
+class. The main ones are as follows:
+
+INIT_THREADS = Initializer threads
+MAX_INITIAL_ROWS = Initial set of rows inserted before test begins
+MAX_ITERATIONS = Each client does these many transactions in the test
+MAX_LOW_STRESS_ROWS = Num of rows worked over in a transaction
+MAX_OPERATIONS_PER_CONN = Num of transaction batches made by a client before closing the connection
+NUMTESTER1 = Number of Tester1 testers
+NUMTESTER2 = Number of Tester2 testers
+NUMTESTER3 = Number of Tester3 testers
+NUM_HIGH_STRESS_ROWS = Maximum rows to be selected
+NUM_UNTOUCHED_ROWS = Number of rows on which Update/Delete operations are not performed
+
+START_SERVER_IN_SAME_VM= Set to true/false to start Network Server in the same VM.
+
+The System property 'derby.nstest.backupRestore' can be set to false for turning off
+Backup/Restore/Re-Encryption. By default the Backup/Restore/Re-Encryption thread is
+always started.
+
+KNOWN ISSUES:
+=============
+
+With the addition of the Backup/Restore/Re-Encryption thread, long runs of this test are blocked
+by:
+DERBY-1947 - OOM after repeated calls to boot and shutdown a database
+
+FUTURE WORK:
+============
+
+- Move location of test variables from NsTest.java to a common area
+- Ability to start the NW Server as a separate process passing independent VM args
+- Ability to run using JUnit test runners
+- Use larger BLOB/CLOB sizes
+- Other Derby feature integration testing
+- Work on reporting
+
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml Mon Mar 5 14:01:23 2007
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!-- ==================================================================== -->
+<!-- Derby build file -->
+<!-- ==================================================================== -->
+
+<project default="nstest" basedir="../../../../../..">
+
+<!-- ==================================================================== -->
+<!-- Set properties -->
+<!-- ==================================================================== -->
+
+ <property name="properties.dir" value="tools/ant/properties"/>
+
+ <!-- User settings -->
+ <property file="${user.home}/ant.properties"/>
+
+ <!-- Significant dirs -->
+ <property file="${properties.dir}/dirs.properties"/>
+ <property file="${properties.dir}/derbytesting.properties"/>
+
+ <!-- Compiler settings -->
+ <property file="${properties.dir}/defaultcompiler.properties"/>
+ <property file="${properties.dir}/${build.compiler}.properties"/>
+
+ <!-- Parser properties -->
+ <property file="${properties.dir}/parser.properties"/>
+
+ <!-- Compile-time classpath properties files -->
+ <property file="${properties.dir}/extrapath.properties"/>
+ <property file="${properties.dir}/compilepath.properties"/>
+ <property file="${user.home}/properties/derbytesting.properties"/>
+ <property file="${ant.home}/properties/derbytesting.properties"/>
+
+ <!-- Release and Version info -->
+ <property file="${properties.dir}/release.properties"/>
+
+<!-- ============ Begin Targets ============== -->
+
+ <target name="nstest"
+ description="N/W server system test">
+ <javac
+ source="1.4"
+ target="1.4"
+ bootclasspath="${empty}"
+ nowarn="on"
+ debug="true"
+ depend="${depend}"
+ deprecation="${deprecation}"
+ optimize="${optimize}"
+ proceed="${proceed}"
+ verbose="${verbose}"
+ srcdir="${derby.testing.src.dir}"
+ destdir="${out.dir}">
+ <classpath>
+ <pathelement path="${java14compile.classpath}"/>
+ <pathelement path="${junit}"/>
+ </classpath>
+ <include name="${derby.testing.system.dir}/nstest/**/*.java"/>
+ </javac>
+
+
+ </target>
+
+<!-- ============= End Targets ============== -->
+
+<!-- ============= End Project ============== -->
+
+</project>
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,185 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.init.DbSetup
+
+ 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.init;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * DbSetup: Creates database and builds single user table with indexes
+ */
+public class DbSetup {
+
+ /**
+ * The main database setup method
+ */
+ public static boolean doIt(Connection conn) throws Throwable {
+ Statement s = null;
+ ResultSet rs = null;
+ boolean finished = false;
+
+ System.out.println("dbSetup.doIt() starting...");
+
+ try {
+ conn.setAutoCommit(false);
+ } catch (Exception e) {
+ System.out.println("FAIL - setAutoCommit() failed:");
+ printException("setting autocommit in dbSetup", e);
+ return (false);
+ }
+
+ try {
+ s = conn.createStatement();
+ rs = s.executeQuery("select tablename from sys.systables "
+ + " where tablename = 'NSTESTTAB'");
+ if (rs.next()) {
+ rs.close();
+ System.out.println("table 'NSTESTTAB' already exists");
+ finished = true;
+ NsTest.schemaCreated = true; // indicates to other classes
+ // that the schema already
+ // exists
+ }
+ } catch (Exception e) {
+ System.out
+ .println("dbSetup.doIt() check existance of table: FAIL -- unexpected exception:");
+ printException(
+ "executing query or processing resultSet to check for table existence",
+ e);
+ return (false);
+ }
+
+ // if we reach here then the table does not exist, so we create it
+ if (finished == false) {
+ try {
+ System.out
+ .println("creating table 'NSTESTTAB' and corresponding indices");
+ s.execute("create table nstesttab (" + "id int,"
+ + "t_char char(100)," + "t_date date,"
+ + "t_decimal decimal," + "t_decimal_nn decimal(10,10),"
+ + "t_double double precision," + "t_float float,"
+ + "t_int int," + "t_longint bigint,"
+ + "t_numeric_large numeric(30,10)," + "t_real real,"
+ + "t_smallint smallint," + "t_time time,"
+ + "t_timestamp timestamp," + "t_varchar varchar(100),"
+ + "t_clob clob(1K)," + "t_blob blob(10K),"
+ + "serialkey bigint generated always as identity, "
+ + "unique (serialkey)) ");
+
+ s.execute("create index t_char_ind on nstesttab ( t_char)");
+ s.execute("create index t_date_ind on nstesttab ( t_date)");
+ s
+ .execute("create index t_decimal_ind on nstesttab ( t_decimal)");
+ s
+ .execute("create index t_decimal_nn_ind on nstesttab ( t_decimal_nn)");
+ s.execute("create index t_double_ind on nstesttab ( t_double)");
+ s.execute("create index t_float_ind on nstesttab ( t_float)");
+ s.execute("create index t_int_ind on nstesttab ( t_int)");
+ s
+ .execute("create index t_longint_ind on nstesttab ( t_longint)");
+ s
+ .execute("create index t_num_lrg_ind on nstesttab ( t_numeric_large)");
+ s.execute("create index t_real_ind on nstesttab ( t_real)");
+ s
+ .execute("create index t_smallint_ind on nstesttab ( t_smallint)");
+ s.execute("create index t_time_ind on nstesttab ( t_time)");
+ s
+ .execute("create index t_timestamp_ind on nstesttab ( t_timestamp)");
+ s
+ .execute("create index t_varchar_ind on nstesttab ( t_varchar)");
+ s
+ .execute("create index t_serialkey_ind on nstesttab (serialkey)");
+
+ System.out
+ .println("creating table 'NSTRIGTAB' and corresponding indices");
+ s.execute("create table NSTRIGTAB (" + "id int,"
+ + "t_char char(100)," + "t_date date,"
+ + "t_decimal decimal," + "t_decimal_nn decimal(10,10),"
+ + "t_double double precision," + "t_float float,"
+ + "t_int int," + "t_longint bigint,"
+ + "t_numeric_large numeric(30,10)," + "t_real real,"
+ + "t_smallint smallint," + "t_time time,"
+ + "t_timestamp timestamp," + "t_varchar varchar(100),"
+ + "t_clob clob(1K)," + "t_blob blob(10K),"
+ + "serialkey bigint )");
+ // create trigger
+ s.execute("CREATE TRIGGER NSTEST_TRIG AFTER DELETE ON nstesttab "
+ + "REFERENCING OLD AS OLDROW FOR EACH ROW MODE DB2SQL "
+ + "INSERT INTO NSTRIGTAB values("
+ + "OLDROW.ID, OLDROW.T_CHAR,OLDROW.T_DATE,"
+ + "OLDROW.T_DECIMAL,OLDROW.T_DECIMAL_NN,OLDROW.T_DOUBLE,"
+ + "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)");
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out
+ .println("FAIL - unexpected exception in dbSetup.doIt() while creating schema:");
+ printException("executing statements to create schema", e);
+ return (false);
+ }
+ }// end of if(finished==false)
+
+ conn.commit();
+ return (true);
+
+ }// end of method doIt()
+
+ // ** This method abstracts exception message printing for all exception
+ // messages. You may want to change
+ // ****it if more detailed exception messages are desired.
+ // ***Method is synchronized so that the output file will contain sensible
+ // stack traces that are not
+ // ****mixed but rather one exception printed at a time
+ public static synchronized void printException(String where, Exception e) {
+ if (e instanceof SQLException) {
+ SQLException se = (SQLException) e;
+
+ if (se.getSQLState().equals("40001"))
+ System.out.println("deadlocked detected");
+ if (se.getSQLState().equals("40XL1"))
+ System.out.println(" lock timeout exception");
+ if (se.getSQLState().equals("23500"))
+ System.out.println(" duplicate key violation");
+ if (se.getNextException() != null) {
+ String m = se.getNextException().getSQLState();
+ System.out.println(se.getNextException().getMessage()
+ + " SQLSTATE: " + m);
+ }
+ }
+ if (e.getMessage().equals(null)) {
+ System.out.println("NULL error message detected");
+ System.out.println("Here is the NULL exection - " + e.toString());
+ System.out.println("Stack trace of the NULL exception - ");
+ e.printStackTrace(System.out);
+ }
+ System.out.println("During " + where + ", exception thrown was : "
+ + e.getMessage());
+ }
+
+}//end of class definition
+
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/DbSetup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,146 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.init.Initializer
+
+ 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.init;
+
+import java.sql.SQLException;
+import java.sql.DriverManager;
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+import org.apache.derbyTesting.system.nstest.utils.DbUtil;
+
+/**
+ * Initializer: Main Class that populates the tables needed for the test
+ */
+public class Initializer {
+
+ private String thread_id;
+
+ private DbUtil dbutil;
+
+ public Initializer(String name) {
+ this.thread_id = name;
+ dbutil = new DbUtil(this.thread_id);
+ }
+
+ // This starts the acutal inserts
+ public void startInserts() {
+
+ Connection conn = null;
+ int insertsRemaining = NsTest.MAX_INITIAL_ROWS;
+
+ // The JDBC driver should have been loaded by nstest.java at this
+ // point, we just need
+ // to get a connection to the database
+ try {
+
+ System.out.println(thread_id
+ + " is getting a connection to the database...");
+
+ if (NsTest.embeddedMode) {
+ conn = DriverManager.getConnection(NsTest.embedDbURL,
+ NsTest.prop);
+ } else {
+ if(NsTest.driver_type.equalsIgnoreCase("DerbyClient")) {
+ System.out.println("-->Using derby client url");
+ conn = DriverManager.getConnection(NsTest.clientDbURL,
+ NsTest.prop);
+ }
+ }
+ } catch (Exception e) {
+ System.out.println("FAIL: " + thread_id
+ + " could not get the database connection");
+ printException("getting database connection in startInserts()", e);
+ }
+
+ // add one to the statistics of client side connections made per jvm
+ NsTest.addStats(NsTest.CONNECTIONS_MADE, 1);
+ System.out.println("Connection number: " + NsTest.numConnections);
+
+ // set autocommit to false to keep transaction control in your hand
+ if (NsTest.AUTO_COMMIT_OFF) {
+ try {
+
+ conn.setAutoCommit(false);
+ } catch (Exception e) {
+ System.out.println("FAIL: " + thread_id
+ + "'s setAutoCommit() failed:");
+ printException("setAutoCommit() in Initializer", e);
+ }
+ }
+
+ while (insertsRemaining-- >= 0) {
+ try {
+ int numInserts = dbutil.add_one_row(conn, thread_id);
+ System.out.println("Intializer.java: exited add_one_row: "
+ + numInserts + " rows");
+ } catch (Exception e) {
+ System.out.println(" FAIL: " + thread_id
+ + " unexpected exception:");
+ printException("add_one_row() in Initializer", e);
+ break;
+ }
+ }// end of while(insertsRemaning-- > 0)
+
+ // commit the huge bulk Insert!
+ if (NsTest.AUTO_COMMIT_OFF) {
+ try {
+ conn.commit();
+ } catch (Exception e) {
+ System.out
+ .println("FAIL: " + thread_id + "'s commit() failed:");
+ printException("commit in Initializer", e);
+ }
+ }
+
+ }// end of startInserts()
+
+ // ** This method abstracts exception message printing for all exception
+ // messages. You may want to change
+ // ****it if more detailed exception messages are desired.
+ // ***Method is synchronized so that the output file will contain sensible
+ // stack traces that are not
+ // ****mixed but rather one exception printed at a time
+ public synchronized void printException(String where, Exception e) {
+ if (e instanceof SQLException) {
+ SQLException se = (SQLException) e;
+
+ if (se.getSQLState().equals("40001"))
+ System.out.println("deadlocked detected");
+ if (se.getSQLState().equals("40XL1"))
+ System.out.println(" lock timeout exception");
+ if (se.getSQLState().equals("23500"))
+ System.out.println(" duplicate key violation");
+ if (se.getNextException() != null) {
+ String m = se.getNextException().getSQLState();
+ System.out.println(se.getNextException().getMessage()
+ + " SQLSTATE: " + m);
+ }
+ }
+ if (e.getMessage().equals(null)) {
+ e.printStackTrace(System.out);
+ }
+ System.out.println("During - " + where
+ + ", the exception thrown was : " + e.getMessage());
+ }
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/Initializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,76 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.init.NWServerThread
+
+ 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.init;
+
+import java.io.PrintWriter;
+import java.net.InetAddress;
+
+import org.apache.derby.drda.NetworkServerControl;
+
+/**
+ * NWServerThread: Start a Network Server in a new Thread, based on the
+ * NsTest.START_SERVER_IN_SAME_VM setting
+ */
+public class NWServerThread extends Thread {
+
+ InetAddress inetaddr = null;
+
+ String address = "localhost";
+
+ int port = 1900;
+
+ public NWServerThread(String address, int port) throws Exception {
+ if (!(address == null)) {
+ if (!(address.equals(""))) {
+ this.address = address;
+ }
+ }
+ if (port > 0) {
+ this.port = port;
+ }
+
+ try {
+ inetaddr = InetAddress.getByName(address);
+
+ } catch (Exception e) {
+ System.out
+ .println("Invalid host address passed, cannot start server");
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /*
+ * Implementation of the run() method to start the server
+ *
+ */
+ public void run() {
+ try {
+ NetworkServerControl nsw = new NetworkServerControl(inetaddr, port);
+ nsw.start(new PrintWriter(System.out));
+ System.out.println("===> Derby Network Server on " + address + ":"
+ + port + " <===");
+ } catch (Exception e) {
+ ;
+ e.printStackTrace();
+ }
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/init/NWServerThread.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,304 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.tester.BackupRestoreReEncryptTester
+
+ 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.tester;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * BackupRestoreReEncryptTester: The thread that invokes the
+ * Backup/Restore/Re-Encrypt functions. By default one instance of this thread
+ * is always started, unless the System property 'derby.nstest.backupRestore'
+ * set to 'false'
+ */
+public class BackupRestoreReEncryptTester extends TesterObject {
+ String logFile = "backup.log";
+
+ PrintWriter logger = null;
+
+ // *******************************************************************************
+ //
+ // Constructor. Get's the name of the thread running this for use in
+ // messages
+ //
+ // *******************************************************************************
+ public BackupRestoreReEncryptTester(String name) throws IOException {
+ super(name);
+ logger = new PrintWriter(new FileWriter(logFile));
+
+ }
+
+ // *********************************************************************************
+ //
+ // This starts the acutal test operations. Overrides the startTesting() of
+ // parent.
+ // Tester3 profile -
+ // Query only kind of client that deals with a large result
+ // set based on a select query that returns a large number of
+ // rows (stress condition). Connection is closed after each
+ // query. The query will need to run in a DIRTY_READ mode, i.e.
+ // READ UNCOMMITTED isolation level. We work over the untouched
+ // portion of rows in the table (i.e. serialkey 1 to NUM_UNTOUCHED_ROWS)
+ //
+ // *********************************************************************************
+ public void startTesting() {
+
+ // The following loop will be done nstest.MAX_ITERATIONS times after
+ // which we exit the thread
+ // Note that a different connection is used for each operation. The
+ // purpose of this client is
+ // to work on a large set of data as defined by the parameter
+ // NUM_HIGH_STRESS_ROWS
+ // This thread could be made to pause (sleep) for a bit between each
+ // iteration.
+ for (int i = 0; i < NsTest.MAX_ITERATIONS; i++) {
+ log(getTimestamp() + " Thread " + getThread_id() + " starting");
+ String message = "";
+ // Get the connection. It will be closed at the end of the loop
+ connex = getConnection();
+ if (connex == null) {
+ System.out.println("FAIL: " + getThread_id()
+ + " could not get the database connection");
+ return; // quit
+ }
+
+ // set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED to
+ // reduce number of
+ // deadlocks/lock issues
+ setIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
+
+ // Now select nstest.NUM_HIGH_STRESS_ROWS number of rows
+ try {
+ doBackup();
+
+ } catch (Exception e) {
+ message = getTimestamp() + "FAILED - BackUp thread doBackup"
+ + getThread_id() + " threw " + e;
+ System.out.println(message);
+ log(message);
+ printException("call to doBackup() in BackupThread ", e);
+ e.printStackTrace();
+ }
+
+ try {
+ doRestoreandReEncrypt();
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.out
+ .println("FAILED at doRestoreandReEncrypt() - BackUp thread "
+ + getThread_id() + " threw " + e);
+ printException(
+ "call to doRestoreandReEncrypt() in BackupThread ", e);
+ log(getTimestamp()
+ + " call to doRestoreandReEncrypt() in BackupThread FAILED "
+ + e.getSQLState() + " " + e);
+
+ e.printStackTrace(logger);
+ }
+
+ // close the connection
+ closeConnection();
+ try {
+ log(getTimestamp() + " Thread " + getThread_id() + " sleeping");
+ Thread.sleep(10 * 60000); // 10 minutes sleep before second
+ // backup
+ } catch (InterruptedException ie) {
+ message = getTimestamp() + "FAILED - " + getThread_id()
+ + " Sleep interrupted " + ie;
+ log(message);
+ }
+
+ }// end of for (int i=0;...)
+
+ System.out.println("Thread " + getThread_id() + " is now terminating");
+
+ }// end of startTesting()
+
+ public void doBackup() throws SQLException {
+ log("--------------------- B A C K U P S E C T I O N B E G I N ------------------------");
+ CallableStatement cs = connex
+ .prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(?, ?)");
+ cs.setString(1, NsTest.BACKUPDIR);
+ cs.setInt(2, 1);
+ long start = System.currentTimeMillis();
+ cs.execute();
+ cs.close();
+ long end = System.currentTimeMillis();
+ log(getTimestamp() + " Backup completed successfully in "
+ + (end - start) / 100 + " seconds");
+ try {
+ String backupDbURL = NsTest.getDriverURL() + NsTest.BACKUPDIR
+ + File.separator + NsTest.dbName + ";" + NsTest.bootPwd;
+ // Consistency check not required everytime
+ doConsistCheck(backupDbURL, "BACKUP");
+
+ } catch (Exception e) {
+ String message = getTimestamp()
+ + "FAILED - BackUp thread doConsistCheck() "
+ + getThread_id() + " threw " + e;
+ log(message);
+ printException("call to doConsistCheck() in BackupThread ", e);
+ e.printStackTrace(logger);
+ }
+ log("--------------------- B A C K U P S E C T I O N E N D ----------------------------");
+ }
+
+ public void doConsistCheck(String dbURL, String dbType) throws SQLException {
+ /*
+ * SELECT schemaname, tablename,
+ * SYSCS_UTIL.SYSCS_CHECK_TABLE(schemaname, tablename) FROM
+ * sys.sysschemas s, sys.systables t WHERE s.schemaid = t.schemaid;
+ */
+ Connection conn = DriverManager.getConnection(dbURL);
+ Statement stmt = conn.createStatement();
+ long start = System.currentTimeMillis();
+ ResultSet rs = stmt
+ .executeQuery("SELECT schemaname, tablename, SYSCS_UTIL.SYSCS_CHECK_TABLE(schemaname, tablename) FROM sys.sysschemas s, sys.systables t WHERE s.schemaid = t.schemaid");
+ while (rs.next()) {
+ // Iterate thru ResultSet
+ rs.getString(1);
+ rs.getString(2);
+ rs.getString(3);
+ }
+ long end = System.currentTimeMillis();
+ log(getTimestamp() + " Consistency Check on the " + dbType
+ + " database Completed successfully " + (end - start) / 100
+ + " seconds");
+ stmt.close();
+ conn.close();
+ shutDownDB(dbURL, dbType);
+ }
+
+ public void doRestoreandReEncrypt() throws SQLException {
+ log("--------------------- R E S T O R E S E C T I O N B E G I N ------------------------");
+ String dbType = "RESTORED";
+ Connection conn = null;
+
+ long newKey = System.currentTimeMillis();
+ String restoreDbURL = NsTest.getDriverURL() + NsTest.RESTOREDIR
+ + File.separator + NsTest.dbName;
+ String dbUrl = restoreDbURL + ";" + NsTest.bootPwd + ";restoreFrom="
+ + NsTest.BACKUPDIR + File.separator + NsTest.dbName;
+ try {
+ conn = DriverManager.getConnection(dbUrl);
+ log(getTimestamp() + " Database restored successfully " + dbUrl);
+ } catch (SQLException e) {
+ log(getTimestamp() + " FAILURE ! to restore database " + dbUrl);
+ e.printStackTrace(logger);
+
+ }
+
+ // Consistency check not required everytime
+ conn.close();
+ dbUrl = restoreDbURL + ";" + NsTest.bootPwd;
+ doConsistCheck(dbUrl, dbType);
+ // DERBY-1737, hence create a new connection
+ log("--------------------- R E S T O R E S E C T I O N E N D ----------------------------");
+
+ conn = DriverManager.getConnection(dbUrl);
+ // Disable log archival
+ // call SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE(1);
+ CallableStatement cs = conn
+ .prepareCall("CALL SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE(?)");
+ cs.setInt(1, 1);
+ cs.execute();
+ conn.close();
+ log(getTimestamp()
+ + " Disable log archival mode to enable re-encryption " + dbUrl);
+ shutDownDB(restoreDbURL, dbType);
+ log("--------------------- ENCRYPT AND RECONNECT S E C T I O N BEGIN ------------------------");
+ String encryptDbURL = restoreDbURL + ";dataEncryption=true;";
+
+ // Try Re-Encrypting Now
+ encryptDbURL += ";" + NsTest.bootPwd + ";newBootPassword=" + newKey;
+
+ long start = System.currentTimeMillis();
+ log(getTimestamp() + " Encrypting database, url = " + encryptDbURL);
+ conn = DriverManager.getConnection(encryptDbURL);
+ conn.close();
+ long end = System.currentTimeMillis();
+ log(getTimestamp()
+ + " Re-encryption completed on restored database in "
+ + (end - start) / 100 + " seconds, url = " + encryptDbURL);
+ // Shutdown the db
+ dbType = "ENCRYPTED";
+ shutDownDB(restoreDbURL, dbType);
+ // Attempt to connect with old key should fail
+ try {
+ conn = DriverManager.getConnection(dbUrl);
+ log(getTimestamp()
+ + " FAILURE ! - Attempt to boot with old password/url should have failed, url ="
+ + dbUrl);
+ } catch (SQLException sqe) {
+ if ((sqe.getSQLState().equalsIgnoreCase("XJ040"))
+ || (sqe.getSQLState().equalsIgnoreCase("XBM06"))) {
+ log(getTimestamp()
+ + " PASS - Unsuccessful attempt to boot with old password/url, "
+ + dbUrl);
+ } else {
+ throw sqe;
+ }
+ }
+ /*
+ * A Shutdown is not needed, since the part gets exected only when a
+ * unsuccessful attempt is made to boot the db with an old password
+ */
+ // shutDownDB(restoreDbURL, dbType);
+ log("--------------------- ENCRYPT AND RECONNECT S E C T I O N END --------------------------");
+ }
+
+ private void shutDownDB(String dbURL, String dbType) throws SQLException {
+ Connection conn = null;
+ dbURL = dbURL + ";shutdown=true";
+ try {
+ conn = DriverManager.getConnection(dbURL);
+
+ } catch (SQLException sqe) {
+ if (conn != null)
+ conn.close();
+ if (!sqe.getSQLState().equalsIgnoreCase("08006")) {
+ throw sqe;
+ } else {
+ log(getTimestamp() + " " + dbType
+ + " database shutdown completed, url = " + dbURL);
+ }
+ }
+ }
+
+ public void log(String msg) {
+ logger.write(msg + "\n");
+ logger.flush();
+
+ System.out.println(msg);
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/BackupRestoreReEncryptTester.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,142 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.tester.Tester1
+
+ 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.tester;
+
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * Tester1 - Threads that keep the connection to the database open forever
+ */
+public class Tester1 extends TesterObject {
+
+ // *******************************************************************************
+ //
+ // Constructor. Get's the name of the thread running this for use in
+ // messages
+ //
+ // *******************************************************************************
+ public Tester1(String name) {
+ super(name);
+ }
+
+ // *********************************************************************************
+ //
+ // This starts the acutal test operations. Overrides the startTesting() of
+ // parent.
+ // Tester1 profile -
+ // The connection to the database is open forever. This client
+ // will do Insert/Update/Delete and simple Select queries over
+ // a small to medium set of data determined randomly over
+ // MAX_LOW_STRESS_ROWS rows. Autocommit is left on else too many deadlocks
+ // occur and the
+ // goal is to test the data flow and connection management of the network
+ // server,
+ // not the transaction management of the database.
+ //
+ // *********************************************************************************
+ public void startTesting() {
+
+ // this connection will remain open forever.
+ connex = getConnection();
+ if (connex == null) {
+ System.out.println("FAIL: " + getThread_id()
+ + " could not get the database connection");
+ return; // quit
+ }
+
+ // set autocommit to false to keep transaction control in your hand
+ // Too many deadlocks amd locking issues if this is not commented out
+ try {
+ connex.setAutoCommit(false);
+ } catch (Exception e) {
+ System.out.println("FAIL: " + getThread_id()
+ + "'s setAutoCommit() failed:");
+ printException("setting AutoCommit", e);
+ }
+
+ // also set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED
+ // to reduce number of
+ // deadlocks
+ setIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
+
+ // The following loop will be done nstest.MAX_ITERATIONS times after
+ // which we exit the thread
+ // Note that the same connection is used for each operation. The
+ // connection is only closed
+ // outside the loop. Since autocommit is on, we make an interation work
+ // over
+ // MAX_LOW_STRESS_ROWS number of rows. This thread could be made to
+ // pause (sleep) for a bit
+ // between each iteration.
+ for (int i = 0; i < NsTest.MAX_ITERATIONS; i++) {
+
+ // Now loop through nstest.MAX_LOW_STRESS_ROWS number of times/rows
+ // before committing.
+ // Here, we do randomly do either insert/update/delete operations or
+ // one select
+ int rnum = (int) (Math.random() * 100) % 4; // returns 0, 1, 2, 3
+ switch (rnum) {
+ case 0: // do a select operation
+ try {
+ int numSelected = doSelectOperation(NsTest.MAX_LOW_STRESS_ROWS);
+ System.out.println(getThread_id() + " selected "
+ + numSelected + " rows");
+ } catch (Exception e) {
+ System.out
+ .println("--> Isolation Level is TRANSACTION_READ_UNCOMMITTED, hence SHOULD NOT FAIL ********* doSelect in thread "
+ + getThread_id() + " threw " + e);
+ printException("doSelectOperation()", e);
+ e.printStackTrace();
+ }
+ break;
+
+ case 1: // do Insert/Update/Delete operations
+ case 2: // do Insert/Update/Delete operations
+ case 3: // do Insert/Update/Delete operations
+ for (int j = 0; j < NsTest.MAX_LOW_STRESS_ROWS; j++) {
+ doIUDOperation();
+ }
+ break;
+ }
+
+ // Letting this be even though autocommit is on so that if later on
+ // if we decide to turn
+ // autocommit off, this automatically takes effect.
+ // commit
+ try {
+ connex.commit();
+ } catch (Exception e) {
+ System.out
+ .println("FAIL: " + getThread_id() + "'s commit() failed:");
+ printException("committing Xn in Tester1", e);
+ }
+ }// end of for (int i=0;...)
+
+ // close the connection before the thread terminates
+ closeConnection();
+ System.out.println("Thread " + getThread_id()+ " is now terminating");
+
+ }//end of startTesting()
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,135 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.tester.Tester2
+
+ 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.tester;
+
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * Tester2 - Threads that frequently opens and closed based on a random choice of number
+ */
+public class Tester2 extends TesterObject {
+
+ //*******************************************************************************
+ //
+ // Constructor. Get's the name of the thread running this for use in messages
+ //
+ //*******************************************************************************
+ public Tester2(String name) {
+ super(name);
+ }
+
+
+ //**************************************************************************************
+ //
+ // This starts the acutal test operations. Overrides the startTesting() of parent.
+ // Tester2 profile -
+ // The connection is frequently opened and closed based on
+ // a random choice between 1 and MAX_OPERATIONS_PER_CONN number of
+ // transaction batches committed by this client type. This client will
+ // do Insert/Update/Delete and simple Select queries over a
+ // small to medium set of data determined randomly over MAX_LOW_STRESS_ROWS rows.
+ //
+ //***************************************************************************************
+ public void startTesting() {
+
+ //The following loop will be done nstest.MAX_ITERATIONS times after which we exit the thread
+ // Note that the connection is frequently opened & closed. Autocommit is left on, so
+ // per connection, we make MAX_OPERATIONS_PER_CONN number of transaction batches
+ // Each transaction batch works over MAX_LOW_STRESS_ROWS number of rows, with each row working
+ // as one transaction (since autocommit is on)
+ for (int i = 0; i < NsTest.MAX_ITERATIONS; i++) {
+
+ //the connection will now open. It closes at the end of the loop
+ connex = getConnection();
+ if (connex == null) {
+ System.out.println("FAIL: " + getThread_id()
+ + " could not get database connection");
+ return; //quit
+ }
+
+ //set autocommit to false to keep transaction control in your hand
+ //Too many deadlocks amd locking issues if this is not commented out
+ try {
+ connex.setAutoCommit(false);
+ } catch (Exception e) {
+ System.out.println("FAIL: " + getThread_id()
+ + "'s setAutoCommit() failed:");
+ printException("setting AutoCommit in Tester2", e);
+ }
+
+ //also set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED to reduce number of
+ // deadlocks
+ setIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
+
+ //Now do MAX_OPERATIONS_PER_CONN transaction batches within this connection
+ for (int numOp = 1; numOp < NsTest.MAX_OPERATIONS_PER_CONN; numOp++) {
+
+ //Now loop through nstest.MAX_LOW_STRESS_ROWS number of times/rows
+ // Here, we do randomly do either insert/update/delete operations or one select
+ int rnum = (int) (Math.random() * 100) % 4; //returns 0, 1, 2, 3
+
+ switch (rnum) {
+ case 0: //do a select operation
+ try {
+ int numSelected = doSelectOperation(NsTest.MAX_LOW_STRESS_ROWS);
+ System.out.println(getThread_id() + " selected "
+ + numSelected + " rows");
+ } catch (Exception e) {
+ System.out.println("doSelect in thread " + getThread_id()
+ + " threw ");
+ printException("doSelectOperation() in Tester2", e);
+ }
+ break;
+
+ case 1: //do Insert/Update/Delete operations
+ case 2: //do Insert/Update/Delete operations
+ case 3: //do Insert/Update/Delete operations
+ for (int j = 0; j < NsTest.MAX_LOW_STRESS_ROWS; j++) {
+ doIUDOperation();
+ }
+ break;
+ }
+
+ //Letting this be even though autocommit is on so that if later on if we decide to turn
+ // autocommit off, this automatically takes effect.
+ //commit
+ try {
+ connex.commit();
+ } catch (Exception e) {
+ System.out.println("FAIL: " + getThread_id()
+ + "'s commit() failed:");
+ printException("committing Xn in Tester2", e);
+ }
+ }//end of for(int numOp=1...)
+
+ //close the connection for the next iteration
+ closeConnection();
+
+ }//end of for (int i=0;...)
+
+ System.out.println("Thread " + getThread_id() + " is now terminating");
+
+ }//end of startTesting()
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java?view=auto&rev=514882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java Mon Mar 5 14:01:23 2007
@@ -0,0 +1,94 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.system.nstest.tester.Tester3
+
+ 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.tester;
+
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.nstest.NsTest;
+
+/**
+ * Tester3 - Threads that opens/closes the connection to the database after each query
+ */
+public class Tester3 extends TesterObject {
+
+ //*******************************************************************************
+ //
+ // Constructor. Get's the name of the thread running this for use in messages
+ //
+ //*******************************************************************************
+ public Tester3(String name) {
+ super(name);
+ }
+
+ //*********************************************************************************
+ //
+ // This starts the acutal test operations. Overrides the startTesting() of parent.
+ // Tester3 profile -
+ // Query only kind of client that deals with a large result
+ // set based on a select query that returns a large number of
+ // rows (stress condition). Connection is closed after each
+ // query. The query will need to run in a DIRTY_READ mode, i.e.
+ // READ UNCOMMITTED isolation level. We work over the untouched
+ // portion of rows in the table (i.e. serialkey 1 to NUM_UNTOUCHED_ROWS)
+ //
+ //*********************************************************************************
+ public void startTesting() {
+
+ //The following loop will be done nstest.MAX_ITERATIONS times after which we exit the thread
+ // Note that a different connection is used for each operation. The purpose of this client is
+ // to work on a large set of data as defined by the parameter NUM_HIGH_STRESS_ROWS
+ // This thread could be made to pause (sleep) for a bit between each iteration.
+ for (int i = 0; i < NsTest.MAX_ITERATIONS; i++) {
+ //Get the connection. It will be closed at the end of the loop
+ connex = getConnection();
+ if (connex == null) {
+ System.out.println("FAIL: " + getThread_id()
+ + " could not get the database connection");
+ return; //quit
+ }
+
+ // set isolation level to Connection.TRANSACTION_READ_UNCOMMITTED to reduce number of
+ // deadlocks/lock issues
+ setIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
+
+ //Now select nstest.NUM_HIGH_STRESS_ROWS number of rows
+ try {
+ int numSelected = doSelectOperation(NsTest.NUM_HIGH_STRESS_ROWS);
+ System.out.println(getThread_id()+" Tester3: Rows selected "+numSelected);
+ } catch (Exception e) {
+ System.out.println("doSelect in thread " + getThread_id()
+ + " threw ");
+ printException("doSelectOperation() in Tester3 of "+getThread_id(), e);
+ }
+
+ //close the connection
+ closeConnection();
+
+ //Thread.sleep(10 * 60000); //10 minutes
+
+ }//end of for (int i=0;...)
+
+ System.out.println("Thread " + getThread_id() + " is now terminating");
+
+ }//end of startTesting()
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/nstest/tester/Tester3.java
------------------------------------------------------------------------------
svn:eol-style = native