env001.tcl
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 5k
Category:

MySQL

Development Platform:

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: env001.tcl,v 11.21 2000/11/09 19:24:08 sue Exp $
  7. #
  8. # Test of env remove interface.
  9. proc env001 { } {
  10. global errorInfo
  11. global errorCode
  12. source ./include.tcl
  13. set testfile $testdir/env.db
  14. set t1 $testdir/t1
  15. puts "Env001: Test of environment remove interface."
  16. env_cleanup $testdir
  17. # Try opening without Create flag should error
  18. puts "tEnv001.a: Open without create (should fail)."
  19. catch {set env [berkdb env -home $testdir]} ret
  20. error_check_good env:fail [is_substr $ret "no such file"] 1
  21. # Now try opening with create
  22. puts "tEnv001.b: Open with create."
  23. set env [berkdb env -create -mode 0644 -home $testdir]
  24. error_check_bad env:$testdir $env NULL
  25. error_check_good env:$testdir [is_substr $env "env"] 1
  26. # Make sure that close works.
  27. puts "tEnv001.c: Verify close."
  28. error_check_good env:close:$env [$env close] 0
  29. # Make sure we can reopen -- this doesn't work on Windows
  30. # because if there is only one opener, the region disappears
  31. # when it is closed.  We can't do a second opener, because
  32. # that will fail on HP-UX.
  33. puts "tEnv001.d: Remove on closed environments."
  34. if { $is_windows_test != 1 } {
  35. puts "ttEnv001.d.1: Verify re-open."
  36. set env [berkdb env -home $testdir]
  37. error_check_bad env:$testdir $env NULL
  38. error_check_good env:$testdir [is_substr $env "env"] 1
  39. # remove environment
  40. puts "ttEnv001.d.2: Close environment."
  41. error_check_good env:close [$env close] 0
  42. puts "ttEnv001.d.3: Try remove with force (should succeed)."
  43. error_check_good 
  44.     envremove [berkdb envremove -force -home $testdir] 0
  45. }
  46. if { $is_windows_test != 1 && $is_hp_test != 1 } {
  47. puts "tEnv001.e: Remove on open environments."
  48. puts "ttEnv001.e.1: Env is open by single proc,
  49.     remove no force."
  50. set env [berkdb env -create -mode 0644 -home $testdir]
  51. error_check_bad env:$testdir $env NULL
  52. error_check_good env:$testdir [is_substr $env "env"] 1
  53. set stat [catch {berkdb envremove -home $testdir} ret]
  54. error_check_good env:remove $stat 1
  55. error_check_good env:close [$env close] 0
  56. }
  57. puts 
  58.     "ttEnv001.e.2: Env is open by single proc, remove with force."
  59. # Now that envremove doesn't do a close, this won't work on Windows.
  60. if { $is_windows_test != 1 && $is_hp_test != 1} {
  61. set env [berkdb env -create -mode 0644 -home $testdir]
  62. error_check_bad env:$testdir $env NULL
  63. error_check_good env:$testdir [is_substr $env "env"] 1
  64. set stat [catch {berkdb envremove -force -home $testdir} ret]
  65. error_check_good env:remove(force) $ret 0
  66. #
  67. # Even though the underlying env is gone, we need to close
  68. # the handle.
  69. #
  70. catch {$env close}
  71. }
  72. puts "ttEnv001.e.3: Env is open by 2 procs, remove no force."
  73. # should fail
  74. set env [berkdb env -create -mode 0644 -home $testdir]
  75. error_check_bad env:$testdir $env NULL
  76. error_check_good env:$testdir [is_substr $env "env"] 1
  77. set f1 [open |$tclsh_path r+]
  78. puts $f1 "source $test_path/test.tcl"
  79. set remote_env [send_cmd $f1 "berkdb env -home $testdir"]
  80. error_check_good remote:env_open [is_valid_env $remote_env] TRUE
  81. # First close our env, but leave remote open
  82. error_check_good env:close [$env close] 0
  83. catch {berkdb envremove -home $testdir} ret
  84. error_check_good envremove:2procs:noforce [is_substr $errorCode EBUSY] 1
  85. #
  86. # even though it failed, $env is no longer valid, so remove it in
  87. # the remote process
  88. set remote_close [send_cmd $f1 "$remote_env close"]
  89. error_check_good remote_close $remote_close 0
  90. # exit remote process
  91. set err [catch { close $f1 } result]
  92. error_check_good close_remote_process $err 0
  93. puts "ttEnv001.e.4: Env is open by 2 procs, remove with force."
  94. # You cannot do this on windows because you can't remove files that
  95. # are open, so we skip this test for Windows.  On UNIX, it should
  96. # succeed
  97. if { $is_windows_test != 1 && $is_hp_test != 1 } {
  98. set env [berkdb env -create -mode 0644 -home $testdir]
  99. error_check_bad env:$testdir $env NULL
  100. error_check_good env:$testdir [is_substr $env "env"] 1
  101. set f1 [open |$tclsh_path r+]
  102. puts $f1 "source $test_path/test.tcl"
  103. set remote_env [send_cmd $f1 "berkdb env -home $testdir"]
  104. error_check_good remote:env_open [is_valid_env $remote_env] TRUE
  105. catch {berkdb envremove -force -home $testdir} ret
  106. error_check_good envremove:2procs:force $ret 0
  107. #
  108. # We still need to close our handle.
  109. #
  110. catch {$env close} ret
  111. # Close down remote process
  112. set err [catch { close $f1 } result]
  113. error_check_good close_remote_process $err 0
  114. }
  115. # Try opening in a different dir
  116. puts "tEnv001.f: Try opening env in another directory."
  117. if { [file exists $testdir/NEWDIR] != 1 } {
  118. file mkdir $testdir/NEWDIR
  119. }
  120. set eflags "-create -home $testdir/NEWDIR -mode 0644"
  121. set env [eval {berkdb env} $eflags]
  122. error_check_bad env:open $env NULL
  123. error_check_good env:close [$env close] 0
  124. error_check_good berkdb:envremove 
  125.     [berkdb envremove -home $testdir/NEWDIR] 0
  126. puts "tEnv001 complete."
  127. }