ctl_v3_alarm_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2016 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 e2e
  15. import (
  16. "strings"
  17. "testing"
  18. )
  19. func TestCtlV3Alarm(t *testing.T) { testCtl(t, alarmTest, withQuota(64*1024)) }
  20. func alarmTest(cx ctlCtx) {
  21. // test small put still works
  22. smallbuf := strings.Repeat("a", int(cx.quotaBackendBytes/100))
  23. if err := ctlV3Put(cx, "abc", smallbuf, ""); err != nil {
  24. cx.t.Fatal(err)
  25. }
  26. // test big put (to be rejected, and trigger quota alarm)
  27. bigbuf := strings.Repeat("a", int(cx.quotaBackendBytes))
  28. if err := ctlV3Put(cx, "abc", bigbuf, ""); err != nil {
  29. if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
  30. cx.t.Fatal(err)
  31. }
  32. }
  33. if err := ctlV3Alarm(cx, "list", "alarm:NOSPACE"); err != nil {
  34. cx.t.Fatal(err)
  35. }
  36. // alarm is on rejecting Puts and Txns
  37. if err := ctlV3Put(cx, "def", smallbuf, ""); err != nil {
  38. if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
  39. cx.t.Fatal(err)
  40. }
  41. }
  42. // turn off alarm
  43. if err := ctlV3Alarm(cx, "disarm", "alarm:NOSPACE"); err != nil {
  44. cx.t.Fatal(err)
  45. }
  46. // put one more key below quota
  47. if err := ctlV3Put(cx, "ghi", smallbuf, ""); err != nil {
  48. cx.t.Fatal(err)
  49. }
  50. }
  51. func ctlV3Alarm(cx ctlCtx, cmd string, as ...string) error {
  52. cmdArgs := append(cx.PrefixArgs(), "alarm", cmd)
  53. return spawnWithExpects(cmdArgs, as...)
  54. }