本文整理汇总了Java中org.h2.tools.Server.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java Server.shutdown方法的具体用法?Java Server.shutdown怎么用?Java Server.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.Server
的用法示例。
在下文中一共展示了Server.shutdown方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTransfer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testTransfer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties", "null");
File transfer = new File("transfer");
transfer.mkdirs();
try {
FileOutputStream f = new FileOutputStream("transfer/test.txt");
f.write("Hello World".getBytes());
f.close();
WebClient client = new WebClient();
String url = "http://localhost:8182";
String result = client.get(url);
client.readSessionId(result);
String test = client.get(url, "transfer/test.txt");
assertEquals("Hello World", test);
new File("transfer/testUpload.txt").delete();
client.upload(url + "/transfer/testUpload.txt",
"testUpload.txt", new ByteArrayInputStream(
"Hallo Welt".getBytes()));
byte[] d = IOUtils.readBytesAndClose(
new FileInputStream("transfer/testUpload.txt"), -1);
assertEquals("Hallo Welt", new String(d));
new File("transfer/testUpload.txt").delete();
} finally {
server.shutdown();
FileUtils.deleteRecursive("transfer", true);
}
}
示例2: testServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testServer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties",
"null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
client.setAcceptLanguage("de-de,de;q=0.5");
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
assertEquals("text/html", client.getContentType());
assertContains(result, "Einstellung");
client.get(url, "favicon.ico");
assertEquals("image/x-icon", client.getContentType());
client.get(url, "ico_ok.gif");
assertEquals("image/gif", client.getContentType());
client.get(url, "tree.js");
assertEquals("text/javascript", client.getContentType());
client.get(url, "stylesheet.css");
assertEquals("text/css", client.getContentType());
client.get(url, "admin.do");
try {
client.get(url, "adminShutdown.do");
} catch (IOException e) {
// expected
Thread.sleep(1000);
}
} finally {
server.shutdown();
}
// it should be stopped now
server = Server.createTcpServer("-tcpPort", "9101");
server.start();
server.stop();
}
示例3: testIfExists
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testIfExists() throws Exception {
Connection conn = getConnection("jdbc:h2:mem:webExists",
getUser(), getPassword());
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-ifExists", "-web", "-webPort", "8182",
"-properties", "null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:webExists" +
"&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_");
assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:web" +
"&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_");
assertContains(result, "Exception");
} finally {
server.shutdown();
conn.close();
}
}
示例4: contextDestroyed
import org.h2.tools.Server; //导入方法依赖的package包/类
@Override
public void contextDestroyed(final ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
Server h2TestDb = (Server) context.getAttribute(H2_TESTDB);
if (h2TestDb != null) {
h2TestDb.shutdown();
}
}
示例5: contextDestroyed
import org.h2.tools.Server; //导入方法依赖的package包/类
@Override
public void contextDestroyed(final ServletContextEvent sce) {
final ServletContext context = sce.getServletContext();
final Server h2TestDb = (Server) context.getAttribute(H2_TESTDB);
if (h2TestDb != null) {
h2TestDb.shutdown();
}
}
示例6: testServerMain
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testServerMain() throws SQLException {
String result;
Connection conn;
result = runServer(0, new String[]{"-?"});
assertTrue(result.contains("Starts the H2 Console"));
assertTrue(result.indexOf("Unknown option") < 0);
result = runServer(1, new String[]{"-xy"});
assertTrue(result.contains("Starts the H2 Console"));
assertTrue(result.contains("Feature not supported"));
result = runServer(0, new String[]{"-tcp",
"-tcpPort", "9001", "-tcpPassword", "abc"});
assertTrue(result.contains("tcp://"));
assertTrue(result.contains(":9001"));
assertTrue(result.contains("only local"));
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = getConnection("jdbc:h2:tcp://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.contains("Shutting down"));
result = runServer(0, new String[]{"-tcp",
"-tcpAllowOthers", "-tcpPort", "9001", "-tcpPassword", "abcdef", "-tcpSSL"});
assertTrue(result.contains("ssl://"));
assertTrue(result.contains(":9001"));
assertTrue(result.contains("others can"));
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"ssl://localhost:9001", "-tcpPassword", "abcdef"});
assertTrue(result.contains("Shutting down"));
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
result = runServer(0, new String[]{
"-web", "-webPort", "9002", "-webAllowOthers", "-webSSL",
"-pg", "-pgAllowOthers", "-pgPort", "9003",
"-tcp", "-tcpAllowOthers", "-tcpPort", "9006", "-tcpPassword", "abc"});
Server stop = server;
assertTrue(result.contains("https://"));
assertTrue(result.contains(":9002"));
assertTrue(result.contains("pg://"));
assertTrue(result.contains(":9003"));
assertTrue(result.contains("others can"));
assertTrue(result.indexOf("only local") < 0);
assertTrue(result.contains("tcp://"));
assertTrue(result.contains(":9006"));
conn = getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"tcp://localhost:9006", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.contains("Shutting down"));
stop.shutdown();
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
}
示例7: testTools
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testTools() throws Exception {
if (config.memory || config.cipher != null) {
return;
}
deleteDb("web");
Connection conn = getConnection("web");
conn.createStatement().execute(
"create table test(id int) as select 1");
conn.close();
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182",
"-properties", "null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "tools.jsp");
FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Backup&args=-dir," +
getBaseDir() + ",-db,web,-file," +
getBaseDir() + "/backup.zip");
deleteDb("web");
assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip"));
result = client.get(url,
"tools.do?tool=DeleteDbFiles&args=-dir," +
getBaseDir() + ",-db,web");
String fn = getBaseDir() + "/web";
if (config.mvStore) {
fn += Constants.SUFFIX_MV_FILE;
} else {
fn += Constants.SUFFIX_PAGE_FILE;
}
assertFalse(FileUtils.exists(fn));
result = client.get(url, "tools.do?tool=Restore&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() +
"/backup.zip");
assertTrue(FileUtils.exists(fn));
FileUtils.delete(getBaseDir() + "/web.h2.sql");
FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Recover&args=-dir," +
getBaseDir() + ",-db,web");
assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.sql"));
FileUtils.delete(getBaseDir() + "/web.h2.sql");
result = client.get(url, "tools.do?tool=RunScript&args=-script," +
getBaseDir() + "/web.h2.sql,-url," + getURL("web", true) +
",-user," + getUser() + ",-password," + getPassword());
FileUtils.delete(getBaseDir() + "/web.h2.sql");
assertTrue(FileUtils.exists(fn));
deleteDb("web");
} finally {
server.shutdown();
}
}