123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- # 2001 September 15
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library. The
- # focus of this script is page cache subsystem.
- #
- # $Id: pager.test,v 1.11 2002/02/02 18:49:21 drh Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- if {[info commands pager_open]!=""} {
- # Basic sanity check. Open and close a pager.
- #
- do_test pager-1.0 {
- catch {file delete -force ptf1.db}
- catch {file delete -force ptf1.db-journal}
- set v [catch {
- set ::p1 [pager_open ptf1.db 10]
- } msg]
- } {0}
- do_test pager-1.1 {
- pager_stats $::p1
- } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
- do_test pager-1.2 {
- pager_pagecount $::p1
- } {0}
- do_test pager-1.3 {
- pager_stats $::p1
- } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
- do_test pager-1.4 {
- pager_close $::p1
- } {}
- # Try to write a few pages.
- #
- do_test pager-2.1 {
- set v [catch {
- set ::p1 [pager_open ptf1.db 10]
- } msg]
- } {0}
- do_test pager-2.2 {
- set v [catch {
- set ::g1 [page_get $::p1 0]
- } msg]
- lappend v $msg
- } {1 SQLITE_ERROR}
- do_test pager-2.3.1 {
- set ::gx [page_lookup $::p1 1]
- } {}
- do_test pager-2.3.2 {
- pager_stats $::p1
- } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
- do_test pager-2.3.3 {
- set v [catch {
- set ::g1 [page_get $::p1 1]
- } msg]
- if {$v} {lappend v $msg}
- set v
- } {0}
- do_test pager-2.3.3 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.3.4 {
- set ::gx [page_lookup $::p1 1]
- expr {$::gx!=""}
- } {1}
- do_test pager-2.3.5 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.3.6 {
- expr $::g1==$::gx
- } {1}
- do_test pager-2.3.7 {
- page_unref $::gx
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.4 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.5 {
- pager_pagecount $::p1
- } {0}
- do_test pager-2.6 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.7 {
- page_number $::g1
- } {1}
- do_test pager-2.8 {
- page_read $::g1
- } {}
- do_test pager-2.9 {
- page_unref $::g1
- } {}
- do_test pager-2.10 {
- pager_stats $::p1
- } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 1 ovfl 0}
- do_test pager-2.11 {
- set ::g1 [page_get $::p1 1]
- expr {$::g1!=0}
- } {1}
- do_test pager-2.12 {
- page_number $::g1
- } {1}
- do_test pager-2.13 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 2 ovfl 0}
- do_test pager-2.14 {
- set v [catch {
- page_write $::g1 "Page-One"
- } msg]
- lappend v $msg
- } {0 {}}
- do_test pager-2.15 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 1 state 2 err 0 hit 0 miss 2 ovfl 0}
- do_test pager-2.16 {
- page_read $::g1
- } {Page-One}
- do_test pager-2.17 {
- set v [catch {
- pager_commit $::p1
- } msg]
- lappend v $msg
- } {0 {}}
- do_test pager-2.20 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
- do_test pager-2.19 {
- pager_pagecount $::p1
- } {1}
- do_test pager-2.21 {
- pager_stats $::p1
- } {ref 1 page 1 max 10 size 1 state 1 err 0 hit 0 miss 2 ovfl 0}
- do_test pager-2.22 {
- page_unref $::g1
- } {}
- do_test pager-2.23 {
- pager_stats $::p1
- } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 2 ovfl 0}
- do_test pager-2.24 {
- set v [catch {
- page_get $::p1 1
- } ::g1]
- if {$v} {lappend v $::g1}
- set v
- } {0}
- do_test pager-2.25 {
- page_read $::g1
- } {Page-One}
- do_test pager-2.26 {
- set v [catch {
- page_write $::g1 {page-one}
- } msg]
- lappend v $msg
- } {0 {}}
- do_test pager-2.27 {
- page_read $::g1
- } {page-one}
- do_test pager-2.28 {
- set v [catch {
- pager_rollback $::p1
- } msg]
- lappend v $msg
- } {0 {}}
- do_test pager-2.29 {
- page_read $::g1
- } {Page-One}
- do_test pager-2.99 {
- pager_close $::p1
- } {}
- do_test pager-3.1 {
- set v [catch {
- set ::p1 [pager_open ptf1.db 15]
- } msg]
- if {$v} {lappend v $msg}
- set v
- } {0}
- do_test pager-3.2 {
- pager_pagecount $::p1
- } {1}
- do_test pager-3.3 {
- set v [catch {
- set ::g(1) [page_get $::p1 1]
- } msg]
- if {$v} {lappend v $msg}
- set v
- } {0}
- do_test pager-3.4 {
- page_read $::g(1)
- } {Page-One}
- do_test pager-3.5 {
- for {set i 2} {$i<=20} {incr i} {
- set gx [page_get $::p1 $i]
- page_write $gx "Page-$i"
- page_unref $gx
- }
- pager_commit $::p1
- } {}
- for {set i 2} {$i<=20} {incr i} {
- do_test pager-3.6.[expr {$i-1}] [subst {
- set gx \[page_get $::p1 $i\]
- set v \[page_read \$gx\]
- page_unref \$gx
- set v
- }] "Page-$i"
- }
- for {set i 1} {$i<=20} {incr i} {
- regsub -all CNT {
- set ::g1 [page_get $::p1 CNT]
- set ::g2 [page_get $::p1 CNT]
- set ::vx [page_read $::g2]
- expr {$::g1==$::g2}
- } $i body;
- do_test pager-3.7.$i.1 $body {1}
- regsub -all CNT {
- page_unref $::g2
- set vy [page_read $::g1]
- expr {$vy==$::vx}
- } $i body;
- do_test pager-3.7.$i.2 $body {1}
- regsub -all CNT {
- page_unref $::g1
- set gx [page_get $::p1 CNT]
- set vy [page_read $gx]
- page_unref $gx
- expr {$vy==$::vx}
- } $i body;
- do_test pager-3.7.$i.3 $body {1}
- }
- do_test pager-3.99 {
- pager_close $::p1
- } {}
- # tests of the checkpoint mechanism and api
- #
- do_test pager-4.0 {
- set v [catch {
- file delete -force ptf1.db
- set ::p1 [pager_open ptf1.db 15]
- } msg]
- if {$v} {lappend v $msg}
- set v
- } {0}
- do_test pager-4.1 {
- set g1 [page_get $::p1 1]
- page_write $g1 "Page-1 v0"
- for {set i 2} {$i<=20} {incr i} {
- set gx [page_get $::p1 $i]
- page_write $gx "Page-$i v0"
- page_unref $gx
- }
- pager_commit $::p1
- } {}
- for {set i 1} {$i<=20} {incr i} {
- do_test pager-4.2.$i {
- set gx [page_get $p1 $i]
- set v [page_read $gx]
- page_unref $gx
- set v
- } "Page-$i v0"
- }
- do_test pager-4.3 {
- lrange [pager_stats $::p1] 0 1
- } {ref 1}
- do_test pager-4.4 {
- lrange [pager_stats $::p1] 8 9
- } {state 1}
- for {set i 1} {$i<20} {incr i} {
- do_test pager-4.5.$i.0 {
- set res {}
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- set value [page_read $gx]
- page_unref $gx
- set shouldbe "Page-$j v[expr {$i-1}]"
- if {$value!=$shouldbe} {
- lappend res $value $shouldbe
- }
- }
- set res
- } {}
- do_test pager-4.5.$i.1 {
- page_write $g1 "Page-1 v$i"
- lrange [pager_stats $p1] 8 9
- } {state 2}
- do_test pager-4.5.$i.2 {
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- page_write $gx "Page-$j v$i"
- page_unref $gx
- if {$j==$i} {
- pager_ckpt_begin $p1
- }
- }
- } {}
- do_test pager-4.5.$i.3 {
- set res {}
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- set value [page_read $gx]
- page_unref $gx
- set shouldbe "Page-$j v$i"
- if {$value!=$shouldbe} {
- lappend res $value $shouldbe
- }
- }
- set res
- } {}
- do_test pager-4.5.$i.4 {
- pager_rollback $p1
- set res {}
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- set value [page_read $gx]
- page_unref $gx
- set shouldbe "Page-$j v[expr {$i-1}]"
- if {$value!=$shouldbe} {
- lappend res $value $shouldbe
- }
- }
- set res
- } {}
- do_test pager-4.5.$i.5 {
- page_write $g1 "Page-1 v$i"
- lrange [pager_stats $p1] 8 9
- } {state 2}
- do_test pager-4.5.$i.6 {
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- page_write $gx "Page-$j v$i"
- page_unref $gx
- if {$j==$i} {
- pager_ckpt_begin $p1
- }
- }
- } {}
- do_test pager-4.5.$i.7 {
- pager_ckpt_rollback $p1
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- set value [page_read $gx]
- page_unref $gx
- if {$j<=$i || $i==1} {
- set shouldbe "Page-$j v$i"
- } else {
- set shouldbe "Page-$j v[expr {$i-1}]"
- }
- if {$value!=$shouldbe} {
- lappend res $value $shouldbe
- }
- }
- set res
- } {}
- do_test pager-4.5.$i.8 {
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- page_write $gx "Page-$j v$i"
- page_unref $gx
- if {$j==$i} {
- pager_ckpt_begin $p1
- }
- }
- } {}
- do_test pager-4.5.$i.9 {
- pager_ckpt_commit $p1
- for {set j 2} {$j<=20} {incr j} {
- set gx [page_get $p1 $j]
- set value [page_read $gx]
- page_unref $gx
- set shouldbe "Page-$j v$i"
- if {$value!=$shouldbe} {
- lappend res $value $shouldbe
- }
- }
- set res
- } {}
- do_test pager-4.5.$i.10 {
- pager_commit $p1
- lrange [pager_stats $p1] 8 9
- } {state 1}
- }
- do_test pager-4.99 {
- pager_close $::p1
- } {}
- file delete -force ptf1.db
- } ;# end if( not mem: and has pager_open command );
- finish_test
|