Annotation of embedaddon/sqlite3/test/zerodamage.test, revision 1.1

1.1     ! misho       1: # 2011 December 21
        !             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: # This file implements tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
        !            13: # and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
        !            14: #
        !            15: # The name of this file comes from the fact that we used to call the
        !            16: # POWERSAFE_OVERWRITE property ZERO_DAMAGE.
        !            17: #
        !            18: 
        !            19: set testdir [file dirname $argv0]
        !            20: source $testdir/tester.tcl
        !            21: set testprefix wal5
        !            22: 
        !            23: ifcapable !vtab {
        !            24:   finish_test
        !            25:   return
        !            26: }
        !            27: 
        !            28: # POWERSAFE_OVERWRITE defaults to true
        !            29: #
        !            30: do_test zerodamage-1.0 {
        !            31:   file_control_powersafe_overwrite db -1
        !            32: } {0 1}
        !            33: 
        !            34: # Check the ability to turn zero-damage on and off.
        !            35: #
        !            36: do_test zerodamage-1.1 {
        !            37:   file_control_powersafe_overwrite db 0
        !            38:   file_control_powersafe_overwrite db -1
        !            39: } {0 0}
        !            40: do_test zerodamage-1.2 {
        !            41:   file_control_powersafe_overwrite db 1
        !            42:   file_control_powersafe_overwrite db -1
        !            43: } {0 1}
        !            44: 
        !            45: # Run a transaction with zero-damage on, a small page size and a much larger
        !            46: # sectorsize.  Verify that the maximum journal size is small - that the
        !            47: # rollback journal is not being padded.
        !            48: #
        !            49: do_test zerodamage-2.0 {
        !            50:   db close
        !            51:   testvfs tv -default 1
        !            52:   tv sectorsize 8192
        !            53:   sqlite3 db file:test.db?psow=TRUE -uri 1
        !            54:   unset -nocomplain ::max_journal_size
        !            55:   set ::max_journal_size 0
        !            56:   proc xDeleteCallback {method file args} {
        !            57:     set sz [file size $file]
        !            58:     if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
        !            59:   }
        !            60:   tv filter xDelete
        !            61:   tv script xDeleteCallback
        !            62:   register_wholenumber_module db
        !            63:   db eval {
        !            64:     PRAGMA page_size=1024;
        !            65:     PRAGMA journal_mode=DELETE;
        !            66:     PRAGMA cache_size=5;
        !            67:     CREATE VIRTUAL TABLE nums USING wholenumber;
        !            68:     CREATE TABLE t1(x, y);
        !            69:     INSERT INTO t1 SELECT value, randomblob(100) FROM nums
        !            70:                     WHERE value BETWEEN 1 AND 400;
        !            71:   }
        !            72:   set ::max_journal_size 0
        !            73:   db eval {
        !            74:     UPDATE t1 SET y=randomblob(50) WHERE x=123;
        !            75:   }
        !            76:   concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
        !            77: } {0 1 2576}
        !            78: 
        !            79: # Repeat the previous step with zero-damage turned off.  This time the
        !            80: # maximum rollback journal size should be much larger.
        !            81: #
        !            82: do_test zerodamage-2.1 {
        !            83:   set ::max_journal_size 0
        !            84:   db close
        !            85:   sqlite3 db file:test.db?psow=FALSE -uri 1
        !            86:   db eval {
        !            87:     UPDATE t1 SET y=randomblob(50) WHERE x=124;
        !            88:   }
        !            89:   concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
        !            90: } {0 0 24704}
        !            91: 
        !            92: # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
        !            93: # WAL file does not get too big.
        !            94: #
        !            95: do_test zerodamage-3.0 {
        !            96:   db eval {
        !            97:      PRAGMA journal_mode=WAL;
        !            98:   }
        !            99:   db close
        !           100:   sqlite3 db file:test.db?psow=TRUE -uri 1
        !           101:   db eval {
        !           102:      UPDATE t1 SET y=randomblob(50) WHERE x=124;
        !           103:   }
        !           104:   file size test.db-wal
        !           105: } {1080}
        !           106: 
        !           107: # Repeat the previous with POWERSAFE_OVERWRITE off.  Verify that the WAL file
        !           108: # is padded.
        !           109: #
        !           110: do_test zerodamage-3.1 {
        !           111:   db close
        !           112:   sqlite3 db file:test.db?psow=FALSE -uri 1
        !           113:   db eval {
        !           114:      UPDATE t1 SET y=randomblob(50) WHERE x=124;
        !           115:   }
        !           116:   file size test.db-wal
        !           117: } {8416}
        !           118: 
        !           119: finish_test

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