Annotation of embedaddon/sqlite3/test/fallocate.test, revision 1.1
1.1 ! misho 1: # 2010 July 28
! 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:
! 13: set testdir [file dirname $argv0]
! 14: source $testdir/tester.tcl
! 15:
! 16: file_control_chunksize_test db main [expr 1024*1024]
! 17:
! 18: do_test fallocate-1.1 {
! 19: execsql {
! 20: PRAGMA page_size = 1024;
! 21: PRAGMA auto_vacuum = 1;
! 22: CREATE TABLE t1(a, b);
! 23: }
! 24: file size test.db
! 25: } [expr 1*1024*1024]
! 26:
! 27: do_test fallocate-1.2 {
! 28: execsql { INSERT INTO t1 VALUES(1, zeroblob(1024*900)) }
! 29: file size test.db
! 30: } [expr 1*1024*1024]
! 31:
! 32: do_test fallocate-1.3 {
! 33: execsql { INSERT INTO t1 VALUES(2, zeroblob(1024*900)) }
! 34: file size test.db
! 35: } [expr 2*1024*1024]
! 36:
! 37: do_test fallocate-1.4 {
! 38: execsql { DELETE FROM t1 WHERE a = 1 }
! 39: file size test.db
! 40: } [expr 1*1024*1024]
! 41:
! 42: do_test fallocate-1.5 {
! 43: execsql { DELETE FROM t1 WHERE a = 2 }
! 44: file size test.db
! 45: } [expr 1*1024*1024]
! 46:
! 47: do_test fallocate-1.6 {
! 48: execsql { PRAGMA freelist_count }
! 49: } {0}
! 50:
! 51: # Start a write-transaction and read the "database file size" field from
! 52: # the journal file. This field should be set to the number of pages in
! 53: # the database file based on the size of the file on disk, not the actual
! 54: # logical size of the database within the file.
! 55: #
! 56: # We need to check this to verify that if in the unlikely event a rollback
! 57: # causes a database file to grow, the database grows to its previous size
! 58: # on disk, not to the minimum size required to hold the database image.
! 59: #
! 60: do_test fallocate-1.7 {
! 61: execsql { BEGIN; INSERT INTO t1 VALUES(1, 2); }
! 62: if {[permutation] != "inmemory_journal"} {
! 63: hexio_get_int [hexio_read test.db-journal 16 4]
! 64: } else {
! 65: set {} 1024
! 66: }
! 67: } {1024}
! 68: do_test fallocate-1.8 { execsql { COMMIT } } {}
! 69:
! 70:
! 71: #-------------------------------------------------------------------------
! 72: # The following tests - fallocate-2.* - test that things work in WAL
! 73: # mode as well.
! 74: #
! 75: set skipwaltests [expr {
! 76: [permutation]=="journaltest" || [permutation]=="inmemory_journal"
! 77: }]
! 78: ifcapable !wal { set skipwaltests 1 }
! 79:
! 80: if {!$skipwaltests} {
! 81: db close
! 82: forcedelete test.db
! 83: sqlite3 db test.db
! 84: file_control_chunksize_test db main [expr 32*1024]
! 85:
! 86: do_test fallocate-2.1 {
! 87: execsql {
! 88: PRAGMA page_size = 1024;
! 89: PRAGMA journal_mode = WAL;
! 90: CREATE TABLE t1(a, b);
! 91: }
! 92: file size test.db
! 93: } [expr 32*1024]
! 94:
! 95: do_test fallocate-2.2 {
! 96: execsql { INSERT INTO t1 VALUES(1, zeroblob(35*1024)) }
! 97: execsql { PRAGMA wal_checkpoint }
! 98: file size test.db
! 99: } [expr 64*1024]
! 100:
! 101: do_test fallocate-2.3 {
! 102: execsql { DELETE FROM t1 }
! 103: execsql { VACUUM }
! 104: file size test.db
! 105: } [expr 64*1024]
! 106:
! 107: do_test fallocate-2.4 {
! 108: execsql { PRAGMA wal_checkpoint }
! 109: file size test.db
! 110: } [expr 32*1024]
! 111:
! 112: do_test fallocate-2.5 {
! 113: execsql {
! 114: INSERT INTO t1 VALUES(2, randomblob(35*1024));
! 115: PRAGMA wal_checkpoint;
! 116: INSERT INTO t1 VALUES(3, randomblob(128));
! 117: DELETE FROM t1 WHERE a = 2;
! 118: VACUUM;
! 119: }
! 120: file size test.db
! 121: } [expr 64*1024]
! 122:
! 123: do_test fallocate-2.6 {
! 124: sqlite3 db2 test.db
! 125: execsql { BEGIN ; SELECT count(a) FROM t1 } db2
! 126: execsql {
! 127: INSERT INTO t1 VALUES(4, randomblob(128));
! 128: PRAGMA wal_checkpoint;
! 129: }
! 130: file size test.db
! 131: } [expr 64*1024]
! 132:
! 133: do_test fallocate-2.7 {
! 134: execsql { SELECT count(b) FROM t1 } db2
! 135: } {1}
! 136:
! 137: do_test fallocate-2.8 {
! 138: execsql { COMMIT } db2
! 139: execsql { PRAGMA wal_checkpoint }
! 140: file size test.db
! 141: } [expr 32*1024]
! 142: }
! 143:
! 144:
! 145: finish_test
! 146:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>