Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / tcl / txn007.tcl
1 # See the file LICENSE for redistribution information.
2 #
3 # Copyright (c) 1996, 2012 Oracle and/or its affiliates.  All rights reserved.
4 #
5 # $Id$
6 #
7 #TEST   txn007
8 #TEST   Test of DB_TXN_WRITE_NOSYNC
9 proc txn007 { { iter 50 } } {
10         source ./include.tcl
11         set testfile txn007.db
12
13         puts "Txn007: DB_TXN_WRITE_NOSYNC"
14         env_cleanup $testdir
15
16         # Open/create the txn region
17         puts "\tTxn007.a: Create env and database with -wrnosync"
18         set e [berkdb_env -create -home $testdir -txn -wrnosync]
19         error_check_good env_open [is_valid_env $e] TRUE
20
21         # Open/create database
22         set db [berkdb open -auto_commit -env $e \
23             -create -btree -dup $testfile]
24         error_check_good db_open [is_valid_db $db] TRUE
25
26         # Put some data
27         puts "\tTxn007.b: Put $iter data items in individual transactions"
28         for { set i 1 } { $i < $iter } { incr i } {
29                 # Start a transaction
30                 set txn [$e txn]
31                 error_check_good txn [is_valid_txn $txn $e] TRUE
32                 $db put -txn $txn key$i data$i
33                 error_check_good txn_commit [$txn commit] 0
34         }
35         set stat [$e log_stat]
36         puts "\tTxn007.c: Check log stats"
37         foreach i $stat {
38                 set txt [lindex $i 0]
39                 if { [string equal $txt {Times log written}] == 1 } {
40                         set wrval [lindex $i 1]
41                 }
42                 if { [string equal $txt {Times log flushed to disk}] == 1 } {
43                         set syncval [lindex $i 1]
44                 }
45         }
46         error_check_good wrval [expr $wrval >= $iter] 1
47         #
48         # We should have written at least 'iter' number of times,
49         # but not synced on any of those.
50         #
51         set val [expr $wrval - $iter]
52         error_check_good syncval [expr $syncval <= $val] 1
53
54         error_check_good db_close [$db close] 0
55         error_check_good env_close [$e close] 0
56 }