rbutemplimit.test 3.4 KB

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