file_pipeline_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 wal
  15. import (
  16. "io/ioutil"
  17. "math"
  18. "os"
  19. "testing"
  20. "go.uber.org/zap"
  21. )
  22. func TestFilePipeline(t *testing.T) {
  23. tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. defer os.RemoveAll(tdir)
  28. fp := newFilePipeline(zap.NewExample(), tdir, SegmentSizeBytes)
  29. defer fp.Close()
  30. f, ferr := fp.Open()
  31. if ferr != nil {
  32. t.Fatal(ferr)
  33. }
  34. f.Close()
  35. }
  36. func TestFilePipelineFailPreallocate(t *testing.T) {
  37. tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. defer os.RemoveAll(tdir)
  42. fp := newFilePipeline(zap.NewExample(), tdir, math.MaxInt64)
  43. defer fp.Close()
  44. f, ferr := fp.Open()
  45. if f != nil || ferr == nil { // no space left on device
  46. t.Fatal("expected error on invalid pre-allocate size, but no error")
  47. }
  48. }
  49. func TestFilePipelineFailLockFile(t *testing.T) {
  50. tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
  51. if err != nil {
  52. t.Fatal(err)
  53. }
  54. os.RemoveAll(tdir)
  55. fp := newFilePipeline(zap.NewExample(), tdir, math.MaxInt64)
  56. defer fp.Close()
  57. f, ferr := fp.Open()
  58. if f != nil || ferr == nil { // no such file or directory
  59. t.Fatal("expected error on invalid pre-allocate size, but no error")
  60. }
  61. }