private void testOne(int seed) throws SQLException {
org.h2.Driver.load();
deleteDb("index");
printTime("testIndex " + seed);
Random random = new Random(seed);
int distinct, prefixLength;
if (random.nextBoolean()) {
distinct = random.nextInt(8000) + 1;
prefixLength = random.nextInt(8000) + 1;
} else if (random.nextBoolean()) {
distinct = random.nextInt(16000) + 1;
prefixLength = random.nextInt(100) + 1;
} else {
distinct = random.nextInt(10) + 1;
prefixLength = random.nextInt(10) + 1;
}
boolean delete = random.nextBoolean();
StringBuilder buff = new StringBuilder();
for (int j = 0; j < prefixLength; j++) {
buff.append("x");
if (buff.length() % 10 == 0) {
buff.append(buff.length());
}
}
String prefix = buff.toString().substring(0, prefixLength);
DeleteDbFiles.execute(getBaseDir() + "/index", null, true);
Connection conn = getConnection("index");
try {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE a(text VARCHAR PRIMARY KEY)");
PreparedStatement prepInsert = conn.prepareStatement("INSERT INTO a VALUES(?)");
PreparedStatement prepDelete = conn.prepareStatement("DELETE FROM a WHERE text=?");
PreparedStatement prepDeleteAllButOne = conn.prepareStatement("DELETE FROM a WHERE text <> ?");
int count = 0;
for (int i = 0; i < 1000; i++) {
int y = random.nextInt(distinct);
try {
prepInsert.setString(1, prefix + y);
prepInsert.executeUpdate();
count++;
} catch (SQLException e) {
if (e.getSQLState().equals("23505")) {
// ignore
} else {
TestBase.logError("error", e);
break;
}
}
if (delete && random.nextInt(10) == 1) {
if (random.nextInt(4) == 1) {
try {
prepDeleteAllButOne.setString(1, prefix + y);
int deleted = prepDeleteAllButOne.executeUpdate();
if (deleted < count - 1) {
printError(seed, "deleted:" + deleted + " i:" + i);