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

--no commit message

--no commit message
上级 26e617c5
......@@ -14,5 +14,6 @@ public interface Service {
void stop();
boolean isRunning();
boolean getAllowOthers();
String getName();
String getType();
}
......@@ -248,6 +248,10 @@ public class TcpServer implements Service {
return "TCP";
}
public String getName() {
return "H2 TCP Server";
}
public void logInternalError(String string) {
if (TcpServer.logInternalErrors) {
System.out.println(string);
......
......@@ -157,19 +157,20 @@ public class FtpServer implements Service {
public void init(String[] args) throws Exception {
for (int i = 0; args != null && i < args.length; i++) {
if ("-ftpPort".equals(args[i])) {
String a = args[i];
if ("-ftpPort".equals(a)) {
port = MathUtils.decodeInt(args[++i]);
} else if ("-ftpDir".equals(args[i])) {
} else if ("-ftpDir".equals(a)) {
root = FileUtils.normalize(args[++i]);
} else if ("-ftpRead".equals(args[i])) {
} else if ("-ftpRead".equals(a)) {
readUserName = args[++i];
} else if ("-ftpWrite".equals(args[i])) {
} else if ("-ftpWrite".equals(a)) {
writeUserName = args[++i];
} else if ("-ftpWritePassword".equals(args[i])) {
} else if ("-ftpWritePassword".equals(a)) {
writePassword = args[++i];
} else if ("-log".equals(args[i])) {
} else if ("-log".equals(a)) {
log = Boolean.valueOf(args[++i]).booleanValue();
} else if ("-ftpTask".equals(args[i])) {
} else if ("-ftpTask".equals(a)) {
allowTask = Boolean.valueOf(args[++i]).booleanValue();
}
}
......@@ -216,6 +217,10 @@ public class FtpServer implements Service {
return "FTP";
}
public String getName() {
return "H2 FTP Server";
}
void log(String s) {
if (log) {
System.out.println(s);
......
......@@ -177,6 +177,10 @@ public class PgServer implements Service {
public String getType() {
return "PG";
}
public String getName() {
return "H2 PG Server";
}
public boolean getIfExists() {
return ifExists;
......
......@@ -336,6 +336,10 @@ public class WebServer implements Service {
return "Web";
}
public String getName() {
return "H2 Console Server";
}
void setAllowOthers(boolean b) {
allowOthers = b;
}
......
......@@ -150,6 +150,13 @@ java org.h2.test.TestAll timer
/*
write more tests for the command line tools
Changelog:
Certain setting in the Server didn't work (see bug...)
avoid creating thousands of trace.db files
Known Problems:
link to history page, bug page
Add a link to the google code bug page
......
......@@ -4,7 +4,9 @@
*/
package org.h2.test.unit;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
......@@ -28,6 +30,7 @@ public class TestTools extends TestBase {
public void test() throws Exception {
deleteDb("utils");
testServerMain();
testRemove();
testConvertTraceFile();
testManagementDb();
......@@ -39,6 +42,51 @@ public class TestTools extends TestBase {
testRecover();
}
private void testServerMain() throws Exception {
String result;
Connection conn;
org.h2.Driver.load();
result = runServer(new String[]{"-?"}, 1);
check(result.indexOf("[options]") >= 0);
check(result.indexOf("Unknown option") < 0);
result = runServer(new String[]{"-xy"}, 1);
check(result.indexOf("[options]") >= 0);
check(result.indexOf("Unknown option") >= 0);
result = runServer(new String[]{"-tcp", "-tcpAllowOthers", "false", "-tcpPort", "9001", "-tcpPassword", "abc"}, 0);
check(result.indexOf("tcp://") >= 0);
check(result.indexOf(":9001") >= 0);
check(result.indexOf("only local") >= 0);
check(result.indexOf("[options]") < 0);
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(new String[]{"-tcpShutdown", "tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce", "true"}, 0);
check(result.indexOf("Shutting down") >= 0);
result = runServer(new String[]{"-tcp", "-tcpAllowOthers", "true", "-tcpPort", "9001", "-tcpPassword", "def", "-tcpSSL", "true"}, 0);
check(result.indexOf("ssl://") >= 0);
check(result.indexOf(":9001") >= 0);
check(result.indexOf("others can") >= 0);
check(result.indexOf("[options]") < 0);
conn = DriverManager.getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(new String[]{"-tcpShutdown", "ssl://localhost:9001", "-tcpPassword", "def", "-tcpShutdownForce", "false"}, 0);
check(result.indexOf("Shutting down") >= 0);
}
private String runServer(String[] args, int exitCode) throws Exception {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(buff);
int gotCode = new Server().run(args, ps);
check(exitCode, gotCode);
ps.flush();
String s = new String(buff.toByteArray());
return s;
}
private void testConvertTraceFile() throws Exception {
deleteDb("toolsConvertTraceFile");
Class.forName("org.h2.Driver");
......@@ -213,7 +261,6 @@ public class TestTools extends TestBase {
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/test", "sa", "");
conn.close();
server.stop();
server = Server.createTcpServer(
new String[] { "-ifExists", "true", "-tcpPassword", "abc", "-baseDir", baseDir }).start();
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论