1# 2014 August 30 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 13source [file join [file dirname [info script]] rbu_common.tcl] 14set ::testprefix rbutemplimit 15 16db close 17sqlite3_shutdown 18sqlite3_config_uri 1 19 20proc setup_databases {} { 21 forcedelete test.db2 22 forcedelete test.db 23 sqlite3 db test.db 24 execsql { 25 -- Create target database schema. 26 -- 27 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100)); 28 CREATE TABLE t2(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100)); 29 CREATE INDEX i1b ON t1(b); 30 CREATE INDEX i1c ON t1(c); 31 CREATE INDEX i2b ON t2(b); 32 CREATE INDEX i2c ON t2(c); 33 34 -- Create a large RBU database. 35 -- 36 ATTACH 'test.db2' AS rbu; 37 CREATE TABLE rbu.data_t1(a, b, c, rbu_control); 38 WITH s(i) AS ( 39 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000 40 ) 41 INSERT INTO data_t1 SELECT i, randomblob(100), randomblob(100), 0 FROM s; 42 CREATE TABLE rbu.data_t2(a, b, c, rbu_control); 43 WITH s(i) AS ( 44 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15000 45 ) 46 INSERT INTO data_t2 SELECT i, randomblob(100), randomblob(100), 0 FROM s; 47 } 48 db close 49} 50 51proc run_rbu_cachesize {target rbu cachesize temp_limit} { 52 sqlite3rbu rbu $target $rbu 53 rbu temp_size_limit $temp_limit 54 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize" 55 while 1 { 56 set rc [rbu step] 57 set ::A([rbu temp_size]) 1 58 if {$rc!="SQLITE_OK"} break 59 } 60 list [catch {rbu close} msg] $msg 61} 62 63proc step_rbu_cachesize {target rbu stepsize cachesize temp_limit} { 64 set res "" 65 while 1 { 66 sqlite3rbu rbu $target $rbu 67 rbu temp_size_limit $temp_limit 68 if { [rbu temp_size_limit -1]!=$temp_limit } { error "round trip problem!" } 69 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize" 70 for {set i 0} {$i < $stepsize} {incr i} { 71 set rc [rbu step] 72 set ::A([rbu temp_size]) 1 73 if {$rc!="SQLITE_OK"} break 74 } 75 set res [list [catch {rbu close} msg] $msg] 76 if {$res != "0 SQLITE_OK"} break 77 } 78 set res 79} 80 81do_test 1.1.0 { setup_databases } {} 82 83do_test 1.1.1 { 84 unset -nocomplain ::A 85 run_rbu_cachesize test.db test.db2 10 0 86} {0 SQLITE_DONE} 87 88do_test 1.1.2 { llength [array names ::A] } 3 89 90do_test 1.1.3 { 91 foreach {a0 a1 a2} [lsort -integer [array names ::A]] {} 92 list [expr $a0==0] \ 93 [expr $a1>1048576] [expr $a1<1200000] \ 94 [expr $a2>1500000] [expr $a2<1700000] 95} {1 1 1 1 1} 96 97do_test 1.2.1 { 98 setup_databases 99 run_rbu_cachesize test.db test.db2 10 1000000 100} {1 SQLITE_FULL} 101do_test 1.2.2 { info commands rbu } {} 102 103do_test 1.3.1 { 104 setup_databases 105 run_rbu_cachesize test.db test.db2 10 1300000 106} {1 SQLITE_FULL} 107do_test 1.3.2 { info commands rbu } {} 108 109do_test 1.4.1 { 110 setup_databases 111 run_rbu_cachesize test.db test.db2 10 1800000 112} {0 SQLITE_DONE} 113do_test 1.4.2 { info commands rbu } {} 114 115do_test 1.5.1 { 116 setup_databases 117 unset -nocomplain ::A 118 step_rbu_cachesize test.db test.db2 1000 10 2400000 119} {0 SQLITE_DONE} 120do_test 1.5.2 { info commands rbu } {} 121 122do_test 1.6.1 { 123 setup_databases 124 unset -nocomplain ::A 125 step_rbu_cachesize test.db test.db2 1000 10 1400000 126} {1 SQLITE_FULL} 127do_test 1.6.2 { info commands rbu } {} 128 129finish_test 130