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 [2/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
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/Sttest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/Sttest.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/Sttest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/Sttest.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,528 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.sttest.Sttest
+ * 
+ * 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.sttest;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Random;
+
+import org.apache.derby.tools.JDBCDisplayUtil;
+import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.system.sttest.tools.MemCheck;
+import org.apache.derbyTesting.system.sttest.utils.Datatypes;
+import org.apache.derbyTesting.system.sttest.utils.Setup;
+import org.apache.derbyTesting.system.sttest.utils.StStatus;
+
+/*
+ * * Sttest.java * 'Sttest' is short for 'single table test.' Sttest.java
+ * supplies * the main entry point and the top level code for controlling the *
+ * actions of the test, including the ddl for the table and indexes. * The
+ * purpose of the test is to exercise the store code by running * updates on the
+ * single table for an indefinitely long time, with * an indefinitely large
+ * number of user connections, each randomly * executing one of a small number
+ * of update procedures with random * data. The test sets a minimum and maximum
+ * number of rows, builds * the table up to the minimum number of rows, and from
+ * that point * either gradually grows the table to the max size, or gradually *
+ * shrinks it to the min size. Periodically memory use is reported, * and the
+ * table is compressed, to keep performance from deteriorating.
+ */
+public class Sttest extends Thread {
+	
+	static int loops = 200;
+	
+	static int rowcount = 0;
+	
+	static int testcount = 0;
+	
+	static int connections_to_make = 250;
+	
+	static Random rand;
+	
+	static boolean increase = true;
+	
+	static boolean not_finished = true;
+	
+	static int targetmax = 100000; //build up to 1GB database
+	
+	static int targetmin = 90000;
+	
+	static int insertsize = 7;
+	
+	static int updatesize = 1;
+	
+	static int deletesize = 1;
+	
+	static boolean fatal = false;
+	
+	static int rows = 0;
+	
+	static boolean countlock = false;
+	
+	static int delete_freq = 1;
+	
+	static int locker_id = -1;
+	
+	static final int INIT = 0;
+	
+	static final int GROW = 1;
+	
+	static final int SHRINK = 2;
+	
+	static int mode = INIT;
+	
+	static int count_timer = 0;
+	
+	static int inserts_to_try = 0;
+	
+	static final int INITIAL_CONNECTIONS = 2; //initial connections should be
+	
+	// low, otherwise deadlock will
+	// happen.
+	
+	static boolean startByIJ = false;
+	
+	static String dbURL = "jdbc:derby:testDB";
+	
+	static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
+	
+	static StStatus status = null;
+	
+	int thread_id;
+	
+	int ind = 0;
+	
+	public static void main(String[] args) throws SQLException, IOException,
+	InterruptedException, Exception, Throwable {
+		System.getProperties().put("derby.locks.deadlockTimeout", "60");
+		System.getProperties().put("derby.locks.waitTimeout", "200");
+		System.out.println("Test Sttest starting");
+		System.getProperties().put("derby.infolog.append", "true");
+		System.getProperties().put("derby.stream.error.logSeverityLevel", "0");
+		//get any properties user may have set in Sttest.properties file
+		//these will override any of those set above
+		userProperties();
+		Class.forName(driver).newInstance();
+		if (Setup.doit(dbURL) == false)
+			System.exit(1);
+		status = new StStatus();
+		sttTop();
+	}
+	
+	static void userProperties() throws Throwable {
+		FileInputStream fileIn = null;
+		try {
+			fileIn = new FileInputStream("Sttest.properties");
+		} catch (Exception e) {
+			System.out
+			.println("user control file 'Sttest.properties' not found; using defaults");
+		}
+		if (fileIn != null) {
+			Properties props = new Properties();
+			props.load(fileIn);
+			fileIn.close();
+			String prop = null;
+			prop = props.getProperty("connections");
+			if (prop != null)
+				connections_to_make = Integer.parseInt(prop);
+			prop = props.getProperty("dbURL");
+			if (prop != null)
+				dbURL = prop;
+			prop = props.getProperty("driver");
+			if (prop != null)
+				driver = prop;
+			//allows us to get any other properties into the system
+			Properties sysprops = System.getProperties();
+			Enumeration list = props.propertyNames();
+			String s = null;
+			while (list.hasMoreElements()) {
+				s = (String) list.nextElement();
+				sysprops.put(s, props.getProperty(s));
+			}
+		}
+		System.out.println("driver = " + driver);
+		System.out.println("dbURL = " + dbURL);
+		System.out.println("connections = " + connections_to_make);
+	}
+	
+	public static void sttTop() throws SQLException, IOException,
+	InterruptedException, Exception, Throwable {
+		rand = new Random();
+		Datatypes.rand = rand;
+		//harder to actually delete rows when there are
+		//more connections, so repeat operation more often
+		delete_freq = 1 + connections_to_make % 5;
+		initial_data();
+		Date d = new Date();
+		System.out.println("updates starting, loop " + loops + " " + d);
+		status.firstMessage(connections_to_make, d);
+		// check memory in separate thread-- allows us to monitor
+		// usage during database calls
+		// 200,000 msec = 3min, 20 sec delay between checks
+		MemCheck mc = new MemCheck(200000);
+		mc.start();
+		Sttest testsessions[] = new Sttest[connections_to_make];
+		for (int i = 0; i < connections_to_make; i++) {
+			testsessions[i] = new Sttest(i);
+			testsessions[i].start();
+			sleep(3000);
+		}
+		for (int i = 0; i < connections_to_make; i++) {
+			testsessions[i].join();
+		}
+		try {
+			mc.stopNow = true;
+			mc.join();
+		} catch (Throwable t) {
+			throw (t);
+		}
+	}
+	
+	Sttest(int num) throws SQLException {
+		this.thread_id = num;
+	}
+	
+	static synchronized void reset_loops(int myloopcount) {
+		if (myloopcount == loops)
+			loops--;
+		// otherwise some other thread got there first and reset it
+	}
+	
+	// available to force synchronization of get_countlock(), ...
+	static synchronized void locksync() {
+		return;
+	}
+	
+	static synchronized boolean get_countlock() {
+		locksync();
+		return (countlock);
+	}
+	
+	static synchronized boolean set_countlock(boolean state) {
+		locksync();
+		if (state == true && countlock == true)
+			return (false);
+		countlock = state;
+		return (true);
+	}
+	
+	static synchronized void changerowcount(int in) {
+		rowcount += in;
+	}
+	
+	static synchronized void changerowcount2zero() {
+		rowcount = 0;
+	}
+	
+	static void initial_data() throws Exception, Throwable {
+		System.out.println("start initial data");
+		Connection conn = null;
+		int rows = 0;
+		try {
+			conn = mystartJBMS();
+		} catch (Throwable t) {
+			throw (t);
+		}
+		// our goal is to get up to minimum table size
+		int x = Datatypes.get_table_count(conn);
+		if (x != -1) {
+			rows = x;
+		}
+		if (conn != null) {
+			conn.commit();
+			conn.close();
+		}
+		System.out.println("initial rowcount = " + rows);
+		rowcount = rows;
+		if (rows >= targetmin) {
+			mode = GROW;
+			System.out.println("initial data not needed");
+			return;
+		}
+		inserts_to_try = targetmin - rows;
+		System.out.println("inserts_to_try: " + inserts_to_try);
+		Sttest testthreads[] = new Sttest[INITIAL_CONNECTIONS];
+		for (int i = 0; i < INITIAL_CONNECTIONS; i++) {
+			testthreads[i] = new Sttest(i);
+			testthreads[i].start();
+		}
+		for (int i = 0; i < INITIAL_CONNECTIONS; i++) {
+			testthreads[i].join();
+		}
+		mode = GROW;
+		System.out.println("complete initial data");
+		return;
+	}
+	
+	public void run() {
+		Connection conn = null;
+		Date d = null;
+		try {
+			conn = mystartJBMS();
+		} catch (Throwable t) {
+			return;
+		}
+		Runtime rt = null;
+		int tick = 0;
+		int ind2 = 0;
+		int myloops = loops;
+		while (not_finished) {
+			if (loops <= 0)
+				break;// done
+			// thread-private copy to be checked against global copy
+			// before attempting to update
+			myloops = loops;
+			if (fatal == true)
+				break;
+			if (mode == INIT && inserts_to_try <= 0) {
+				break;
+			}
+			// test rowcount
+			if (mode == GROW && rowcount > targetmax) {
+				System.out.println("hit targetmax with " + rowcount + " " + d);
+				d = new Date();
+				mode = SHRINK;
+				reset_loops(myloops);
+				insertsize = 1;
+				deletesize = 12;
+				if (set_countlock(true) == true) {
+					System.out.println("t" + thread_id + " counting");
+					try {
+						checkrowcount(conn);
+						MemCheck.showmem();
+						status.updateStatus();
+					} catch (Exception e) {
+						System.out.println("unexpected exception in rowcount");
+						set_countlock(false);
+						System.exit(1);
+					}
+					MemCheck.showmem();
+				}
+				set_countlock(false);
+				yield();
+			} else if (mode == GROW && rowcount >= targetmax) {
+				d = new Date();
+				System.out.println("hit targetmax with " + rowcount + " " + d);
+				mode = SHRINK;
+				insertsize = 1;
+				deletesize = 12;
+			} else if (mode == SHRINK && rowcount <= targetmin) {
+				d = new Date();
+				System.out.println("hit targetmin with " + rowcount + " " + d);
+				mode = GROW;
+				reset_loops(myloops);
+				insertsize = 8;
+				deletesize = 1;
+				if (set_countlock(true) == true) {
+					System.out.println("t" + thread_id + " counting");
+					try {
+						checkrowcount(conn);
+						MemCheck.showmem();
+						status.updateStatus();
+					} catch (Exception e) {
+						System.out.println("unexpected exception in rowcount");
+						set_countlock(false);
+						System.exit(1);
+					}
+					MemCheck.showmem();
+				}
+				set_countlock(false);
+				yield();
+			}
+			// don't interfere with count query
+			while (get_countlock() == true) {
+				try {
+					sleep(1000);
+				} catch (java.lang.InterruptedException ex) {
+					System.out.println("unexpected sleep interruption");
+					break;
+				}
+			}
+			try {
+				System.out.println("Thread " + thread_id);
+				if (mode == INIT)
+					ind = 0;
+				else
+					ind = Math.abs(rand.nextInt() % 3);
+				System.out.println("ind=" + ind);
+				switch (ind) {
+				case 0:
+					ind2 = Math.abs(rand.nextInt() % insertsize);
+					System.out.println("t" + thread_id + " insert "
+							+ String.valueOf(ind2 + 1));
+					for (int i = 0; i <= ind2; i++) {
+						Datatypes.add_one_row(conn, thread_id);
+						conn.commit();
+						if (mode == INIT) {
+							inserts_to_try--;
+						}
+						yield();
+						changerowcount(1);
+					}
+					break;
+				case 1:
+					ind2 = Math.abs(rand.nextInt() % updatesize);
+					System.out.println("t" + thread_id + " update "
+							+ String.valueOf(ind2 + 1));
+					for (int i = 0; i <= ind2; i++) {
+						Datatypes.update_one_row(conn, thread_id);
+						conn.commit();
+						yield();
+					}
+					break;
+				case 2:
+					ind2 = Math.abs(rand.nextInt() % deletesize);
+					System.out.println("t" + thread_id + " delete "
+							+ String.valueOf(ind2 + 1));
+					int del_rows = 0;
+					del_rows = Datatypes.delete_some(conn, thread_id, ind2 + 1);
+					System.out.println("del_rows after calling delete_some:"
+							+ del_rows);
+					yield();
+					changerowcount(-1 * del_rows);
+					//commits are done inside delete_some()
+					break;
+				} //end switch
+				
+			} catch (SQLException se) {
+				if (se.getSQLState() == null)
+					se.printStackTrace();
+				if (se.getSQLState().equals("40001")) {
+					System.out.println("t" + thread_id + " deadlock op = "
+							+ ind);
+					continue;
+				}
+				if (se.getSQLState().equals("40XL1")) {
+					System.out
+					.println("t" + thread_id + " timeout op = " + ind);
+					continue;
+				}
+				if (se.getSQLState().equals("23500")) {
+					System.out.println("t" + thread_id
+							+ " duplicate key violation\n");
+					continue;
+				}
+				if (se.getSQLState().equals("23505")) {
+					System.out.println("t" + thread_id
+							+ " duplicate key violation\n");
+					continue;
+				}
+				System.out.println("t" + thread_id
+						+ " FAIL -- unexpected exception:");
+				JDBCDisplayUtil.ShowException(System.out, se);
+				fatal = true;
+				break;
+			} catch (Throwable e) {
+				e.printStackTrace();
+				if (e.getMessage().equals("java.lang.ThreadDeath")) {
+					System.out.println("caught threaddeath and continuing\n");
+				} else {
+					fatal = true;
+					e.printStackTrace();
+				}
+			}
+		}//end while
+		try {
+			conn.close();
+		} catch (Throwable e) {
+			e.printStackTrace();
+		}
+		System.out.println("Thread finished: " + thread_id);
+	}
+	
+	static synchronized void checkrowcount(Connection conn)
+	throws java.lang.Exception {
+		int x = Datatypes.get_table_count(conn);
+		if (x == -1) { // count timed itself out
+			System.out.println("table count timed out");
+		} else {
+			System.out.println("rowcount by select: " + x
+					+ " client rowcount = " + rowcount);
+			changerowcount(x - rowcount);
+		}
+		conn.commit();
+	}
+	
+	static public Connection mystartJBMS() throws Throwable {
+		Connection conn = null;
+		if (startByIJ == true) {
+			conn = ij.startJBMS();
+		} else
+			try {
+				conn = DriverManager.getConnection(dbURL + ";create=false");
+				conn.setAutoCommit(false);
+				conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+				System.out.println("got the connection in question");
+			} catch (SQLException se) {
+				System.out.println("connect failed  for " + dbURL);
+				JDBCDisplayUtil.ShowException(System.out, se);
+			}
+			return (conn);
+	}
+	
+	static synchronized void compress(Connection conn)
+	throws java.lang.Exception {
+		Statement s = null;
+		int tick = 1;
+		boolean locked = false;
+		while (locked == false) {
+			try {
+				s = conn.createStatement();
+				s.execute("lock table Datatypes in exclusive mode");
+				s.close();
+				locked = true;
+			} catch (SQLException se) {
+				// not now lockable
+				if (se.getSQLState().equals("X0X02")) {
+					Thread.sleep(20000);
+					if (tick++ < 10) {
+						System.out
+						.println("compress: cannot lock table, retrying "
+								+ tick + "\n");
+						continue;
+					} else {
+						System.out.println("compress timed out\n");
+						return;
+					}
+				} else
+					JDBCDisplayUtil.ShowException(System.out, se);
+			}
+		}
+		System.out.println("compressing table");
+		try {
+			s = conn.createStatement();
+			s.execute("alter table Datatypes compress");
+			conn.commit();
+			System.out.println("table compressed");
+		} catch (SQLException se) {
+			System.out.println("compress table: FAIL -- unexpected exception:");
+			JDBCDisplayUtil.ShowException(System.out, se);
+		}
+	}
+}
\ No newline at end of file

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

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

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/MemCheck.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/MemCheck.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/MemCheck.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/tools/MemCheck.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,62 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.sttest.MemCheck
+ * 
+ * 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.sttest.tools;
+
+import java.util.Date;
+
+public class MemCheck extends Thread {
+	int delay = 200000;
+	
+	public boolean stopNow = false;
+	
+	public MemCheck() {
+	}
+	
+	public MemCheck(int num) {
+		delay = num;
+	}
+	
+	public void run() {
+		while (stopNow == false) {
+			try {
+				showmem();
+				sleep(delay);
+			} catch (java.lang.InterruptedException ie) {
+				System.out.println("memcheck: unexpected error in sleep");
+			}
+		}
+	}
+	
+	public static void showmem() {
+		Runtime rt = null;
+		Date d = null;
+		rt = Runtime.getRuntime();
+		d = new Date();
+		System.out.println("total memory: " + rt.totalMemory() + " free: "
+				+ rt.freeMemory() + " " + d.toString());
+	}
+	
+	public static void main(String argv[]) {
+		System.out.println("MemCheck starting");
+		MemCheck mc = new MemCheck();
+		mc.run();
+	}
+}
\ No newline at end of file

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/CompressTable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/CompressTable.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/CompressTable.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/CompressTable.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,116 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.sttest.CompressTable
+ * 
+ * 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.sttest.utils;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Date;
+
+import org.apache.derby.tools.JDBCDisplayUtil;
+import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.system.sttest.tools.MemCheck;
+
+/**
+ * This class is used to compress the table to retrieve the space after deletion
+ */
+public class CompressTable {
+	
+	static boolean startByIJ = false;
+	
+	static String dbURL = "jdbc:derby:testDB";
+	
+	static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
+	
+	public static void main(String[] args) throws SQLException, IOException,
+	InterruptedException, Exception, Throwable {
+		Connection conn = null;
+		Date d = null;
+		
+		Class.forName(driver).newInstance();
+		
+		try {
+			conn = mystartJBMS();
+		} catch (Throwable t) {
+			return;
+		}
+		MemCheck mc = new MemCheck(200000);
+		mc.start();
+		compress(conn);
+		System.exit(0);
+	}
+	
+	static public Connection mystartJBMS() throws Throwable {
+		Connection conn = null;
+		if (startByIJ == true)
+			conn = ij.startJBMS();
+		else
+			try {
+				conn = DriverManager.getConnection(dbURL + ";create=false");
+				conn.setAutoCommit(false);
+			} catch (SQLException se) {
+				System.out.println("connect failed  for " + dbURL);
+				JDBCDisplayUtil.ShowException(System.out, se);
+			}
+			return (conn);
+	}
+	
+	static synchronized void compress(Connection conn)
+	throws java.lang.Exception {
+		Statement s = null;
+		int tick = 1;
+		boolean locked = false;
+		while (locked == false) {
+			try {
+				s = conn.createStatement();
+				s.execute("lock table Datatypes in exclusive mode");
+				s.close();
+				locked = true;
+			} catch (SQLException se) {
+				// not now lockable
+				if (se.getSQLState().equals("X0X02")) {
+					Thread.sleep(20000);
+					if (tick++ < 10) {
+						System.out
+						.println("compress: cannot lock table, retrying "
+								+ tick + "\n");
+						continue;
+					} else {
+						System.out.println("compress timed out\n");
+						return;
+					}
+				} else
+					JDBCDisplayUtil.ShowException(System.out, se);
+			}
+		}
+		System.out.println("compressing table");
+		try {
+			s = conn.createStatement();
+			s.execute("alter table Datatypes compress");
+			System.out.println("table compressed");
+		} catch (SQLException se) {
+			System.out.println("compress table: FAIL -- unexpected exception:");
+			JDBCDisplayUtil.ShowException(System.out, se);
+		}
+	}
+}
\ No newline at end of file

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Datatypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Datatypes.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Datatypes.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Datatypes.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,720 @@
+/*
+ 
+ Derby - Class org.apache.derbyTesting.system.sttest.Datatypes
+ 
+ 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.sttest.utils;
+
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Random;
+import java.util.Vector;
+import org.apache.derby.tools.JDBCDisplayUtil;
+
+
+/**
+ * This class is used to insert, delete and updated the rows
+ */
+public class Datatypes {
+	
+	public static final int TCHAR = 0;
+	
+	public static final int TBLOB = 1;
+	
+	public static final int TCLOB = 2;
+	
+	public static final int TDATE = 3;
+	
+	public static final int TDECIMAL = 4;
+	
+	public static final int TDECIMALNN = 5;
+	
+	public static final int TDOUBLE = 6;
+	
+	public static final int TFLOAT = 7;
+	
+	public static final int TINT = 8;
+	
+	public static final int TLONGINT = 9;
+	
+	public static final int TNUMERICLARGE = 10;
+	
+	public static final int TREAL = 11;
+	
+	public static final int TSMALLINT = 12;
+	
+	public static final int TTIME = 13;
+	
+	public static final int TTIMESTAMP = 14;
+	
+	public static final int TVARCHAR = 15;
+	
+	public static final int NUMTYPES = 15;
+	
+	static String[] fileName = new String[35];
+	
+	static String[] fileName1 = new String[35];
+	
+	static String[] fileName2 = new String[35];
+	
+	static long[] fileLength = { 16644, 65949, 65675, 65675, 9894, 26651,
+			37370, 9676, 32191, 26883, 52817, 34590, 59510, 52063, 19723, 9894,
+			10937, 12522, 10962, 29815, 13605, 1620, 13800, 14606, 10126,
+			14430, 21757, 7765, 11431, 14047, 10992, 20141, 11357, 8609, 23259 };
+	
+	static long[] fileLength1 = { 6285, 6944, 58937, 28225, 89773, 31076,
+			11577, 43729, 29501, 14044, 3258, 10590, 0, 2588, 3270, 3433, 4149,
+			2778, 1529, 6672, 1918, 1308, 1899, 6143, 6554, 15456, 16617, 571,
+			13657, 5000, 10000, 401, 401, 401, 401 };
+	
+	public static String[] colnames = { "t_char", "t_blob", "t_clob", "t_date",
+			"t_decimal", "t_decimal_nn", "t_double", "t_float", "t_int",
+			"t_longint", "t_numeric_large", "t_real", "t_smallint", "t_time",
+			"t_timestamp", "t_varchar"
+			
+	};
+	
+	public static Random rand;
+	
+	public static synchronized void add_one_row(Connection conn, int thread_id)
+	throws Exception {
+		try {
+			//initialize();
+			PreparedStatement ps = conn.prepareStatement(
+					" insert into Datatypes (id,t_char,t_blob," + "t_clob,"
+					+ " t_date, t_decimal, t_decimal_nn, t_double, "
+					+ " t_float, t_int, t_longint, t_numeric_large,"
+					+ " t_real, t_smallint, t_time, t_timestamp,"
+					+ " t_varchar) values ("
+					+ " ?,?, ?,?, ?, ?,?, ?, ?, ?,?, ?, ?, ?, ?, ?,?)" //autoincrement
+					// feature
+					// added,
+					// so
+					// we
+					// need
+					// to
+					// specify
+					// the
+					// column
+					// name
+					// for prepared statement, otherwise auto increment
+					// column will think
+					// it is trying to update/insert a null value to the column.
+					, Statement.RETURN_GENERATED_KEYS);
+			int ind = rand.nextInt();
+			int id_ind = ind;
+			double x;
+			Date dt = new Date(1);
+			Time tt = new Time(1);
+			Timestamp ts = new Timestamp(1);
+			String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
+			boolean bo = false;
+			Vector vec = null;
+			Integer ji = null;
+			ps.setInt(1, ind);
+			// scramble the string
+			int i1 = Math.abs(ind % 100);
+			String cs2 = cs.substring(i1, 99) + cs.substring(0, i1);
+			int i2 = i1 < 89 ? i1 + 10 : i1;
+			ps.setString(2, cs2.substring(0, i2));
+			//"t_blob"
+			int j = (int) (Math.random() * 35);
+			fileName[j] = "p" + j + ".jpg";
+			InputStream fileIn = Datatypes.class
+			.getResourceAsStream(fileName[j]);
+			ps.setBinaryStream(3, fileIn, (int) fileLength[j]);
+			//"t_clob
+			int k = (int) (Math.random() * 35);
+			fileName1[k] = "t" + k + ".txt";
+			InputStream fileIn1 = Datatypes.class
+			.getResourceAsStream(fileName1[k]);
+			ps.setAsciiStream(4, fileIn1, (int) fileLength1[k]);
+			//"t_ndate"
+			dt.setTime(Math.abs(rand.nextLong() / 150000));
+			ps.setDate(5, dt);
+			//"t_decimal"
+			x = Math.abs(rand.nextInt() % 18);
+			if (x > 5)
+				x = 5;
+			ps.setDouble(6, Math.abs(rand.nextDouble() * Math.pow(10, x)));
+			//"t_decimal_nn"
+			ps.setDouble(7, rand.nextDouble());
+			//"t_double"
+			ps.setDouble(8, rand.nextDouble()
+					* Math.pow(10, Math.abs(rand.nextInt() % 300)));
+			//"t_float"
+			ps.setFloat(9, rand.nextFloat()
+					* (float) Math.pow(10, Math.abs(rand.nextInt() % 30)));
+			//"t_int"
+			ps.setInt(10, rand.nextInt());
+			//"t_longint"
+			ps.setLong(11, rand.nextLong());
+			//"t_numeric_large"
+			x = Math.abs(rand.nextInt() % 30);
+			if (x > 30)
+				x = 31;
+			ps.setDouble(12, Math.abs(rand.nextDouble() * Math.pow(10, x)));
+			//"t_real"
+			ps.setFloat(13, rand.nextFloat()
+					* (float) Math.pow(10, Math.abs(rand.nextInt() % 7)));
+			//"t_smallint"
+			ps.setInt(14, rand.nextInt() % (256 * 128));
+			//"t_time"
+			tt.setTime(Math.abs(rand.nextInt()));
+			ps.setTime(15, tt);
+			//"t_timestamp"
+			ts.setTime(Math.abs(rand.nextLong() / 50000));
+			ps.setTimestamp(16, ts);
+			//"t_varchar"
+			ps.setString(17, cs.substring(Math.abs(rand.nextInt() % 100)));
+			int rows = ps.executeUpdate();
+			if (rows == 1) {
+				
+				System.out.println("t" + thread_id + " inserted row with id "
+						+ id_ind);
+				ResultSet rs = ps.getGeneratedKeys();
+				
+				while (rs.next()) {
+					ResultSetMetaData rsmd = rs.getMetaData();
+					int numCols = rsmd.getColumnCount();
+				}
+			} else
+				System.out.println("t" + thread_id + " insert failed");
+			
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+		}
+	}
+	
+	//pick quantity number of rows randomly and delete them
+	public static int delete_some(Connection conn, int thread_id, int quantity)
+	throws Exception {
+		PreparedStatement ps = null;
+		int list[] = pick_some(conn, thread_id, quantity);
+		//delete them
+		int rows = 0;
+		try {
+			ps = conn.prepareStatement(" delete from  Datatypes where id = ?");
+			for (int i = 0; i < quantity; i++) {
+				ps.setInt(1, list[i]);
+				rows += ps.executeUpdate();
+				System.out.println("t" + thread_id + " deleted "
+						+ " row with id " + list[i]);
+			}
+			if (ps != null)
+				ps.close();
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+			return (rows);
+		}
+		// all deletes in a single transaction, to force some overlap of
+		// transactions
+		// by different threads
+		conn.commit();
+		return (rows);
+	}
+	
+	//get a random set of row ids
+	public static int[] pick_some(Connection conn, int thread_id, int quantity)
+	throws Exception {
+		System.out.println("quantity in pick_some is: " + quantity);
+		int ind = 0;
+		PreparedStatement ps = null;
+		ResultSet rs = null;
+		//pick the rows
+		try {
+			ps = conn
+			.prepareStatement(" select id from  Datatypes where id = ?");
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+			return (null);
+		}
+		int list[] = new int[quantity];
+		int j = 0;
+		for (int i = 0; i < quantity; i++) {
+			ind = rand.nextInt();
+			try {
+				ps.setInt(1, ind);
+				rs = ps.executeQuery();
+				if (rs.next()) {
+					//keep trying till we get a good one
+					j = rs.getInt(1);
+					if (rs.wasNull()) {
+						System.out.println("rs.wasNull() ind is " + ind);
+						i--;
+						continue;
+					}
+					list[i] = j;
+					
+					System.out.println("list[1] in picksome=:" + list[i]);
+				} else {
+					System.out.println("thread " + thread_id
+							+ ", select for delete: no row found");
+				}
+				//don't worry about consistency; if row with this id
+				//gets changed by another thread we will just forge ahead;
+				//otherwise we gets lots of deadlocks
+				conn.commit();
+			} catch (SQLException se) {
+				if (se.getNextException() == null)
+					throw se;
+				String m = se.getNextException().getSQLState();
+				System.out.println(se.getNextException().getMessage()
+						+ " SQLSTATE: " + m);
+				return (null);
+			}
+		}
+		if (rs != null)
+			rs.close();
+		if (ps != null)
+			ps.close();
+		return (list);
+	}
+	
+	public static void delete_one_row(Connection conn, int thread_id)
+	throws Exception {
+		
+		PreparedStatement ps = null;
+		PreparedStatement ps2 = null;
+		String column = null;
+		int ind = 0;
+		ResultSet rs = null;
+		ind = Math.abs(rand.nextInt());
+		while (ind % NUMTYPES == TDECIMAL || ind % NUMTYPES == TVARCHAR
+				|| ind % NUMTYPES == TCHAR)
+			ind = Math.abs(rand.nextInt());
+		column = colnames[ind % NUMTYPES];
+		try {
+			ps = conn.prepareStatement(" select cast (max (" + column + ") as "
+					+ " char(120)) from Datatypes where " + column + " <= ? ");
+			ps2 = conn.prepareStatement(" delete from  Datatypes where "
+					+ column + " = ?");
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+			return;
+		}
+		String ds = null;
+		String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
+		double d = 0.0;
+		float f = 0;
+		BigDecimal bdec = null;
+		switch (ind % NUMTYPES) {
+		case TCHAR:
+			ds = cs.substring(Math.abs(rand.nextInt() % 100));
+			ps.setString(1, ds);
+			break;
+		case TDATE:
+			Date dt = new Date(1);
+			dt.setTime(Math.abs(rand.nextLong() / 150000));
+			ps.setString(1, dt.toString());
+			ds = dt.toString();
+			break;
+		case TDECIMAL:
+			d = rand.nextDouble() * Math.pow(10, rand.nextInt() % 18);
+			bdec = new BigDecimal(d);
+			ps.setString(1, String.valueOf(bdec));
+			ds = String.valueOf(d);
+			break;
+		case TDECIMALNN:
+			d = rand.nextDouble();
+			bdec = new BigDecimal(d);
+			ps.setString(1, String.valueOf(bdec));
+			ds = String.valueOf(d);
+			break;
+		case TDOUBLE:
+			d = rand.nextDouble() * Math.pow(10, rand.nextInt() % 300);
+			ps.setString(1, String.valueOf(d));
+			ds = String.valueOf(d);
+			break;
+		case TFLOAT:
+			f = rand.nextFloat() * (float) Math.pow(10, rand.nextInt() % 30);
+			ps.setString(1, String.valueOf(f));
+			ds = String.valueOf(f);
+			break;
+		case TINT:
+			ps.setString(1, String.valueOf(rand.nextInt()));
+			ds = String.valueOf(rand.nextInt());
+			break;
+		case TLONGINT:
+			ps.setString(1, String.valueOf(rand.nextLong()));
+			ds = String.valueOf(rand.nextLong());
+			break;
+		case TNUMERICLARGE:
+			d = rand.nextDouble() * Math.pow(10, rand.nextInt() % 50);
+			bdec = new BigDecimal(d);
+			ps.setString(1, String.valueOf(bdec));
+			ds = String.valueOf(d);
+			break;
+		case TREAL:
+			f = rand.nextFloat() * (float) Math.pow(10, rand.nextInt() % 7);
+			ps.setString(1, String.valueOf(f));
+			ds = String.valueOf(f);
+			break;
+		case TSMALLINT:
+			int i = rand.nextInt() % (256 * 128);
+			ps.setString(1, String.valueOf(i));
+			ds = String.valueOf(i);
+			break;
+		case TTIME:
+			Time tt = new Time(1);
+			tt.setTime(Math.abs(rand.nextInt()));
+			ps.setString(1, "time'" + tt.toString() + "'");
+			ds = "time'" + tt.toString() + "'";
+			break;
+		case TTIMESTAMP:
+			Timestamp ts = new Timestamp(1);
+			ts.setTime(Math.abs(rand.nextLong() / 50000));
+			ps.setString(1, "timestamp'" + ts.toString() + "'");
+			ds = "timestamp'" + ts.toString() + "'";
+			break;
+		case TVARCHAR:
+			ds = cs.substring(Math.abs(rand.nextInt() % 100));
+			ps.setString(1, ds);
+			break;
+		}
+		System.out.println("t" + thread_id + " delete " + column
+				+ " select seed " + ds);
+		String ds3 = null;
+		String ds4 = null;
+		int rows = 0;
+		boolean cleanuponly = false;
+		try {
+			rs = ps.executeQuery();
+			if (rs.next()) {
+				ds3 = rs.getString(1);
+				if (rs.wasNull()) {
+					cleanuponly = true;
+				} else {
+					ds4 = ds3.trim();
+					ds3 = ds4;
+				}
+			}
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+		}
+		if (ps != null)
+			try {
+				ps.close();
+			} catch (SQLException se) {
+				if (se.getNextException() == null)
+					throw se;
+				String m = se.getNextException().getSQLState();
+				System.out.println(se.getNextException().getMessage()
+						+ " SQLSTATE: " + m);
+			}
+			if (rs != null)
+				try {
+					rs.close();
+				} catch (SQLException se) {
+					if (se.getNextException() == null)
+						throw se;
+					String m = se.getNextException().getSQLState();
+					System.out.println(se.getNextException().getMessage()
+							+ " SQLSTATE: " + m);
+				}
+				if (cleanuponly == false) {
+					System.out.println("t" + thread_id + " delete where " + column
+							+ " = " + ds3);
+					try {
+						ps2.setString(1, ds3);
+						rows = ps2.executeUpdate();
+						
+					} catch (SQLException se) {
+						if (se.getNextException() == null)
+							throw se;
+						String m = se.getNextException().getSQLState();
+						System.out.println(se.getNextException().getMessage()
+								+ " SQLSTATE: " + m);
+					}
+					
+					if (rows > 0)
+						System.out.println("t" + thread_id + " deleted " + rows
+								+ " row(s)");
+					else
+						System.out.println("t" + thread_id + " delete failed.");
+				}
+				if (ps2 != null)
+					try {
+						ps2.close();
+					} catch (SQLException se) {
+						if (se.getNextException() == null)
+							throw se;
+						String m = se.getNextException().getSQLState();
+						System.out.println(se.getNextException().getMessage()
+								+ " SQLSTATE: " + m);
+					}
+	}
+	
+	public static synchronized void update_one_row(Connection conn,
+			int thread_id) throws Exception {
+		PreparedStatement ps2 = null;
+		Statement stmt = conn.createStatement();
+		ResultSet rs;
+		String column = null;
+		int ind = 0;
+		long max = 0;
+		long min = 0;
+		double x;
+		long id_to_update;
+		rs = stmt.executeQuery("select max(serialkey) from Datatypes");
+		while (rs.next())
+			max = rs.getLong(1);
+		rs = stmt.executeQuery("select min(serialkey) from Datatypes");
+		while (rs.next())
+			min = rs.getLong(1);
+		id_to_update = (min + 1) + (Math.abs(rand.nextLong()) % (max - min));
+		if (id_to_update == 0)
+			id_to_update = 1;
+		ind = Math.abs(rand.nextInt());
+		column = colnames[ind % NUMTYPES];
+		try {
+			conn
+			.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+			ps2 = conn.prepareStatement(" update Datatypes set " + column
+					+ " = ? " + " where serialkey = " + id_to_update);
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			return;
+		}
+		String ds = null;
+		String ds2 = null;
+		String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
+		double d = 0.0;
+		float f = 0;
+		BigDecimal bdec = null;
+		int type = (ind % NUMTYPES);
+		int ji = 0;
+		boolean bo = false;
+		switch (type) {
+		case TCHAR:
+			ds2 = cs.substring(Math.abs(rand.nextInt() % 100));
+			ps2.setString(1, ds2);
+			break;
+		case TDATE:
+			Date dt = new Date(1);
+			dt.setTime(Math.abs(rand.nextLong() / 150000));
+			dt.setTime(Math.abs(rand.nextLong() / 150000));
+			ps2.setDate(1, dt);
+			ds2 = dt.toString();
+			break;
+		case TDECIMAL:
+			x = Math.abs(rand.nextInt() % 18);
+			if (x > 5)
+				x = 5;
+			d = rand.nextDouble() * Math.pow(10, x);
+			bdec = new BigDecimal(d);
+			ps2.setBigDecimal(1, bdec);
+			ds2 = String.valueOf(d);
+			break;
+		case TDECIMALNN:
+			ds = String.valueOf(d);
+			d = rand.nextDouble();
+			bdec = new BigDecimal(d);
+			ps2.setBigDecimal(1, bdec);
+			ds2 = String.valueOf(d);
+			break;
+			
+		case TDOUBLE:
+			d = rand.nextDouble() * Math.pow(10, rand.nextInt() % 300);
+			ps2.setDouble(1, d);
+			ds2 = String.valueOf(d);
+			break;
+		case TFLOAT:
+			ds = String.valueOf(f);
+			f = rand.nextFloat() * (float) Math.pow(10, rand.nextInt() % 30);
+			ps2.setFloat(1, f);
+			ds2 = String.valueOf(f);
+			break;
+		case TINT:
+			int i = rand.nextInt();
+			ds2 = String.valueOf(i);
+			ps2.setInt(1, i);
+			break;
+		case TLONGINT:
+			long l = rand.nextLong();
+			ds2 = String.valueOf(l);
+			ps2.setLong(1, l);
+			break;
+		case TNUMERICLARGE:
+			ds = String.valueOf(d);
+			x = Math.abs(rand.nextInt() % 30);
+			if (x > 30)
+				x = 31;
+			d = rand.nextDouble() * Math.pow(10, x);
+			bdec = new BigDecimal(d);
+			ps2.setBigDecimal(1, bdec);
+			ds2 = String.valueOf(d);
+			break;
+		case TREAL:
+			ds = String.valueOf(f);
+			f = rand.nextFloat() * (float) Math.pow(10, rand.nextInt() % 7);
+			ps2.setFloat(1, f);
+			ds2 = String.valueOf(f);
+			break;
+		case TSMALLINT:
+			i = rand.nextInt() % (256 * 128);
+			ds = String.valueOf(i);
+			short si = (short) i;
+			ps2.setShort(1, si);
+			ds2 = String.valueOf(si);
+			break;
+		case TTIME:
+			Time tt = new Time(1);
+			tt.setTime(Math.abs(rand.nextInt()));
+			ps2.setTime(1, tt);
+			ds2 = tt.toString();
+			break;
+		case TTIMESTAMP:
+			Timestamp ts = new Timestamp(1);
+			ts.setTime(Math.abs(rand.nextLong() / 50000));
+			ps2.setTimestamp(1, ts);
+			ds2 = ts.toString();
+			break;
+		case TVARCHAR:
+			ds2 = cs.substring(Math.abs(rand.nextInt() % 100));
+			ps2.setString(1, ds2);
+			break;
+		case TBLOB:
+			int j = (int) (Math.random() * 35);
+			fileName[j] = "p" + j + ".jpg";
+			InputStream fileIn = Datatypes.class
+			.getResourceAsStream(fileName[j]);
+			ps2.setBinaryStream(1, fileIn, (int) fileLength[j]);
+			break;
+		case TCLOB:
+			int k = (int) (Math.random() * 35);
+			fileName1[k] = "t" + k + ".txt";
+			InputStream fileIn1 = Datatypes.class
+			.getResourceAsStream(fileName1[k]);
+			ps2.setAsciiStream(1, fileIn1, (int) fileLength1[k]);
+			break;
+		}
+		int rows = 0;
+		boolean cleanuponly = false;
+		if (cleanuponly == false) {
+			System.out.println("t" + thread_id + " update " + column);
+			try {
+				rows = ps2.executeUpdate();
+				
+			} catch (SQLException se) {
+				if (se.getNextException() == null)
+					throw se;
+				String m = se.getNextException().getSQLState();
+				System.out.println(se.getNextException().getMessage()
+						+ " SQLSTATE: " + m);
+			}
+			if (rows > 0)
+				System.out.println("t" + thread_id + " updated 1 row with id "
+						+ id_to_update);
+			else
+				System.out.println("t" + thread_id + " update failed.");
+		}
+		if (ps2 != null)
+			try {
+				ps2.close();
+				rs.close();
+			} catch (SQLException se) {
+				if (se.getNextException() == null)
+					throw se;
+				String m = se.getNextException().getSQLState();
+				System.out.println(se.getNextException().getMessage()
+						+ " SQLSTATE: " + m);
+			}
+	}
+	
+	public static synchronized int get_table_count(Connection conn)
+	throws Exception {
+		PreparedStatement ps = null;
+		ResultSet rs = null;
+		int rows = 0;
+		boolean locked = false;
+		int tick = 1;
+		while (locked == false) {
+			try {
+				Statement s = conn.createStatement();
+				s.execute("lock table Datatypes in exclusive mode");
+				s.close();
+				locked = true;
+			} catch (SQLException se) {
+				// not now lockable
+				if (se.getSQLState().equals("X0X02")) {
+					Thread.sleep(20000);
+					if (tick++ < 60) {
+						System.out
+						.println("count: cannot lock table, retrying "
+								+ tick + "\n");
+						continue;
+					} else {
+						System.out.println("count timed out\n");
+						return (-1);
+					}
+				} else
+					JDBCDisplayUtil.ShowException(System.out, se);
+			}
+		}
+		try {
+			ps = conn.prepareStatement(" select count (*) from Datatypes ");
+			rs = ps.executeQuery();
+			if (rs.next())
+				rows = rs.getInt(1);
+			if (ps != null)
+				ps.close();
+		} catch (SQLException se) {
+			if (se.getNextException() == null)
+				throw se;
+			String m = se.getNextException().getSQLState();
+			System.out.println(se.getNextException().getMessage()
+					+ " SQLSTATE: " + m);
+		}
+		System.out.println("rows in calling initial_data()" + rows);
+		locked = true;
+		return (rows);
+	}
+}
\ No newline at end of file

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Setup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Setup.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Setup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/Setup.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,119 @@
+/*
+ 
+ Derby - Class org.apache.derbyTesting.system.sttest.Setup
+ 
+ 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.sttest.utils;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.derby.tools.JDBCDisplayUtil;
+
+/**
+ * creates database and builds single user table with indexes
+ */
+public class Setup {
+	public static boolean doit(String dbURL) throws Throwable {
+		Connection conn = null;
+		Statement s = null;
+		ResultSet rs = null;
+		boolean finished = false;
+		System.out.println("dbsetup start");
+		try {
+			conn = DriverManager.getConnection(dbURL + ";create=true");
+			conn.setAutoCommit(false);
+			conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+		} catch (SQLException se) {
+			System.out.println("connect failed for " + dbURL);
+			JDBCDisplayUtil.ShowException(System.out, se);
+			return (false);
+		}
+		try {
+			s = conn.createStatement();
+			rs = s.executeQuery("select tablename from sys.systables "
+					+ " where tablename = 'DATATYPES'");
+			if (rs.next()) {
+				rs.close();
+				System.out.println("table 'DATATYPES' already exists");
+				finished = true;
+			}
+		} catch (SQLException se) {
+			System.out.println("create table: FAIL -- unexpected exception:");
+			JDBCDisplayUtil.ShowException(System.out, se);
+			return (false);
+		}
+		if (finished == false)
+			try {
+				System.out.println("creating table 'DATATYPES'");
+				s
+				.execute("create 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),"
+						+ "unique (serialkey), " + "unique (id))");
+				s.execute("create index t_char_ind on Datatypes ( t_char)");
+				s.execute("create index t_date_ind on Datatypes ( t_date)");
+				s
+				.execute("create index t_decimal_ind on Datatypes ( t_decimal)");
+				s
+				.execute("create index t_decimal_nn_ind on Datatypes ( t_decimal_nn)");
+				s.execute("create index t_double_ind on Datatypes ( t_double)");
+				s.execute("create index t_float_ind on Datatypes ( t_float)");
+				s.execute("create index t_int_ind on Datatypes ( t_int)");
+				s
+				.execute("create index t_longint_ind on Datatypes ( t_longint)");
+				s
+				.execute("create index t_numeric_larg_ind on Datatypes ( t_numeric_large)");
+				s.execute("create index t_real_ind on Datatypes ( t_real)");
+				s
+				.execute("create index t_smallint_ind on Datatypes ( t_smallint)");
+				s.execute("create index t_time_ind on Datatypes ( t_time)");
+				s
+				.execute("create index t_timestamp_ind on Datatypes ( t_timestamp)");
+				s
+				.execute("create index t_varchar_ind on Datatypes ( t_varchar)");
+				conn.commit();
+				conn.close();
+			} catch (SQLException se) {
+				System.out
+				.println("create table: FAIL -- unexpected exception:");
+				JDBCDisplayUtil.ShowException(System.out, se);
+				return (false);
+			}
+			return (true);
+	}
+}
\ No newline at end of file

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/StStatus.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/StStatus.java?view=auto&rev=501639
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/StStatus.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/sttest/utils/StStatus.java Tue Jan 30 15:27:51 2007
@@ -0,0 +1,72 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.sttest.StStatus
+ * 
+ * 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.sttest.utils;
+
+/**
+ * This class is used to give the information about the memory status
+ */
+import java.util.Date;
+import java.io.*;
+
+public class StStatus {
+	static final int messageCount = 20;
+	
+	int cycles = 0;
+	
+	int currentThreads = 0;
+	
+	int currentMessage = 0;
+	
+	public String firstMessage = null;
+	
+	public String[] messages;
+	
+	public StStatus() {
+		messages = new String[messageCount];
+	}
+	
+	public void firstMessage(int Threadcount, Date d) {
+		currentThreads = Threadcount;
+		firstMessage = "starting: " + d.toString() + " threads: "
+		+ currentThreads;
+	}
+	
+	public void updateStatus() throws IOException {
+		Date d = new Date();
+		cycles++;
+		int counter = currentMessage % messageCount;
+		Runtime rt = Runtime.getRuntime();
+		messages[counter] = "Total memory: " + rt.totalMemory()
+		+ " free memory: " + rt.freeMemory() + " cycles: " + cycles
+		+ " threads: " + currentThreads + " " + d;
+		currentMessage++;
+		//overwrite messages file with current set of messages
+		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
+		"Sttest.log")));
+		out.println(firstMessage);
+		for (int i = 0; i < messageCount; i++) {
+			if (messages[i] != null)
+				out.println(messages[i]);
+		}
+		out.flush();
+		out.close();
+	}
+}
\ No newline at end of file

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



Mime
View raw message