store_v2_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2017 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. // +build !v2v3
  15. package store_test
  16. import (
  17. "testing"
  18. "github.com/coreos/etcd/pkg/testutil"
  19. "github.com/coreos/etcd/store"
  20. )
  21. type v2TestStore struct {
  22. store.Store
  23. }
  24. func (s *v2TestStore) Close() {}
  25. func newTestStore(t *testing.T, ns ...string) StoreCloser {
  26. return &v2TestStore{store.New(ns...)}
  27. }
  28. // Ensure that the store can recover from a previously saved state.
  29. func TestStoreRecover(t *testing.T) {
  30. s := newTestStore(t)
  31. defer s.Close()
  32. var eidx uint64 = 4
  33. s.Create("/foo", true, "", false, store.TTLOptionSet{ExpireTime: store.Permanent})
  34. s.Create("/foo/x", false, "bar", false, store.TTLOptionSet{ExpireTime: store.Permanent})
  35. s.Update("/foo/x", "barbar", store.TTLOptionSet{ExpireTime: store.Permanent})
  36. s.Create("/foo/y", false, "baz", false, store.TTLOptionSet{ExpireTime: store.Permanent})
  37. b, err := s.Save()
  38. testutil.AssertNil(t, err)
  39. s2 := newTestStore(t)
  40. s2.Recovery(b)
  41. e, err := s.Get("/foo/x", false, false)
  42. testutil.AssertEqual(t, e.Node.CreatedIndex, uint64(2))
  43. testutil.AssertEqual(t, e.Node.ModifiedIndex, uint64(3))
  44. testutil.AssertEqual(t, e.EtcdIndex, eidx)
  45. testutil.AssertNil(t, err)
  46. testutil.AssertEqual(t, *e.Node.Value, "barbar")
  47. e, err = s.Get("/foo/y", false, false)
  48. testutil.AssertEqual(t, e.EtcdIndex, eidx)
  49. testutil.AssertNil(t, err)
  50. testutil.AssertEqual(t, *e.Node.Value, "baz")
  51. }