consistent_watchable_store_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2015 CoreOS, Inc.
  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 storage
  15. import "testing"
  16. type indexVal uint64
  17. func (v *indexVal) ConsistentIndex() uint64 { return uint64(*v) }
  18. func TestConsistentWatchableStoreConsistentIndex(t *testing.T) {
  19. var idx indexVal
  20. s := newConsistentWatchableStore(tmpPath, &idx)
  21. defer cleanup(s, tmpPath)
  22. tests := []uint64{1, 2, 3, 5, 10}
  23. for i, tt := range tests {
  24. idx = indexVal(tt)
  25. s.Put([]byte("foo"), []byte("bar"))
  26. id := s.TxnBegin()
  27. g := s.consistentIndex()
  28. s.TxnEnd(id)
  29. if g != tt {
  30. t.Errorf("#%d: index = %d, want %d", i, g, tt)
  31. }
  32. }
  33. }
  34. func TestConsistentWatchableStoreSkip(t *testing.T) {
  35. idx := indexVal(5)
  36. s := newConsistentWatchableStore(tmpPath, &idx)
  37. defer cleanup(s, tmpPath)
  38. s.Put([]byte("foo"), []byte("bar"))
  39. // put is skipped
  40. rev := s.Put([]byte("foo"), []byte("bar"))
  41. if rev != 0 {
  42. t.Errorf("rev = %d, want 0", rev)
  43. }
  44. }