walpersist.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # 2011 July 26
  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 contains tests for using WAL with persistent WAL file mode.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. source $testdir/lock_common.tcl
  17. set ::testprefix walpersist
  18. ifcapable !wal {
  19. finish_test
  20. return
  21. }
  22. do_test walpersist-1.0 {
  23. db eval {
  24. PRAGMA journal_mode=WAL;
  25. CREATE TABLE t1(a);
  26. INSERT INTO t1 VALUES(randomblob(5000));
  27. }
  28. file exists test.db-wal
  29. } {1}
  30. do_test walpersist-1.1 {
  31. file exists test.db-shm
  32. } {1}
  33. do_test walpersist-1.2 {
  34. db close
  35. list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
  36. } {1 0 0}
  37. do_test walpersist-1.3 {
  38. sqlite3 db test.db
  39. db eval {SELECT length(a) FROM t1}
  40. } {5000}
  41. do_test walpersist-1.4 {
  42. list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
  43. } {1 1 1}
  44. do_test walpersist-1.5 {
  45. file_control_persist_wal db -1
  46. } {0 0}
  47. do_test walpersist-1.6 {
  48. file_control_persist_wal db 1
  49. } {0 1}
  50. do_test walpersist-1.7 {
  51. file_control_persist_wal db -1
  52. } {0 1}
  53. do_test walpersist-1.8 {
  54. file_control_persist_wal db 0
  55. } {0 0}
  56. do_test walpersist-1.9 {
  57. file_control_persist_wal db -1
  58. } {0 0}
  59. do_test walpersist-1.10 {
  60. file_control_persist_wal db 1
  61. } {0 1}
  62. do_test walpersist-1.11 {
  63. db close
  64. list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
  65. } {1 1 1}
  66. # Make sure the journal_size_limit works to limit the size of the
  67. # persisted wal file. In persistent-wal mode, any non-negative
  68. # journal_size_limit causes the WAL file to be truncated to zero bytes
  69. # when closing.
  70. #
  71. forcedelete test.db test.db-shm test.db-wal
  72. do_test walpersist-2.1 {
  73. sqlite3 db test.db
  74. db eval {
  75. PRAGMA journal_mode=WAL;
  76. PRAGMA wal_autocheckpoint=OFF;
  77. PRAGMA journal_size_limit=12000;
  78. CREATE TABLE t1(x);
  79. INSERT INTO t1 VALUES(randomblob(50000));
  80. UPDATE t1 SET x=randomblob(50000);
  81. }
  82. expr {[file size test.db-wal]>100000}
  83. } {1}
  84. do_test walpersist-2.2 {
  85. file_control_persist_wal db 1
  86. db close
  87. concat [file exists test.db-wal] [file size test.db-wal]
  88. } {1 0}
  89. do_test walpersist-2.3 {
  90. sqlite3 db test.db
  91. execsql { PRAGMA integrity_check }
  92. } {ok}
  93. do_test 3.1 {
  94. catch {db close}
  95. forcedelete test.db test.db-shm test.db-wal
  96. sqlite3 db test.db
  97. execsql {
  98. PRAGMA page_size = 1024;
  99. PRAGMA journal_mode = WAL;
  100. PRAGMA wal_autocheckpoint=128;
  101. PRAGMA journal_size_limit=16384;
  102. CREATE TABLE t1(a, b, PRIMARY KEY(a, b));
  103. }
  104. } {wal 128 16384}
  105. do_test 3.2 {
  106. for {set i 0} {$i<200} {incr i} {
  107. execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) }
  108. }
  109. file_control_persist_wal db 1
  110. db close
  111. } {}
  112. do_test walpersist-3.3 {
  113. file size test.db-wal
  114. } {0}
  115. do_test walpersist-3.4 {
  116. sqlite3 db test.db
  117. execsql { PRAGMA integrity_check }
  118. } {ok}
  119. finish_test