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.db;
07:
08: import java.io.File;
09: import java.sql.Connection;
10: import java.sql.Statement;
11:
12: import org.h2.test.TestBase;
13:
14: /**
15: * Tests if disk space is reused after deleting many rows.
16: */
17: public class TestSpaceReuse extends TestBase {
18:
19: public void test() throws Exception {
20: if (config.memory) {
21: return;
22: }
23: deleteDb("spaceReuse");
24: long first = 0, now = 0;
25: for (int i = 0; i < 10; i++) {
26: Connection conn = getConnection("spaceReuse");
27: Statement stat = conn.createStatement();
28: stat.execute("create table if not exists t(i int)");
29: stat
30: .execute("insert into t select x from system_range(1, 500)");
31: conn.close();
32: conn = getConnection("spaceReuse");
33: conn.createStatement().execute("delete from t");
34: conn.close();
35: now = new File(baseDir + "/spaceReuse.data.db").length();
36: if (first == 0) {
37: first = now;
38: }
39: }
40: if (now > first) {
41: error("first: " + first + " now: " + now);
42: }
43: }
44:
45: }
|