提交 2da176f4 authored 作者: Andrei Tokar's avatar Andrei Tokar

test for SHUTDOWN DEFRAG of a big database added

上级 79746f08
......@@ -133,6 +133,7 @@ import org.h2.test.store.TestCacheLIRS;
import org.h2.test.store.TestCacheLongKeyLIRS;
import org.h2.test.store.TestConcurrent;
import org.h2.test.store.TestDataUtils;
import org.h2.test.store.TestDefrag;
import org.h2.test.store.TestFreeSpace;
import org.h2.test.store.TestKillProcessWhileWriting;
import org.h2.test.store.TestMVRTree;
......@@ -922,6 +923,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestFileLockSerialized());
addTest(new TestFileLockProcess());
addTest(new TestFileSystem());
addTest(new TestDefrag());
addTest(new TestTools());
addTest(new TestSampleApps());
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.store;
import static org.h2.engine.Constants.SUFFIX_MV_FILE;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* Test off-line compaction procedure used by SHUTDOWN DEFRAG command
*
* @author <a href='mailto:andrei.tokar@gmail.com'>Andrei Tokar</a>
*/
public class TestDefrag extends TestDb
{
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
@Override
public boolean isEnabled() {
return config.mvStore && !config.memory && config.big && !config.travis;
}
@Override
public void test() throws Exception {
String dbName = getTestName();
deleteDb(dbName);
File dbFile = new File(getBaseDir(), dbName + SUFFIX_MV_FILE);
try (Connection c = getConnection(dbName)) {
try (Statement st = c.createStatement()) {
st.execute("CREATE TABLE IF NOT EXISTS test (id INT PRIMARY KEY, txt varchar)" +
" AS SELECT x, x || SPACE(200) FROM SYSTEM_RANGE(1,10000000)");
}
long origSize = dbFile.length();
assertTrue(origSize > 4_000_000_000L);
try (Statement st = c.createStatement()) {
st.execute("shutdown defrag");
}
long compactedSize = dbFile.length();
assertTrue(compactedSize < 400_000_000);
}
try (Connection c = getConnection(dbName + ";LAZY_QUERY_EXECUTION=1")) {
try (Statement st = c.createStatement()) {
ResultSet rs = st.executeQuery("SELECT * FROM test");
int count = 0;
while (rs.next()) {
++count;
assertEquals(count, rs.getInt(1));
assertTrue(rs.getString(2).startsWith(count + " "));
}
assertEquals(10_000_000, count);
}
}
deleteDb(dbName);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论