sl@0: # 2007 May 04 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing the incremental vacuum feature. sl@0: # sl@0: # $Id: incrvacuum2.test,v 1.5 2008/05/07 07:13:16 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If this build of the library does not support auto-vacuum, omit this sl@0: # whole file. sl@0: ifcapable {!autovacuum || !pragma} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # If the OMIT_INCRBLOB symbol was defined at compile time, there sl@0: # is no zeroblob() function available. So create a similar sl@0: # function here using Tcl. It doesn't return a blob, but it returns sl@0: # data of the required length, which is good enough for this sl@0: # test file. sl@0: ifcapable !incrblob { sl@0: proc zeroblob {n} { string repeat 0 $n } sl@0: db function zeroblob zeroblob sl@0: } sl@0: sl@0: sl@0: # Create a database in incremental vacuum mode that has many sl@0: # pages on the freelist. sl@0: # sl@0: do_test incrvacuum2-1.1 { sl@0: execsql { sl@0: PRAGMA page_size=1024; sl@0: PRAGMA auto_vacuum=incremental; sl@0: CREATE TABLE t1(x); sl@0: INSERT INTO t1 VALUES(zeroblob(30000)); sl@0: DELETE FROM t1; sl@0: } sl@0: file size test.db sl@0: } {32768} sl@0: sl@0: # Vacuum off a single page. sl@0: # sl@0: do_test incrvacuum2-1.2 { sl@0: execsql { sl@0: PRAGMA incremental_vacuum(1); sl@0: } sl@0: file size test.db sl@0: } {31744} sl@0: sl@0: # Vacuum off five pages sl@0: # sl@0: do_test incrvacuum2-1.3 { sl@0: execsql { sl@0: PRAGMA incremental_vacuum(5); sl@0: } sl@0: file size test.db sl@0: } {26624} sl@0: sl@0: # Vacuum off all the rest sl@0: # sl@0: do_test incrvacuum2-1.4 { sl@0: execsql { sl@0: PRAGMA incremental_vacuum(1000); sl@0: } sl@0: file size test.db sl@0: } {3072} sl@0: sl@0: # Make sure incremental vacuum works on attached databases. sl@0: # sl@0: ifcapable attach { sl@0: do_test incrvacuum2-2.1 { sl@0: file delete -force test2.db test2.db-journal sl@0: execsql { sl@0: ATTACH DATABASE 'test2.db' AS aux; sl@0: PRAGMA aux.auto_vacuum=incremental; sl@0: CREATE TABLE aux.t2(x); sl@0: INSERT INTO t2 VALUES(zeroblob(30000)); sl@0: INSERT INTO t1 SELECT * FROM t2; sl@0: DELETE FROM t2; sl@0: DELETE FROM t1; sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {32768 32768} sl@0: do_test incrvacuum2-2.2 { sl@0: execsql { sl@0: PRAGMA aux.incremental_vacuum(1) sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {32768 31744} sl@0: do_test incrvacuum2-2.3 { sl@0: execsql { sl@0: PRAGMA aux.incremental_vacuum(5) sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {32768 26624} sl@0: do_test incrvacuum2-2.4 { sl@0: execsql { sl@0: PRAGMA main.incremental_vacuum(5) sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {27648 26624} sl@0: do_test incrvacuum2-2.5 { sl@0: execsql { sl@0: PRAGMA aux.incremental_vacuum sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {27648 3072} sl@0: do_test incrvacuum2-2.6 { sl@0: execsql { sl@0: PRAGMA incremental_vacuum(1) sl@0: } sl@0: list [file size test.db] [file size test2.db] sl@0: } {26624 3072} sl@0: } sl@0: sl@0: do_test incrvacuum2-3.1 { sl@0: execsql { sl@0: PRAGMA auto_vacuum = 'full'; sl@0: BEGIN; sl@0: CREATE TABLE abc(a); sl@0: INSERT INTO abc VALUES(randstr(1500,1500)); sl@0: COMMIT; sl@0: } sl@0: } {} sl@0: do_test incrvacuum2-3.2 { sl@0: execsql { sl@0: BEGIN; sl@0: DELETE FROM abc; sl@0: PRAGMA incremental_vacuum; sl@0: COMMIT; sl@0: } sl@0: } {} sl@0: sl@0: integrity_check incremental2-3.3 sl@0: sl@0: finish_test