提交 f2e6dd8e authored 作者: Noel Grandin's avatar Noel Grandin

improve TestKillRestart debugging

so we catch more output if stuff goes wrong
上级 79a16ace
...@@ -9,7 +9,6 @@ import java.io.IOException; ...@@ -9,7 +9,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
/** /**
...@@ -51,29 +50,39 @@ public class OutputCatcher extends Thread { ...@@ -51,29 +50,39 @@ public class OutputCatcher extends Thread {
@Override @Override
public void run() { public void run() {
StringBuilder buff = new StringBuilder(); final StringBuilder buff = new StringBuilder();
while (true) { try {
try { while (true) {
int x = in.read(); try {
if (x < 0) { int x = in.read();
break; if (x < 0) {
} break;
if (x < ' ') { }
if (buff.length() > 0) { if (x < ' ') {
String s = buff.toString(); if (buff.length() > 0) {
buff.setLength(0); String s = buff.toString();
synchronized (list) { buff.setLength(0);
list.add(s); synchronized (list) {
list.notifyAll(); list.add(s);
list.notifyAll();
}
} }
} else {
buff.append((char) x);
} }
} else { } catch (IOException e) {
buff.append((char) x); break;
}
}
IOUtils.closeSilently(in);
} finally {
// just in case something goes wrong, make sure we store any partial output we got
if (buff.length() > 0) {
synchronized (list) {
list.add(buff.toString());
list.notifyAll();
} }
} catch (IOException e) {
break;
} }
} }
IOUtils.closeSilently(in);
} }
} }
...@@ -42,7 +42,7 @@ public class TestKillRestart extends TestBase { ...@@ -42,7 +42,7 @@ public class TestKillRestart extends TestBase {
int len = getSize(2, 15); int len = getSize(2, 15);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Process p = Runtime.getRuntime().exec(procDef); Process p = new ProcessBuilder().redirectErrorStream(true).command(procDef).start();
InputStream in = p.getInputStream(); InputStream in = p.getInputStream();
OutputCatcher catcher = new OutputCatcher(in); OutputCatcher catcher = new OutputCatcher(in);
catcher.start(); catcher.start();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论