sl@0: # 2008 August 29 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: # sl@0: # This file is focused on testing the pcache module. sl@0: # sl@0: # $Id: pcache.test,v 1.2 2008/09/05 05:29:09 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: sl@0: # The pcache module limits the number of pages available to purgeable sl@0: # caches to the sum of the 'cache_size' values for the set of open sl@0: # caches. This block of tests, pcache-1.*, test that the library behaves sl@0: # corrctly when it is forced to exceed this limit. sl@0: # sl@0: do_test pcache-1.1 { sl@0: db close sl@0: pcache_stats sl@0: } {current 0 max 0 min 0 recyclable 0} sl@0: sl@0: do_test pcache-1.2 { sl@0: sqlite3 db test.db sl@0: execsql { sl@0: PRAGMA cache_size=10; sl@0: PRAGMA auto_vacuum=0; sl@0: } sl@0: pcache_stats sl@0: } {current 1 max 10 min 10 recyclable 1} sl@0: sl@0: do_test pcache-1.3 { sl@0: execsql { sl@0: BEGIN; sl@0: CREATE TABLE t1(a, b, c); sl@0: CREATE TABLE t2(a, b, c); sl@0: CREATE TABLE t3(a, b, c); sl@0: CREATE TABLE t4(a, b, c); sl@0: CREATE TABLE t5(a, b, c); sl@0: } sl@0: pcache_stats sl@0: } {current 6 max 10 min 10 recyclable 0} sl@0: sl@0: do_test pcache-1.4 { sl@0: execsql { sl@0: CREATE TABLE t6(a, b, c); sl@0: CREATE TABLE t7(a, b, c); sl@0: CREATE TABLE t8(a, b, c); sl@0: CREATE TABLE t9(a, b, c); sl@0: } sl@0: pcache_stats sl@0: } {current 10 max 10 min 10 recyclable 0} sl@0: sl@0: do_test pcache-1.5 { sl@0: sqlite3 db2 test.db sl@0: execsql "PRAGMA cache_size=10" db2 sl@0: pcache_stats sl@0: } {current 11 max 20 min 20 recyclable 1} sl@0: sl@0: do_test pcache-1.6 { sl@0: execsql { sl@0: BEGIN; sl@0: SELECT * FROM sqlite_master; sl@0: } db2 sl@0: pcache_stats sl@0: } {current 11 max 20 min 20 recyclable 0} sl@0: sl@0: # At this point connection db2 has a read lock on the database file and a sl@0: # single pinned page in its cache. Connection [db] is holding 10 dirty sl@0: # pages. It cannot recycle them because of the read lock held by db2. sl@0: # sl@0: do_test pcache-1.6 { sl@0: execsql { sl@0: CREATE INDEX i1 ON t1(a, b); sl@0: CREATE INDEX i2 ON t2(a, b); sl@0: CREATE INDEX i3 ON t3(a, b); sl@0: CREATE INDEX i4 ON t4(a, b); sl@0: CREATE INDEX i5 ON t5(a, b); sl@0: CREATE INDEX i6 ON t6(a, b); sl@0: CREATE INDEX i7 ON t7(a, b); sl@0: CREATE INDEX i8 ON t8(a, b); sl@0: CREATE INDEX i9 ON t9(a, b); sl@0: } sl@0: pcache_stats sl@0: } {current 20 max 20 min 20 recyclable 0} sl@0: sl@0: do_test pcache-1.7 { sl@0: execsql { sl@0: CREATE TABLE t10(a, b, c); sl@0: } sl@0: pcache_stats sl@0: } {current 21 max 20 min 20 recyclable 0} sl@0: sl@0: # Rolling back the transaction held by db2 at this point releases a pinned sl@0: # page. Because the number of allocated pages is greater than the sl@0: # configured maximum, this page should be freed immediately instead of sl@0: # recycled. sl@0: # sl@0: do_test pcache-1.8 { sl@0: execsql {ROLLBACK} db2 sl@0: pcache_stats sl@0: } {current 20 max 20 min 20 recyclable 0} sl@0: sl@0: do_test pcache-1.9 { sl@0: execsql COMMIT sl@0: pcache_stats sl@0: } {current 20 max 20 min 20 recyclable 20} sl@0: sl@0: do_test pcache-1.10 { sl@0: db2 close sl@0: pcache_stats sl@0: } {current 10 max 10 min 10 recyclable 10} sl@0: sl@0: do_test pcache-1.11 { sl@0: execsql { PRAGMA cache_size = 20 } sl@0: pcache_stats sl@0: } {current 10 max 20 min 10 recyclable 10} sl@0: sl@0: do_test pcache-1.12 { sl@0: execsql { sl@0: SELECT * FROM t1 ORDER BY a; SELECT * FROM t1; sl@0: SELECT * FROM t2 ORDER BY a; SELECT * FROM t2; sl@0: SELECT * FROM t3 ORDER BY a; SELECT * FROM t3; sl@0: SELECT * FROM t4 ORDER BY a; SELECT * FROM t4; sl@0: SELECT * FROM t5 ORDER BY a; SELECT * FROM t5; sl@0: SELECT * FROM t6 ORDER BY a; SELECT * FROM t6; sl@0: SELECT * FROM t7 ORDER BY a; SELECT * FROM t7; sl@0: SELECT * FROM t8 ORDER BY a; SELECT * FROM t8; sl@0: SELECT * FROM t9 ORDER BY a; SELECT * FROM t9; sl@0: } sl@0: pcache_stats sl@0: } {current 19 max 20 min 10 recyclable 19} sl@0: sl@0: do_test pcache-1.13 { sl@0: execsql { PRAGMA cache_size = 15 } sl@0: pcache_stats sl@0: } {current 15 max 15 min 10 recyclable 15} sl@0: sl@0: finish_test sl@0: