package stress; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.net.URL; import java.net.URLClassLoader; import java.sql.*; import java.util.ArrayList; import java.util.Properties; public class TestSQLStatementsMultiThreaded { static final String stresdata_tb = "data"; static final String createtbl_prefix = "CREATE TABLE "+stresdata_tb+" (\n" +" id int(11) NOT NULL default '0',\n" +" t int(11) NOT NULL default '0',\n" +" myvarchar varchar(64) default NULL,\n" +" mytext text default NULL,\n" ; static final String fielddef = " bigint(20) NOT NULL default '0',\n"; //static final String createtbl_suffix = " PRIMARY KEY (id,t)\n" + ") TYPE=MyISAM;"; static final String createtbl_suffix = " PRIMARY KEY (id,t)\n" + ") TYPE=InnoDB;"; public static void main(String[] args) throws Exception { if(args.length<1) { System.err.println(" [nf [nid [ntests [nbatches]]]]"); System.exit(1); } int ai=0; String filename = args[ai++]; boolean doPS = Boolean.valueOf(args.length > ai ? args[ai++] : "true").booleanValue(); int NF = Integer.parseInt(args.length > ai ? args[ai++] : "200"); //different fields int N_ID = Integer.parseInt(args.length > ai ? args[ai++] : "50"); //different ids int NTBB = Integer.parseInt(args.length > ai ? args[ai++] : "10"); //tests for each id, per batch int NB = Integer.parseInt(args.length > ai ? args[ai++] : "5"); //batches int NUMTESTS = NB * NTBB; //------ Properties props = new Properties(); props.load(new FileInputStream(filename)); props.store(new FileOutputStream(FileDescriptor.err), "config file: "+filename); System.err.println("------------"); String user = (String)props.remove("user"); String pwd = (String)props.remove("pwd"); String path = (String)props.remove("path"); String url = (String)props.remove("url"); String driverclass = (String)props.remove("driverclass"); String spaths = (String)props.remove("paths"); File[] paths = null; if(spaths!=null) { String[] sa = spaths.split(","); paths = new File[sa.length]; for (int i = 0; i < sa.length; i++) { paths[i] = new File(sa[i]); } } props.store(new FileOutputStream(FileDescriptor.out), "actual parameters"); System.out.println("------------"); Connection[] conn = new Connection[N_ID]; try { ArrayList ulist = new ArrayList(); File f = new File(path.replace('/', File.separatorChar)); System.out.println(f + " : " + f.exists()); ulist.add(f.toURL()); if (paths != null) { for (int i = 0; i < paths.length; i++) { ulist.add(paths[i].toURL()); } } URL[] ua = (URL[])ulist.toArray(new URL[ulist.size()]); for (int i = 0; i < ua.length; i++) { System.out.println("url classpath: " + ua[i]); } URLClassLoader uc = new URLClassLoader(ua); Driver d = (Driver)uc.loadClass(driverclass).newInstance(); props.setProperty("user", user); if (pwd != null) props.setProperty("password", pwd); //conn = d.connect(url, props); for(int i = 0; i < conn.length; i++ ) { conn[i] = d.connect(url, props); } //------------------------------- prepareDB(conn[0], NF); //testGetMetadataAndClose(conn); workIt(conn, NF, N_ID, NUMTESTS); //workItBatch(conn[0], NF, N_ID, NTBB, NB); //------------------------------- } catch (Exception e) { e.printStackTrace(); } finally { for(int i=0; i