1062d4cb0Sdanielk1977# 2008 August 29 2062d4cb0Sdanielk1977# 3062d4cb0Sdanielk1977# The author disclaims copyright to this source code. In place of 4062d4cb0Sdanielk1977# a legal notice, here is a blessing: 5062d4cb0Sdanielk1977# 6062d4cb0Sdanielk1977# May you do good and not evil. 7062d4cb0Sdanielk1977# May you find forgiveness for yourself and forgive others. 8062d4cb0Sdanielk1977# May you share freely, never taking more than you give. 9062d4cb0Sdanielk1977# 10062d4cb0Sdanielk1977#*********************************************************************** 11062d4cb0Sdanielk1977# 12062d4cb0Sdanielk1977# This file is focused on testing the pcache module. 13062d4cb0Sdanielk1977# 14ea24ac4bSdanielk1977# $Id: pcache.test,v 1.5 2009/05/08 06:52:48 danielk1977 Exp $ 15062d4cb0Sdanielk1977 16062d4cb0Sdanielk1977set testdir [file dirname $argv0] 17062d4cb0Sdanielk1977source $testdir/tester.tcl 18062d4cb0Sdanielk1977 1968928b6cSdan# Do not use a codec for tests in this file, as the database file is 2068928b6cSdan# manipulated directly using tcl scripts (using the [hexio_write] command). 2168928b6cSdan# 2268928b6cSdando_not_use_codec 23062d4cb0Sdanielk1977 24986d3b95Sdrh# Only works with a mode-2 pcache where all pcaches share a single set 25986d3b95Sdrh# of pages. 26986d3b95Sdrh# 27986d3b95Sdrhifcapable {!memorymanage && threadsafe} { 28986d3b95Sdrh finish_test 29986d3b95Sdrh return 30986d3b95Sdrh} 31986d3b95Sdrh 32062d4cb0Sdanielk1977# The pcache module limits the number of pages available to purgeable 33062d4cb0Sdanielk1977# caches to the sum of the 'cache_size' values for the set of open 34062d4cb0Sdanielk1977# caches. This block of tests, pcache-1.*, test that the library behaves 35062d4cb0Sdanielk1977# corrctly when it is forced to exceed this limit. 36062d4cb0Sdanielk1977# 37062d4cb0Sdanielk1977do_test pcache-1.1 { 38062d4cb0Sdanielk1977 db close 39062d4cb0Sdanielk1977 pcache_stats 40062d4cb0Sdanielk1977} {current 0 max 0 min 0 recyclable 0} 41062d4cb0Sdanielk1977 42062d4cb0Sdanielk1977do_test pcache-1.2 { 43062d4cb0Sdanielk1977 sqlite3 db test.db 44f7cbfae9Sdanielk1977 execsql { 456fa0fe13Sdanielk1977 PRAGMA cache_size=12; 46f7cbfae9Sdanielk1977 PRAGMA auto_vacuum=0; 473492f4f9Sdan PRAGMA mmap_size=0; 48f7cbfae9Sdanielk1977 } 49062d4cb0Sdanielk1977 pcache_stats 506fa0fe13Sdanielk1977} {current 1 max 12 min 10 recyclable 1} 51062d4cb0Sdanielk1977 52062d4cb0Sdanielk1977do_test pcache-1.3 { 53062d4cb0Sdanielk1977 execsql { 54062d4cb0Sdanielk1977 BEGIN; 55062d4cb0Sdanielk1977 CREATE TABLE t1(a, b, c); 56062d4cb0Sdanielk1977 CREATE TABLE t2(a, b, c); 57062d4cb0Sdanielk1977 CREATE TABLE t3(a, b, c); 58062d4cb0Sdanielk1977 CREATE TABLE t4(a, b, c); 59062d4cb0Sdanielk1977 CREATE TABLE t5(a, b, c); 60062d4cb0Sdanielk1977 } 61062d4cb0Sdanielk1977 pcache_stats 626fa0fe13Sdanielk1977} {current 6 max 12 min 10 recyclable 0} 63062d4cb0Sdanielk1977 64062d4cb0Sdanielk1977do_test pcache-1.4 { 65062d4cb0Sdanielk1977 execsql { 66062d4cb0Sdanielk1977 CREATE TABLE t6(a, b, c); 67062d4cb0Sdanielk1977 CREATE TABLE t7(a, b, c); 68062d4cb0Sdanielk1977 CREATE TABLE t8(a, b, c); 69062d4cb0Sdanielk1977 CREATE TABLE t9(a, b, c); 70062d4cb0Sdanielk1977 } 71062d4cb0Sdanielk1977 pcache_stats 726fa0fe13Sdanielk1977} {current 10 max 12 min 10 recyclable 0} 73062d4cb0Sdanielk1977 74062d4cb0Sdanielk1977do_test pcache-1.5 { 75062d4cb0Sdanielk1977 sqlite3 db2 test.db 76*957026acSdrh execsql "PRAGMA cache_size; PRAGMA cache_size=10" db2 77062d4cb0Sdanielk1977 pcache_stats 786fa0fe13Sdanielk1977} {current 11 max 22 min 20 recyclable 1} 79062d4cb0Sdanielk1977 80ee03d629Sdrhdo_test pcache-1.6.1 { 81062d4cb0Sdanielk1977 execsql { 82062d4cb0Sdanielk1977 BEGIN; 83062d4cb0Sdanielk1977 SELECT * FROM sqlite_master; 84062d4cb0Sdanielk1977 } db2 85062d4cb0Sdanielk1977 pcache_stats 866fa0fe13Sdanielk1977} {current 11 max 22 min 20 recyclable 0} 87062d4cb0Sdanielk1977 88062d4cb0Sdanielk1977# At this point connection db2 has a read lock on the database file and a 89062d4cb0Sdanielk1977# single pinned page in its cache. Connection [db] is holding 10 dirty 90062d4cb0Sdanielk1977# pages. It cannot recycle them because of the read lock held by db2. 91062d4cb0Sdanielk1977# 92ee03d629Sdrhdo_test pcache-1.6.2 { 93062d4cb0Sdanielk1977 execsql { 94062d4cb0Sdanielk1977 CREATE INDEX i1 ON t1(a, b); 95062d4cb0Sdanielk1977 CREATE INDEX i2 ON t2(a, b); 96062d4cb0Sdanielk1977 CREATE INDEX i3 ON t3(a, b); 97062d4cb0Sdanielk1977 CREATE INDEX i4 ON t4(a, b); 98062d4cb0Sdanielk1977 CREATE INDEX i5 ON t5(a, b); 99062d4cb0Sdanielk1977 CREATE INDEX i6 ON t6(a, b); 100062d4cb0Sdanielk1977 CREATE INDEX i7 ON t7(a, b); 101062d4cb0Sdanielk1977 CREATE INDEX i8 ON t8(a, b); 102062d4cb0Sdanielk1977 CREATE INDEX i9 ON t9(a, b); 1036fa0fe13Sdanielk1977 CREATE INDEX i10 ON t9(a, b); 1046fa0fe13Sdanielk1977 CREATE INDEX i11 ON t9(a, b); 105062d4cb0Sdanielk1977 } 106062d4cb0Sdanielk1977 pcache_stats 1076fa0fe13Sdanielk1977} {current 23 max 22 min 20 recyclable 0} 108062d4cb0Sdanielk1977 109062d4cb0Sdanielk1977do_test pcache-1.7 { 110062d4cb0Sdanielk1977 execsql { 111062d4cb0Sdanielk1977 CREATE TABLE t10(a, b, c); 112062d4cb0Sdanielk1977 } 113062d4cb0Sdanielk1977 pcache_stats 1146fa0fe13Sdanielk1977} {current 24 max 22 min 20 recyclable 0} 115062d4cb0Sdanielk1977 116062d4cb0Sdanielk1977# Rolling back the transaction held by db2 at this point releases a pinned 117062d4cb0Sdanielk1977# page. Because the number of allocated pages is greater than the 118062d4cb0Sdanielk1977# configured maximum, this page should be freed immediately instead of 119062d4cb0Sdanielk1977# recycled. 120062d4cb0Sdanielk1977# 121062d4cb0Sdanielk1977do_test pcache-1.8 { 122062d4cb0Sdanielk1977 execsql {ROLLBACK} db2 123062d4cb0Sdanielk1977 pcache_stats 1246fa0fe13Sdanielk1977} {current 23 max 22 min 20 recyclable 0} 125062d4cb0Sdanielk1977 126062d4cb0Sdanielk1977do_test pcache-1.9 { 127062d4cb0Sdanielk1977 execsql COMMIT 128062d4cb0Sdanielk1977 pcache_stats 1296fa0fe13Sdanielk1977} {current 22 max 22 min 20 recyclable 22} 130062d4cb0Sdanielk1977 131062d4cb0Sdanielk1977do_test pcache-1.10 { 132062d4cb0Sdanielk1977 db2 close 133062d4cb0Sdanielk1977 pcache_stats 1346fa0fe13Sdanielk1977} {current 12 max 12 min 10 recyclable 12} 135062d4cb0Sdanielk1977 136062d4cb0Sdanielk1977do_test pcache-1.11 { 137062d4cb0Sdanielk1977 execsql { PRAGMA cache_size = 20 } 138062d4cb0Sdanielk1977 pcache_stats 1396fa0fe13Sdanielk1977} {current 12 max 20 min 10 recyclable 12} 140062d4cb0Sdanielk1977 141062d4cb0Sdanielk1977do_test pcache-1.12 { 142062d4cb0Sdanielk1977 execsql { 143062d4cb0Sdanielk1977 SELECT * FROM t1 ORDER BY a; SELECT * FROM t1; 144062d4cb0Sdanielk1977 SELECT * FROM t2 ORDER BY a; SELECT * FROM t2; 145062d4cb0Sdanielk1977 SELECT * FROM t3 ORDER BY a; SELECT * FROM t3; 146062d4cb0Sdanielk1977 SELECT * FROM t4 ORDER BY a; SELECT * FROM t4; 147062d4cb0Sdanielk1977 SELECT * FROM t5 ORDER BY a; SELECT * FROM t5; 148062d4cb0Sdanielk1977 SELECT * FROM t6 ORDER BY a; SELECT * FROM t6; 149062d4cb0Sdanielk1977 SELECT * FROM t7 ORDER BY a; SELECT * FROM t7; 150062d4cb0Sdanielk1977 SELECT * FROM t8 ORDER BY a; SELECT * FROM t8; 151062d4cb0Sdanielk1977 SELECT * FROM t9 ORDER BY a; SELECT * FROM t9; 152062d4cb0Sdanielk1977 } 153062d4cb0Sdanielk1977 pcache_stats 154062d4cb0Sdanielk1977} {current 19 max 20 min 10 recyclable 19} 155062d4cb0Sdanielk1977 156062d4cb0Sdanielk1977do_test pcache-1.13 { 157062d4cb0Sdanielk1977 execsql { PRAGMA cache_size = 15 } 158062d4cb0Sdanielk1977 pcache_stats 159062d4cb0Sdanielk1977} {current 15 max 15 min 10 recyclable 15} 160062d4cb0Sdanielk1977 161ea24ac4bSdanielk1977do_test pcache-1.14 { 162ea24ac4bSdanielk1977 hexio_write test.db 24 [hexio_render_int32 1000] 163ea24ac4bSdanielk1977 execsql { SELECT * FROM sqlite_master } 164ea24ac4bSdanielk1977 pcache_stats 165ea24ac4bSdanielk1977} {current 2 max 15 min 10 recyclable 2} 166ea24ac4bSdanielk1977 167ea24ac4bSdanielk1977do_test pcache-1.15 { 168ea24ac4bSdanielk1977 execsql { 169ea24ac4bSdanielk1977 SELECT * FROM t1 ORDER BY a; SELECT * FROM t1; 170ea24ac4bSdanielk1977 SELECT * FROM t2 ORDER BY a; SELECT * FROM t2; 171ea24ac4bSdanielk1977 SELECT * FROM t3 ORDER BY a; SELECT * FROM t3; 172ea24ac4bSdanielk1977 SELECT * FROM t4 ORDER BY a; SELECT * FROM t4; 173ea24ac4bSdanielk1977 SELECT * FROM t5 ORDER BY a; SELECT * FROM t5; 174ea24ac4bSdanielk1977 SELECT * FROM t6 ORDER BY a; SELECT * FROM t6; 175ea24ac4bSdanielk1977 SELECT * FROM t7 ORDER BY a; SELECT * FROM t7; 176ea24ac4bSdanielk1977 SELECT * FROM t8 ORDER BY a; SELECT * FROM t8; 177ea24ac4bSdanielk1977 SELECT * FROM t9 ORDER BY a; SELECT * FROM t9; 178ea24ac4bSdanielk1977 } 179ea24ac4bSdanielk1977 pcache_stats 180ea24ac4bSdanielk1977} {current 14 max 15 min 10 recyclable 14} 181ea24ac4bSdanielk1977 182062d4cb0Sdanielk1977finish_test 183