os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/pager2.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2001 September 15
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.  The
sl@0
    12
# focus of this script is page cache subsystem.
sl@0
    13
#
sl@0
    14
# $Id: pager2.test,v 1.7 2008/08/20 14:49:25 danielk1977 Exp $
sl@0
    15
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
# Don't run this test file if the pager test interface [pager_open] is not
sl@0
    21
# available, or the library was compiled without in-memory database support.
sl@0
    22
#
sl@0
    23
if {[info commands pager_open]!=""} {
sl@0
    24
ifcapable memorydb {
sl@0
    25
db close
sl@0
    26
sl@0
    27
# Basic sanity check.  Open and close a pager.
sl@0
    28
#
sl@0
    29
do_test pager2-1.0 {
sl@0
    30
  set v [catch {
sl@0
    31
    set ::p1 [pager_open :memory: 10]
sl@0
    32
  } msg]
sl@0
    33
} {0}
sl@0
    34
do_test pager2-1.1 {
sl@0
    35
  pager_stats $::p1
sl@0
    36
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
sl@0
    37
do_test pager2-1.2 {
sl@0
    38
  pager_pagecount $::p1
sl@0
    39
} {0}
sl@0
    40
do_test pager2-1.3 {
sl@0
    41
  pager_stats $::p1
sl@0
    42
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
sl@0
    43
do_test pager2-1.4 {
sl@0
    44
  pager_close $::p1
sl@0
    45
} {}
sl@0
    46
sl@0
    47
# Try to write a few pages.
sl@0
    48
#
sl@0
    49
do_test pager2-2.1 {
sl@0
    50
  set v [catch {
sl@0
    51
    set ::p1 [pager_open :memory: 10]
sl@0
    52
  } msg]
sl@0
    53
} {0}
sl@0
    54
#do_test pager2-2.2 {
sl@0
    55
#  set v [catch {
sl@0
    56
#    set ::g1 [page_get $::p1 0]
sl@0
    57
#  } msg]
sl@0
    58
#  lappend v $msg
sl@0
    59
#} {1 SQLITE_ERROR}
sl@0
    60
do_test pager2-2.3.1 {
sl@0
    61
  set ::gx [page_lookup $::p1 1]
sl@0
    62
} {}
sl@0
    63
do_test pager2-2.3.2 {
sl@0
    64
  pager_stats $::p1
sl@0
    65
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
sl@0
    66
do_test pager2-2.3.3 {
sl@0
    67
  set v [catch {
sl@0
    68
    set ::g1 [page_get $::p1 1]
sl@0
    69
  } msg]
sl@0
    70
  if {$v} {lappend v $msg}
sl@0
    71
  set v
sl@0
    72
} {0}
sl@0
    73
do_test pager2-2.3.3 {
sl@0
    74
  pager_stats $::p1
sl@0
    75
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
sl@0
    76
do_test pager2-2.3.4 {
sl@0
    77
  set ::gx [page_lookup $::p1 1]
sl@0
    78
  page_unref $::gx
sl@0
    79
  expr {$::gx!=""}
sl@0
    80
} {1}
sl@0
    81
do_test pager2-2.3.5 {
sl@0
    82
  pager_stats $::p1
sl@0
    83
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
sl@0
    84
do_test pager2-2.3.6 {
sl@0
    85
  expr {$::g1==$::gx}
sl@0
    86
} {1}
sl@0
    87
do_test pager2-2.3.7 {
sl@0
    88
  pager_stats $::p1
sl@0
    89
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
sl@0
    90
do_test pager2-2.4 {
sl@0
    91
  pager_stats $::p1
sl@0
    92
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
sl@0
    93
do_test pager2-2.5 {
sl@0
    94
  pager_pagecount $::p1
sl@0
    95
} {0}
sl@0
    96
do_test pager2-2.6 {
sl@0
    97
  pager_stats $::p1
sl@0
    98
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
sl@0
    99
do_test pager2-2.7 {
sl@0
   100
  page_number $::g1
sl@0
   101
} {1}
sl@0
   102
do_test pager2-2.8 {
sl@0
   103
  page_read $::g1
sl@0
   104
} {}
sl@0
   105
do_test pager2-2.9 {
sl@0
   106
  page_unref $::g1
sl@0
   107
} {}
sl@0
   108
do_test pager2-2.10 {
sl@0
   109
  pager_stats $::p1
sl@0
   110
} {ref 0 page 1 max 10 size 0 state 0 err 0 hit 0 miss 1 ovfl 0}
sl@0
   111
do_test pager2-2.11 {
sl@0
   112
  set ::g1 [page_get $::p1 1]
sl@0
   113
  expr {$::g1!=0}
sl@0
   114
} {1}
sl@0
   115
do_test pager2-2.12 {
sl@0
   116
  page_number $::g1
sl@0
   117
} {1}
sl@0
   118
do_test pager2-2.13 {
sl@0
   119
  pager_stats $::p1
sl@0
   120
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 1 miss 1 ovfl 0}
sl@0
   121
do_test pager2-2.14 {
sl@0
   122
  set v [catch {
sl@0
   123
    page_write $::g1 "Page-One"
sl@0
   124
  } msg]
sl@0
   125
  lappend v $msg
sl@0
   126
} {0 {}}
sl@0
   127
do_test pager2-2.15 {
sl@0
   128
  pager_stats $::p1
sl@0
   129
} {ref 1 page 1 max 10 size 1 state 4 err 0 hit 1 miss 1 ovfl 0}
sl@0
   130
do_test pager2-2.16 {
sl@0
   131
  page_read $::g1
sl@0
   132
} {Page-One}
sl@0
   133
do_test pager2-2.17 {
sl@0
   134
  set v [catch {
sl@0
   135
    pager_commit $::p1
sl@0
   136
  } msg]
sl@0
   137
  lappend v $msg
sl@0
   138
} {0 {}}
sl@0
   139
do_test pager2-2.20 {
sl@0
   140
  pager_stats $::p1
sl@0
   141
} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
sl@0
   142
do_test pager2-2.19 {
sl@0
   143
  pager_pagecount $::p1
sl@0
   144
} {1}
sl@0
   145
do_test pager2-2.21 {
sl@0
   146
  pager_stats $::p1
sl@0
   147
} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
sl@0
   148
do_test pager2-2.22 {
sl@0
   149
  page_unref $::g1
sl@0
   150
} {}
sl@0
   151
do_test pager2-2.23 {
sl@0
   152
  pager_stats $::p1
sl@0
   153
} {ref 0 page 1 max 10 size 1 state 0 err 0 hit 1 miss 1 ovfl 0}
sl@0
   154
do_test pager2-2.24 {
sl@0
   155
  set v [catch {
sl@0
   156
    page_get $::p1 1
sl@0
   157
  } ::g1]
sl@0
   158
  if {$v} {lappend v $::g1}
sl@0
   159
  set v
sl@0
   160
} {0}
sl@0
   161
do_test pager2-2.25 {
sl@0
   162
  page_read $::g1
sl@0
   163
} {Page-One}
sl@0
   164
do_test pager2-2.26 {
sl@0
   165
  set v [catch {
sl@0
   166
    page_write $::g1 {page-one}
sl@0
   167
  } msg]
sl@0
   168
  lappend v $msg
sl@0
   169
} {0 {}}
sl@0
   170
do_test pager2-2.27 {
sl@0
   171
  page_read $::g1
sl@0
   172
} {page-one}
sl@0
   173
do_test pager2-2.28 {
sl@0
   174
  set v [catch {
sl@0
   175
    pager_rollback $::p1
sl@0
   176
  } msg]
sl@0
   177
  lappend v $msg
sl@0
   178
} {0 {}}
sl@0
   179
do_test pager2-2.29 {
sl@0
   180
  page_unref $::g1
sl@0
   181
  set ::g1 [page_get $::p1 1]
sl@0
   182
  page_read $::g1
sl@0
   183
} {Page-One}
sl@0
   184
do_test pager2-2.99 {
sl@0
   185
  page_unref $::g1
sl@0
   186
} {}
sl@0
   187
sl@0
   188
#do_test pager2-3.1 {
sl@0
   189
#  set v [catch {
sl@0
   190
#    set ::p1 [pager_open :memory: 15]
sl@0
   191
#  } msg]
sl@0
   192
#  if {$v} {lappend v $msg}
sl@0
   193
#  set v
sl@0
   194
#} {0}
sl@0
   195
do_test pager2-3.2 {
sl@0
   196
  pager_pagecount $::p1
sl@0
   197
} {1}
sl@0
   198
do_test pager2-3.3 {
sl@0
   199
  set v [catch {
sl@0
   200
    set ::g(1) [page_get $::p1 1]
sl@0
   201
  } msg]
sl@0
   202
  if {$v} {lappend v $msg}
sl@0
   203
  set v
sl@0
   204
} {0}
sl@0
   205
do_test pager2-3.4 {
sl@0
   206
  page_read $::g(1)
sl@0
   207
} {Page-One}
sl@0
   208
do_test pager2-3.5 {
sl@0
   209
  for {set i 2} {$i<=20} {incr i} {
sl@0
   210
    set gx [page_get $::p1 $i]
sl@0
   211
    page_write $gx "Page-$i"
sl@0
   212
    page_unref $gx
sl@0
   213
  }
sl@0
   214
  pager_commit $::p1
sl@0
   215
  page_unref $::g(1)
sl@0
   216
} {}
sl@0
   217
for {set i 2} {$i<=20} {incr i} {
sl@0
   218
  do_test pager2-3.6.[expr {$i-1}] [subst {
sl@0
   219
    set gx \[page_get $::p1 $i\]
sl@0
   220
    set v \[page_read \$gx\]
sl@0
   221
    page_unref \$gx
sl@0
   222
    set v
sl@0
   223
  }] "Page-$i"
sl@0
   224
}
sl@0
   225
for {set i 1} {$i<=20} {incr i} {
sl@0
   226
  regsub -all CNT {
sl@0
   227
    set ::g1 [page_get $::p1 CNT]
sl@0
   228
    set ::g2 [page_get $::p1 CNT]
sl@0
   229
    set ::vx [page_read $::g2]
sl@0
   230
    expr {$::g1==$::g2}
sl@0
   231
  } $i body;
sl@0
   232
  do_test pager2-3.7.$i.1 $body {1}
sl@0
   233
  regsub -all CNT {
sl@0
   234
    page_unref $::g2
sl@0
   235
    set vy [page_read $::g1]
sl@0
   236
    expr {$vy==$::vx}
sl@0
   237
  } $i body;
sl@0
   238
  do_test pager2-3.7.$i.2 $body {1}
sl@0
   239
  regsub -all CNT {
sl@0
   240
    page_unref $::g1
sl@0
   241
    set gx [page_get $::p1 CNT]
sl@0
   242
    set vy [page_read $gx]
sl@0
   243
    page_unref $gx
sl@0
   244
    expr {$vy==$::vx}
sl@0
   245
  } $i body;
sl@0
   246
  do_test pager2-3.7.$i.3 $body {1}
sl@0
   247
}
sl@0
   248
do_test pager2-3.99 {
sl@0
   249
  pager_close $::p1
sl@0
   250
} {}
sl@0
   251
sl@0
   252
# tests of the checkpoint mechanism and api
sl@0
   253
#
sl@0
   254
do_test pager2-4.0 {
sl@0
   255
  set v [catch {
sl@0
   256
    set ::p1 [pager_open :memory: 15]
sl@0
   257
  } msg]
sl@0
   258
  if {$v} {lappend v $msg}
sl@0
   259
  set v
sl@0
   260
} {0}
sl@0
   261
do_test pager2-4.1 {
sl@0
   262
  set g1 [page_get $::p1 1]
sl@0
   263
  page_write $g1 "Page-1 v0"
sl@0
   264
  for {set i 2} {$i<=20} {incr i} {
sl@0
   265
    set gx [page_get $::p1 $i]
sl@0
   266
    page_write $gx "Page-$i v0"
sl@0
   267
    page_unref $gx
sl@0
   268
  }
sl@0
   269
  pager_commit $::p1
sl@0
   270
} {}
sl@0
   271
for {set i 1} {$i<=20} {incr i} {
sl@0
   272
  do_test pager2-4.2.$i {
sl@0
   273
    set gx [page_get $p1 $i]
sl@0
   274
    set v [page_read $gx]
sl@0
   275
    page_unref $gx
sl@0
   276
    set v
sl@0
   277
  } "Page-$i v0"
sl@0
   278
}
sl@0
   279
do_test pager2-4.3 {
sl@0
   280
  lrange [pager_stats $::p1] 0 1
sl@0
   281
} {ref 1}
sl@0
   282
do_test pager2-4.4 {
sl@0
   283
  lrange [pager_stats $::p1] 8 9
sl@0
   284
} {state 1}
sl@0
   285
sl@0
   286
for {set i 1} {$i<20} {incr i} {
sl@0
   287
  do_test pager2-4.5.$i.0 {
sl@0
   288
    set res {}
sl@0
   289
    for {set j 2} {$j<=20} {incr j} {
sl@0
   290
      set gx [page_get $p1 $j]
sl@0
   291
      set value [page_read $gx]
sl@0
   292
      page_unref $gx
sl@0
   293
      set shouldbe "Page-$j v[expr {$i-1}]"
sl@0
   294
      if {$value!=$shouldbe} {
sl@0
   295
        lappend res $value $shouldbe
sl@0
   296
      }
sl@0
   297
    }
sl@0
   298
    set res
sl@0
   299
  } {}
sl@0
   300
  do_test pager2-4.5.$i.1 {
sl@0
   301
    page_write $g1 "Page-1 v$i"
sl@0
   302
    lrange [pager_stats $p1] 8 9
sl@0
   303
  } {state 4}
sl@0
   304
  do_test pager2-4.5.$i.2 {
sl@0
   305
    for {set j 2} {$j<=20} {incr j} {
sl@0
   306
      set gx [page_get $p1 $j]
sl@0
   307
      page_write $gx "Page-$j v$i"
sl@0
   308
      page_unref $gx
sl@0
   309
      if {$j==$i} {
sl@0
   310
        pager_stmt_begin $p1
sl@0
   311
      }
sl@0
   312
    }
sl@0
   313
  } {}
sl@0
   314
  do_test pager2-4.5.$i.3 {
sl@0
   315
    set res {}
sl@0
   316
    for {set j 2} {$j<=20} {incr j} {
sl@0
   317
      set gx [page_get $p1 $j]
sl@0
   318
      set value [page_read $gx]
sl@0
   319
      page_unref $gx
sl@0
   320
      set shouldbe "Page-$j v$i"
sl@0
   321
      if {$value!=$shouldbe} {
sl@0
   322
        lappend res $value $shouldbe
sl@0
   323
      }
sl@0
   324
    }
sl@0
   325
    set res
sl@0
   326
  } {}
sl@0
   327
  do_test pager2-4.5.$i.4 {
sl@0
   328
    pager_rollback $p1
sl@0
   329
    set res {}
sl@0
   330
    for {set j 2} {$j<=20} {incr j} {
sl@0
   331
      set gx [page_get $p1 $j]
sl@0
   332
      set value [page_read $gx]
sl@0
   333
      page_unref $gx
sl@0
   334
      set shouldbe "Page-$j v[expr {$i-1}]"
sl@0
   335
      if {$value!=$shouldbe} {
sl@0
   336
        lappend res $value $shouldbe
sl@0
   337
      }
sl@0
   338
    }
sl@0
   339
    set res
sl@0
   340
  } {}
sl@0
   341
breakpoint
sl@0
   342
  do_test pager2-4.5.$i.5 {
sl@0
   343
    page_write $g1 "Page-1 v$i"
sl@0
   344
    lrange [pager_stats $p1] 8 9
sl@0
   345
  } {state 4}
sl@0
   346
  do_test pager2-4.5.$i.6 {
sl@0
   347
    for {set j 2} {$j<=20} {incr j} {
sl@0
   348
      set gx [page_get $p1 $j]
sl@0
   349
      page_write $gx "Page-$j v$i"
sl@0
   350
      page_unref $gx
sl@0
   351
      if {$j==$i} {
sl@0
   352
        pager_stmt_begin $p1
sl@0
   353
      }
sl@0
   354
    }
sl@0
   355
  } {}
sl@0
   356
  do_test pager2-4.5.$i.7 {
sl@0
   357
    pager_stmt_rollback $p1
sl@0
   358
    for {set j 2} {$j<=20} {incr j} {
sl@0
   359
      set gx [page_get $p1 $j]
sl@0
   360
      set value [page_read $gx]
sl@0
   361
      page_unref $gx
sl@0
   362
      if {$j<=$i || $i==1} {
sl@0
   363
        set shouldbe "Page-$j v$i"
sl@0
   364
      } else {
sl@0
   365
        set shouldbe "Page-$j v[expr {$i-1}]"
sl@0
   366
      }
sl@0
   367
      if {$value!=$shouldbe} {
sl@0
   368
        lappend res $value $shouldbe
sl@0
   369
      }
sl@0
   370
    }
sl@0
   371
    set res
sl@0
   372
  } {}
sl@0
   373
  do_test pager2-4.5.$i.8 {
sl@0
   374
    for {set j 2} {$j<=20} {incr j} {
sl@0
   375
      set gx [page_get $p1 $j]
sl@0
   376
      page_write $gx "Page-$j v$i"
sl@0
   377
      page_unref $gx
sl@0
   378
      if {$j==$i} {
sl@0
   379
        pager_stmt_begin $p1
sl@0
   380
      }
sl@0
   381
    }
sl@0
   382
  } {}
sl@0
   383
  do_test pager2-4.5.$i.9 {
sl@0
   384
    pager_stmt_commit $p1
sl@0
   385
    for {set j 2} {$j<=20} {incr j} {
sl@0
   386
      set gx [page_get $p1 $j]
sl@0
   387
      set value [page_read $gx]
sl@0
   388
      page_unref $gx
sl@0
   389
      set shouldbe "Page-$j v$i"
sl@0
   390
      if {$value!=$shouldbe} {
sl@0
   391
        lappend res $value $shouldbe
sl@0
   392
      }
sl@0
   393
    }
sl@0
   394
    set res
sl@0
   395
  } {}
sl@0
   396
  do_test pager2-4.5.$i.10 {
sl@0
   397
    pager_commit $p1
sl@0
   398
    lrange [pager_stats $p1] 8 9
sl@0
   399
  } {state 1}
sl@0
   400
}
sl@0
   401
sl@0
   402
do_test pager2-4.99 {
sl@0
   403
  page_unref $::g1
sl@0
   404
  pager_close $::p1
sl@0
   405
} {}
sl@0
   406
sl@0
   407
} ;# ifcapable inmemory
sl@0
   408
} ;# end if( has pager_open command );
sl@0
   409
sl@0
   410
sl@0
   411
finish_test