xref: /sqlite-3.40.0/test/pcache2.test (revision 03bc525a)
1b5774cfaSdrh# 2008 September 15
2b5774cfaSdrh#
3b5774cfaSdrh# The author disclaims copyright to this source code.  In place of
4b5774cfaSdrh# a legal notice, here is a blessing:
5b5774cfaSdrh#
6b5774cfaSdrh#    May you do good and not evil.
7b5774cfaSdrh#    May you find forgiveness for yourself and forgive others.
8b5774cfaSdrh#    May you share freely, never taking more than you give.
9b5774cfaSdrh#
10b5774cfaSdrh#***********************************************************************
11b5774cfaSdrh#
12b5774cfaSdrh# This file is focused on testing the pcache module.
13b5774cfaSdrh#
14f16c6246Sdanielk1977# $Id: pcache2.test,v 1.5 2009/07/18 14:36:24 danielk1977 Exp $
15b5774cfaSdrh
16b5774cfaSdrhset testdir [file dirname $argv0]
17b5774cfaSdrhsource $testdir/tester.tcl
18b5774cfaSdrh
19*03bc525aSdantest_set_config_pagecache 0 0
20*03bc525aSdan
21b5774cfaSdrh# Set up a pcache memory pool so that we can easily track how many
22b5774cfaSdrh# pages are being used for cache.
23b5774cfaSdrh#
24b5774cfaSdrhdo_test pcache2-1.1 {
25b5774cfaSdrh  db close
26ac8d7b35Sdanielk1977  sqlite3_reset_auto_extension
27b5774cfaSdrh  sqlite3_shutdown
28b5774cfaSdrh  sqlite3_config_pagecache 6000 100
29c54357ccSdrh  sqlite3_config singlethread
30b5774cfaSdrh  sqlite3_initialize
31ac8d7b35Sdanielk1977  autoinstall_test_functions
32b5774cfaSdrh  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
33b5774cfaSdrh  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
34b5774cfaSdrh} {0 0 0}
35b5774cfaSdrh
36b5774cfaSdrh# Open up two database connections to separate files.
37b5774cfaSdrh#
38b5774cfaSdrhdo_test pcache2-1.2 {
39fda06befSmistachkin  forcedelete test.db test.db-journal
40b5774cfaSdrh  sqlite3 db test.db
41957026acSdrh  db eval {PRAGMA cache_size=10; SELECT 1 FROM sqlite_master;}
42b5774cfaSdrh  lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
43b5774cfaSdrh} {2}
44b5774cfaSdrhdo_test pcache2-1.3 {
45fda06befSmistachkin  forcedelete test2.db test2.db-journal
46b5774cfaSdrh  sqlite3 db2 test2.db
47957026acSdrh  db2 eval {PRAGMA cache_size=50; SELECT 1 FROM sqlite_master;}
48b5774cfaSdrh  lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
49b5774cfaSdrh} {4}
50b5774cfaSdrh
51627a3d6aSdanielk1977
52b5774cfaSdrh# Make lots of changes on the first connection.  Verify that the
53b5774cfaSdrh# page cache usage does not grow to consume the page space set aside
54b5774cfaSdrh# for the second connection.
55b5774cfaSdrh#
56b5774cfaSdrhdo_test pcache2-1.4 {
57b5774cfaSdrh  db eval {
58b5774cfaSdrh     CREATE TABLE t1(a,b);
59b5774cfaSdrh     CREATE TABLE t2(x,y);
60b5774cfaSdrh     INSERT INTO t1 VALUES(1, zeroblob(800));
61b5774cfaSdrh     INSERT INTO t1 VALUES(2, zeroblob(800));
62b5774cfaSdrh     INSERT INTO t2 SELECT * FROM t1;
63b5774cfaSdrh     INSERT INTO t1 SELECT x+2, y FROM t2;
64b5774cfaSdrh     INSERT INTO t2 SELECT a+10, b FROM t1;
65b5774cfaSdrh     INSERT INTO t1 SELECT x+10, y FROM t2;
66b5774cfaSdrh     INSERT INTO t2 SELECT a+100, b FROM t1;
67b5774cfaSdrh     INSERT INTO t1 SELECT x+100, y FROM t2;
68b5774cfaSdrh     INSERT INTO t2 SELECT a+1000, b FROM t1;
69b5774cfaSdrh     INSERT INTO t1 SELECT x+1000, y FROM t2;
70b5774cfaSdrh  }
71b5774cfaSdrh  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
72b5774cfaSdrh} {0 13 13}
73b5774cfaSdrh
744bd3ce69Sdanielk1977db close
75b5774cfaSdrhcatch {db2 close}
76ac8d7b35Sdanielk1977sqlite3_reset_auto_extension
774bd3ce69Sdanielk1977sqlite3_shutdown
784bd3ce69Sdanielk1977sqlite3_config_pagecache 0 0
79c54357ccSdrhsqlite3_config serialized
80ac8d7b35Sdanielk1977sqlite3_initialize
81ac8d7b35Sdanielk1977autoinstall_test_functions
82ac8d7b35Sdanielk1977
83*03bc525aSdantest_restore_config_pagecache
84b5774cfaSdrhfinish_test
85