}
}
System.out.println("#Started; driver: " + driver + " url: " + url + " user: " + user + " password: " + password);
try {
System.out.println("#Starting...");
Random random = new Random();
boolean wasRunning = false;
for (int i = 0; i < 3000; i++) {
if (i > 1000 && connections.size() > 1 && tables.size() > 1) {
System.out.println("#Running connections: " + connections.size() + " tables: " + tables.size());
wasRunning = true;
}
if (connections.size() < 1) {
openConnection();
}
if (tables.size() < 1) {
createTable(random);
}
int p = random.nextInt(100);
if ((p -= 2) <= 0) {
// 2%: open new connection
if (connections.size() < 5) {
openConnection();
}
} else if ((p -= 1) <= 0) {
// 1%: close connection
if (connections.size() > 1) {
Connection conn = connections.remove(random.nextInt(connections.size()));
if (random.nextBoolean()) {
conn.close();
}
}
} else if ((p -= 10) <= 0) {
// 10% create table
createTable(random);
} else if ((p -= 20) <= 0) {
// 20% large insert, delete, or update
if (tables.size() > 0) {
Connection conn = connections.get(random.nextInt(connections.size()));
Statement stat = conn.createStatement();
String table = tables.get(random.nextInt(tables.size()));
if (random.nextBoolean()) {
// 10% insert
stat.execute("INSERT INTO " + table + "(NAME) SELECT 'Hello ' || X FROM SYSTEM_RANGE(0, 20)");
} else if (random.nextBoolean()) {
// 5% update
stat.execute("UPDATE " + table + " SET NAME='Hallo Welt'");
} else {
// 5% delete
stat.execute("DELETE FROM " + table);
}
}
} else if ((p -= 5) < 0) {
// 5% truncate or drop table
if (tables.size() > 0) {
Connection conn = connections.get(random.nextInt(connections.size()));
Statement stat = conn.createStatement();
String table = tables.get(random.nextInt(tables.size()));
if (random.nextBoolean()) {
stat.execute("TRUNCATE TABLE " + table);
} else {
stat.execute("DROP TABLE " + table);
System.out.println("#Info table dropped: " + table);
tables.remove(table);
}
}
} else if ((p -= 30) <= 0) {
// 30% insert
if (tables.size() > 0) {
Connection conn = connections.get(random.nextInt(connections.size()));
Statement stat = conn.createStatement();
String table = tables.get(random.nextInt(tables.size()));
stat.execute("INSERT INTO " + table + "(NAME) VALUES('Hello World')");
}
} else {
// 32% delete
if (tables.size() > 0) {
Connection conn = connections.get(random.nextInt(connections.size()));
Statement stat = conn.createStatement();
String table = tables.get(random.nextInt(tables.size()));
stat.execute("DELETE FROM " + table + " WHERE ID = SELECT MIN(ID) FROM " + table);
}
}
}
System.out.println("#Fail: end " + wasRunning);