PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/sqlite/test/fallocate.test

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