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

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1996, 1997, 1998, 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: test019.tcl,v 11.14 2000/08/25 14:21:54 sue Exp $
  7. #
  8. # Test019 { access_method nentries }
  9. # Test the partial get functionality.
  10. proc test019 { method {nentries 10000} args } {
  11. global fixed_len
  12. global rand_init
  13. source ./include.tcl
  14. set args [convert_args $method $args]
  15. set omethod [convert_method $method]
  16. puts "Test019: $method ($args) $nentries partial get test"
  17. # Create the database and open the dictionary
  18. set eindex [lsearch -exact $args "-env"]
  19. #
  20. # If we are using an env, then testfile should just be the db name.
  21. # Otherwise it is the test directory and the name.
  22. if { $eindex == -1 } {
  23. set testfile $testdir/test019.db
  24. set env NULL
  25. } else {
  26. set testfile test019.db
  27. incr eindex
  28. set env [lindex $args $eindex]
  29. }
  30. cleanup $testdir $env
  31. set db [eval {berkdb_open 
  32.      -create -truncate -mode 0644} $args {$omethod $testfile}]
  33. error_check_good dbopen [is_valid_db $db] TRUE
  34. set did [open $dict]
  35. berkdb srand $rand_init
  36. set pflags ""
  37. set gflags ""
  38. set txn ""
  39. set count 0
  40. if { [is_record_based $method] == 1 } {
  41. append gflags " -recno"
  42. }
  43. puts "tTest019.a: put/get loop"
  44. for { set i 0 } { [gets $did str] != -1 && $i < $nentries } 
  45.     { incr i } {
  46. if { [is_record_based $method] == 1 } {
  47. set key [expr $i + 1]
  48. } else {
  49. set key $str
  50. }
  51. set repl [berkdb random_int $fixed_len 100]
  52. set data [chop_data $method [replicate $str $repl]]
  53. set ret [eval {$db put} $txn {-nooverwrite $key $data}]
  54. error_check_good dbput:$key $ret 0
  55. set ret [eval {$db get} $txn $gflags {$key}]
  56. error_check_good 
  57.     dbget:$key $ret [list [list $key [pad_data $method $data]]]
  58. set kvals($key) $repl
  59. }
  60. close $did
  61. puts "tTest019.b: partial get loop"
  62. set did [open $dict]
  63. for { set i 0 } { [gets $did str] != -1 && $i < $nentries } 
  64.     { incr i } {
  65. if { [is_record_based $method] == 1 } {
  66. set key [expr $i + 1]
  67. } else {
  68. set key $str
  69. }
  70. set data [replicate $str $kvals($key)]
  71. if { [is_fixed_length $method] == 1 } {
  72. set maxndx $fixed_len
  73. } else {
  74. set maxndx [expr [string length $data] - 1]
  75. }
  76. set beg [berkdb random_int 0 [expr $maxndx - 1]]
  77. set len [berkdb random_int 1 [expr $maxndx - $beg]]
  78. set ret [eval {$db get} 
  79.     $txn {-partial [list $beg $len]} $gflags {$key}]
  80. # In order for tcl to handle this, we have to overwrite the
  81. # last character with a NULL.  That makes the length one less
  82. # than we expect.
  83. set k [lindex [lindex $ret 0] 0]
  84. set d [lindex [lindex $ret 0] 1]
  85. error_check_good dbget_key $k $key
  86. # If $d contains some of the padding, we want to get rid of it.
  87. set firstnull [string first "" $d]
  88. if { $firstnull == -1 } { set firstnull [string length $d] }
  89. error_check_good dbget_data 
  90.     [string range $d 0 [expr $firstnull - 1]] 
  91.     [string range $data $beg [expr $beg + $len - 1]]
  92. }
  93. error_check_good db_close [$db close] 0
  94. close $did
  95. }