failure_case_kill.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package tester
  15. import "github.com/coreos/etcd/functional/rpcpb"
  16. func injectKill(clus *Cluster, idx int) error {
  17. return clus.sendOperation(idx, rpcpb.Operation_KillEtcd)
  18. }
  19. func recoverKill(clus *Cluster, idx int) error {
  20. return clus.sendOperation(idx, rpcpb.Operation_RestartEtcd)
  21. }
  22. func newFailureKillOneFollower(clus *Cluster) Failure {
  23. ff := failureByFunc{
  24. failureCase: rpcpb.FailureCase_KILL_ONE_FOLLOWER,
  25. injectMember: injectKill,
  26. recoverMember: recoverKill,
  27. }
  28. f := &failureFollower{ff, -1, -1}
  29. return &failureDelay{
  30. Failure: f,
  31. delayDuration: clus.GetFailureDelayDuration(),
  32. }
  33. }
  34. func newFailureKillLeader(clus *Cluster) Failure {
  35. ff := failureByFunc{
  36. failureCase: rpcpb.FailureCase_KILL_LEADER,
  37. injectMember: injectKill,
  38. recoverMember: recoverKill,
  39. }
  40. f := &failureLeader{ff, -1, -1}
  41. return &failureDelay{
  42. Failure: f,
  43. delayDuration: clus.GetFailureDelayDuration(),
  44. }
  45. }
  46. func newFailureKillQuorum(clus *Cluster) Failure {
  47. f := &failureQuorum{
  48. failureCase: rpcpb.FailureCase_KILL_QUORUM,
  49. injectMember: injectKill,
  50. recoverMember: recoverKill,
  51. }
  52. return &failureDelay{
  53. Failure: f,
  54. delayDuration: clus.GetFailureDelayDuration(),
  55. }
  56. }
  57. func newFailureKillAll(clus *Cluster) Failure {
  58. f := &failureAll{
  59. failureCase: rpcpb.FailureCase_KILL_ALL,
  60. injectMember: injectKill,
  61. recoverMember: recoverKill,
  62. }
  63. return &failureDelay{
  64. Failure: f,
  65. delayDuration: clus.GetFailureDelayDuration(),
  66. }
  67. }
  68. func newFailureKillOneFollowerUntilTriggerSnapshot(clus *Cluster) Failure {
  69. return &failureUntilSnapshot{
  70. failureCase: rpcpb.FailureCase_KILL_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT,
  71. Failure: newFailureKillOneFollower(clus),
  72. }
  73. }
  74. func newFailureKillLeaderUntilTriggerSnapshot(clus *Cluster) Failure {
  75. return &failureUntilSnapshot{
  76. failureCase: rpcpb.FailureCase_KILL_LEADER_UNTIL_TRIGGER_SNAPSHOT,
  77. Failure: newFailureKillLeader(clus),
  78. }
  79. }