use of org.h2.tools.Restore in project h2database by h2database.
the class TestWeb method testTools.
private void testTools() throws Exception {
if (config.memory || config.cipher != null) {
return;
}
deleteDb(getTestName());
Connection conn = getConnection(getTestName());
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," + getTestName() + ",-file," + getBaseDir() + "/backup.zip");
deleteDb(getTestName());
assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip"));
result = client.get(url, "tools.do?tool=DeleteDbFiles&args=-dir," + getBaseDir() + ",-db," + getTestName());
String fn = getBaseDir() + "/" + getTestName();
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," + getTestName() + ",-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," + getTestName());
assertTrue(FileUtils.exists(getBaseDir() + "/" + getTestName() + ".h2.sql"));
FileUtils.delete(getBaseDir() + "/web.h2.sql");
result = client.get(url, "tools.do?tool=RunScript&args=-script," + getBaseDir() + "/" + getTestName() + ".h2.sql,-url," + getURL(getTestName(), true) + ",-user," + getUser() + ",-password," + getPassword());
FileUtils.delete(getBaseDir() + "/" + getTestName() + ".h2.sql");
assertTrue(FileUtils.exists(fn));
deleteDb(getTestName());
} finally {
server.shutdown();
}
}
use of org.h2.tools.Restore in project h2database by h2database.
the class TestGeneralCommonTableQueries method testSimple3RowRecursiveQueryWithLazyEval.
private void testSimple3RowRecursiveQueryWithLazyEval() throws Exception {
String[] expectedRowData = new String[] { "|6" };
String[] expectedColumnTypes = new String[] { "BIGINT" };
String[] expectedColumnNames = new String[] { "SUM(N)" };
// back up the config - to restore it after this test
TestAll backupConfig = config;
config = new TestAll();
try {
// Test with settings: lazy mvStore memory mvcc multiThreaded
// connection url is
// mem:script;MV_STORE=true;LOG=1;LOCK_TIMEOUT=50;MVCC=TRUE;
// MULTI_THREADED=TRUE;LAZY_QUERY_EXECUTION=1
config.lazy = true;
config.mvStore = true;
config.memory = true;
config.mvcc = true;
config.multiThreaded = true;
String setupSQL = "--no config set";
String withQuery = "select sum(n) from (\n" + " with recursive r(n) as (\n" + " (select 1) union all (select n+1 from r where n < 3) \n" + " )\n" + " select n from r \n" + ")\n";
int maxRetries = 10;
int expectedNumberOfRows = expectedRowData.length;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setupSQL, withQuery, maxRetries - 1, expectedColumnTypes);
} finally {
config = backupConfig;
}
}
use of org.h2.tools.Restore in project h2database by h2database.
the class WebApp method tools.
private String tools() {
try {
String toolName = (String) attributes.get("tool");
session.put("tool", toolName);
String args = (String) attributes.get("args");
String[] argList = StringUtils.arraySplit(args, ',', false);
Tool tool = null;
if ("Backup".equals(toolName)) {
tool = new Backup();
} else if ("Restore".equals(toolName)) {
tool = new Restore();
} else if ("Recover".equals(toolName)) {
tool = new Recover();
} else if ("DeleteDbFiles".equals(toolName)) {
tool = new DeleteDbFiles();
} else if ("ChangeFileEncryption".equals(toolName)) {
tool = new ChangeFileEncryption();
} else if ("Script".equals(toolName)) {
tool = new Script();
} else if ("RunScript".equals(toolName)) {
tool = new RunScript();
} else if ("ConvertTraceFile".equals(toolName)) {
tool = new ConvertTraceFile();
} else if ("CreateCluster".equals(toolName)) {
tool = new CreateCluster();
} else {
throw DbException.throwInternalError(toolName);
}
ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
PrintStream out = new PrintStream(outBuff, false, "UTF-8");
tool.setOut(out);
try {
tool.runTool(argList);
out.flush();
String o = new String(outBuff.toByteArray(), StandardCharsets.UTF_8);
String result = PageParser.escapeHtml(o);
session.put("toolResult", result);
} catch (Exception e) {
session.put("toolResult", getStackTrace(0, e, true));
}
} catch (Exception e) {
server.traceError(e);
}
return "tools.jsp";
}
Aggregations