|
1 # 2008 August 29 |
|
2 # |
|
3 # The author disclaims copyright to this source code. In place of |
|
4 # a legal notice, here is a blessing: |
|
5 # |
|
6 # May you do good and not evil. |
|
7 # May you find forgiveness for yourself and forgive others. |
|
8 # May you share freely, never taking more than you give. |
|
9 # |
|
10 #*********************************************************************** |
|
11 # |
|
12 # This file is focused on testing the pcache module. |
|
13 # |
|
14 # $Id: pcache.test,v 1.2 2008/09/05 05:29:09 danielk1977 Exp $ |
|
15 |
|
16 set testdir [file dirname $argv0] |
|
17 source $testdir/tester.tcl |
|
18 |
|
19 |
|
20 # The pcache module limits the number of pages available to purgeable |
|
21 # caches to the sum of the 'cache_size' values for the set of open |
|
22 # caches. This block of tests, pcache-1.*, test that the library behaves |
|
23 # corrctly when it is forced to exceed this limit. |
|
24 # |
|
25 do_test pcache-1.1 { |
|
26 db close |
|
27 pcache_stats |
|
28 } {current 0 max 0 min 0 recyclable 0} |
|
29 |
|
30 do_test pcache-1.2 { |
|
31 sqlite3 db test.db |
|
32 execsql { |
|
33 PRAGMA cache_size=10; |
|
34 PRAGMA auto_vacuum=0; |
|
35 } |
|
36 pcache_stats |
|
37 } {current 1 max 10 min 10 recyclable 1} |
|
38 |
|
39 do_test pcache-1.3 { |
|
40 execsql { |
|
41 BEGIN; |
|
42 CREATE TABLE t1(a, b, c); |
|
43 CREATE TABLE t2(a, b, c); |
|
44 CREATE TABLE t3(a, b, c); |
|
45 CREATE TABLE t4(a, b, c); |
|
46 CREATE TABLE t5(a, b, c); |
|
47 } |
|
48 pcache_stats |
|
49 } {current 6 max 10 min 10 recyclable 0} |
|
50 |
|
51 do_test pcache-1.4 { |
|
52 execsql { |
|
53 CREATE TABLE t6(a, b, c); |
|
54 CREATE TABLE t7(a, b, c); |
|
55 CREATE TABLE t8(a, b, c); |
|
56 CREATE TABLE t9(a, b, c); |
|
57 } |
|
58 pcache_stats |
|
59 } {current 10 max 10 min 10 recyclable 0} |
|
60 |
|
61 do_test pcache-1.5 { |
|
62 sqlite3 db2 test.db |
|
63 execsql "PRAGMA cache_size=10" db2 |
|
64 pcache_stats |
|
65 } {current 11 max 20 min 20 recyclable 1} |
|
66 |
|
67 do_test pcache-1.6 { |
|
68 execsql { |
|
69 BEGIN; |
|
70 SELECT * FROM sqlite_master; |
|
71 } db2 |
|
72 pcache_stats |
|
73 } {current 11 max 20 min 20 recyclable 0} |
|
74 |
|
75 # At this point connection db2 has a read lock on the database file and a |
|
76 # single pinned page in its cache. Connection [db] is holding 10 dirty |
|
77 # pages. It cannot recycle them because of the read lock held by db2. |
|
78 # |
|
79 do_test pcache-1.6 { |
|
80 execsql { |
|
81 CREATE INDEX i1 ON t1(a, b); |
|
82 CREATE INDEX i2 ON t2(a, b); |
|
83 CREATE INDEX i3 ON t3(a, b); |
|
84 CREATE INDEX i4 ON t4(a, b); |
|
85 CREATE INDEX i5 ON t5(a, b); |
|
86 CREATE INDEX i6 ON t6(a, b); |
|
87 CREATE INDEX i7 ON t7(a, b); |
|
88 CREATE INDEX i8 ON t8(a, b); |
|
89 CREATE INDEX i9 ON t9(a, b); |
|
90 } |
|
91 pcache_stats |
|
92 } {current 20 max 20 min 20 recyclable 0} |
|
93 |
|
94 do_test pcache-1.7 { |
|
95 execsql { |
|
96 CREATE TABLE t10(a, b, c); |
|
97 } |
|
98 pcache_stats |
|
99 } {current 21 max 20 min 20 recyclable 0} |
|
100 |
|
101 # Rolling back the transaction held by db2 at this point releases a pinned |
|
102 # page. Because the number of allocated pages is greater than the |
|
103 # configured maximum, this page should be freed immediately instead of |
|
104 # recycled. |
|
105 # |
|
106 do_test pcache-1.8 { |
|
107 execsql {ROLLBACK} db2 |
|
108 pcache_stats |
|
109 } {current 20 max 20 min 20 recyclable 0} |
|
110 |
|
111 do_test pcache-1.9 { |
|
112 execsql COMMIT |
|
113 pcache_stats |
|
114 } {current 20 max 20 min 20 recyclable 20} |
|
115 |
|
116 do_test pcache-1.10 { |
|
117 db2 close |
|
118 pcache_stats |
|
119 } {current 10 max 10 min 10 recyclable 10} |
|
120 |
|
121 do_test pcache-1.11 { |
|
122 execsql { PRAGMA cache_size = 20 } |
|
123 pcache_stats |
|
124 } {current 10 max 20 min 10 recyclable 10} |
|
125 |
|
126 do_test pcache-1.12 { |
|
127 execsql { |
|
128 SELECT * FROM t1 ORDER BY a; SELECT * FROM t1; |
|
129 SELECT * FROM t2 ORDER BY a; SELECT * FROM t2; |
|
130 SELECT * FROM t3 ORDER BY a; SELECT * FROM t3; |
|
131 SELECT * FROM t4 ORDER BY a; SELECT * FROM t4; |
|
132 SELECT * FROM t5 ORDER BY a; SELECT * FROM t5; |
|
133 SELECT * FROM t6 ORDER BY a; SELECT * FROM t6; |
|
134 SELECT * FROM t7 ORDER BY a; SELECT * FROM t7; |
|
135 SELECT * FROM t8 ORDER BY a; SELECT * FROM t8; |
|
136 SELECT * FROM t9 ORDER BY a; SELECT * FROM t9; |
|
137 } |
|
138 pcache_stats |
|
139 } {current 19 max 20 min 10 recyclable 19} |
|
140 |
|
141 do_test pcache-1.13 { |
|
142 execsql { PRAGMA cache_size = 15 } |
|
143 pcache_stats |
|
144 } {current 15 max 15 min 10 recyclable 15} |
|
145 |
|
146 finish_test |
|
147 |