private int selectInsteadOfUpdatePct = 25;\r
private int rollbackChancePct = 15;\r
private int maxTables = 0;\r
+ public static boolean[] threadsDone;\r
+\r
\r
private boolean sequentialIds = false;\r
private static Integer currentId = -1;\r
private static final List<String> defaultTableNames = Arrays.asList(new String[] {"persons", "persons2"});\r
\r
private boolean explainConnection = true;\r
+ private boolean endInSelect = true;\r
\r
public static class Employee {\r
public final int empid;\r
\r
doLog("");\r
}\r
+ threadsDone[threadId] = true;\r
\r
+ if (endInSelect) {\r
+ doLog("Ending in select to ensure all db's are in sync");\r
+ while (!allThreadsDone()) {\r
+ try {\r
+ Thread.sleep(1000);\r
+ } catch (InterruptedException e) {\r
+ continue;\r
+ }\r
+ }\r
+ doLog("All threads are done. Ending in select");\r
+ if (connection==null) {\r
+ try {\r
+ doLog("Opening new connection");\r
+ connection = DriverManager.getConnection(connectionString);\r
+ connection.setAutoCommit(false);\r
+ } catch (SQLException e) {\r
+ e.printStackTrace();\r
+ return;\r
+ }\r
+ }\r
+ for (String tableName : tableNames) {\r
+ try {\r
+ Statement querySt = connection.createStatement();\r
+ ResultSet rs = executeQueryTimed("select * from " + tableName, querySt, false);\r
+ while (rs.next()) {\r
+ // doLog("PersonId = " + rs.getInt("personId") + ", lastname = " + rs.getString("lastname") + ", firstname = " + rs.getString("firstname"));\r
+ Employee emp = new Employee(rs.getInt("personId"), rs.getString("lastname"), rs.getString("firstname"), rs.getString("address"), rs.getString("city"));\r
+ doLog("Found: " + emp);\r
+ }\r
+ querySt.close();\r
+ } catch (SQLException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ \r
if (connection!=null) {\r
try {\r
doLog("Closing connection at end");\r
doLog("All done.");\r
}\r
\r
- private void doLog(String string) {\r
+ private boolean allThreadsDone() {\r
+ for (Boolean b: this.threadsDone) {\r
+ if (!b) {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+\r
+ private void doLog(String string) {\r
System.out.println(">> Thread " + threadId + " " + sdf.format(new java.util.Date()) + " >> " + string);\r
}\r
\r
- public static void main(String[] args) {\r
+ public static void main(String[] args) throws InterruptedException {\r
MdbcTestMultiClient mtc = new MdbcTestMultiClient(args);\r
mtc.runTests(); \r
}\r
\r
- private void runTests() {\r
+ private void runTests() throws InterruptedException {\r
if (randomSeed==null) {\r
randomSeed = new Random().nextLong();\r
}\r
doLog("Using random seed = " + randomSeed);\r
Random seedRandom = new Random(randomSeed);\r
+ this.threadsDone = new boolean[connectionStrings.size()];\r
+\r
for (int i=0; i<connectionStrings.size(); i++) {\r
MdbcTestMultiClient mt = new MdbcTestMultiClient(this, i);\r
mt.setRandomSeed(seedRandom.nextLong());\r
Thread t = new Thread(mt);\r
t.start();\r
}\r
+ \r
}\r
\r
}\r