01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.unit;
07:
08: import java.sql.Connection;
09: import java.sql.DriverManager;
10: import java.sql.Statement;
11:
12: import org.h2.test.TestBase;
13: import org.h2.tools.DeleteDbFiles;
14:
15: /**
16: * Tests database recovery.
17: */
18: public class TestRecovery extends TestBase {
19:
20: public void test() throws Exception {
21: DeleteDbFiles.execute(baseDir, "recovery", true);
22: Class.forName("org.h2.Driver");
23: String url = "jdbc:h2:" + baseDir + "/recovery;write_delay=0";
24: Connection conn1 = DriverManager.getConnection(url, "sa", "sa");
25: Statement stat1 = conn1.createStatement();
26: Connection conn2 = DriverManager.getConnection(url, "sa", "sa");
27: Statement stat2 = conn2.createStatement();
28: stat1
29: .execute("create table test as select * from system_range(1, 100)");
30: stat1.execute("create table abc(id int)");
31: conn2.setAutoCommit(false);
32: // this is not committed
33: // recovery might try to roll back this
34: stat2.execute("delete from test");
35: // overwrite the data of test
36: stat1
37: .execute("insert into abc select * from system_range(1, 100)");
38: stat1.execute("shutdown immediately");
39: // Recover.execute("data", null);
40: Connection conn = DriverManager.getConnection(url, "sa", "sa");
41: conn.close();
42: }
43:
44: }
|