File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / walhook.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 10 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

    1: # 2010 April 19
    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: # This file implements regression tests for SQLite library.  The
   12: # focus of this file is testing the operation of the library in
   13: # "PRAGMA journal_mode=WAL" mode.
   14: # 
   15: # More specifically, this file contains regression tests for the 
   16: # sqlite3_wal_hook() mechanism, including the sqlite3_wal_autocheckpoint()
   17: # and "PRAGMA wal_autocheckpoint" convenience interfaces.
   18: #
   19: 
   20: set testdir [file dirname $argv0]
   21: source $testdir/tester.tcl
   22: source $testdir/wal_common.tcl
   23: 
   24: ifcapable !wal {finish_test ; return }
   25: 
   26: set ::wal_hook [list]
   27: proc wal_hook {zDb nEntry} {
   28:   lappend ::wal_hook $zDb $nEntry
   29:   return 0
   30: }
   31: db wal_hook wal_hook
   32: 
   33: do_test walhook-1.1 {
   34:   execsql { 
   35:     PRAGMA page_size = 1024;
   36:     PRAGMA auto_vacuum = 0;
   37:     PRAGMA journal_mode = wal;
   38:     PRAGMA synchronous = normal;
   39:     CREATE TABLE t1(i PRIMARY KEY, j);
   40:   }
   41:   set ::wal_hook
   42: } {main 3}
   43: 
   44: do_test walhook-1.2 {
   45:   set ::wal_hook [list]
   46:   execsql { INSERT INTO t1 VALUES(1, 'one') }
   47:   set ::wal_hook
   48: } {main 5}
   49: do_test walhook-1.3 {
   50:   proc wal_hook {args} { db eval {PRAGMA wal_checkpoint}; return 0 }
   51:   execsql { INSERT INTO t1 VALUES(2, 'two') }
   52:   file size test.db
   53: } [expr 3*1024]
   54: do_test walhook-1.4 {
   55:   proc wal_hook {zDb nEntry} { 
   56:     execsql { PRAGMA wal_checkpoint }
   57:     return 0
   58:   }
   59:   execsql { CREATE TABLE t2(a, b) }
   60:   file size test.db
   61: } [expr 4*1024]
   62: 
   63: do_test walhook-1.5 {
   64:   sqlite3 db2 test.db
   65:   proc wal_hook {zDb nEntry} {
   66:     execsql { PRAGMA wal_checkpoint } db2
   67:     return 0
   68:   }
   69:   execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
   70:   file size test.db
   71: } [expr 6*1024]
   72: 
   73: db2 close
   74: db close
   75: sqlite3 db test.db
   76: do_test walhook-2.1 {
   77:   execsql { PRAGMA synchronous = NORMAL }
   78:   execsql { PRAGMA wal_autocheckpoint }
   79: } {1000}
   80: do_test walhook-2.2 {
   81:   execsql { PRAGMA wal_autocheckpoint = 10}
   82: } {10}
   83: do_test walhook-2.3 {
   84:   execsql { PRAGMA wal_autocheckpoint }
   85: } {10}
   86: 
   87: #
   88: # The database connection is configured with "PRAGMA wal_autocheckpoint = 10".
   89: # Check that transactions are written to the log file until it contains at
   90: # least 10 frames, then the database is checkpointed. Subsequent transactions
   91: # are written into the start of the log file.
   92: #
   93: foreach {tn sql dbpages logpages} {
   94:   4 "CREATE TABLE t4(x PRIMARY KEY, y)"   6   3
   95:   5 "INSERT INTO t4 VALUES(1, 'one')"     6   5
   96:   6 "INSERT INTO t4 VALUES(2, 'two')"     6   7
   97:   7 "INSERT INTO t4 VALUES(3, 'three')"   6   9
   98:   8 "INSERT INTO t4 VALUES(4, 'four')"    8  11
   99:   9 "INSERT INTO t4 VALUES(5, 'five')"    8  11
  100: } {
  101:   do_test walhook-2.$tn {
  102:     execsql $sql
  103:     list [file size test.db] [file size test.db-wal]
  104:   } [list [expr $dbpages*1024] [wal_file_size $logpages 1024]]
  105: }
  106: 
  107: catch { db2 close }
  108: catch { db close }
  109: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>