Unverified 提交 f07266ae authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #784 from andreitokar/use_floating_ports

Hardcoded port numbers should not be used in unit tests
...@@ -1056,8 +1056,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -1056,8 +1056,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
DeleteDbFiles.execute(TestBase.BASE_TEST_DIR, null, true); DeleteDbFiles.execute(TestBase.BASE_TEST_DIR, null, true);
FileUtils.deleteRecursive("trace.db", false); FileUtils.deleteRecursive("trace.db", false);
if (networked) { if (networked) {
String[] args = ssl ? new String[] { "-tcpSSL", "-tcpPort", "9192" } String[] args = ssl ? new String[] { "-tcpSSL" } : new String[0];
: new String[] { "-tcpPort", "9192" };
server = Server.createTcpServer(args); server = Server.createTcpServer(args);
try { try {
server.start(); server.start();
...@@ -1079,6 +1078,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -1079,6 +1078,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
FileUtils.deleteRecursive(TestBase.BASE_TEST_DIR, true); FileUtils.deleteRecursive(TestBase.BASE_TEST_DIR, true);
} }
public int getPort() {
return server == null ? 9192 : server.getPort();
}
/** /**
* Print system information. * Print system information.
*/ */
......
...@@ -265,9 +265,9 @@ public abstract class TestBase { ...@@ -265,9 +265,9 @@ public abstract class TestBase {
} }
if (config.networked) { if (config.networked) {
if (config.ssl) { if (config.ssl) {
url = "ssl://localhost:9192/" + name; url = "ssl://localhost:"+config.getPort()+"/" + name;
} else { } else {
url = "tcp://localhost:9192/" + name; url = "tcp://localhost:"+config.getPort()+"/" + name;
} }
} else if (config.googleAppEngine) { } else if (config.googleAppEngine) {
url = "gae://" + name + url = "gae://" + name +
......
...@@ -49,8 +49,6 @@ public class TestCluster extends TestBase { ...@@ -49,8 +49,6 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
...@@ -58,9 +56,9 @@ public class TestCluster extends TestBase { ...@@ -58,9 +56,9 @@ public class TestCluster extends TestBase {
Connection conn; Connection conn;
Statement stat; Statement stat;
Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = n1.getPort();
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false); String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port1, "-baseDir", getBaseDir() + "/node1").start();
conn = getConnection(url1, user, password); conn = getConnection(url1, user, password);
stat = conn.createStatement(); stat = conn.createStatement();
...@@ -68,10 +66,11 @@ public class TestCluster extends TestBase { ...@@ -68,10 +66,11 @@ public class TestCluster extends TestBase {
stat.execute("insert into t1 values(1, repeat('Hello', 50))"); stat.execute("insert into t1 values(1, repeat('Hello', 50))");
conn.close(); conn.close();
Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = n2.getPort();
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
String serverList = "localhost:" + port1 + ",localhost:" + port2;
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true); String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
...@@ -89,8 +88,6 @@ public class TestCluster extends TestBase { ...@@ -89,8 +88,6 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
...@@ -99,15 +96,17 @@ public class TestCluster extends TestBase { ...@@ -99,15 +96,17 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
Server server1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = server1.getPort();
Server server2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = server2.getPort();
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true); String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String serverList = "localhost:" + port1 + ",localhost:" + port2;
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true); String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server server1 = org.h2.tools.Server.createTcpServer(
"-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server server2 = org.h2.tools.Server.createTcpServer(
"-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -152,8 +151,6 @@ public class TestCluster extends TestBase { ...@@ -152,8 +151,6 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
...@@ -162,15 +159,16 @@ public class TestCluster extends TestBase { ...@@ -162,15 +159,16 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = n1.getPort();
Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = n2.getPort();
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true); String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String serverList = "localhost:" + port1 + ",localhost:" + port2;
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true); String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -200,8 +198,6 @@ public class TestCluster extends TestBase { ...@@ -200,8 +198,6 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
...@@ -210,15 +206,16 @@ public class TestCluster extends TestBase { ...@@ -210,15 +206,16 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = n1.getPort();
Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = n2.getPort();
String serverList = "localhost:" + port1 + ",localhost:" + port2;
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true); String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true); String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -257,23 +254,23 @@ public class TestCluster extends TestBase { ...@@ -257,23 +254,23 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
String user = getUser(), password = getPassword(); String user = getUser(), password = getPassword();
Connection conn; Connection conn;
Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = n1.getPort();
Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = n2.getPort();
String serverList = "localhost:" + port1 + ",localhost:" + port2;
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true); String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true); String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -309,22 +306,18 @@ public class TestCluster extends TestBase { ...@@ -309,22 +306,18 @@ public class TestCluster extends TestBase {
if (config.memory || config.networked || config.cipher != null) { if (config.memory || config.networked || config.cipher != null) {
return; return;
} }
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles(); deleteFiles();
org.h2.Driver.load(); org.h2.Driver.load();
String user = getUser(), password = getPassword(); String user = getUser(), password = getPassword();
Connection conn; Connection conn;
Statement stat; Statement stat;
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", false);
int len = 10; int len = 10;
// initialize the database // initialize the database
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
"" + port1, "-baseDir", getBaseDir() + "/node1").start(); int port1 = n1.getPort();
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false);
conn = getConnection(url1, user, password); conn = getConnection(url1, user, password);
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar) as " + stat.execute("create table test(id int primary key, name varchar) as " +
...@@ -333,10 +326,12 @@ public class TestCluster extends TestBase { ...@@ -333,10 +326,12 @@ public class TestCluster extends TestBase {
stat.execute("grant all on test to test"); stat.execute("grant all on test to test");
// start the second server // start the second server
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
"" + port2 , "-baseDir", getBaseDir() + "/node2").start(); int port2 = n2.getPort();
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
// copy the database and initialize the cluster // copy the database and initialize the cluster
String serverList = "localhost:" + port1 + ",localhost:" + port2;
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList", "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -347,6 +342,7 @@ public class TestCluster extends TestBase { ...@@ -347,6 +342,7 @@ public class TestCluster extends TestBase {
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
// test the cluster connection // test the cluster connection
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", false);
Connection connApp = getConnection(urlCluster + Connection connApp = getConnection(urlCluster +
";AUTO_RECONNECT=TRUE", user, password); ";AUTO_RECONNECT=TRUE", user, password);
check(connApp, len, "'" + serverList + "'"); check(connApp, len, "'" + serverList + "'");
......
...@@ -66,17 +66,18 @@ public class TestReadOnly extends TestBase { ...@@ -66,17 +66,18 @@ public class TestReadOnly extends TestBase {
"jdbc:h2:zip:"+dir+"/readonly.zip!/readonlyInZip", getUser(), getPassword()); "jdbc:h2:zip:"+dir+"/readonly.zip!/readonlyInZip", getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir); Server server = Server.createTcpServer("-baseDir", dir);
server.start(); server.start();
int port = server.getPort();
try { try {
conn = getConnection( conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonlyInZip", "jdbc:h2:tcp://localhost:" + port + "/zip:readonly.zip!/readonlyInZip",
getUser(), getPassword()); getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
FilePathZip2.register(); FilePathZip2.register();
conn = getConnection( conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonlyInZip", "jdbc:h2:tcp://localhost:" + port + "/zip2:readonly.zip!/readonlyInZip",
getUser(), getPassword()); getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1"); conn.createStatement().execute("select * from test where id=1");
conn.close(); conn.close();
......
...@@ -93,8 +93,9 @@ public class TestAutoReconnect extends TestBase { ...@@ -93,8 +93,9 @@ public class TestAutoReconnect extends TestBase {
"AUTO_SERVER=TRUE;OPEN_NEW=TRUE"; "AUTO_SERVER=TRUE;OPEN_NEW=TRUE";
restart(); restart();
} else { } else {
server = Server.createTcpServer("-tcpPort", "8181").start(); server = Server.createTcpServer().start();
url = "jdbc:h2:tcp://localhost:8181/" + getBaseDir() + "/" + getTestName() + ";" + int port = server.getPort();
url = "jdbc:h2:tcp://localhost:" + port + "/" + getBaseDir() + "/" + getTestName() + ";" +
"FILE_LOCK=SOCKET;AUTO_RECONNECT=TRUE"; "FILE_LOCK=SOCKET;AUTO_RECONNECT=TRUE";
} }
......
...@@ -114,17 +114,18 @@ public class TestOldVersion extends TestBase { ...@@ -114,17 +114,18 @@ public class TestOldVersion extends TestBase {
} }
private void testOldClientNewServer() throws Exception { private void testOldClientNewServer() throws Exception {
Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001"); Server server = org.h2.tools.Server.createTcpServer();
server.start(); server.start();
int port = server.getPort();
assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect( assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect(
"jdbc:h2:tcp://localhost:9001/mem:test", null); "jdbc:h2:tcp://localhost:" + port + "/mem:test", null);
server.stop(); server.stop();
Class<?> serverClass = cl.loadClass("org.h2.tools.Server"); Class<?> serverClass = cl.loadClass("org.h2.tools.Server");
Method m; Method m;
m = serverClass.getMethod("createTcpServer", String[].class); m = serverClass.getMethod("createTcpServer", String[].class);
Object serverOld = m.invoke(null, new Object[] { new String[] { Object serverOld = m.invoke(null, new Object[] { new String[] {
"-tcpPort", "9001" } }); "-tcpPort", "" + port } });
m = serverOld.getClass().getMethod("start"); m = serverOld.getClass().getMethod("start");
m.invoke(serverOld); m.invoke(serverOld);
Connection conn; Connection conn;
......
...@@ -826,10 +826,9 @@ public class TestTools extends TestBase { ...@@ -826,10 +826,9 @@ public class TestTools extends TestBase {
int count = getSize(2, 10); int count = getSize(2, 10);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Server tcpServer = Server. Server tcpServer = Server.
createTcpServer("-tcpPort", "9192").start(); createTcpServer().start();
tcpServer.stop(); tcpServer.stop();
tcpServer = Server.createTcpServer("-tcpPassword", "abc", tcpServer = Server.createTcpServer("-tcpPassword", "abc").start();
"-tcpPort", "9192").start();
tcpServer.stop(); tcpServer.stop();
} }
} }
...@@ -1066,67 +1065,67 @@ public class TestTools extends TestBase { ...@@ -1066,67 +1065,67 @@ public class TestTools extends TestBase {
deleteDb("test"); deleteDb("test");
Server tcpServer = Server.createTcpServer( Server tcpServer = Server.createTcpServer(
"-baseDir", getBaseDir(), "-baseDir", getBaseDir(),
"-tcpPort", "9192",
"-tcpAllowOthers").start(); "-tcpAllowOthers").start();
remainingServers.add(tcpServer); remainingServers.add(tcpServer);
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", ""); final int port = tcpServer.getPort();
conn = getConnection("jdbc:h2:tcp://localhost:"+ port +"/test", "sa", "");
conn.close(); conn.close();
// must not be able to use a different base dir // must not be able to use a different base dir
new AssertThrows(ErrorCode.IO_EXCEPTION_1) { new AssertThrows(ErrorCode.IO_EXCEPTION_1) {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:9192/../test", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+ port +"/../test", "sa", "");
}}; }};
new AssertThrows(ErrorCode.IO_EXCEPTION_1) { new AssertThrows(ErrorCode.IO_EXCEPTION_1) {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:9192/../test2/test", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+port+"/../test2/test", "sa", "");
}}; }};
tcpServer.stop(); tcpServer.stop();
Server tcpServerWithPassword = Server.createTcpServer( Server tcpServerWithPassword = Server.createTcpServer(
"-ifExists", "-ifExists",
"-tcpPassword", "abc", "-tcpPassword", "abc",
"-baseDir", getBaseDir(), "-baseDir", getBaseDir()).start();
"-tcpPort", "9192").start(); final int prt = tcpServerWithPassword.getPort();
remainingServers.add(tcpServerWithPassword); remainingServers.add(tcpServerWithPassword);
// must not be able to create new db // must not be able to create new db
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) { new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:9192/test2", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+prt+"/test2", "sa", "");
}}; }};
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) { new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:9192/test2;ifexists=false", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+prt+"/test2;ifexists=false", "sa", "");
}}; }};
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", ""); conn = getConnection("jdbc:h2:tcp://localhost:"+prt+"/test", "sa", "");
conn.close(); conn.close();
new AssertThrows(ErrorCode.WRONG_USER_OR_PASSWORD) { new AssertThrows(ErrorCode.WRONG_USER_OR_PASSWORD) {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
Server.shutdownTcpServer("tcp://localhost:9192", "", true, false); Server.shutdownTcpServer("tcp://localhost:"+prt, "", true, false);
}}; }};
conn = getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", ""); conn = getConnection("jdbc:h2:tcp://localhost:"+prt+"/test", "sa", "");
// conn.close(); // conn.close();
Server.shutdownTcpServer("tcp://localhost:9192", "abc", true, false); Server.shutdownTcpServer("tcp://localhost:"+prt, "abc", true, false);
// check that the database is closed // check that the database is closed
deleteDb("test"); deleteDb("test");
// server must have been closed // server must have been closed
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this). assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
getConnection("jdbc:h2:tcp://localhost:9192/test", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+prt+"/test", "sa", "");
JdbcUtils.closeSilently(conn); JdbcUtils.closeSilently(conn);
// Test filesystem prefix and escape from baseDir // Test filesystem prefix and escape from baseDir
deleteDb("testSplit"); deleteDb("testSplit");
server = Server.createTcpServer( server = Server.createTcpServer(
"-baseDir", getBaseDir(), "-baseDir", getBaseDir(),
"-tcpPort", "9192",
"-tcpAllowOthers").start(); "-tcpAllowOthers").start();
conn = getConnection("jdbc:h2:tcp://localhost:9192/split:testSplit", "sa", ""); final int p = server.getPort();
conn = getConnection("jdbc:h2:tcp://localhost:"+p+"/split:testSplit", "sa", "");
conn.close(); conn.close();
assertThrows(ErrorCode.IO_EXCEPTION_1, this). assertThrows(ErrorCode.IO_EXCEPTION_1, this).
getConnection("jdbc:h2:tcp://localhost:9192/../test", "sa", ""); getConnection("jdbc:h2:tcp://localhost:"+p+"/../test", "sa", "");
server.stop(); server.stop();
deleteDb("testSplit"); deleteDb("testSplit");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论