summaryrefslogtreecommitdiff
path: root/test/sql/bdb_logsize.test
blob: a6ff017cfd720d64ea3d8fb4e3359a8f1ef03a14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for the pragma 
# journal_size_limit, which has been redefined for Berekeley DB to set
# the size of log files, and how often those logfiles can be removed
# after a checkpoint.
#


set testdir [file dirname $argv0]/../../lang/sql/sqlite/test
source $testdir/tester.tcl
reset_db

# Test that pragma journal_size_limit works as expected.
#

set ::logsize 2097152

# Returns default value of 2MB
do_test logsize-1.1 {
  execsql {
    PRAGMA journal_size_limit;
  }
} $logsize
 
# Changes log size to 10K
do_test logsize-1.2 {
  execsql {
     PRAGMA journal_size_limit=10240;
  }
} {10240}

# Ignores values that are too small
do_test logsize-1.3 {
  execsql { 
      PRAGMA journal_size_limit=10;
  }
} {10240}

# Resets to the default when given a value of -1
do_test logsize-1.4 {
  execsql {
    PRAGMA journal_size_limit=-1;
  }
} $::logsize

set ::logfile test.db-journal/log.0000000001

# Check that the first log is 10K after setting
# logs to 10K
do_test logsize-2.0 {
  execsql {
    PRAGMA page_size=1024;
    PRAGMA journal_size_limit=10240;
    CREATE TABLE test(a varchar[100], b varchar[100], c varchar[100]);
  } 
  # Find the first log file
  set ::logfile [lindex [glob test.db-journal/log.*] 0]
  expr [file size $::logfile]/1024
} [expr 10240/1024]

# Check that the ninth log is the default after changing logs
# to the default
do_test logsize-2.1 {
  set counter 1
  while { [file exists $::logfile] == 1 } {
    set counter [expr $counter + 1]
    set ::logfile test.db-journal/log.000000000$counter
  }
  set counter [expr $counter + 1]
  set ::logfile test.db-journal/log.000000000$counter
  execsql {
    PRAGMA journal_size_limit=-1;
  }
  while { [file exists $::logfile] == 0 } {
    execsql {
      CREATE TABLE test2(int);
      DROP TABLE test2;
    }
  }
  expr [file size $::logfile]/1024
} [expr $::logsize/1024]

# Test that the first log file has been removed
do_test logsize-2.2 {
  file exists test.db-journal/log.0000000001
} {0}

finish_test