01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.synth;
07:
08: import java.sql.Connection;
09: import java.sql.DriverManager;
10: import java.sql.PreparedStatement;
11: import java.util.ArrayList;
12: import java.util.Random;
13:
14: import org.h2.store.FileLister;
15: import org.h2.test.TestBase;
16: import org.h2.test.unit.SelfDestructor;
17:
18: /**
19: * Test application for {@link TestKill}.
20: */
21: public class TestKillProcess {
22: public static void main(String[] args) throws Exception {
23: SelfDestructor.startCountdown(60);
24: try {
25: Class.forName("org.h2.Driver");
26: String url = args[0], user = args[1], password = args[2];
27: String baseDir = args[3];
28: int accounts = Integer.parseInt(args[4]);
29:
30: Random random = new Random();
31: Connection conn1 = DriverManager.getConnection(url, user,
32: password);
33:
34: PreparedStatement prep1a = conn1
35: .prepareStatement("INSERT INTO LOG(ACCOUNTID, AMOUNT) VALUES(?, ?)");
36: PreparedStatement prep1b = conn1
37: .prepareStatement("UPDATE ACCOUNT SET SUM=SUM+? WHERE ID=?");
38: conn1.setAutoCommit(false);
39: long time = System.currentTimeMillis();
40: String d = null;
41: for (int i = 0;; i++) {
42: long t = System.currentTimeMillis();
43: if (t > time + 1000) {
44: ArrayList list = FileLister.getDatabaseFiles(
45: baseDir, "kill", true);
46: System.out.println("inserting... i:" + i + " d:"
47: + d + " files:" + list.size());
48: time = t;
49: }
50: if (i > 10000) {
51: // System.out.println("halt");
52: // Runtime.getRuntime().halt(0);
53: // conn.createStatement().execute("SHUTDOWN IMMEDIATELY");
54: // System.exit(0);
55: }
56: int account = random.nextInt(accounts);
57: int value = random.nextInt(100);
58: prep1a.setInt(1, account);
59: prep1a.setInt(2, value);
60: prep1a.execute();
61: prep1b.setInt(1, value);
62: prep1b.setInt(2, account);
63: prep1b.execute();
64: conn1.commit();
65: if (random.nextInt(100) < 2) {
66: d = "D" + random.nextInt(1000);
67: account = random.nextInt(accounts);
68: conn1.createStatement().execute(
69: "UPDATE TEST_A SET DATA='" + d
70: + "' WHERE ID=" + account);
71: conn1.createStatement().execute(
72: "UPDATE TEST_B SET DATA='" + d
73: + "' WHERE ID=" + account);
74: }
75: }
76: } catch (Throwable e) {
77: TestBase.logError("error", e);
78: }
79: }
80:
81: }
|