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

--no commit message

--no commit message
上级 b604d5d1
......@@ -61,6 +61,7 @@ import org.h2.test.jdbc.TestZloty;
import org.h2.test.jdbc.xa.TestXA;
import org.h2.test.server.TestNestedLoop;
import org.h2.test.synth.TestBtreeIndex;
import org.h2.test.synth.TestKillRestart;
import org.h2.test.synth.TestCrashAPI;
import org.h2.test.synth.TestHaltApp;
import org.h2.test.synth.TestJoin;
......@@ -556,6 +557,9 @@ write tests using the PostgreSQL JDBC driver
new TestUpdatableResultSet().runTest(this);
new TestXA().runTest(this);
new TestZloty().runTest(this);
// synthetic
new TestKillRestart().runTest(this);
afterTest();
}
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.synth;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import org.h2.util.IOUtils;
class OutputCatcher extends Thread {
private InputStream in;
private LinkedList list = new LinkedList();
OutputCatcher(InputStream in) {
this.in = in;
}
String readLine(long wait) {
long start = System.currentTimeMillis();
while (true) {
synchronized (list) {
if (list.size() > 0) {
return (String) list.removeFirst();
}
try {
list.wait(wait);
} catch (InterruptedException e) {
}
long time = System.currentTimeMillis() - start;
if (time >= wait) {
return null;
}
}
}
}
public void run() {
StringBuffer buff = new StringBuffer();
while (true) {
try {
int x = in.read();
if (x < 0) {
break;
}
if (x < ' ') {
if (buff.length() > 0) {
String s = buff.toString();
buff.setLength(0);
synchronized (list) {
list.add(s);
list.notifyAll();
}
}
} else {
buff.append((char) x);
}
} catch (IOException e) {
// ignore
}
}
IOUtils.closeSilently(in);
}
}
......@@ -14,7 +14,6 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Random;
import org.h2.test.TestAll;
......@@ -193,61 +192,6 @@ public abstract class TestHalt extends TestBase {
}
}
private static class OutputCatcher extends Thread {
private InputStream in;
private LinkedList list = new LinkedList();
OutputCatcher(InputStream in) {
this.in = in;
}
private String readLine(long wait) {
long start = System.currentTimeMillis();
while (true) {
synchronized (list) {
if (list.size() > 0) {
return (String) list.removeFirst();
}
try {
list.wait(wait);
} catch (InterruptedException e) {
}
long time = System.currentTimeMillis() - start;
if (time >= wait) {
return null;
}
}
}
}
public void run() {
StringBuffer buff = new StringBuffer();
while (true) {
try {
int x = in.read();
if (x < 0) {
break;
}
if (x < ' ') {
if (buff.length() > 0) {
String s = buff.toString();
buff.setLength(0);
synchronized (list) {
list.add(s);
list.notifyAll();
}
}
} else {
buff.append((char) x);
}
} catch (IOException e) {
// ignore
}
}
IOUtils.closeSilently(in);
}
}
public Connection getConnectionHSQLDB() throws Exception {
File lock = new File("test.lck");
while (lock.exists()) {
......
package org.h2.test.synth;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Random;
import org.h2.test.TestBase;
public class TestKillRestart extends TestBase {
public void test() throws Exception {
deleteDb("corrupt");
String url = getURL("corrupt", true);
// String url = getURL("corrupt;CACHE_SIZE=2048;WRITE_DELAY=0;STORAGE=TEXT", true);
String user = getUser(), password = getPassword();
String[] procDef = new String[] { "java.exe", "-cp", "bin", getClass().getName(), "-url", url, "-user", user,
"-password", password };
for (int i = 0; i < 10; i++) {
Process p = Runtime.getRuntime().exec(procDef);
// InputStream err = p.getErrorStream();
InputStream in = p.getInputStream();
OutputCatcher catcher = new OutputCatcher(in);
catcher.start();
while (true) {
String s = catcher.readLine(5000);
// System.out.println("> " + s);
if (s == null) {
error("No reply from process");
} else if (!s.startsWith("#")) {
// System.out.println(s);
error("Expected: #..., got: " + s);
} else if (s.startsWith("#Running")) {
Thread.sleep(100);
printTime("Killing..." + i);
p.destroy();
break;
} else if (s.startsWith("#Fail")) {
error("Failed: " + s);
}
}
}
}
public static void main(String[] args) throws Exception {
String driver = "org.h2.Driver";
String url = "jdbc:h2:test", user = "sa", password = "sa";
for (int i = 0; i < args.length; i++) {
if ("-url".equals(args[i])) {
url = args[++i];
} else if ("-driver".equals(args[i])) {
driver = args[++i];
} else if ("-user".equals(args[i])) {
user = args[++i];
} else if ("-password".equals(args[i])) {
password = args[++i];
}
}
System.out.println("#Started; driver: " + driver + " url: " + url + " user: " + user + " password: " + password);
try {
Class.forName(driver);
System.out.println("#Opening...");
Connection conn = DriverManager.getConnection(url, user, password);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS TEST(ID IDENTITY, NAME VARCHAR)");
stat.execute("CREATE TABLE IF NOT EXISTS TEST2(ID IDENTITY, NAME VARCHAR)");
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
while (rs.next()) {
rs.getLong("ID");
rs.getString("NAME");
}
rs = stat.executeQuery("SELECT * FROM TEST2");
while (rs.next()) {
rs.getLong("ID");
rs.getString("NAME");
}
stat.execute("DROP ALL OBJECTS DELETE FILES");
System.out.println("#Closing with delete...");
conn.close();
System.out.println("#Starting...");
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
stat.execute("CREATE TABLE TEST2(ID IDENTITY, NAME VARCHAR)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(NAME) VALUES(?)");
PreparedStatement prep2 = conn.prepareStatement("INSERT INTO TEST2(NAME) VALUES(?)");
Random r = new Random(0);
// Runnable stopper = new Runnable() {
// public void run() {
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// }
// System.out.println("#Halt...");
// Runtime.getRuntime().halt(0);
// }
// };
// new Thread(stopper).start();
for (int i = 0; i < 2000; i++) {
if (i == 100) {
System.out.println("#Running...");
}
if (r.nextBoolean()) {
if (r.nextBoolean()) {
prep.setString(1, new String(new char[r.nextInt(30) * 10]));
prep.execute();
} else {
prep2.setString(1, new String(new char[r.nextInt(30) * 10]));
prep2.execute();
}
} else {
if (r.nextBoolean()) {
conn.createStatement().execute("UPDATE TEST SET NAME = NULL");
} else {
conn.createStatement().execute("UPDATE TEST2 SET NAME = NULL");
}
}
}
} catch (Throwable e) {
e.printStackTrace(System.out);
System.out.println("#Fail: " + e.toString());
}
}
}
......@@ -509,3 +509,4 @@ imports bnot severity colon braces suppress star bxor band bor unary bsr puppy l
forge chr trunc gabealbert tunebackup manifest
lumber thus taking repositories ago delegated mention leaks pgsql seeded felt efficiently mill mentioned forgot leaked restarted clearing occupies randomness warn implementing abstraction
spfile svr pkey synced semicolon terminating
framework constructing architectural jmatter workgroup upgraded naked
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论