libdb/test/sql/bdb_pragmas.test
2011-09-13 13:44:24 -04:00

219 lines
4.6 KiB
Text

#
# 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 some simple Berkeley DB specific
# pragmas.
#
set testdir [file dirname $argv0]/../../lang/sql/sqlite/test
source $testdir/tester.tcl
reset_db
# Test that pragma trickle works as expected.
#
do_test bdb_pragmas-1.1 {
execsql {
PRAGMA trickle;
}
} {0}
# Test that it's just ignored before an open happens
do_test bdb_pragmas-1.2 {
execsql {
PRAGMA trickle=123;
}
} {0}
do_test bdb_pragmas-1.3 {
execsql {
CREATE TABLE t1(n int, log int);
PRAGMA trickle;
}
} {0}
do_test bdb_pragmas-1.4 {
execsql {
PRAGMA trickle=10;
}
} {10}
# populate so there will be something to trickle
do_test bdb_pragmas-1.5 {
for {set i 1} {$i<=2000} {incr i} {
for {set j 0} {(1<<$j)<$i} {incr j} {}
execsql "INSERT INTO t1 VALUES($i,$j)"
}
} {}
do_test bdb_pragmas-1.6 {
execsql {
PRAGMA trickle=50;
}
} {50}
# TODO: Verify that something actually trickled?
do_test bdb_pragmas-1.7 {
set v [catch { execsql {
PRAGMA trickle=weoin;
}} msg]
lappend v $msg
} {1 {Invalid trickle value weoin, must be a percentage.}}
do_test bdb_pragmas-1.8 {
set v [catch { execsql {
PRAGMA trickle=12039;
}} msg]
lappend v $msg
} {1 {Invalid trickle value 12039, must be a percentage.}}
integrity_check bdb_pragmas-1.99
reset_db
# Test bdbsql_system_memory pragma
do_test bdb_pragmas-2.1 {
execsql {
PRAGMA bdbsql_system_memory;
}
} {0}
do_test bdb_pragmas-2.2 {
execsql {
PRAGMA bdbsql_system_memory=-1;
}
} {-1}
do_test bdb_pragmas-2.3 {
set v [catch { execsql {
PRAGMA bdbsql_system_memory=asdub;
}} msg]
lappend v $msg
} {1 {Invalid value bdbsql_system_memory asdub needs to be a base segment id, see DB_ENV->set_shm_key documentation for more information.}}
do_test bdb_pragmas-2.4 {
execsql {
PRAGMA bdbsql_system_memory=123;
}
} {123}
# Verify that turning system mem off actually works.
do_test bdb_pragmas-2.5 {
execsql {
PRAGMA bdbsql_system_memory=-1;
}
} {-1}
do_test bdb_pragmas-2.6 {
execsql {
PRAGMA bdbsql_system_memory;
}
} {0}
do_test bdb_pragmas-2.7 {
execsql {
PRAGMA bdbsql_system_memory=123;
}
} {123}
# Trigger the database create.
do_test bdb_pragmas-2.8 {
execsql { CREATE TABLE t1(x int, log int); }
for {set i 1} {$i<=20} {incr i} {
for {set j 0} {(1<<$j)<$i} {incr j} {}
execsql "INSERT INTO t1 VALUES($i,$j)"
}
} {}
# Check to see if the region files were created (if so, it's not working).
do_test bdb_pragmas-2.9 {
set ::regionfile [lindex [glob test.db-journal/__db.*] 0]
llength $::regionfile
} {1}
do_test bdb_pragmas-2.10 {
execsql {
PRAGMA bdbsql_system_memory;
}
} {1}
do_test bdb_pragmas-2.11 {
set v [catch { execsql {
PRAGMA bdbsql_system_memory=124;
}} msg]
lappend v $msg
} {1 {Cannot set bdbsql_system_memory after accessing the database}}
integrity_check bdb_pragmas-2.99
reset_db
# Test bdbsql_error_file pragma
do_test bdb_pragma-3.1 {
execsql {
PRAGMA bdbsql_error_file;
}
} {Default}
# Test set bdbql_error_file pragma before opening env.
# Create a sqequence to generate error.
do_test bdb_pragma-3.2 {
execsql {
PRAGMA bdbsql_error_file = "a.txt";
select create_sequence("b", "maxvalue", 3, "cache", 2);
select nextval("b");
select nextval("b");
select nextval("b");
select nextval("b");
}
} {a.txt 0 0 1 2 3}
# Trigger a DB sequence error and save the internal error message to a.txt
do_test bdb_pragma-3.3 {
set v [catch { execsql {
select nextval("b");
}} msg]
lappend v $msg
} {1 {Sequence value out of bounds.}}
# Test set bdbql_error_file pragma after opening env.
do_test bdb_pragma-3.4 {
execsql {
PRAGMA bdbsql_error_file = "b.txt";
}
} {b.txt}
# Trigger a DB sequence error and save the internal error message to b.txt
do_test bdb_pragma-3.5 {
set v [catch { execsql {
select nextval("b");
}} msg]
lappend v $msg
} {1 {Sequence value out of bounds.}}
#Ensure the error message has been saved to error file as expected.
do_test bdb_pragma-3.6 {
set fd [open "./a.txt" r]
set res [read $fd]
close $fd
file delete -force ./a.txt
set pat {BDB4011 Sequence overflow}
regexp $pat $res
} {1}
do_test bdb_pragma-3.7 {
set fd [open "./b.txt" r]
set res [read $fd]
close $fd
db close
file delete -force ./b.txt
set pat {BDB4011 Sequence overflow}
regexp $pat $res
} {1}
finish_test