Enhance the command-line completion extension to return the names of
[sqlite.git] / ext / rbu / rbutemplimit.test
blob274f870b73e80475de72074ad171d78a7920b18b
1 # 2014 August 30
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 source [file join [file dirname [info script]] rbu_common.tcl]
14 set ::testprefix rbutemplimit
16 db close
17 sqlite3_shutdown
18 sqlite3_config_uri 1
20 proc 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
51 proc 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
63 proc 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     sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
69     for {set i 0} {$i < $stepsize} {incr i} {
70       set rc [rbu step]
71       set ::A([rbu temp_size]) 1
72       if {$rc!="SQLITE_OK"} break
73     }
74     set res [list [catch {rbu close} msg] $msg]
75     if {$res != "0 SQLITE_OK"} break
76   }
77   set res
80 do_test 1.1.0 { setup_databases } {}
82 do_test 1.1.1 {
83   unset -nocomplain ::A
84   run_rbu_cachesize test.db test.db2 10 0
85 } {0 SQLITE_DONE}
87 do_test 1.1.2 { llength [array names ::A] } 3
89 do_test 1.1.3 { 
90   foreach {a0 a1 a2} [lsort -integer [array names ::A]] {}
91   list [expr $a0==0]                         \
92        [expr $a1>1048576] [expr $a1<1200000] \
93        [expr $a2>1500000] [expr $a2<1700000]
94 } {1 1 1 1 1}
96 do_test 1.2.1 {
97   setup_databases
98   run_rbu_cachesize test.db test.db2 10 1000000
99 } {1 SQLITE_FULL}
100 do_test 1.2.2 { info commands rbu } {}
102 do_test 1.3.1 {
103   setup_databases
104   run_rbu_cachesize test.db test.db2 10 1300000
105 } {1 SQLITE_FULL}
106 do_test 1.3.2 { info commands rbu } {}
108 do_test 1.4.1 {
109   setup_databases
110   run_rbu_cachesize test.db test.db2 10 1800000
111 } {0 SQLITE_DONE}
112 do_test 1.4.2 { info commands rbu } {}
114 do_test 1.5.1 {
115   setup_databases
116   unset -nocomplain ::A
117   step_rbu_cachesize test.db test.db2 1000 10 2400000
118 } {0 SQLITE_DONE}
119 do_test 1.5.2 { info commands rbu } {}
121 do_test 1.6.1 {
122   setup_databases
123   unset -nocomplain ::A
124   step_rbu_cachesize test.db test.db2 1000 10 1400000
125 } {1 SQLITE_FULL}
126 do_test 1.6.2 { info commands rbu } {}
128 finish_test