dddbcdcc68
FossilOrigin-Name: f6a6d2b8872c05089810b1e095f39011f3035408
175 lines
3.8 KiB
Plaintext
175 lines
3.8 KiB
Plaintext
# 2007 April 26
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# May you do good and not evil.
|
|
# May you find forgiveness for yourself and forgive others.
|
|
# May you share freely, never taking more than you give.
|
|
#
|
|
#***********************************************************************
|
|
# This file implements regression tests for SQLite library. The
|
|
# focus of this file is testing the incremental vacuum feature.
|
|
#
|
|
# $Id: incrvacuum.test,v 1.1 2007/04/26 14:42:36 danielk1977 Exp $
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
# If this build of the library does not support auto-vacuum, omit this
|
|
# whole file.
|
|
ifcapable {!autovacuum || !pragma} {
|
|
finish_test
|
|
return
|
|
}
|
|
|
|
#---------------------------------------------------------------------
|
|
# Test the pragma on an empty database.
|
|
#
|
|
do_test incrvacuum-1.1 {
|
|
execsql {
|
|
pragma auto_vacuum;
|
|
}
|
|
} {0}
|
|
do_test incrvacuum-1.2 {
|
|
execsql {
|
|
pragma auto_vacuum = 'full';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {1}
|
|
do_test incrvacuum-1.3 {
|
|
execsql {
|
|
pragma auto_vacuum = 'incremental';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {2}
|
|
do_test incrvacuum-1.4 {
|
|
execsql {
|
|
pragma auto_vacuum = 'invalid';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {0}
|
|
do_test incrvacuum-1.5 {
|
|
execsql {
|
|
pragma auto_vacuum = 1;
|
|
pragma auto_vacuum;
|
|
}
|
|
} {1}
|
|
do_test incrvacuum-1.6 {
|
|
execsql {
|
|
pragma auto_vacuum = '2';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {2}
|
|
do_test incrvacuum-1.7 {
|
|
execsql {
|
|
pragma auto_vacuum = 5;
|
|
pragma auto_vacuum;
|
|
}
|
|
} {0}
|
|
|
|
#---------------------------------------------------------------------
|
|
# Test the pragma on a non-empty database. It is possible to toggle
|
|
# the connection between "full" and "incremental" mode, but not to
|
|
# change from either of these to "none", or from "none" to "full" or
|
|
# "incremental".
|
|
#
|
|
do_test incrvacuum-2.1 {
|
|
execsql {
|
|
pragma auto_vacuum = 1;
|
|
CREATE TABLE abc(a, b, c);
|
|
}
|
|
} {}
|
|
do_test incrvacuum-2.2 {
|
|
execsql {
|
|
pragma auto_vacuum = 'none';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {1}
|
|
do_test incrvacuum-2.3 {
|
|
execsql {
|
|
pragma auto_vacuum = 'incremental';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {2}
|
|
do_test incrvacuum-2.4 {
|
|
execsql {
|
|
pragma auto_vacuum = 'full';
|
|
pragma auto_vacuum;
|
|
}
|
|
} {1}
|
|
|
|
#---------------------------------------------------------------------
|
|
# Test that when the auto_vacuum mode is "incremental", the database
|
|
# does not shrink when pages are removed from it. But it does if
|
|
# the mode is set to "full".
|
|
#
|
|
do_test incrvacuum-3.1 {
|
|
execsql {
|
|
pragma auto_vacuum;
|
|
}
|
|
} {1}
|
|
do_test incrvacuum-3.2 {
|
|
set ::str [string repeat 1234567890 110]
|
|
execsql {
|
|
PRAGMA auto_vacuum = 2;
|
|
BEGIN;
|
|
CREATE TABLE tbl2(str);
|
|
INSERT INTO tbl2 VALUES($::str);
|
|
COMMIT;
|
|
}
|
|
# 5 pages:
|
|
#
|
|
# 1 -> database header
|
|
# 2 -> first back-pointer page
|
|
# 3 -> table abc
|
|
# 4 -> table tbl2
|
|
# 5 -> table tbl2 overflow page.
|
|
#
|
|
expr {[file size test.db] / 1024}
|
|
} {5}
|
|
do_test incrvacuum-3.3 {
|
|
execsql {
|
|
DROP TABLE abc;
|
|
DELETE FROM tbl2;
|
|
}
|
|
expr {[file size test.db] / 1024}
|
|
} {5}
|
|
do_test incrvacuum-3.4 {
|
|
execsql {
|
|
PRAGMA auto_vacuum = 1;
|
|
INSERT INTO tbl2 VALUES('hello world');
|
|
}
|
|
expr {[file size test.db] / 1024}
|
|
} {3}
|
|
|
|
#---------------------------------------------------------------------
|
|
# Try to run a simple incremental vacuum.
|
|
#
|
|
do_test incrvacuum-4.1 {
|
|
set ::str [string repeat 1234567890 110]
|
|
execsql {
|
|
PRAGMA auto_vacuum = 2;
|
|
INSERT INTO tbl2 VALUES($::str);
|
|
CREATE TABLE tbl1(a, b, c);
|
|
}
|
|
expr {[file size test.db] / 1024}
|
|
} {5}
|
|
do_test incrvacuum-4.2 {
|
|
execsql {
|
|
DELETE FROM tbl2;
|
|
DROP TABLE tbl1;
|
|
}
|
|
expr {[file size test.db] / 1024}
|
|
} {5}
|
|
do_test incrvacuum-4.3 {
|
|
set ::nStep 0
|
|
db eval {INCREMENTAL VACUUM} {
|
|
incr ::nStep
|
|
}
|
|
list [expr {[file size test.db] / 1024}] $::nStep
|
|
} {3 2}
|
|
|
|
finish_test
|
|
|