提交 572abc02 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 b4f64a3d
......@@ -55,9 +55,9 @@ public class ShowProgress implements DatabaseEventListener {
time = System.currentTimeMillis();
int len = 1000;
for (int i = 0; i < len; i++) {
long last = System.currentTimeMillis();
if (last > time + 1000) {
time = last;
long now = System.currentTimeMillis();
if (now > time + 1000) {
time = now;
System.out.println("Inserting " + (100L * i / len) + "%");
}
prep.setInt(1, i);
......
......@@ -22,16 +22,16 @@ public class BenchA implements Bench {
private static final String FILLER = "abcdefghijklmnopqrstuvwxyz";
private static final int DELTA = 10000;
private Database db;
private Database database;
private int branches;
private int tellers;
private int accounts;
private int size;
private int transactions;
public void init(Database db, int size) throws SQLException {
this.db = db;
this.size = size;
this.database = db;
transactions = size * 30;
int scale = 1;
accounts = size * 50;
......@@ -100,32 +100,31 @@ public class BenchA implements Bench {
public void runTest() throws SQLException {
db.start(this, "Transactions");
db.openConnection();
database.start(this, "Transactions");
database.openConnection();
processTransactions();
db.closeConnection();
db.end();
database.closeConnection();
database.end();
db.openConnection();
database.openConnection();
processTransactions();
db.logMemory(this, "Memory Usage");
db.closeConnection();
database.logMemory(this, "Memory Usage");
database.closeConnection();
}
private void processTransactions() throws SQLException {
Random random = db.getRandom();
Random random = database.getRandom();
int branch = random.nextInt(branches);
int teller = random.nextInt(tellers);
int transactions = size * 30;
PreparedStatement updateAccount = db.prepare("UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
PreparedStatement selectBalance = db.prepare("SELECT ABALANCE FROM ACCOUNTS WHERE AID=?");
PreparedStatement updateTeller = db.prepare("UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?");
PreparedStatement updateBranch = db.prepare("UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?");
PreparedStatement insertHistory = db.prepare("INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)");
PreparedStatement updateAccount = database.prepare("UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
PreparedStatement selectBalance = database.prepare("SELECT ABALANCE FROM ACCOUNTS WHERE AID=?");
PreparedStatement updateTeller = database.prepare("UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?");
PreparedStatement updateBranch = database.prepare("UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?");
PreparedStatement insertHistory = database.prepare("INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)");
int accountsPerBranch = accounts / branches;
db.setAutoCommit(false);
database.setAutoCommit(false);
for (int i = 0; i < transactions; i++) {
int account;
......@@ -142,18 +141,18 @@ public class BenchA implements Bench {
updateAccount.setBigDecimal(1, delta);
updateAccount.setInt(2, account);
db.update(updateAccount, "updateAccount");
database.update(updateAccount, "updateAccount");
updateTeller.setBigDecimal(1, delta);
updateTeller.setInt(2, teller);
db.update(updateTeller, "updateTeller");
database.update(updateTeller, "updateTeller");
updateBranch.setBigDecimal(1, delta);
updateBranch.setInt(2, branch);
db.update(updateBranch, "updateBranch");
database.update(updateBranch, "updateBranch");
selectBalance.setInt(1, account);
db.queryReadResult(selectBalance);
database.queryReadResult(selectBalance);
insertHistory.setInt(1, account);
insertHistory.setInt(2, teller);
......@@ -164,9 +163,9 @@ public class BenchA implements Bench {
// insertHistory.setDate(5, new java.sql.Date(current));
insertHistory.setTimestamp(5, new java.sql.Timestamp(current));
insertHistory.setString(6, BenchA.FILLER);
db.update(insertHistory, "insertHistory");
database.update(insertHistory, "insertHistory");
db.commit();
database.commit();
}
updateAccount.close();
selectBalance.close();
......
......@@ -22,7 +22,7 @@ import java.util.Random;
public class BenchB implements Bench, Runnable {
// master data
private Database db;
private Database database;
private int scale = 1;
private int branches = 1;
private int tellers = 10;
......@@ -47,7 +47,7 @@ public class BenchB implements Bench, Runnable {
private BenchB(BenchB master, int seed) throws SQLException {
this.master = master;
random = new Random(seed);
conn = master.db.openNewConnection();
conn = master.database.openNewConnection();
conn.setAutoCommit(false);
updateAccount = conn.prepareStatement(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
......@@ -62,7 +62,7 @@ public class BenchB implements Bench, Runnable {
}
public void init(Database db, int size) throws SQLException {
this.db = db;
this.database = db;
this.transactionPerClient = size;
db.start(this, "Init");
......@@ -181,6 +181,7 @@ public class BenchB implements Bench, Runnable {
public void runTest() throws Exception {
Database db = database;
db.start(this, "Transactions");
db.openConnection();
processTransactions();
......
......@@ -169,7 +169,7 @@ public class BenchC implements Bench {
int districtsPerWarehouse = 10;
int customersPerDistrict = 300;
private Database db;
private Database database;
private int ordersPerDistrict = 300;
......@@ -180,7 +180,7 @@ public class BenchC implements Bench {
public void init(Database db, int size) throws SQLException {
this.db = db;
this.database = db;
random = new BenchCRandom();
......@@ -206,17 +206,17 @@ public class BenchC implements Bench {
private void load() throws SQLException {
for (String sql : TABLES) {
db.dropTable(sql);
database.dropTable(sql);
}
for (String sql : CREATE_SQL) {
db.update(sql);
database.update(sql);
}
db.setAutoCommit(false);
database.setAutoCommit(false);
loadItem();
loadWarehouse();
loadCustomer();
loadOrder();
db.commit();
database.commit();
trace("Load done");
}
......@@ -225,13 +225,13 @@ public class BenchC implements Bench {
}
private void trace(int i, int max) {
db.trace(action, i, max);
database.trace(action, i, max);
}
private void loadItem() throws SQLException {
trace("Loading item table");
boolean[] original = random.getBoolean(items, items / 10);
PreparedStatement prep = db.prepare(
PreparedStatement prep = database.prepare(
"INSERT INTO ITEM(I_ID, I_IM_ID, I_NAME, I_PRICE, I_DATA) " +
"VALUES(?, ?, ?, ?, ?)");
for (int id = 1; id <= items; id++) {
......@@ -246,17 +246,17 @@ public class BenchC implements Bench {
prep.setString(3, name);
prep.setBigDecimal(4, price);
prep.setString(5, data);
db.update(prep, "insertItem");
database.update(prep, "insertItem");
trace(id, items);
if (id % commitEvery == 0) {
db.commit();
database.commit();
}
}
}
private void loadWarehouse() throws SQLException {
trace("Loading warehouse table");
PreparedStatement prep = db.prepare(
PreparedStatement prep = database.prepare(
"INSERT INTO WAREHOUSE(W_ID, W_NAME, W_STREET_1, " +
"W_STREET_2, W_CITY, W_STATE, W_ZIP, W_TAX, W_YTD) " +
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
......@@ -279,11 +279,11 @@ public class BenchC implements Bench {
prep.setString(7, zip);
prep.setBigDecimal(8, tax);
prep.setBigDecimal(9, ytd);
db.update(prep, "insertWarehouse");
database.update(prep, "insertWarehouse");
loadStock(id);
loadDistrict(id);
if (id % commitEvery == 0) {
db.commit();
database.commit();
}
}
}
......@@ -297,7 +297,7 @@ public class BenchC implements Bench {
loadCustomerSub(districtId, id);
trace(i++, max);
if (i % commitEvery == 0) {
db.commit();
database.commit();
}
}
}
......@@ -305,7 +305,7 @@ public class BenchC implements Bench {
private void loadCustomerSub(int dId, int wId) throws SQLException {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
PreparedStatement prepCustomer = db.prepare(
PreparedStatement prepCustomer = database.prepare(
"INSERT INTO CUSTOMER(C_ID, C_D_ID, C_W_ID, " +
"C_FIRST, C_MIDDLE, C_LAST, " +
"C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, " +
......@@ -313,7 +313,7 @@ public class BenchC implements Bench {
"C_CREDIT_LIM, C_DISCOUNT, C_BALANCE, C_DATA, " +
"C_YTD_PAYMENT, C_PAYMENT_CNT, C_DELIVERY_CNT) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement prepHistory = db.prepare(
PreparedStatement prepHistory = database.prepare(
"INSERT INTO HISTORY(H_C_ID, H_C_D_ID, H_C_W_ID, " +
"H_W_ID, H_D_ID, H_DATE, H_AMOUNT, H_DATA) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
......@@ -367,7 +367,7 @@ public class BenchC implements Bench {
prepCustomer.setBigDecimal(19, ytdPayment);
prepCustomer.setInt(20, paymentCnt);
prepCustomer.setInt(21, deliveryCnt);
db.update(prepCustomer, "insertCustomer");
database.update(prepCustomer, "insertCustomer");
BigDecimal amount = new BigDecimal("10.00");
String hData = random.getString(12, 24);
prepHistory.setInt(1, cId);
......@@ -378,7 +378,7 @@ public class BenchC implements Bench {
prepHistory.setTimestamp(6, timestamp);
prepHistory.setBigDecimal(7, amount);
prepHistory.setString(8, hData);
db.update(prepHistory, "insertHistory");
database.update(prepHistory, "insertHistory");
}
}
......@@ -397,14 +397,14 @@ public class BenchC implements Bench {
private void loadOrderSub(int dId, int wId) throws SQLException {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
int[] orderid = random.getPermutation(ordersPerDistrict);
PreparedStatement prepOrder = db.prepare(
PreparedStatement prepOrder = database.prepare(
"INSERT INTO ORDERS(O_ID, O_C_ID, O_D_ID, O_W_ID, " +
"O_ENTRY_D, O_CARRIER_ID, O_OL_CNT, O_ALL_LOCAL) " +
"VALUES(?, ?, ?, ?, ?, ?, ?, 1)");
PreparedStatement prepNewOrder = db.prepare(
PreparedStatement prepNewOrder = database.prepare(
"INSERT INTO NEW_ORDER (NO_O_ID, NO_D_ID, NO_W_ID) " +
"VALUES (?, ?, ?)");
PreparedStatement prepLine = db.prepare(
PreparedStatement prepLine = database.prepare(
"INSERT INTO ORDER_LINE(" +
"OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, " +
"OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, " +
......@@ -428,9 +428,9 @@ public class BenchC implements Bench {
prepNewOrder.setInt(1, oId);
prepNewOrder.setInt(2, dId);
prepNewOrder.setInt(3, wId);
db.update(prepNewOrder, "newNewOrder");
database.update(prepNewOrder, "newNewOrder");
}
db.update(prepOrder, "insertOrder");
database.update(prepOrder, "insertOrder");
for (int ol = 1; ol <= olCnt; ol++) {
int id = random.getInt(1, items);
int supplyId = wId;
......@@ -451,9 +451,9 @@ public class BenchC implements Bench {
prepLine.setInt(7, quantity);
prepLine.setBigDecimal(8, amount);
prepLine.setString(9, distInfo);
db.update(prepLine, "insertOrderLine");
database.update(prepLine, "insertOrderLine");
if (i++ % commitEvery == 0) {
db.commit();
database.commit();
}
}
}
......@@ -462,7 +462,7 @@ public class BenchC implements Bench {
private void loadStock(int wId) throws SQLException {
trace("Loading stock table (warehouse " + wId + ")");
boolean[] original = random.getBoolean(items, items / 10);
PreparedStatement prep = db.prepare(
PreparedStatement prep = database.prepare(
"INSERT INTO STOCK(S_I_ID, S_W_ID, S_QUANTITY, " +
"S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, " +
"S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10, " +
......@@ -501,9 +501,9 @@ public class BenchC implements Bench {
prep.setInt(15, 0);
prep.setInt(16, 0);
prep.setInt(17, 0);
db.update(prep, "insertStock");
database.update(prep, "insertStock");
if (id % commitEvery == 0) {
db.commit();
database.commit();
}
trace(id, items);
}
......@@ -512,7 +512,7 @@ public class BenchC implements Bench {
private void loadDistrict(int wId) throws SQLException {
BigDecimal ytd = new BigDecimal("300000.00");
int nextId = 3001;
PreparedStatement prep = db.prepare(
PreparedStatement prep = database.prepare(
"INSERT INTO DISTRICT(D_ID, D_W_ID, D_NAME, " +
"D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, " +
"D_TAX, D_YTD, D_NEXT_O_ID) " +
......@@ -537,26 +537,26 @@ public class BenchC implements Bench {
prep.setBigDecimal(9, tax);
prep.setBigDecimal(10, ytd);
prep.setInt(11, nextId);
db.update(prep, "insertDistrict");
database.update(prep, "insertDistrict");
trace(dId, districtsPerWarehouse);
}
}
public void runTest() throws SQLException {
db.start(this, "Transactions");
db.openConnection();
database.start(this, "Transactions");
database.openConnection();
for (int i = 0; i < 70; i++) {
BenchCThread process = new BenchCThread(db, this, random, i);
BenchCThread process = new BenchCThread(database, this, random, i);
process.process();
}
db.closeConnection();
db.end();
database.closeConnection();
database.end();
db.openConnection();
BenchCThread process = new BenchCThread(db, this, random, 0);
database.openConnection();
BenchCThread process = new BenchCThread(database, this, random, 0);
process.process();
db.logMemory(this, "Memory Usage");
db.closeConnection();
database.logMemory(this, "Memory Usage");
database.closeConnection();
}
public String getName() {
......
......@@ -17,11 +17,11 @@ import java.util.Random;
*/
public class BenchSimple implements Bench {
Database db;
Database database;
int records;
public void init(Database db, int size) throws SQLException {
this.db = db;
this.database = db;
this.records = size * 60;
db.start(this, "Init");
......@@ -53,6 +53,7 @@ public class BenchSimple implements Bench {
public void runTest() throws SQLException {
PreparedStatement prep;
Database db = database;
Random random = db.getRandom();
db.openConnection();
......
......@@ -34,7 +34,7 @@ class Database {
private int id;
private String name, url, user, password;
private ArrayList<String[]> replace = new ArrayList<String[]>();
private String action;
private String currentAction;
private long startTime;
private Connection conn;
private Statement stat;
......@@ -182,12 +182,12 @@ class Database {
* @return the opened connection
*/
Connection openNewConnection() throws SQLException {
Connection conn = DriverManager.getConnection(url, user, password);
Connection newConn = DriverManager.getConnection(url, user, password);
if (url.startsWith("jdbc:derby:")) {
// Derby: use higher cache size
Statement stat = null;
Statement s = null;
try {
stat = conn.createStatement();
s = newConn.createStatement();
// stat.execute("CALL
// SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageCacheSize',
// '64')");
......@@ -195,19 +195,19 @@ class Database {
// SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageSize',
// '8192')");
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(s);
}
} else if (url.startsWith("jdbc:hsqldb:")) {
// HSQLDB: use a WRITE_DELAY of 1 second
Statement stat = null;
Statement s = null;
try {
stat = conn.createStatement();
stat.execute("SET WRITE_DELAY 1");
s = newConn.createStatement();
s.execute("SET WRITE_DELAY 1");
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(s);
}
}
return conn;
return newConn;
}
/**
......@@ -222,9 +222,9 @@ class Database {
* Close the database connection.
*/
void closeConnection() throws SQLException {
// if(!serverHSQLDB && url.startsWith("jdbc:hsqldb:")) {
// stat.execute("SHUTDOWN");
// }
// if(!serverHSQLDB && url.startsWith("jdbc:hsqldb:")) {
// stat.execute("SHUTDOWN");
// }
conn.close();
stat = null;
conn = null;
......@@ -236,12 +236,12 @@ class Database {
* @param prop the properties with the translations to use
*/
void setTranslations(Properties prop) {
String id = url.substring("jdbc:".length());
id = id.substring(0, id.indexOf(':'));
String databaseType = url.substring("jdbc:".length());
databaseType = databaseType.substring(0, databaseType.indexOf(':'));
for (Object k : prop.keySet()) {
String key = (String) k;
if (key.startsWith(id + ".")) {
String pattern = key.substring(id.length() + 1);
if (key.startsWith(databaseType + ".")) {
String pattern = key.substring(databaseType.length() + 1);
pattern = StringUtils.replaceAll(pattern, "_", " ");
pattern = StringUtils.toUpperEnglish(pattern);
String replacement = prop.getProperty(key);
......@@ -264,8 +264,8 @@ class Database {
private String getSQL(String sql) {
for (String[] pair : replace) {
String pattern = pair[0];
String replace = pair[1];
sql = StringUtils.replaceAll(sql, pattern, replace);
String replacement = pair[1];
sql = StringUtils.replaceAll(sql, pattern, replacement);
}
return sql;
}
......@@ -277,7 +277,7 @@ class Database {
* @param action the action
*/
void start(Bench bench, String action) {
this.action = bench.getName() + ": " + action;
this.currentAction = bench.getName() + ": " + action;
this.startTime = System.currentTimeMillis();
}
......@@ -287,7 +287,7 @@ class Database {
*/
void end() {
long time = System.currentTimeMillis() - startTime;
log(action, "ms", (int) time);
log(currentAction, "ms", (int) time);
if (test.collect) {
totalTime += time;
}
......@@ -310,10 +310,10 @@ class Database {
* Execute an SQL statement.
*
* @param prep the prepared statement
* @param trace the trace message
* @param traceMessage the trace message
*/
void update(PreparedStatement prep, String trace) throws SQLException {
test.trace(trace);
void update(PreparedStatement prep, String traceMessage) throws SQLException {
test.trace(traceMessage);
prep.executeUpdate();
if (test.collect) {
executedStatements++;
......@@ -410,12 +410,12 @@ class Database {
* @return the result set
*/
ResultSet query(PreparedStatement prep) throws SQLException {
// long time = System.currentTimeMillis();
// long time = System.currentTimeMillis();
ResultSet rs = prep.executeQuery();
// time = System.currentTimeMillis() - time;
// if(time > 100) {
// System.out.println("time="+time);
// }
// time = System.currentTimeMillis() - time;
// if(time > 100) {
// System.out.println("time="+time);
// }
if (test.collect) {
executedStatements++;
}
......
......@@ -92,8 +92,8 @@ public class Coverage {
}
}
private void addExclude(String file) {
exclude.add(file);
private void addExclude(String fileName) {
exclude.add(fileName);
}
private boolean isExcluded(String s) {
......
......@@ -108,12 +108,12 @@ public class TestIndex extends TestBase {
private void testRandomized() throws SQLException {
boolean reopen = !config.memory;
Random random = new Random(1);
Random rand = new Random(1);
reconnect();
stat.execute("CREATE TABLE TEST(ID identity)");
int len = getSize(100, 1000);
for (int i = 0; i < len; i++) {
switch (random.nextInt(4)) {
switch (rand.nextInt(4)) {
case 0:
if (reopen) {
trace("reconnect");
......@@ -144,16 +144,16 @@ public class TestIndex extends TestBase {
int len = getSize(1000, 10000);
stat.execute("insert into testA select x, 'Hello' from system_range(1, " + len + ")");
stat.execute("insert into testB select x, 'Hello' from system_range(1, " + len + ")");
Random random = new Random(1);
Random rand = new Random(1);
for (int i = 0; i < len; i++) {
int x = random.nextInt(len);
int x = rand.nextInt(len);
String sql = "";
switch(random.nextInt(3)) {
switch(rand.nextInt(3)) {
case 0:
sql = "delete from testA where id = " + x;
break;
case 1:
sql = "update testA set name = " + random.nextInt(100) + " where id = " + x;
sql = "update testA set name = " + rand.nextInt(100) + " where id = " + x;
break;
case 2:
sql = "select name from testA where id = " + x;
......@@ -314,21 +314,21 @@ public class TestIndex extends TestBase {
prep.setInt(1, a);
prep.setInt(2, a);
prep.execute();
assertEquals(1, getValue(stat, "SELECT COUNT(*) FROM TEST WHERE A=" + a));
assertEquals(0, getValue(stat, "SELECT COUNT(*) FROM TEST WHERE A=-1-" + a));
assertEquals(1, getValue("SELECT COUNT(*) FROM TEST WHERE A=" + a));
assertEquals(0, getValue("SELECT COUNT(*) FROM TEST WHERE A=-1-" + a));
}
reconnect();
prep = conn.prepareStatement("DELETE FROM TEST WHERE A=?");
for (int a = 0; a < len; a++) {
if (getValue(stat, "SELECT COUNT(*) FROM TEST WHERE A=" + a) != 1) {
assertEquals(1, getValue(stat, "SELECT COUNT(*) FROM TEST WHERE A=" + a));
if (getValue("SELECT COUNT(*) FROM TEST WHERE A=" + a) != 1) {
assertEquals(1, getValue("SELECT COUNT(*) FROM TEST WHERE A=" + a));
}
prep.setInt(1, a);
assertEquals(1, prep.executeUpdate());
}
assertEquals(0, getValue(stat, "SELECT COUNT(*) FROM TEST"));
assertEquals(0, getValue("SELECT COUNT(*) FROM TEST"));
}
private void testMultiColumnIndex() throws SQLException {
......@@ -346,13 +346,13 @@ public class TestIndex extends TestBase {
stat.execute("CREATE INDEX ON TEST(A, B)");
prep = conn.prepareStatement("DELETE FROM TEST WHERE A=?");
for (int a = 0; a < len; a++) {
log(stat, "SELECT * FROM TEST");
assertEquals(2, getValue(stat, "SELECT COUNT(*) FROM TEST WHERE A=" + (len - a - 1)));
assertEquals((len - a) * 2, getValue(stat, "SELECT COUNT(*) FROM TEST"));
log("SELECT * FROM TEST");
assertEquals(2, getValue("SELECT COUNT(*) FROM TEST WHERE A=" + (len - a - 1)));
assertEquals((len - a) * 2, getValue("SELECT COUNT(*) FROM TEST"));
prep.setInt(1, len - a - 1);
prep.execute();
}
assertEquals(0, getValue(stat, "SELECT COUNT(*) FROM TEST"));
assertEquals(0, getValue("SELECT COUNT(*) FROM TEST"));
}
private void testMultiColumnHashIndex() throws SQLException {
......@@ -392,17 +392,17 @@ public class TestIndex extends TestBase {
ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE DATA <> 'i('||a||','||b||')u('||a||','||b||')'");
assertFalse(rs.next());
assertEquals(len * (len / 2), getValue(stat, "SELECT COUNT(*) FROM TEST"));
assertEquals(len * (len / 2), getValue("SELECT COUNT(*) FROM TEST"));
stat.execute("DROP TABLE TEST");
}
private int getValue(Statement stat, String sql) throws SQLException {
private int getValue(String sql) throws SQLException {
ResultSet rs = stat.executeQuery(sql);
rs.next();
return rs.getInt(1);
}
private void log(Statement stat, String sql) throws SQLException {
private void log(String sql) throws SQLException {
trace(sql);
ResultSet rs = stat.executeQuery(sql);
int cols = rs.getMetaData().getColumnCount();
......
......@@ -23,7 +23,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
private long last;
private int lastState = -1;
private String url;
private String databaseUrl;
public TestListener() {
start = last = System.currentTimeMillis();
......@@ -102,12 +102,12 @@ public class TestListener extends TestBase implements DatabaseEventListener {
}
public void closingDatabase() {
if (url.toUpperCase().indexOf("CIPHER") >= 0) {
if (databaseUrl.toUpperCase().indexOf("CIPHER") >= 0) {
return;
}
Connection conn = null;
try {
conn = DriverManager.getConnection(url, getUser(), getPassword());
conn = DriverManager.getConnection(databaseUrl, getUser(), getPassword());
conn.createStatement().execute("DROP TABLE TEST2");
conn.close();
} catch (SQLException e) {
......@@ -118,16 +118,16 @@ public class TestListener extends TestBase implements DatabaseEventListener {
}
public void init(String url) {
this.url = url;
this.databaseUrl = url;
}
public void opened() {
if (url.toUpperCase().indexOf("CIPHER") >= 0) {
if (databaseUrl.toUpperCase().indexOf("CIPHER") >= 0) {
return;
}
Connection conn = null;
try {
conn = DriverManager.getConnection(url, getUser(), getPassword());
conn = DriverManager.getConnection(databaseUrl, getUser(), getPassword());
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST2(ID INT)");
conn.close();
} catch (SQLException e) {
......
......@@ -590,10 +590,10 @@ public class TestLob extends TestBase {
len = 100;
}
int start = 1, increment = 19;
int first = 1, increment = 19;
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(ID, B, C) VALUES(?, ?, ?)");
for (int i = start; i < len; i += increment) {
for (int i = first; i < len; i += increment) {
int l = i;
prep.setInt(1, i);
prep.setBinaryStream(2, getRandomStream(l, i), -1);
......@@ -615,7 +615,7 @@ public class TestLob extends TestBase {
}
prep = conn.prepareStatement("UPDATE TEST SET B=?, C=? WHERE ID=?");
for (int i = start; i < len; i += increment) {
for (int i = first; i < len; i += increment) {
int l = i;
prep.setBinaryStream(1, getRandomStream(l, -i), -1);
prep.setCharacterStream(2, getRandomReader(l, -i), -1);
......
......@@ -81,20 +81,20 @@ public class TestMemoryUsage extends TestBase {
return;
}
deleteDb("memoryUsage");
Connection conn = getConnection("memoryUsage");
conn = getConnection("memoryUsage");
Statement stat = conn.createStatement();
stat.execute("SET MAX_LENGTH_INPLACE_LOB 32768");
stat.execute("SET CACHE_SIZE 8000");
stat.execute("CREATE TABLE TEST(ID IDENTITY, DATA CLOB)");
freeSoftReferences();
try {
int start = MemoryUtils.getMemoryUsed();
int base = MemoryUtils.getMemoryUsed();
for (int i = 0; i < 4; i++) {
stat.execute("INSERT INTO TEST(DATA) SELECT SPACE(32000) FROM SYSTEM_RANGE(1, 200)");
freeSoftReferences();
int used = MemoryUtils.getMemoryUsed();
if ((used - start) > 16000) {
fail("Used: " + (used - start));
if ((used - base) > 16000) {
fail("Used: " + (used - base));
}
}
} finally {
......@@ -122,7 +122,7 @@ public class TestMemoryUsage extends TestBase {
return;
}
deleteDb("memoryUsage");
Connection conn = getConnection("memoryUsage");
conn = getConnection("memoryUsage");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar(255))");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, space(200))");
......@@ -134,13 +134,13 @@ public class TestMemoryUsage extends TestBase {
prep.setInt(1, i);
prep.executeUpdate();
}
int start = MemoryUtils.getMemoryUsed();
int base = MemoryUtils.getMemoryUsed();
stat.execute("create index idx_test_id on test(id)");
System.gc();
System.gc();
int used = MemoryUtils.getMemoryUsed();
if ((used - start) > getSize(7500, 12000)) {
fail("Used: " + (used - start));
if ((used - base) > getSize(7500, 12000)) {
fail("Used: " + (used - base));
}
stat.execute("drop table test");
conn.close();
......
......@@ -49,9 +49,8 @@ public class TestMultiThread extends TestBase implements Runnable {
}
public void test() throws Exception {
Connection conn = getConnection();
Statement stat = conn.createStatement();
conn = getConnection();
stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
int len = getSize(10, 200);
Thread[] threads = new Thread[len];
......
......@@ -50,7 +50,7 @@ public class TestMultiThreadedKernel extends TestBase {
public void run() {
Connection conn = null;
try {
for (int i = 0; i < 100 && !stop; i++) {
for (int j = 0; j < 100 && !stop; j++) {
conn = DriverManager.getConnection(url, user, password);
Statement stat = conn.createStatement();
stat.execute("create local temporary table temp(id identity)");
......
......@@ -145,13 +145,13 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
threads[i] = new Thread() {
public void run() {
try {
Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement prep = conn.prepareStatement("insert into employee values(?, ?, 0)");
Connection c = DriverManager.getConnection(url, user, password);
PreparedStatement prep = c.prepareStatement("insert into employee values(?, ?, 0)");
int id = getNextId();
prep.setInt(1, id);
prep.setString(2, "employee " + id);
prep.execute();
conn.close();
c.close();
} catch (Throwable e) {
TestBase.logError("insert", e);
}
......
......@@ -270,16 +270,16 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
}
}
public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) {
this.triggerName = triggerName;
public void init(Connection conn, String schemaName, String trigger, String tableName, boolean before, int type) {
this.triggerName = trigger;
if (!"TEST".equals(tableName)) {
throw new AssertionError("supposed to be TEST");
}
if ((triggerName.endsWith("AFTER") && before) || (triggerName.endsWith("BEFORE") && !before)) {
throw new AssertionError("triggerName: " + triggerName + " before:" + before);
if ((trigger.endsWith("AFTER") && before) || (trigger.endsWith("BEFORE") && !before)) {
throw new AssertionError("triggerName: " + trigger + " before:" + before);
}
if ((triggerName.startsWith("UPD") && type != UPDATE) || (triggerName.startsWith("INS") && type != INSERT) || (triggerName.startsWith("DEL") && type != DELETE)) {
throw new AssertionError("triggerName: " + triggerName + " type:" + type);
if ((trigger.startsWith("UPD") && type != UPDATE) || (trigger.startsWith("INS") && type != INSERT) || (trigger.startsWith("DEL") && type != DELETE)) {
throw new AssertionError("triggerName: " + trigger + " type:" + type);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论