提交 a4f19e7d authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 c9b81c49
...@@ -39,7 +39,7 @@ public abstract class TestBase { ...@@ -39,7 +39,7 @@ public abstract class TestBase {
/** /**
* The test configuration. * The test configuration.
*/ */
protected TestAll config; public TestAll config;
/** /**
* The time when the test was started. * The time when the test was started.
...@@ -363,6 +363,7 @@ public abstract class TestBase { ...@@ -363,6 +363,7 @@ public abstract class TestBase {
e = new Exception(s); e = new Exception(s);
} }
System.out.println("ERROR: " + s + " " + e.toString() + " ------------------------------"); System.out.println("ERROR: " + s + " " + e.toString() + " ------------------------------");
System.out.flush();
e.printStackTrace(); e.printStackTrace();
try { try {
TraceSystem ts = new TraceSystem(null, false); TraceSystem ts = new TraceSystem(null, false);
...@@ -377,6 +378,7 @@ public abstract class TestBase { ...@@ -377,6 +378,7 @@ public abstract class TestBase {
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
System.err.flush();
} }
/** /**
......
...@@ -36,6 +36,8 @@ public class TestMultiThreaded extends TestBase { ...@@ -36,6 +36,8 @@ public class TestMultiThreaded extends TestBase {
private Statement stat; private Statement stat;
private Random random; private Random random;
private volatile Throwable exception; private volatile Throwable exception;
private boolean stop;
Processor(Connection conn, int id) throws SQLException { Processor(Connection conn, int id) throws SQLException {
this.id = id; this.id = id;
stat = conn.createStatement(); stat = conn.createStatement();
...@@ -48,20 +50,22 @@ public class TestMultiThreaded extends TestBase { ...@@ -48,20 +50,22 @@ public class TestMultiThreaded extends TestBase {
int count = 0; int count = 0;
ResultSet rs; ResultSet rs;
try { try {
while (!isInterrupted()) { while (!stop) {
switch(random.nextInt(6)) { switch(random.nextInt(6)) {
case 0: case 0:
// insert a row for this connection // insert a row for this connection
trace("insert " + id + " count: " + count); traceThread("insert " + id + " count: " + count);
stat.execute("INSERT INTO TEST(NAME) VALUES('"+ id +"')"); stat.execute("INSERT INTO TEST(NAME) VALUES('"+ id +"')");
traceThread("insert done");
count++; count++;
break; break;
case 1: case 1:
// delete a row for this connection // delete a row for this connection
if (count > 0) { if (count > 0) {
trace("delete " + id + " count: " + count); traceThread("delete " + id + " count: " + count);
int updateCount = stat.executeUpdate( int updateCount = stat.executeUpdate(
"DELETE FROM TEST WHERE NAME = '"+ id +"' AND ROWNUM()<2"); "DELETE FROM TEST WHERE NAME = '"+ id +"' AND ROWNUM()<2");
traceThread("delete done");
if (updateCount != 1) { if (updateCount != 1) {
throw new Error("Expected: 1 Deleted: " + updateCount); throw new Error("Expected: 1 Deleted: " + updateCount);
} }
...@@ -70,8 +74,9 @@ public class TestMultiThreaded extends TestBase { ...@@ -70,8 +74,9 @@ public class TestMultiThreaded extends TestBase {
break; break;
case 2: case 2:
// select the number of rows of this connection // select the number of rows of this connection
trace("select " + id + " count: " + count); traceThread("select " + id + " count: " + count);
rs = stat.executeQuery("SELECT COUNT(*) FROM TEST WHERE NAME = '"+ id +"'"); rs = stat.executeQuery("SELECT COUNT(*) FROM TEST WHERE NAME = '"+ id +"'");
traceThread("select done");
rs.next(); rs.next();
int got = rs.getInt(1); int got = rs.getInt(1);
if (got != count) { if (got != count) {
...@@ -79,16 +84,19 @@ public class TestMultiThreaded extends TestBase { ...@@ -79,16 +84,19 @@ public class TestMultiThreaded extends TestBase {
} }
break; break;
case 3: case 3:
// insert a row traceThread("insert");
stat.execute("INSERT INTO TEST(NAME) VALUES(NULL)"); stat.execute("INSERT INTO TEST(NAME) VALUES(NULL)");
traceThread("insert done");
break; break;
case 4: case 4:
// delete a row traceThread("delete");
stat.execute("DELETE FROM TEST WHERE NAME IS NULL"); stat.execute("DELETE FROM TEST WHERE NAME IS NULL");
traceThread("delete done");
break; break;
case 5: case 5:
// select rows traceThread("select");
rs = stat.executeQuery("SELECT * FROM TEST WHERE NAME IS NULL"); rs = stat.executeQuery("SELECT * FROM TEST WHERE NAME IS NULL");
traceThread("select done");
while (rs.next()) { while (rs.next()) {
rs.getString(1); rs.getString(1);
} }
...@@ -99,6 +107,15 @@ public class TestMultiThreaded extends TestBase { ...@@ -99,6 +107,15 @@ public class TestMultiThreaded extends TestBase {
exception = e; exception = e;
} }
} }
private void traceThread(String s) {
if (config.traceTest) {
trace(id + " " + s);
}
}
public void stopNow() {
this.stop = true;
}
} }
public void test() throws Exception { public void test() throws Exception {
...@@ -109,38 +126,46 @@ public class TestMultiThreaded extends TestBase { ...@@ -109,38 +126,46 @@ public class TestMultiThreaded extends TestBase {
int size = getSize(2, 4); int size = getSize(2, 4);
Connection[] connList = new Connection[size]; Connection[] connList = new Connection[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
connList[i] = getConnection("multiThreaded;MULTI_THREADED=1"); connList[i] = getConnection("multiThreaded;MULTI_THREADED=1;TRACE_LEVEL_SYSTEM_OUT=1");
} }
Connection conn = connList[0]; Connection conn = connList[0];
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("SET LOCK_TIMEOUT 10000");
stat.execute("CREATE SEQUENCE TEST_SEQ"); stat.execute("CREATE SEQUENCE TEST_SEQ");
stat.execute("CREATE TABLE TEST(ID BIGINT DEFAULT NEXT VALUE FOR TEST_SEQ, NAME VARCHAR)"); stat.execute("CREATE TABLE TEST(ID BIGINT DEFAULT NEXT VALUE FOR TEST_SEQ, NAME VARCHAR)");
// stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"); // stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
// stat.execute("CREATE INDEX IDX_TEST_NAME ON TEST(NAME)"); // stat.execute("CREATE INDEX IDX_TEST_NAME ON TEST(NAME)");
trace("init done");
Processor[] processors = new Processor[size]; Processor[] processors = new Processor[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
conn = connList[i]; conn = connList[i];
conn.createStatement().execute("SET LOCK_TIMEOUT 1000");
processors[i] = new Processor(conn, i); processors[i] = new Processor(conn, i);
processors[i].start(); processors[i].start();
trace("started " + i);
Thread.sleep(100);
} }
for (int t = 0; t < 2; t++) { for (int t = 0; t < 2; t++) {
Thread.sleep(1000); Thread.sleep(1000);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Processor p = processors[i]; Processor p = processors[i];
if (p.getException() != null) { if (p.getException() != null) {
throw new Exception(p.getException()); throw new Exception("" + i, p.getException());
}
} }
} }
trace("stopping");
for (int i = 0; i < size; i++) {
Processor p = processors[i];
p.stopNow();
} }
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Processor p = processors[i]; Processor p = processors[i];
p.interrupt();
p.join(100); p.join(100);
if (p.getException() != null) { if (p.getException() != null) {
throw new Exception(p.getException()); throw new Exception(p.getException());
} }
} }
trace("close");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
connList[i].close(); connList[i].close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论