db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r501639 [1/2] - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system: mailjdbc/ mailjdbc/data/ mailjdbc/schema/ mailjdbc/tasks/ mailjdbc/utils/ sttest/ sttest/data/ sttest/tools/ sttest/utils/
Date Tue, 30 Jan 2007 23:27:53 GMT
Author: myrnavl
Date: Tue Jan 30 15:27:51 2007
New Revision: 501639

URL: http://svn.apache.org/viewvc?view=rev&rev=501639
Log:
DERBY-2134 - add 2 long running system tests to Derby
patch contributed by Manjula Kutty

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/MailJdbc.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/README.txt   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/data/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/data/Resource.jar   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/derby.properties   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/LogFile.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/PerfTime.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/Statements.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/ThreadUtils.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/README.txt   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/Sttest.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/data/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/data/Resource.jar   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/MemCheck.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/CompressTable.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Datatypes.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Setup.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/StStatus.java   (with props)

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/MailJdbc.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/MailJdbc.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/MailJdbc.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/MailJdbc.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,41 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.MailJdbc
+ * 
+ * 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.mailjdbc;
+
+import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
+import org.apache.derbyTesting.system.mailjdbc.utils.ThreadUtils;
+import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
+/**
+ * This has the main method with arguements for embedded and NWserver.
+ */
+public class MailJdbc {
+	//Prints out the activities/transactions done by the test
+	public static LogFile logAct = new LogFile("Activity.out");
+
+	public static void main(String[] args) throws Exception {
+		String type = args[0];
+		System.out.println("Test started with " + type + " driver");
+		//Loads the driver
+		DbTasks.jdbcLoad(type);
+		//Starts all 4 threads
+		ThreadUtils.startThreads();
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/README.txt
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/README.txt?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/README.txt (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/README.txt Tue Jan 30 15:27:51 2007
@@ -0,0 +1,100 @@
+           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.    
+
+mailjdbc package - mail client scenario test
+
+Contents
+
+1. About the Mailjdbc test
+2. Design
+3. Schema
+4. Test goals
+5. Exit criteria
+6. How to run the test
+
+1. About the Mailjdbc test
+
+ This test will mimic how a typical mail client can  use Derby as their database
+
+2. Design
+
+There will be a total of 4 threads to mimic a single users mail client activity
+1. User activity on the inbox
+	How the user uses his inbox. Like reading, deleting, moving to folders etc.
+2. Purging  ( deleting the mails which are older than the specified date)
+	This thread will delete the mails which are older than n days, (where n can be any number of days)
+3. Backup
+	Back up thread will back up the mail db at every day or so
+4. Syncing (adding random number of rows on a particular time interval)
+	This thread will be mimicking the refresh mechanism on the inbox. After each refresh a random number of rows will be added to the db.
+
+
+The test will also do periodic dump of the database size  using the size of the files
+Start with no data and grow up to the maximum size  and then at some point the db size should flatten out 
+
+3. Schema
+
+The schema for this test is as follows
+
+Tables
+
+1.Table name : 	Inbox
+	Columns: 	id (generated key) Primary key
+			From (string)
+			To (String)
+			Date (String)
+			Message (CLOB)
+			folder_id (Integer)
+2.Table name : 	Attachment
+	Columns: 	id (Integer) foreign key
+			Attach_id(Integer)
+			attachment (Blob)
+Id + attach_id - Primary key
+
+3.Table name : 	Folder
+	Columns: 	folderid (generated key)
+			foldername(string)
+			
+4. Test goals
+
+Since the test is going to run continuously with the 4 threads , the duration of about 2 weeks will mimic more or less of about 4 months of user activity on a mail client. The stress on the test can be increased by  increasing the size of the data instead of increasing the number of connections. These are the two methods that the test is going to use for increasing the stress
+
+Increasing the size of the file attachments
+Reducing the size of the virtual memory
+
+For both conditions the performance of the database should be about the same. 
+
+5. Exit criteria
+
+1. There should not be any fatal failures
+2. No unwanted lock time outs or deadlocks
+
+
+6. How to run the test
+
+1. Make the appropriate changes for derby client or jcc , if you are testing the netWorkServer
+2. Make sure you have java in your environment and put the Derby jars including the derbyTesting.jar in your classpath
+3. Then run java org.apche.derbyTesting.system.mailjdbc.MailJdbc embedded
+ or
+ java org.apche.derbyTesting.system.mailjdbc.MailJdbc NetworkServer
+
+There are 2 output files. 
+1. Activity.out - which will give all the activities done by the test
+2. Performance.out - which will give you the time for each transaction.
+ 
+There is no explicit exit condition.  This test usually runs for more than 2 weeks. Check for ERROR and Exception in both the out files
+and derby.log.

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/data/Resource.jar
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/data/Resource.jar?view=auto&rev=501639
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/data/Resource.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/derby.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/derby.properties?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/derby.properties (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/derby.properties Tue Jan 30 15:27:51 2007
@@ -0,0 +1,13 @@
+derby.database.sqlAuthorization=true
+derby.connection.requireAuthentication=true
+derby.infolog.append=true
+derby.authentication.provider=BUILTIN
+derby.stream.error.logSeverityLevel=0
+
+#derby.language.logStatementText=true
+
+# User's Definitions
+derby.user.REFRESH=Refresh
+derby.user.BACKUP=Backup
+derby.user.PURGE=Purge
+derby.user.BROWSE=Browse

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql Tue Jan 30 15:27:51 2007
@@ -0,0 +1,56 @@
+--
+--   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.
+--
+--Drop table inbox;
+
+CREATE TABLE inbox (id bigint generated always as identity (start with 1,increment by 1),
+					from_name varchar(64),
+					to_name varchar(64),
+					message clob(3M),
+					date timestamp,
+					folder_id Integer,
+					to_delete smallint default 0,
+					exp_date timestamp,
+					attach_id smallint default 0,
+					size_problem varchar(32672),
+					CONSTRAINT inbox__pk PRIMARY KEY (id));
+					
+CREATE TABLE attach (id bigint not null,
+					attach_id integer not null,
+		      		attachment blob(5M),
+		      		CONSTRAINT attach__pk PRIMARY KEY (id,attach_id),
+		      		constraint attach_fk foreign key (id) references inbox(id)
+		      		ON DELETE CASCADE );
+
+--Drop table folders;
+		      		
+CREATE TABLE folders (folder_id integer generated always as identity (start with 1,increment by 1),
+					 foldername varchar(16));
+					 
+
+insert into folders (foldername) values('folder1');
+insert into folders (foldername) values('folder2');
+insert into folders (foldername) values('folder3');
+insert into folders (foldername) values('folder4');
+insert into folders (foldername) values('folder5');
+
+
+CREATE INDEX id_Index ON inbox(id); 
+CREATE INDEX to_delete_Index ON inbox(to_delete); 
+CREATE INDEX to_name_Index ON inbox(to_name); 
+CREATE INDEX date_Index ON inbox(date); 
+CREATE INDEX attach_Index ON inbox(attach_id); 
+CREATE INDEX attach_at_Index ON attach(attach_id); 

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,89 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.tasks.Backup
+ * 
+ * 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.mailjdbc.tasks;
+/**
+ * This class is used to do the back up activity and inline compression
+ */
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
+import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
+
+public class Backup extends Thread {
+	private boolean isRunning = false;
+
+	private DbTasks dbtasks = new DbTasks();
+
+	private Connection conn = DbTasks.getConnection("BACKUP", "Backup");
+
+	public Backup(String name) {
+		setName(name);
+	}
+
+	public void run() {
+		try {
+			while (true) {
+				doWork();
+				try {
+					Thread.sleep(150000);
+				} catch (InterruptedException ie) {
+					MailJdbc.logAct.logMsg("#### " + getName()
+							+ "...Interrupted");
+				}
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "Error while sleeping the thread in Backup: "
+					+ e.getMessage());
+		}
+
+	}
+
+	//Notifies backup thread is active and then does compress and takes Backup
+	private void doWork() {
+		isRunning = true;
+		try {
+			DoCompress();
+			DoBackup();
+		} catch (Exception e) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "Error while doing work with the thread in Backup: "
+					+ e.getMessage());
+			e.printStackTrace();
+		}
+	}
+
+	public void DoCompress() {
+		dbtasks.compressTable(conn, "INBOX", this.getName());
+		dbtasks.compressTable(conn, "ATTACH", this.getName());
+	}
+
+	public void DoBackup() {
+		dbtasks.Backup(conn, this.getName());
+	}
+
+	public boolean isRunning() {
+		return isRunning;
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,84 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.tasks.Browse
+ * 
+ * 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.mailjdbc.tasks;
+/**
+ * This class is used to do read, and update activity on the inbox and attach table
+ */
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
+import org.apache.derbyTesting.system.mailjdbc.utils.ThreadUtils;
+import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
+
+public class Browse extends Thread {
+	private DbTasks dbtasks = new DbTasks();
+
+	private Connection conn = DbTasks.getConnection("BROWSE", "Browse");
+
+	public Browse(String name) {
+		//sets the name of the thread
+		setName(name);
+	}
+
+	public void run() {
+		try {
+			while (true) {
+				//*Does the functions like browsing the inbox, delete mail by
+				// the user,
+				//*moving mails to different folders
+				readInbox(conn, this.getName());
+				deleteMailByUser(conn, this.getName());
+				moveToFolders(conn, this.getName());
+				Thread.sleep(30000);
+				//Checking whther Refresh thread is running after doing the
+				// work
+				// If not interrupt the thread to do a refresh
+				if (ThreadUtils.isThreadRunning("Refresh Thread")) {
+					MailJdbc.logAct.logMsg("******** Refresh is running");
+				} else {
+					Refresh th = (Refresh) ThreadUtils
+							.getThread("Refresh Thread");
+					th.interrupt();
+				}
+			}
+		} catch (Exception e) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "Error while sleeping the thread in Browse: "
+					+ e.getMessage());
+			e.printStackTrace();
+		}
+
+	}
+
+	public void readInbox(Connection conn, String thread_name) {
+		dbtasks.readMail(conn, thread_name);
+		dbtasks.totals();
+	}
+
+	public void deleteMailByUser(Connection conn, String thread_name) {
+		dbtasks.deleteMailByUser(conn, thread_name);
+	}
+
+	public void moveToFolders(Connection conn, String thread_name) {
+		dbtasks.moveToFolders(conn, thread_name);
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,73 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.tasks.Purge
+ * 
+ * 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.mailjdbc.tasks;
+/**
+ * This class is used to delete and mails which are older than a day
+ */
+
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
+import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
+
+public class Purge extends Thread {
+	//This thread behaves as a backend service which will mionitor the expiry
+	// date and size of the database
+	//and deletes them.
+	private DbTasks dbtasks = new DbTasks();
+
+	private Connection conn = DbTasks.getConnection("PURGE", "Purge");
+
+	public Purge(String name) {
+		//Sets the thread name
+		setName(name);
+	}
+
+	public void run() {
+		try {
+			while (true) {
+				//Wait for some activity to happen before deleting the mails,
+				// so sleep for sometime
+				Thread.sleep(120000);
+				//Deleting mails
+				purgeFromInbox(conn);
+				//Gets the size of the database
+				DoDbSizeCheck();
+				int sleep_time = (int) (Math.random() * 15000);
+				Thread.sleep(sleep_time);
+			}
+		} catch (Exception e) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "Error while sleeping the thread in Purge: "
+					+ e.getMessage());
+			e.printStackTrace();
+		}
+	}
+
+	public void purgeFromInbox(Connection conn) {
+		dbtasks.deleteMailByExp(conn, this.getName());
+	}
+
+	public void DoDbSizeCheck() {
+		dbtasks.checkDbSize(conn, this.getName());
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,113 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.tasks.Refresh
+ * 
+ * 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.mailjdbc.tasks;
+/**
+ * This class is used to insert, delete and update the rows
+ */
+
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
+import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
+
+public class Refresh extends Thread {
+	//This is the thread which does most of the work.
+	private boolean isRunning = false;
+
+	private DbTasks dbtasks = new DbTasks();
+
+	private Connection conn = DbTasks.getConnection("REFRESH", "Refresh");
+
+	public Refresh(String name) {
+		//sets the thread name
+		setName(name);
+	}
+
+	public void run() {
+		try {
+			//Applying permission to other threads/users
+			grantRevoke(conn, this.getName());
+			while (true) {
+				doWork();
+				try {
+					Thread.sleep(60000);
+				} catch (InterruptedException ie) {
+					MailJdbc.logAct.logMsg("#### " + getName()
+							+ "...Interrupted");
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "Error while sleeping the thread in refresh: "
+					+ e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @throws InterruptedException
+	 */
+	private void doWork() {
+		isRunning = true;
+		//Thread is running and does inserting the mails and deleting the mails
+		try {
+			insertMail(conn, this.getName());
+
+		} catch (Exception e) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + "insertMail() failed "
+					+ e.getMessage());
+		}
+		try {
+			MailJdbc.logAct.logMsg(LogFile.INFO + "Deleting mail by refresh");
+			deleteMailByRefresh(conn, this.getName());
+		} catch (Exception e) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR
+					+ "deleteMailByRefresh() failed " + e.getMessage());
+		}
+		isRunning = false;
+		MailJdbc.logAct.logMsg(LogFile.INFO + "Refresh doWork() completed");
+	}
+
+	public void grantRevoke(Connection conn, String thread_name)
+			throws Exception {
+		dbtasks.grantRevoke(conn, thread_name);
+	}
+
+	public void insertMail(Connection conn, String thread_name)
+			throws Exception {
+		dbtasks.insertMail(conn, thread_name);
+	}
+
+	public void deleteMailByRefresh(Connection conn, String thread_name)
+			throws Exception {
+
+		dbtasks.deleteMailByThread(conn, thread_name);
+	}
+
+	/**
+	 * @return Returns the isRunning.
+	 */
+	public boolean isRunning() {
+		return isRunning;
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,959 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.utils.DbTasks
+ *
+ * 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.mailjdbc.utils;
+/**
+ * This class is used all other classes for various tasks like insert, delete, backup etc
+ */
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+
+public class DbTasks extends Thread {
+	private static Process pr;
+
+	public static LogFile log = new LogFile("performance.out");
+
+	static boolean saveAutoCommit;
+
+	private static int id_count = 0;
+
+	public static int insert_count = 0;
+
+	public static int delete_count = 0;
+
+	public static int clob_count = 0;
+
+	public static int blob_count = 0;
+
+	public static Properties prop = new Properties();
+
+	public static void jdbcLoad(String driverType) {
+		String type = driverType;
+		if (driverType.equalsIgnoreCase("embedded")) {
+			setSystemProperty("driver", "org.apache.derby.jdbc.EmbeddedDriver");
+			MailJdbc.logAct
+					.logMsg(" \n*****************************************************");
+			MailJdbc.logAct.logMsg("\n\n\tStarting the test in Embedded mode");
+			MailJdbc.logAct
+					.logMsg("\n\n*****************************************************");
+			//setting the properties like user, password etc for both the
+			// database and the backup datatbase
+			setSystemProperty("database", "jdbc:derby:mailsdb;create=true");
+			setSystemProperty("ij.user", "REFRESH");
+			setSystemProperty("ij.password", "Refresh");
+			setSystemProperty("backup_database",
+					"jdbc:derby:/mailjdbc/mailbackup/mailsdb");
+		} else {
+			setSystemProperty("driver", "org.apache.derby.jdbc.ClientDriver");
+			setSystemProperty("database",
+					"jdbc:derby://localhost:1527/mailsdb;create=true;user=REFRESH;password=Refresh");
+		}
+		try {
+			// Create the schema (tables)
+			long s_schema = System.currentTimeMillis();
+			org.apache.derby.tools.ij
+					.main(new String[] { "-fr",
+							"/org/apache/derbyTesting/system/mailjdbc/schema/schema.sql" });
+			long e_schema = System.currentTimeMillis();
+			log
+					.logMsg(" \n*****************************************************");
+			log.logMsg("\n\n\tPerformance Info for the Test on" + s_schema);
+			log
+					.logMsg("\n\n*****************************************************");
+			log.logMsg(LogFile.INFO + "Schema Creation :"
+					+ PerfTime.readableTime(e_schema - s_schema));
+			System.out.println("created the schema");
+		} catch (Exception e) {
+			log.logMsg(LogFile.ERROR
+					+ "Exception while running loading and creating tables: "
+					+ e.getMessage());
+			e.printStackTrace();
+			errorPrint(e);
+		}
+
+	}
+
+	public static Connection getConnection(String usr, String passwd) {
+		try {
+			//Returns the Connection object
+			Class.forName(System.getProperty("driver")).newInstance();
+			prop.setProperty("user", usr);
+			prop.setProperty("password", passwd);
+			Connection con = DriverManager.getConnection(System
+					.getProperty("database"), prop);
+			return con;
+		} catch (Exception e) {
+			log.logMsg(LogFile.ERROR
+					+ "Error while getting connection for threads:"
+					+ e.getMessage());
+			e.printStackTrace();
+			errorPrint(e);
+			return null;
+		}
+	}
+
+	public void readMail(Connection conn, String thread_name) {
+		//This function will be reading mails from the inbox.
+		//Getiing the number of rows in the table and getting the
+		//size of the attachment (Blob) for a randomly selected row
+		Statement stmt = null;
+		Statement stmt1 = null;
+		int count = 0;
+		int count1 = 0;
+		long size = 0;
+		try {
+			saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			conn
+					.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+			long s_select = System.currentTimeMillis();
+			stmt = conn.createStatement();
+			stmt1 = conn.createStatement();
+			ResultSet rs = stmt.executeQuery(Statements.getRowCount);
+			ResultSet rs1 = stmt1.executeQuery(Statements.getRowCountAtach);
+			while (rs.next()) {
+				count = rs.getInt(1);
+			}
+			while (rs1.next()) {
+				count1 = rs1.getInt(1);
+			}
+			if (count == 0)
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Inbox is empty");
+			long e_select = System.currentTimeMillis();
+			MailJdbc.logAct
+					.logMsg(LogFile.INFO + thread_name + " : "
+							+ "The number of mails in the REFRESH.INBOX are : "
+							+ count);
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "The number of mails in the attachment table are : "
+					+ count1);
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to scan the entire REFRESH.INBOX for count :"
+					+ PerfTime.readableTime(e_select - s_select));
+			if (rs != null)
+				rs.close();
+			if (stmt != null)
+				stmt1.close();
+			if (rs1 != null)
+				rs1.close();
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "SQL Exception while reading : " + sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				errorPrint(sq);
+				sq.printStackTrace();
+			}
+		}
+		try {
+			int attach_id = (int) ((Math.random() * count));
+			ResultSet rs = stmt
+					.executeQuery("select attachment from REFRESH.attach where id  = "
+							+ attach_id);
+			long start = System.currentTimeMillis();
+			if (rs.next()) {
+				size = rs.getBlob(1).length();
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "size of the attachment for id " + attach_id
+						+ " is : " + size);
+			} else
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "no attachment");
+			if (rs != null)
+				rs.close();
+
+			long end = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to get the blob :"
+					+ PerfTime.readableTime(end - start));
+			rs = stmt
+					.executeQuery("select message from REFRESH.INBOX where id  = "
+							+ attach_id);
+			long start_t = System.currentTimeMillis();
+			if (rs.next()) {
+				size = rs.getClob(1).length();
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "size of the message for id " + attach_id + " is : "
+						+ size);
+			} else
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "mail with the id " + attach_id + " does not exist");
+			long end_t = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to get the clob :"
+					+ PerfTime.readableTime(end_t - start_t));
+			if (rs != null)
+				rs.close();
+			if (stmt != null)
+				stmt.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct
+					.logMsg(LogFile.ERROR
+							+ thread_name
+							+ " : "
+							+ "SQL Exception while getting the message and attach size : "
+							+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
+		}
+
+	}
+
+	public synchronized void deleteMailByUser(Connection conn,
+			String thread_name) {
+		//Delete done by the user. Thre user will mark the mails to be deleted
+		// and then
+		int id_count = 0;
+		try {
+			saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			PreparedStatement updateUser = conn
+					.prepareStatement(Statements.updateStr);
+			Statement stmt = conn.createStatement();
+			ResultSet rs = stmt
+					.executeQuery("select max(id)from REFRESH.INBOX ");
+			if (rs.next())
+				id_count = rs.getInt(1);
+			short to_delete = 1;
+			int id = (int) ((Math.random() * id_count));
+			long s_update = System.currentTimeMillis();
+			int delete_count = 0;
+			for (int i = 0; i < id; i++) {
+				updateUser.setShort(1, to_delete);
+				int for_id = (int) ((Math.random() * id_count));
+				updateUser.setInt(2, for_id);
+				int del = updateUser.executeUpdate();
+				delete_count = delete_count + del;
+			}
+			long e_update = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ " Time taken to mark the mails to be deleted :"
+					+ PerfTime.readableTime(e_update - s_update));
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "The number of mails marked to be deleted  by user:"
+					+ delete_count);
+			if (rs != null)
+				rs.close();
+			if (updateUser != null)
+				updateUser.close();
+			if (stmt != null)
+				stmt.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Exception while deleting mail by user: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
+		}
+	}
+
+	public void deleteMailByThread(Connection conn, String thread_name)
+			throws Exception {
+		//Deleting mails which are marked to be deleted
+		try {
+			boolean saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			PreparedStatement deleteThread = conn
+					.prepareStatement(Statements.deleteStr);
+			Statement stmt = conn.createStatement();
+			ResultSet rs = stmt
+					.executeQuery("select count(*) from REFRESH.INBOX where to_delete=1");
+			long s_delete = System.currentTimeMillis();
+			int count = 0;
+			count = deleteThread.executeUpdate();
+			long e_delete = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to delete mails by thread :"
+					+ PerfTime.readableTime(e_delete - s_delete));
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : " + count
+					+ " rows deleted");
+			delete_count = delete_count + count;
+			if (deleteThread != null)
+				deleteThread.close();
+			if (rs != null)
+				rs.close();
+			if (stmt != null)
+				stmt.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Exception while deleting mail by Thread: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
+		}
+
+	}
+
+	public void moveToFolders(Connection conn, String thread_name) {
+		//Changing the folder id of randomly selected rows
+		try {
+			boolean saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			Statement stmt = conn.createStatement();
+			PreparedStatement moveToFolder = conn
+					.prepareStatement(Statements.movefolder);
+			ResultSet rs = stmt.executeQuery(Statements.getRowCount);
+			if (!(rs.next()))
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "no message in the REFRESH.INBOX to move");
+			else {
+				int count = rs.getInt(1);
+				int folder_id = (int) (Math.random() * 5);
+				int message_id = (int) (Math.random() * count);
+				moveToFolder.setInt(1, folder_id);
+				moveToFolder.setInt(2, message_id);
+				long s_folder = System.currentTimeMillis();
+				moveToFolder.executeUpdate();
+				long e_folder = System.currentTimeMillis();
+				log.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Time taken to move a mail to the folder :"
+						+ PerfTime.readableTime(e_folder - s_folder));
+				long s_fselect = System.currentTimeMillis();
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Mail with id : " + message_id
+						+ " is moved to folder with id : " + folder_id);
+			}
+			if (stmt != null)
+				stmt.close();
+			if (moveToFolder != null)
+				moveToFolder.close();
+			if (rs != null)
+				rs.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Exception while moving mail to folders: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
+		}
+
+	}
+
+	public void insertMail(Connection conn, String thread_name)
+			throws Exception {
+		//Inserting rows to the inbox table. Making attach_id of randomly
+		// selected rows to be one
+		//and for those rows inserting blobs in the attach table
+		Statement stmt = conn.createStatement();
+		int num = (int) (Math.random() * 10);
+		try {
+			boolean saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			PreparedStatement insertFirst = conn.prepareStatement(
+					Statements.insertStr, Statement.RETURN_GENERATED_KEYS);
+			String name = new String("ABCD");
+			String l_name = new String("WXYZ");
+			long s_insert = System.currentTimeMillis();
+			for (int i = 0; i < num; i++) {
+				String new_name = new String(increment(name, 60));
+				String new_lname = new String(decrement(name, 60));
+				insertFirst.setString(1, new_name);
+				insertFirst.setString(2, new_lname);
+				insertFirst.setTimestamp(3, new Timestamp(System
+						.currentTimeMillis()));
+				name = new_name;
+				l_name = new_lname;
+				try {
+					File inputfile = new File("l" + num + ".txt");
+					FileReader fr = new FileReader(inputfile);
+					BufferedReader br = new BufferedReader(fr);
+					insertFirst.setCharacterStream(4, fr, (int) inputfile
+							.length());
+				} catch (FileNotFoundException e) {
+					MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+							+ "File not found Exception : " + e.getMessage());
+					errorPrint(e);
+					throw e;
+				}
+				int rand_num = (int) (Math.random() * 10);
+				if (i == rand_num) {
+					ResultSet rs = stmt
+							.executeQuery("select count(*) from REFRESH.INBOX where attach_id>0");
+					while (rs.next()) {
+						id_count = rs.getInt(1);
+						int attach_id = rs.getInt(1) + 1;
+						insertFirst.setInt(5, rs.getInt(1) + 1);
+					}
+
+					if (rs != null)
+						rs.close();
+					conn
+							.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+				} else
+					insertFirst.setInt(5, 0);
+				insertFirst
+						.setString(
+								6,
+								"This column is used only to by pass the space problem. If the problem still exists, then we are going to "
+										+ "have a serious issue here.*****************************************************************************************************");
+				int result = insertFirst.executeUpdate();
+				if (result != 0) {
+					insert_count = insert_count + 1;
+				}
+			}
+			if (insertFirst != null)
+				insertFirst.close();
+			conn.commit();
+			long e_insert = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to insert " + num + "rows :"
+					+ PerfTime.readableTime(e_insert - s_insert));
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "number of mails inserted : " + num);
+
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Error while inserting into REFRESH.INBOX:"
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
+		}
+		try {
+			PreparedStatement insertAttach = conn
+					.prepareStatement(Statements.insertStrAttach);
+			Statement stmt1 = conn.createStatement();
+			ResultSet rs = stmt1
+					.executeQuery("select id,attach_id from REFRESH.INBOX where attach_id> "
+							+ id_count);
+			int row_count = 0;
+			long a_start = System.currentTimeMillis();
+			while (rs.next()) {
+				insertAttach.setInt(1, rs.getInt(1));
+				insertAttach.setInt(2, rs.getInt(2));
+				try {
+					File inputfile = new File("p" + num + ".jpg");
+					InputStream fileIn = new FileInputStream(inputfile); //"pic"+
+					// row_count+".jpg");
+					insertAttach.setBinaryStream(3, fileIn, (int) inputfile
+							.length());
+				} catch (Exception e) {
+					MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+							+ "Exception : " + e.getMessage());
+					errorPrint(e);
+					throw e;
+				}
+				int result_attach = insertAttach.executeUpdate();
+				if (result_attach != 0) {
+					blob_count = blob_count + 1;
+					row_count++;
+				}
+
+			}
+			long a_end = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to insert " + row_count + "attachments :"
+					+ PerfTime.readableTime(a_end - a_start));
+			id_count++;
+			if (rs != null)
+				rs.close();
+			if (stmt != null)
+				stmt.close();
+			if (stmt1 != null)
+				stmt1.close();
+			if (insertAttach != null)
+				insertAttach.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Error while inserting attachments:" + sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
+		}
+	}
+
+	public synchronized void deleteMailByExp(Connection conn, String thread_name) {
+		try {
+			//Deleting mails which are older than 1 day
+			boolean saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(false);
+			long s_delExp = System.currentTimeMillis();
+			Statement selExp = conn.createStatement();
+			PreparedStatement deleteExp = conn
+					.prepareStatement(Statements.delExp);
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "delete mails which are older than 1 day");
+			int count = 0;
+			count = selExp.executeUpdate(Statements.del_jdbc_exp);
+			long e_delExp = System.currentTimeMillis();
+			log.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Time taken to delete " + count + "mails :"
+					+ PerfTime.readableTime(e_delExp - s_delExp));
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ " number of mails deleted : " + count);
+			delete_count = delete_count + count;
+			if (deleteExp != null)
+				deleteExp.close();
+			if (selExp != null)
+				selExp.close();
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (SQLException sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Error while deleting mails by expiry manager: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
+		}
+	}
+
+	public void Backup(Connection conn, String thread_name) {
+		//when the backup thread kicks in, it will use this function to
+		//take the periodic backups
+		long s_backup = System.currentTimeMillis();
+		try {
+			saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(true);
+			CallableStatement cs = conn
+					.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(?, ?)");
+			cs.setString(1, "/mailjdbc/mailbackup");
+			cs.setInt(2, 1);
+			cs.execute();
+			cs.close();
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Finished backing up the Database");
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+		} catch (Throwable sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Error while doing the backup system procedure: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+		}
+		long e_backup = System.currentTimeMillis();
+		log.logMsg(LogFile.INFO + thread_name + " : "
+				+ "Time taken to do backup :"
+				+ PerfTime.readableTime(e_backup - s_backup));
+
+	}
+
+	public void compressTable(Connection conn, String tabname,
+			String thread_name)
+	//preiodically compresses the table to get back the free spaces available
+	// after
+	//the deletion of some rows
+	{
+		long s_compress = System.currentTimeMillis();
+		long dbsize = databaseSize("mailsdb/seg0");
+		MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+				+ "dbsize before compress : " + dbsize);
+		try {
+			boolean saveAutoCommit = conn.getAutoCommit();
+			conn.setAutoCommit(true);
+			CallableStatement cs = conn
+					.prepareCall("CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
+			cs.setString(1, "REFRESH");
+			cs.setString(2, tabname);
+			cs.setShort(3, (short) 1);
+			cs.setShort(4, (short) 1);
+			cs.setShort(5, (short) 1);
+			cs.execute();
+			conn.setAutoCommit(saveAutoCommit);
+			cs.close();
+		} catch (Throwable sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Error while doing the Compress procedure: "
+					+ sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+		}
+		long e_compress = System.currentTimeMillis();
+		MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+				+ "Finished Compressing the table: " + tabname);
+		log.logMsg(LogFile.INFO + thread_name + " : "
+				+ "Time taken to compress the table : " + tabname
+				+ PerfTime.readableTime(e_compress - s_compress));
+		dbsize = databaseSize("mailsdb/seg0");
+		MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+				+ "dbsize after compress : " + dbsize);
+	}
+
+	public synchronized void checkDbSize(Connection conn, String thread_name)
+	//Will give the information about the size of the database in regular
+	// intervals
+	{
+		try {
+			long dbsize = 0;
+			int del_count = 0;
+			int row_count = 0;
+			int count = 0;
+			int new_const = 0;
+			int diff = 0;
+			ArrayList idArray = new ArrayList();
+			Integer id_element = new Integer(0);
+			Statement stmt = conn.createStatement();
+			Statement stmt1 = conn.createStatement();
+			Statement stmt2 = conn.createStatement();
+			Statement stmt3 = conn.createStatement();
+			ResultSet rs = stmt
+					.executeQuery("select count(*) from REFRESH.INBOX ");
+			while (rs.next())
+				count = rs.getInt(1);
+			if (count > 12) {
+				diff = count - 12;
+				ResultSet rs1 = stmt1
+						.executeQuery("select id from REFRESH.INBOX");
+				while (rs1.next()) {
+					id_element = new Integer(rs1.getInt(1));
+					idArray.add(id_element);
+				}
+				for (int i = 0; i <= diff; i++) {
+					del_count = del_count
+							+ stmt3
+									.executeUpdate("delete from REFRESH.INBOX where id ="
+											+ idArray.get(i));
+
+				}
+				if (rs1 != null)
+					rs1.close();
+			}
+			delete_count = delete_count + del_count;
+			if (rs != null)
+				rs.close();
+			if (stmt != null)
+				stmt.close();
+			if (stmt1 != null)
+				stmt1.close();
+			if (stmt2 != null)
+				stmt2.close();
+			if (stmt3 != null)
+				stmt3.close();
+		} catch (Exception fe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " :  "
+					+ fe.getMessage());
+			errorPrint(fe);
+		}
+
+	}
+
+	public void grantRevoke(Connection conn, String thread_name) {
+		try {
+			//Giving appropriate permission to eahc threads
+			saveAutoCommit = conn.getAutoCommit();
+			Statement stmt = conn.createStatement();
+			stmt.execute(Statements.grantSel1);
+			stmt.execute(Statements.grantSel2);
+			stmt.execute(Statements.grantSel3);
+			stmt.execute(Statements.grantSel4);
+			stmt.execute(Statements.grantSel5);
+			stmt.execute(Statements.grantSel6);
+			stmt.execute(Statements.grantSel7);
+			stmt.execute(Statements.grantIns1);
+			stmt.execute(Statements.grantIns2);
+			stmt.execute(Statements.grantIns3);
+			stmt.execute(Statements.grantUp1);
+			stmt.execute(Statements.grantUp2);
+			stmt.execute(Statements.grantUp3);
+			stmt.execute(Statements.grantDel1);
+			stmt.execute(Statements.grantDel2);
+			stmt.execute(Statements.grantDel3);
+			stmt.execute(Statements.grantExe1);
+			stmt.execute(Statements.grantExe2);
+			stmt.execute(Statements.grantExe3);
+			stmt.execute(Statements.grantExe4);
+			stmt.execute(Statements.grantExe5);
+			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
+			if (stmt != null)
+				stmt.close();
+			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+					+ "Finished Granting permissions");
+		} catch (Throwable sqe) {
+			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+					+ "Error while doing Grant Revoke: " + sqe.getMessage());
+			sqe.printStackTrace();
+			errorPrint(sqe);
+
+		}
+
+	}
+
+	public static long databaseSize(String dbname) {
+		File dir = new File(dbname);
+		File[] files = dir.listFiles();
+		long length = 0;
+		int count = 0;
+		for (int i = 0; i < files.length; i++) {
+			length = length + files[i].length();
+			count++;
+		}
+		return length;
+	}
+
+	public static void setSystemProperty(String key, String value) {
+		String svalue = System.getProperty(key);
+		if (svalue == null)
+			System.setProperty(key, value);
+		else
+			value = svalue;
+		MailJdbc.logAct.logMsg(LogFile.INFO + key + "=" + value);
+	}
+
+	public void totals() {
+		MailJdbc.logAct.logMsg(LogFile.INFO + " total number of inserts : "
+				+ insert_count);
+		MailJdbc.logAct.logMsg(LogFile.INFO + " total number of deletes : "
+				+ delete_count);
+		MailJdbc.logAct.logMsg(LogFile.INFO
+				+ " total number of clobs inserted : " + insert_count);
+		MailJdbc.logAct.logMsg(LogFile.INFO
+				+ " total number of blobs inserted : " + blob_count);
+	}
+
+	public static String decrement(String name, int maxLength) {
+		StringBuffer buff = new StringBuffer(name);
+
+		//if the String is '0', return the maximum String
+		StringBuffer tempBuff = new StringBuffer();
+		if (name.length() == 1 && name.charAt(0) == firstChar()) {
+			for (int i = 0; i < maxLength; i++) {
+				tempBuff.append(lastChar());
+			}
+			return tempBuff.toString();
+		}
+
+		//if String is all '000...0', eliminate one '0' and set the rest to 'z'
+		else {
+			boolean isAll0 = true;
+			for (int i = 0; i < buff.length(); i++) {
+				if (buff.charAt(i) != firstChar()) {
+					isAll0 = false;
+					break;
+				}
+			}
+			if (isAll0 == true) {
+				buff.deleteCharAt(0);
+				for (int i = 0; i < buff.length(); i++) {
+					buff.setCharAt(i, lastChar());
+				}
+			}
+			//if the String is not all '000...0', loop starting with the last
+			// char
+			else {
+				for (int i = buff.length() - 1; i >= 0; i--) {
+					//if this char is not '0'
+					if (buff.charAt(i) > firstChar()) {
+						//decrement this char
+						buff.setCharAt(i, previousChar(buff.charAt(i)));
+						break;
+					}
+					//Resetting the counter 000 -> zzz
+					//if this char is '0' and if the char before is not '0',
+					// set this char to 'z' and decrement the char before
+					else
+						buff.setCharAt(i, lastChar());
+					if (buff.charAt(i - 1) < firstChar()) {
+						buff.setCharAt(i - 1, previousChar(buff.charAt(i - 1)));
+						break;
+					}
+				}
+			}
+		}
+		return buff.toString();
+	}
+
+	private static char firstChar() {
+		return (char) 48;
+	}
+
+	private static char lastChar() {
+		return (char) 122;
+	}
+
+	private static char previousChar(char c) {
+		if (c <= 65 && c >= 59)
+			return (char) 57;
+		else if (c <= 97 && c >= 92)
+			return (char) 90;
+		else
+			return (char) (c - 1);
+	}
+
+	public static String increment(String name, int maxLength) {
+
+		//		if (name.length() > maxLength) {
+		//			//String greater than maxLength, so set it to '0'
+		//			return "0";
+		//		}
+		StringBuffer buff = new StringBuffer(name);
+		//check if the String is all 'zzz...z'
+		boolean isAllZ = true;
+		for (int i = 0; i < name.length(); i++) {
+			if (name.charAt(i) != lastChar()) {
+				isAllZ = false;
+				break;
+			}
+		}
+		//if the String is all 'zzz...z', check if it's the maximum length
+		if (isAllZ == true) {
+			if (name.length() >= maxLength) {
+				//String is all 'zzz...z' to maxLength, so set it to '0'
+				return "0";
+			} else {
+				//String is all 'zzz...z' but not maxLength, so set all to 0
+				// and append '0'
+				for (int i = 0; i < buff.length(); i++) {
+					buff.setCharAt(i, firstChar());
+				}
+				buff.append('0');
+			}
+		}
+		//if the String is not all 'zzz...z', loop starting with the last char
+		else {
+			for (int i = buff.length() - 1; i >= 0; i--) {
+				//if this char is not 'z'
+				if (buff.charAt(i) < lastChar()) {
+					//increment this char
+					buff.setCharAt(i, nextChar(buff.charAt(i)));
+					break;
+				}
+				// if this char is 'z' and if the char before is not 'z', set
+				// this char to '0' and increment the char before
+				else
+					buff.setCharAt(i, firstChar());
+				if (buff.charAt(i - 1) < lastChar()) {
+					buff.setCharAt(i - 1, nextChar(buff.charAt(i - 1)));
+					break;
+				}
+			}
+		}
+		return buff.toString();
+	}
+
+	private static char nextChar(char c) {
+		if (c <= 63 && c >= 57)
+			return (char) 65;
+		else if (c <= 95 && c >= 90)
+			return (char) 97;
+		else
+			return (char) (c + 1);
+	}
+
+	static void errorPrint(Throwable e) {
+		if (e instanceof SQLException)
+			SQLExceptionPrint((SQLException) e);
+		else {
+			System.out.println("A non SQL error occured.");
+			e.printStackTrace();
+		}
+	} // END errorPrint
+
+	//  Iterates through a stack of SQLExceptions
+	static void SQLExceptionPrint(SQLException sqle) {
+		while (sqle != null) {
+			System.out.println("\n---SQLException Caught---\n");
+			System.out.println("SQLState:   " + (sqle).getSQLState());
+			System.out.println("Severity: " + (sqle).getErrorCode());
+			System.out.println("Message:  " + (sqle).getMessage());
+			sqle.printStackTrace();
+			sqle = sqle.getNextException();
+		}
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/LogFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/LogFile.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/LogFile.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/LogFile.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,60 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.utils.LogFile
+ * 
+ * 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.mailjdbc.utils;
+
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+
+//	utility class that logs messages to the given log file
+public class LogFile {
+	public static String ERROR = " : ERROR :";
+
+	public static String WARN = " : WARNING :";
+
+	public static String INFO = " : INFO :";
+
+	public PrintWriter log;
+
+	//Constructor that will initialize the output log file
+	public LogFile(String logFileName) {
+		try { //auto-flush printwriter
+			log = new PrintWriter(new FileOutputStream(logFileName), true);
+		} catch (Exception e) {
+			System.out.println("Exception in LogFile.java: " + e.getMessage());
+		}
+	}
+
+	//closing the log file
+	public void closeLog() {
+		try {
+			log.close();
+		} catch (Exception e) {
+			System.out.println("Exception closing the log file: "
+					+ e.getMessage());
+		}
+	}
+
+	//logging the supplied message to the logfile
+	public synchronized void logMsg(String msg) {
+		log.println(msg);
+	}
+}
+

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/PerfTime.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/PerfTime.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/PerfTime.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/PerfTime.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,55 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.utils.PerfTime
+ * 
+ * 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.mailjdbc.utils;
+//utility class that prints out the time in a formatted way
+public class PerfTime {
+	public static String readableTime(long t) {
+		//Returns the time in h.mm.s format
+		long hours = t / (60L * 60L * 1000L);
+		long hoursRemainder = t % (60L * 60L * 1000L);
+		long mins = hoursRemainder / (60L * 1000L);
+		long minsRemainder = hoursRemainder % (60L * 1000L);
+		long secs = minsRemainder / 1000L;
+		long ms = minsRemainder % 1000L;
+
+		StringBuffer sb = new StringBuffer(20);
+		if (hours > 0) {
+			sb.append(hours);
+			sb.append('h');
+		}
+		if (mins > 0) {
+			sb.append(mins);
+			sb.append('m');
+		}
+		sb.append(secs);
+		if (hours == 0 && mins < 5) {
+			sb.append('.');
+			if (ms < 10)
+				sb.append('0');
+			if (ms < 100)
+				sb.append('0');
+			sb.append(ms);
+		}
+		sb.append("s");
+		return sb.toString();
+
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/Statements.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/Statements.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/Statements.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/Statements.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,97 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.utils.Statements
+ * 
+ * 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.mailjdbc.utils;
+//This class has all the SQL statements use for the test
+public class Statements {
+	public static String readStr = "select * from REFRESH.INBOX";
+
+	public static String insertStr = "insert into REFRESH.INBOX(from_name,to_name,date,Message,attach_id,size_problem) values (?,?,?,?,?,?)";
+
+	public static String deleteStr = "delete  from REFRESH.INBOX where to_delete = 1";
+
+	public static String updateStr = "update REFRESH.INBOX set to_delete = ? where id = ?";
+
+	public static String getRowCount = "select count(*)from REFRESH.INBOX";
+
+	public static String getRowCountAtach = "select count(*) from REFRESH.ATTACH";
+
+	public static String getRowCountin = "select count(*)from REFRESH.INBOX where to_name = ?";
+
+	public static String getRowCountdel = "select count(*)from REFRESH.INBOX where to_delete = 1";
+
+	public static String moveStr = "insert into folders (foldername,message_id) (select cast(? as varchar(16)),id from REFRESH.INBOX where date=?)";
+
+	public static String movefolder = "update REFRESH.INBOX set folder_id = ? where id = ?";
+
+	public static String selExp = "select id,date from REFRESH.INBOX ";
+
+	public static String delExp = "delete from REFRESH.INBOX where id = ?";
+
+	public static String del_jdbc_exp = "delete from REFRESH.INBOX where (values {fn TIMESTAMPDIFF(SQL_TSI_DAY,  date,CURRENT_TIMESTAMP)})>1";
+
+	public static String insertStrAttach = "insert into REFRESH.ATTACH (id,attach_id,attachment) values (?,?,?)";
+
+	public static String getTableCount = "select count(*) from sys.systables";
+
+	public static String getRowCountAttach = "select count(*) from REFRESH.ATTACH";
+
+	public static String grantSel1 = "grant select on REFRESH.INBOX to BROWSE";
+
+	public static String grantSel2 = "grant select on REFRESH.ATTACH to BROWSE";
+
+	public static String grantSel3 = "grant select on REFRESH.INBOX to BACKUPVER";
+
+	public static String grantSel4 = "grant select on REFRESH.ATTACH to BACKUPVER";
+
+	public static String grantSel5 = "grant select on REFRESH.ATTACH to PURGE";
+
+	public static String grantSel6 = "grant select on REFRESH.INBOX to PURGE";
+
+	public static String grantSel7 = "grant select on REFRESH.FOLDERS to BROWSE";
+
+	public static String grantIns1 = "grant insert on REFRESH.INBOX to BROWSE";
+
+	public static String grantIns2 = "grant insert on REFRESH.ATTACH to BROWSE";
+
+	public static String grantIns3 = "grant insert on REFRESH.FOLDERS to BROWSE";
+
+	public static String grantUp1 = "grant update on REFRESH.INBOX to BROWSE";
+
+	public static String grantUp2 = "grant update on REFRESH.ATTACH to BROWSE";
+
+	public static String grantUp3 = "grant update on REFRESH.INBOX to BROWSE";
+
+	public static String grantDel1 = "grant delete on REFRESH.INBOX to PURGE";
+
+	public static String grantDel2 = "grant delete on REFRESH.ATTACH to PURGE";
+
+	public static String grantDel3 = "grant delete on REFRESH.FOLDERS to BROWSE";
+
+	public static String grantExe1 = "grant execute on procedure SYSCS_UTIL.SYSCS_BACKUP_DATABASE to BACKUP";
+
+	public static String grantExe2 = "grant execute on procedure SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE  to BACKUP";
+
+	public static String grantExe3 = "grant execute on procedure SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT to BACKUP";
+
+	public static String grantExe4 = "grant execute on procedure SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE to BACKUP";
+
+	public static String grantExe5 = "grant execute on procedure SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE to BACKUP";
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/ThreadUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/ThreadUtils.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/ThreadUtils.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/ThreadUtils.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,101 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.mailjdbc.utils.ThreadUtils
+ * 
+ * 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.mailjdbc.utils;
+/**
+ * This class is used to keep the threads in an ArrayList and starts them 
+ * also checks whether the thread is alive or sleeping
+ */
+import java.util.ArrayList;
+
+import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
+import org.apache.derbyTesting.system.mailjdbc.tasks.Backup;
+import org.apache.derbyTesting.system.mailjdbc.tasks.Browse;
+import org.apache.derbyTesting.system.mailjdbc.tasks.Purge;
+import org.apache.derbyTesting.system.mailjdbc.tasks.Refresh;
+
+public class ThreadUtils {
+	private static ArrayList userThreads = new ArrayList();
+
+	public static ThreadUtils util = new ThreadUtils();
+
+	//constructor which will start the threads
+	public static void startThreads() {
+		util.run();
+	}
+
+	public void run() {
+		Thread t = null;
+		try {
+			//Starting Refresh Thread
+			t = new Refresh("Refresh Thread");
+			t.start();
+			MailJdbc.logAct.logMsg(LogFile.INFO + "Started: " + t.getName());
+			userThreads.add(t);
+			//Starting browsing thread
+			t = new Browse("Browsing Thread");
+			t.start();
+			MailJdbc.logAct.logMsg(LogFile.INFO + "Started: " + t.getName());
+			userThreads.add(t);
+			//Starting Purge Thread
+			t = new Purge("Purging Thread");
+			int sleep_time = (int) (Math.random() * 500);//TODO : Change this
+														 // number to a
+														 // meaningful one)
+			Thread.sleep(sleep_time);
+			t.start();
+			MailJdbc.logAct.logMsg(LogFile.INFO + "Started: " + t.getName());
+			userThreads.add(t);
+			//Starting Backup Thread
+			t = new Backup("Backup Thread");
+			t.start();
+			MailJdbc.logAct.logMsg(LogFile.INFO + "Started: " + t.getName());
+			userThreads.add(t);
+			sleep_time = (int) (Math.random() * 15000);
+			Thread.sleep(sleep_time);
+		} catch (Exception e) {
+			MailJdbc.logAct
+					.logMsg(LogFile.ERROR
+							+ "Exception while starting the threads: "
+							+ e.getMessage());
+		}
+	}
+
+	public static synchronized boolean isThreadRunning(String name) {
+		//checks and returns true is the Refresh thread is active
+		if (name.equalsIgnoreCase("Refresh Thread")) {
+			Refresh rt = (Refresh) userThreads.get(0);
+			return rt.isRunning();
+		} else
+			return false;
+	}
+
+	public static synchronized Thread getThread(String name) {
+		if (name.equalsIgnoreCase("Refresh Thread")) {
+			return (Refresh) userThreads.get(0);
+		} else {
+			return null;
+		}
+	}
+
+	public ThreadUtils getInstance() {
+		return util;
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/README.txt
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/README.txt?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/README.txt (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/README.txt Tue Jan 30 15:27:51 2007
@@ -0,0 +1,90 @@
+           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.    
+
+Sttest package - Single Table Test.
+
+Contents
+
+1. About the Sttest
+2. Design
+3. Schema
+4. Test goals
+5. Exit criteria
+6. How to run the test
+
+1. About the Sttest
+
+A derby database test which creates a single table, and runs updates against that table for a long time, printing a log of its actions to stdout.
+
+2. Design
+
+It is a multi threaded application where each thread acts as a different connection to the database. The  number of threads can be changed.
+It can be changed in the Sttest.java To change the number of connection search for the following string in the Sttest.java file "static int connections_to_make"  and make the changes.
+Also other values like maximum size and minimum size can be changed.  The database has only one table with all the Derby supported datatypes.
+And they are indexed. The test will insert rows till it reaches a particular size and then it does inserts/updates and deletes. It checks whether the table has the max rows and if so will delete 
+some rows which are selected randomly. Similarly the test will check whether the number of rows are less than the minimum number
+then it will insert some rows.
+
+
+3. Schema
+
+The schema for this test is as follows
+
+Table
+
+1.table Datatypes 
+	id int not null
+	t_char char(100)
+	t_blob blob(100K)
+	t_clob clob(100K)
+	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(31,0)
+	t_real real
+	t_smallint smallint
+	t_time time
+	t_timestamp timestamp
+	t_varchar varchar(100)
+	serialkey bigint generated always as identity (start with 1,increment by 1)
+			
+4. Test goals
+
+The usual duration of this test is  2 weeks time without any major issues. You can  increase/decrease the stress by changing the test values
+
+5. Exit criteria
+
+1. There should not be any fatal failures
+2. No unwanted lock time outs or deadlocks
+3. No NPEs
+4. No unwanted Exceptions
+5. No Out of memory Errors
+
+6. How to run the test
+
+1. Make sure you have java in your environment and put the Derby jars including the derbyTesting.jar and resource.jar in your classpath
+2. Then run 
+          java org.apche.derbyTesting.system.sttest.Sttest.java 
+   If you want to get the testoutpuy to a file then run 
+          java org.apche.derbyTesting.system.sttest.Sttest.java>sttest.out 2>&1
+   Which will print the output to a file called sttest.out including warnings and errors
+ 
+There is no explicit exit condition.  This test usually runs for more than 2 weeks. Check for ERROR and Exception in both the out files and derby.log.

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



Mime
View raw message