os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pcache.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pcache.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,147 @@
     1.4 +# 2008 August 29
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +#
    1.15 +# This file is focused on testing the pcache module.
    1.16 +#
    1.17 +# $Id: pcache.test,v 1.2 2008/09/05 05:29:09 danielk1977 Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +
    1.22 +
    1.23 +# The pcache module limits the number of pages available to purgeable
    1.24 +# caches to the sum of the 'cache_size' values for the set of open
    1.25 +# caches. This block of tests, pcache-1.*, test that the library behaves
    1.26 +# corrctly when it is forced to exceed this limit.
    1.27 +#
    1.28 +do_test pcache-1.1 {
    1.29 +  db close
    1.30 +  pcache_stats
    1.31 +} {current 0 max 0 min 0 recyclable 0}
    1.32 +
    1.33 +do_test pcache-1.2 {
    1.34 +  sqlite3 db test.db
    1.35 +  execsql {
    1.36 +    PRAGMA cache_size=10;
    1.37 +    PRAGMA auto_vacuum=0;
    1.38 +  }
    1.39 +  pcache_stats
    1.40 +} {current 1 max 10 min 10 recyclable 1}
    1.41 +
    1.42 +do_test pcache-1.3 {
    1.43 +  execsql {
    1.44 +    BEGIN;
    1.45 +    CREATE TABLE t1(a, b, c);
    1.46 +    CREATE TABLE t2(a, b, c);
    1.47 +    CREATE TABLE t3(a, b, c);
    1.48 +    CREATE TABLE t4(a, b, c);
    1.49 +    CREATE TABLE t5(a, b, c);
    1.50 +  }
    1.51 +  pcache_stats
    1.52 +} {current 6 max 10 min 10 recyclable 0}
    1.53 +
    1.54 +do_test pcache-1.4 {
    1.55 +  execsql {
    1.56 +    CREATE TABLE t6(a, b, c);
    1.57 +    CREATE TABLE t7(a, b, c);
    1.58 +    CREATE TABLE t8(a, b, c);
    1.59 +    CREATE TABLE t9(a, b, c);
    1.60 +  }
    1.61 +  pcache_stats
    1.62 +} {current 10 max 10 min 10 recyclable 0}
    1.63 +
    1.64 +do_test pcache-1.5 {
    1.65 +  sqlite3 db2 test.db
    1.66 +  execsql "PRAGMA cache_size=10" db2
    1.67 +  pcache_stats
    1.68 +} {current 11 max 20 min 20 recyclable 1}
    1.69 +
    1.70 +do_test pcache-1.6 {
    1.71 +  execsql {
    1.72 +    BEGIN;
    1.73 +    SELECT * FROM sqlite_master;
    1.74 +  } db2
    1.75 +  pcache_stats
    1.76 +} {current 11 max 20 min 20 recyclable 0}
    1.77 +
    1.78 +# At this point connection db2 has a read lock on the database file and a 
    1.79 +# single pinned page in its cache. Connection [db] is holding 10 dirty 
    1.80 +# pages. It cannot recycle them because of the read lock held by db2.
    1.81 +#
    1.82 +do_test pcache-1.6 {
    1.83 +  execsql {
    1.84 +    CREATE INDEX i1 ON t1(a, b);
    1.85 +    CREATE INDEX i2 ON t2(a, b);
    1.86 +    CREATE INDEX i3 ON t3(a, b);
    1.87 +    CREATE INDEX i4 ON t4(a, b);
    1.88 +    CREATE INDEX i5 ON t5(a, b);
    1.89 +    CREATE INDEX i6 ON t6(a, b);
    1.90 +    CREATE INDEX i7 ON t7(a, b);
    1.91 +    CREATE INDEX i8 ON t8(a, b);
    1.92 +    CREATE INDEX i9 ON t9(a, b);
    1.93 +  } 
    1.94 +  pcache_stats
    1.95 +} {current 20 max 20 min 20 recyclable 0}
    1.96 +
    1.97 +do_test pcache-1.7 {
    1.98 +  execsql {
    1.99 +    CREATE TABLE t10(a, b, c);
   1.100 +  } 
   1.101 +  pcache_stats
   1.102 +} {current 21 max 20 min 20 recyclable 0}
   1.103 +
   1.104 +# Rolling back the transaction held by db2 at this point releases a pinned
   1.105 +# page. Because the number of allocated pages is greater than the 
   1.106 +# configured maximum, this page should be freed immediately instead of
   1.107 +# recycled.
   1.108 +#
   1.109 +do_test pcache-1.8 {
   1.110 +  execsql {ROLLBACK} db2
   1.111 +  pcache_stats
   1.112 +} {current 20 max 20 min 20 recyclable 0}
   1.113 +
   1.114 +do_test pcache-1.9 {
   1.115 +  execsql COMMIT
   1.116 +  pcache_stats
   1.117 +} {current 20 max 20 min 20 recyclable 20}
   1.118 +
   1.119 +do_test pcache-1.10 {
   1.120 +  db2 close
   1.121 +  pcache_stats
   1.122 +} {current 10 max 10 min 10 recyclable 10}
   1.123 +
   1.124 +do_test pcache-1.11 {
   1.125 +  execsql { PRAGMA cache_size = 20 }
   1.126 +  pcache_stats
   1.127 +} {current 10 max 20 min 10 recyclable 10}
   1.128 +
   1.129 +do_test pcache-1.12 {
   1.130 +  execsql { 
   1.131 +    SELECT * FROM t1 ORDER BY a; SELECT * FROM t1;
   1.132 +    SELECT * FROM t2 ORDER BY a; SELECT * FROM t2;
   1.133 +    SELECT * FROM t3 ORDER BY a; SELECT * FROM t3;
   1.134 +    SELECT * FROM t4 ORDER BY a; SELECT * FROM t4;
   1.135 +    SELECT * FROM t5 ORDER BY a; SELECT * FROM t5;
   1.136 +    SELECT * FROM t6 ORDER BY a; SELECT * FROM t6;
   1.137 +    SELECT * FROM t7 ORDER BY a; SELECT * FROM t7;
   1.138 +    SELECT * FROM t8 ORDER BY a; SELECT * FROM t8;
   1.139 +    SELECT * FROM t9 ORDER BY a; SELECT * FROM t9;
   1.140 +  }
   1.141 +  pcache_stats
   1.142 +} {current 19 max 20 min 10 recyclable 19}
   1.143 +
   1.144 +do_test pcache-1.13 {
   1.145 +  execsql { PRAGMA cache_size = 15 }
   1.146 +  pcache_stats
   1.147 +} {current 15 max 15 min 10 recyclable 15}
   1.148 +
   1.149 +finish_test
   1.150 +