sdb008.tcl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: sdb008.tcl,v 11.14 2000/08/25 14:21:53 sue Exp $
  7. #
  8. # Sub DB Test 8 {access method}
  9. # Use the first 10,000 entries from the dictionary.
  10. # Use a different or random lorder for each subdb.
  11. # Insert each with self as key and data; retrieve each.
  12. # After all are entered, retrieve all; compare output to original.
  13. # Close file, reopen, do retrieve and re-verify.
  14. proc subdb008 { method {nentries 10000} args } {
  15. source ./include.tcl
  16. global rand_init
  17. set args [convert_args $method $args]
  18. set omethod [convert_method $method]
  19. if { [is_queue $method] == 1 } {
  20. puts "Subdb008: skipping for method $method"
  21. return
  22. }
  23. berkdb srand $rand_init
  24. puts "Subdb008: $method ($args) subdb lorder tests"
  25. # Create the database and open the dictionary
  26. set testfile $testdir/subdb008.db
  27. set t1 $testdir/t1
  28. set t2 $testdir/t2
  29. set t3 $testdir/t3
  30. set t4 $testdir/t4
  31. cleanup $testdir NULL
  32. set txn ""
  33. set pflags ""
  34. set gflags ""
  35. if { [is_record_based $method] == 1 } {
  36. set checkfunc subdb008_recno.check
  37. } else {
  38. set checkfunc subdb008.check
  39. }
  40. set nsubdbs 4
  41. set lo [list 4321 1234]
  42. puts "tSubdb008.a: put/get loop"
  43. # Here is the loop where we put and get each key/data pair
  44. for { set i 0 } { $i < $nsubdbs } { incr i } {
  45. set subdb sub$i.db
  46. if { $i >= [llength $lo]} {
  47. set r [berkdb random_int 0 1]
  48. set order [lindex $lo $r]
  49. } else {
  50. set order [lindex $lo $i]
  51. }
  52. set db [eval {berkdb_open -create -mode 0644} 
  53.     $args {-lorder $order $omethod $testfile $subdb}]
  54. set did [open $dict]
  55. set count 0
  56. while { [gets $did str] != -1 && $count < $nentries } {
  57. if { [is_record_based $method] == 1 } {
  58. global kvals
  59. set gflags "-recno"
  60. set key [expr $i * $nentries]
  61. set key [expr $key + $count + 1]
  62. set kvals($key) [pad_data $method $str]
  63. } else {
  64. set key $str
  65. }
  66. set ret [eval {$db put} 
  67.     $txn $pflags {$key [chop_data $method $str]}]
  68. error_check_good put $ret 0
  69. set ret [eval {$db get} $gflags {$key}]
  70. error_check_good 
  71.     get $ret [list [list $key [pad_data $method $str]]]
  72. incr count
  73. }
  74. close $did
  75. error_check_good db_close [$db close] 0
  76. }
  77. # Now we will get each key from the DB and compare the results
  78. # to the original.
  79. for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } {
  80. puts "tSubdb008.b: dump file sub$subdb.db"
  81. set db [berkdb_open -unknown $testfile sub$subdb.db]
  82. dump_file $db $txn $t1 $checkfunc
  83. error_check_good db_close [$db close] 0
  84. # Now compare the keys to see if they match the dictionary
  85. # (or ints)
  86. if { [is_record_based $method] == 1 } {
  87. set oid [open $t2 w]
  88. for {set i 1} {$i <= $nentries} {incr i} {
  89. puts $oid [expr $subdb * $nentries + $i]
  90. }
  91. close $oid
  92. file rename -force $t1 $t3
  93. } else {
  94. set q q
  95. filehead $nentries $dict $t3
  96. filesort $t3 $t2
  97. filesort $t1 $t3
  98. }
  99. error_check_good Subdb008:diff($t3,$t2) 
  100.     [filecmp $t3 $t2] 0
  101. puts "tSubdb008.c: sub$subdb.db: close, open, and dump file"
  102. # Now, reopen the file and run the last test again.
  103. open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc 
  104.     dump_file_direction "-first" "-next" sub$subdb.db
  105. if { [is_record_based $method] != 1 } {
  106. filesort $t1 $t3
  107. }
  108. error_check_good Subdb008:diff($t2,$t3) 
  109.     [filecmp $t2 $t3] 0
  110. # Now, reopen the file and run the last test again in the
  111. # reverse direction.
  112. puts "tSubdb008.d: sub$subdb.db:
  113.     close, open, and dump file in reverse direction"
  114. open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc 
  115.     dump_file_direction "-last" "-prev" sub$subdb.db
  116. if { [is_record_based $method] != 1 } {
  117. filesort $t1 $t3
  118. }
  119. error_check_good Subdb008:diff($t3,$t2) 
  120.     [filecmp $t3 $t2] 0
  121. }
  122. }
  123. # Check function for Subdb008; keys and data are identical
  124. proc subdb008.check { key data } {
  125. error_check_good "key/data mismatch" $data $key
  126. }
  127. proc subdb008_recno.check { key data } {
  128. global dict
  129. global kvals
  130. error_check_good key"$key"_exists [info exists kvals($key)] 1
  131. error_check_good "key/data mismatch, key $key" $data $kvals($key)
  132. }