drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 1 | # 2008 September 15 |
| 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 | # |
danielk1977 | f16c624 | 2009-07-18 14:36:23 +0000 | [diff] [blame] | 14 | # $Id: pcache2.test,v 1.5 2009/07/18 14:36:24 danielk1977 Exp $ |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 19 | # Set up a pcache memory pool so that we can easily track how many |
| 20 | # pages are being used for cache. |
| 21 | # |
| 22 | do_test pcache2-1.1 { |
| 23 | db close |
danielk1977 | ac8d7b3 | 2008-11-13 16:21:50 +0000 | [diff] [blame] | 24 | sqlite3_reset_auto_extension |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 25 | sqlite3_shutdown |
| 26 | sqlite3_config_pagecache 6000 100 |
| 27 | sqlite3_initialize |
danielk1977 | ac8d7b3 | 2008-11-13 16:21:50 +0000 | [diff] [blame] | 28 | autoinstall_test_functions |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 29 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1 |
| 30 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0 |
| 31 | } {0 0 0} |
| 32 | |
| 33 | # Open up two database connections to separate files. |
| 34 | # |
| 35 | do_test pcache2-1.2 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 36 | forcedelete test.db test.db-journal |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 37 | sqlite3 db test.db |
| 38 | db eval {PRAGMA cache_size=10} |
| 39 | lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 |
| 40 | } {2} |
| 41 | do_test pcache2-1.3 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 42 | forcedelete test2.db test2.db-journal |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 43 | sqlite3 db2 test2.db |
| 44 | db2 eval {PRAGMA cache_size=50} |
| 45 | lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 |
| 46 | } {4} |
| 47 | |
danielk1977 | 627a3d6 | 2009-07-18 08:30:44 +0000 | [diff] [blame] | 48 | |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 49 | # Make lots of changes on the first connection. Verify that the |
| 50 | # page cache usage does not grow to consume the page space set aside |
| 51 | # for the second connection. |
| 52 | # |
| 53 | do_test pcache2-1.4 { |
| 54 | db eval { |
| 55 | CREATE TABLE t1(a,b); |
| 56 | CREATE TABLE t2(x,y); |
| 57 | INSERT INTO t1 VALUES(1, zeroblob(800)); |
| 58 | INSERT INTO t1 VALUES(2, zeroblob(800)); |
| 59 | INSERT INTO t2 SELECT * FROM t1; |
| 60 | INSERT INTO t1 SELECT x+2, y FROM t2; |
| 61 | INSERT INTO t2 SELECT a+10, b FROM t1; |
| 62 | INSERT INTO t1 SELECT x+10, y FROM t2; |
| 63 | INSERT INTO t2 SELECT a+100, b FROM t1; |
| 64 | INSERT INTO t1 SELECT x+100, y FROM t2; |
| 65 | INSERT INTO t2 SELECT a+1000, b FROM t1; |
| 66 | INSERT INTO t1 SELECT x+1000, y FROM t2; |
| 67 | } |
| 68 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0 |
| 69 | } {0 13 13} |
| 70 | |
danielk1977 | 4bd3ce6 | 2008-10-14 19:21:51 +0000 | [diff] [blame] | 71 | db close |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 72 | catch {db2 close} |
danielk1977 | ac8d7b3 | 2008-11-13 16:21:50 +0000 | [diff] [blame] | 73 | sqlite3_reset_auto_extension |
danielk1977 | 4bd3ce6 | 2008-10-14 19:21:51 +0000 | [diff] [blame] | 74 | sqlite3_shutdown |
| 75 | sqlite3_config_pagecache 0 0 |
danielk1977 | ac8d7b3 | 2008-11-13 16:21:50 +0000 | [diff] [blame] | 76 | sqlite3_initialize |
| 77 | autoinstall_test_functions |
| 78 | |
drh | b5774cf | 2008-09-15 15:36:57 +0000 | [diff] [blame] | 79 | finish_test |