kvstore_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 (
  16. "crypto/rand"
  17. "encoding/binary"
  18. "math"
  19. "os"
  20. "reflect"
  21. "testing"
  22. "time"
  23. "github.com/coreos/etcd/lease"
  24. "github.com/coreos/etcd/pkg/schedule"
  25. "github.com/coreos/etcd/pkg/testutil"
  26. "github.com/coreos/etcd/storage/backend"
  27. "github.com/coreos/etcd/storage/storagepb"
  28. )
  29. func TestStoreRev(t *testing.T) {
  30. b, tmpPath := backend.NewDefaultTmpBackend()
  31. s := NewStore(b, &lease.FakeLessor{})
  32. defer s.Close()
  33. defer os.Remove(tmpPath)
  34. for i := 1; i <= 3; i++ {
  35. s.Put([]byte("foo"), []byte("bar"), lease.NoLease)
  36. if r := s.Rev(); r != int64(i+1) {
  37. t.Errorf("#%d: rev = %d, want %d", i, r, i+1)
  38. }
  39. }
  40. }
  41. func TestStorePut(t *testing.T) {
  42. tests := []struct {
  43. rev revision
  44. r indexGetResp
  45. wrev revision
  46. wkey []byte
  47. wkv storagepb.KeyValue
  48. wputrev revision
  49. }{
  50. {
  51. revision{1, 0},
  52. indexGetResp{revision{}, revision{}, 0, ErrRevisionNotFound},
  53. revision{1, 1},
  54. newTestKeyBytes(revision{2, 0}, false),
  55. storagepb.KeyValue{
  56. Key: []byte("foo"),
  57. Value: []byte("bar"),
  58. CreateRevision: 2,
  59. ModRevision: 2,
  60. Version: 1,
  61. Lease: 1,
  62. },
  63. revision{2, 0},
  64. },
  65. {
  66. revision{1, 1},
  67. indexGetResp{revision{2, 0}, revision{2, 0}, 1, nil},
  68. revision{1, 2},
  69. newTestKeyBytes(revision{2, 1}, false),
  70. storagepb.KeyValue{
  71. Key: []byte("foo"),
  72. Value: []byte("bar"),
  73. CreateRevision: 2,
  74. ModRevision: 2,
  75. Version: 2,
  76. Lease: 2,
  77. },
  78. revision{2, 1},
  79. },
  80. {
  81. revision{2, 0},
  82. indexGetResp{revision{2, 1}, revision{2, 0}, 2, nil},
  83. revision{2, 1},
  84. newTestKeyBytes(revision{3, 0}, false),
  85. storagepb.KeyValue{
  86. Key: []byte("foo"),
  87. Value: []byte("bar"),
  88. CreateRevision: 2,
  89. ModRevision: 3,
  90. Version: 3,
  91. Lease: 3,
  92. },
  93. revision{3, 0},
  94. },
  95. }
  96. for i, tt := range tests {
  97. s := newFakeStore()
  98. b := s.b.(*fakeBackend)
  99. fi := s.kvindex.(*fakeIndex)
  100. s.currentRev = tt.rev
  101. s.tx = b.BatchTx()
  102. fi.indexGetRespc <- tt.r
  103. s.put([]byte("foo"), []byte("bar"), lease.LeaseID(i+1))
  104. data, err := tt.wkv.Marshal()
  105. if err != nil {
  106. t.Errorf("#%d: marshal err = %v, want nil", i, err)
  107. }
  108. wact := []testutil.Action{
  109. {"put", []interface{}{keyBucketName, tt.wkey, data}},
  110. }
  111. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  112. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  113. }
  114. wact = []testutil.Action{
  115. {"get", []interface{}{[]byte("foo"), tt.wputrev.main}},
  116. {"put", []interface{}{[]byte("foo"), tt.wputrev}},
  117. }
  118. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  119. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  120. }
  121. if s.currentRev != tt.wrev {
  122. t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
  123. }
  124. s.Close()
  125. }
  126. }
  127. func TestStoreRange(t *testing.T) {
  128. key := newTestKeyBytes(revision{2, 0}, false)
  129. kv := storagepb.KeyValue{
  130. Key: []byte("foo"),
  131. Value: []byte("bar"),
  132. CreateRevision: 1,
  133. ModRevision: 2,
  134. Version: 1,
  135. }
  136. kvb, err := kv.Marshal()
  137. if err != nil {
  138. t.Fatal(err)
  139. }
  140. currev := revision{1, 1}
  141. wrev := int64(2)
  142. tests := []struct {
  143. idxr indexRangeResp
  144. r rangeResp
  145. }{
  146. {
  147. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  148. rangeResp{[][]byte{key}, [][]byte{kvb}},
  149. },
  150. {
  151. indexRangeResp{[][]byte{[]byte("foo"), []byte("foo1")}, []revision{{2, 0}, {3, 0}}},
  152. rangeResp{[][]byte{key}, [][]byte{kvb}},
  153. },
  154. }
  155. for i, tt := range tests {
  156. s := newFakeStore()
  157. b := s.b.(*fakeBackend)
  158. fi := s.kvindex.(*fakeIndex)
  159. s.currentRev = currev
  160. s.tx = b.BatchTx()
  161. b.tx.rangeRespc <- tt.r
  162. fi.indexRangeRespc <- tt.idxr
  163. kvs, rev, err := s.rangeKeys([]byte("foo"), []byte("goo"), 1, 0)
  164. if err != nil {
  165. t.Errorf("#%d: err = %v, want nil", i, err)
  166. }
  167. if w := []storagepb.KeyValue{kv}; !reflect.DeepEqual(kvs, w) {
  168. t.Errorf("#%d: kvs = %+v, want %+v", i, kvs, w)
  169. }
  170. if rev != wrev {
  171. t.Errorf("#%d: rev = %d, want %d", i, rev, wrev)
  172. }
  173. wstart, wend := revBytesRange(tt.idxr.revs[0])
  174. wact := []testutil.Action{
  175. {"range", []interface{}{keyBucketName, wstart, wend, int64(0)}},
  176. }
  177. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  178. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  179. }
  180. wact = []testutil.Action{
  181. {"range", []interface{}{[]byte("foo"), []byte("goo"), wrev}},
  182. }
  183. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  184. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  185. }
  186. if s.currentRev != currev {
  187. t.Errorf("#%d: current rev = %+v, want %+v", i, s.currentRev, currev)
  188. }
  189. s.Close()
  190. }
  191. }
  192. func TestStoreDeleteRange(t *testing.T) {
  193. tests := []struct {
  194. rev revision
  195. r indexRangeResp
  196. wkey []byte
  197. wrev revision
  198. wrrev int64
  199. wdelrev revision
  200. }{
  201. {
  202. revision{2, 0},
  203. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  204. newTestKeyBytes(revision{3, 0}, true),
  205. revision{2, 1},
  206. 2,
  207. revision{3, 0},
  208. },
  209. {
  210. revision{2, 1},
  211. indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
  212. newTestKeyBytes(revision{3, 1}, true),
  213. revision{2, 2},
  214. 3,
  215. revision{3, 1},
  216. },
  217. }
  218. for i, tt := range tests {
  219. s := newFakeStore()
  220. b := s.b.(*fakeBackend)
  221. fi := s.kvindex.(*fakeIndex)
  222. s.currentRev = tt.rev
  223. s.tx = b.BatchTx()
  224. fi.indexRangeRespc <- tt.r
  225. n := s.deleteRange([]byte("foo"), []byte("goo"))
  226. if n != 1 {
  227. t.Errorf("#%d: n = %d, want 1", i, n)
  228. }
  229. data, err := (&storagepb.KeyValue{
  230. Key: []byte("foo"),
  231. }).Marshal()
  232. if err != nil {
  233. t.Errorf("#%d: marshal err = %v, want nil", i, err)
  234. }
  235. wact := []testutil.Action{
  236. {"put", []interface{}{keyBucketName, tt.wkey, data}},
  237. }
  238. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  239. t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
  240. }
  241. wact = []testutil.Action{
  242. {"range", []interface{}{[]byte("foo"), []byte("goo"), tt.wrrev}},
  243. {"tombstone", []interface{}{[]byte("foo"), tt.wdelrev}},
  244. }
  245. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  246. t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
  247. }
  248. if s.currentRev != tt.wrev {
  249. t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
  250. }
  251. }
  252. }
  253. func TestStoreCompact(t *testing.T) {
  254. s := newFakeStore()
  255. defer s.Close()
  256. b := s.b.(*fakeBackend)
  257. fi := s.kvindex.(*fakeIndex)
  258. s.currentRev = revision{3, 0}
  259. fi.indexCompactRespc <- map[revision]struct{}{revision{1, 0}: {}}
  260. key1 := newTestKeyBytes(revision{1, 0}, false)
  261. key2 := newTestKeyBytes(revision{2, 0}, false)
  262. b.tx.rangeRespc <- rangeResp{[][]byte{key1, key2}, nil}
  263. s.Compact(3)
  264. s.fifoSched.WaitFinish()
  265. if s.compactMainRev != 3 {
  266. t.Errorf("compact main rev = %d, want 3", s.compactMainRev)
  267. }
  268. end := make([]byte, 8)
  269. binary.BigEndian.PutUint64(end, uint64(4))
  270. wact := []testutil.Action{
  271. {"put", []interface{}{metaBucketName, scheduledCompactKeyName, newTestRevBytes(revision{3, 0})}},
  272. {"range", []interface{}{keyBucketName, make([]byte, 17), end, int64(10000)}},
  273. {"delete", []interface{}{keyBucketName, key2}},
  274. {"put", []interface{}{metaBucketName, finishedCompactKeyName, newTestRevBytes(revision{3, 0})}},
  275. }
  276. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  277. t.Errorf("tx actions = %+v, want %+v", g, wact)
  278. }
  279. wact = []testutil.Action{
  280. {"compact", []interface{}{int64(3)}},
  281. }
  282. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  283. t.Errorf("index action = %+v, want %+v", g, wact)
  284. }
  285. }
  286. func TestStoreRestore(t *testing.T) {
  287. s := newFakeStore()
  288. b := s.b.(*fakeBackend)
  289. fi := s.kvindex.(*fakeIndex)
  290. putkey := newTestKeyBytes(revision{3, 0}, false)
  291. putkv := storagepb.KeyValue{
  292. Key: []byte("foo"),
  293. Value: []byte("bar"),
  294. CreateRevision: 4,
  295. ModRevision: 4,
  296. Version: 1,
  297. }
  298. putkvb, err := putkv.Marshal()
  299. if err != nil {
  300. t.Fatal(err)
  301. }
  302. delkey := newTestKeyBytes(revision{5, 0}, true)
  303. delkv := storagepb.KeyValue{
  304. Key: []byte("foo"),
  305. }
  306. delkvb, err := delkv.Marshal()
  307. if err != nil {
  308. t.Fatal(err)
  309. }
  310. b.tx.rangeRespc <- rangeResp{[][]byte{finishedCompactKeyName}, [][]byte{newTestRevBytes(revision{3, 0})}}
  311. b.tx.rangeRespc <- rangeResp{[][]byte{putkey, delkey}, [][]byte{putkvb, delkvb}}
  312. b.tx.rangeRespc <- rangeResp{[][]byte{scheduledCompactKeyName}, [][]byte{newTestRevBytes(revision{3, 0})}}
  313. s.restore()
  314. if s.compactMainRev != 3 {
  315. t.Errorf("compact rev = %d, want 5", s.compactMainRev)
  316. }
  317. wrev := revision{5, 0}
  318. if !reflect.DeepEqual(s.currentRev, wrev) {
  319. t.Errorf("current rev = %v, want %v", s.currentRev, wrev)
  320. }
  321. wact := []testutil.Action{
  322. {"range", []interface{}{metaBucketName, finishedCompactKeyName, []byte(nil), int64(0)}},
  323. {"range", []interface{}{keyBucketName, newTestRevBytes(revision{1, 0}), newTestRevBytes(revision{math.MaxInt64, math.MaxInt64}), int64(0)}},
  324. {"range", []interface{}{metaBucketName, scheduledCompactKeyName, []byte(nil), int64(0)}},
  325. }
  326. if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
  327. t.Errorf("tx actions = %+v, want %+v", g, wact)
  328. }
  329. wact = []testutil.Action{
  330. {"restore", []interface{}{[]byte("foo"), revision{4, 0}, revision{3, 0}, int64(1)}},
  331. {"tombstone", []interface{}{[]byte("foo"), revision{5, 0}}},
  332. }
  333. if g := fi.Action(); !reflect.DeepEqual(g, wact) {
  334. t.Errorf("index action = %+v, want %+v", g, wact)
  335. }
  336. }
  337. func TestRestoreContinueUnfinishedCompaction(t *testing.T) {
  338. b, tmpPath := backend.NewDefaultTmpBackend()
  339. s0 := NewStore(b, &lease.FakeLessor{})
  340. defer os.Remove(tmpPath)
  341. s0.Put([]byte("foo"), []byte("bar"), lease.NoLease)
  342. s0.Put([]byte("foo"), []byte("bar1"), lease.NoLease)
  343. s0.Put([]byte("foo"), []byte("bar2"), lease.NoLease)
  344. // write scheduled compaction, but not do compaction
  345. rbytes := newRevBytes()
  346. revToBytes(revision{main: 2}, rbytes)
  347. tx := s0.b.BatchTx()
  348. tx.Lock()
  349. tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes)
  350. tx.Unlock()
  351. s0.Close()
  352. s1 := NewStore(b, &lease.FakeLessor{})
  353. // wait for scheduled compaction to be finished
  354. time.Sleep(100 * time.Millisecond)
  355. if _, _, err := s1.Range([]byte("foo"), nil, 0, 2); err != ErrCompacted {
  356. t.Errorf("range on compacted rev error = %v, want %v", err, ErrCompacted)
  357. }
  358. // check the key in backend is deleted
  359. revbytes := newRevBytes()
  360. // TODO: compact should delete main=2 key too
  361. revToBytes(revision{main: 1}, revbytes)
  362. // The disk compaction is done asynchronously and requires more time on slow disk.
  363. // try 5 times for CI with slow IO.
  364. for i := 0; i < 5; i++ {
  365. tx = s1.b.BatchTx()
  366. tx.Lock()
  367. ks, _ := tx.UnsafeRange(keyBucketName, revbytes, nil, 0)
  368. tx.Unlock()
  369. if len(ks) != 0 {
  370. time.Sleep(100 * time.Millisecond)
  371. continue
  372. }
  373. return
  374. }
  375. t.Errorf("key for rev %+v still exists, want deleted", bytesToRev(revbytes))
  376. }
  377. func TestTxnPut(t *testing.T) {
  378. // assign arbitrary size
  379. bytesN := 30
  380. sliceN := 100
  381. keys := createBytesSlice(bytesN, sliceN)
  382. vals := createBytesSlice(bytesN, sliceN)
  383. b, tmpPath := backend.NewDefaultTmpBackend()
  384. s := NewStore(b, &lease.FakeLessor{})
  385. defer cleanup(s, b, tmpPath)
  386. for i := 0; i < sliceN; i++ {
  387. id := s.TxnBegin()
  388. base := int64(i + 2)
  389. rev, err := s.TxnPut(id, keys[i], vals[i], lease.NoLease)
  390. if err != nil {
  391. t.Error("txn put error")
  392. }
  393. if rev != base {
  394. t.Errorf("#%d: rev = %d, want %d", i, rev, base)
  395. }
  396. s.TxnEnd(id)
  397. }
  398. }
  399. func TestTxnBlockBackendForceCommit(t *testing.T) {
  400. b, tmpPath := backend.NewDefaultTmpBackend()
  401. s := NewStore(b, &lease.FakeLessor{})
  402. defer os.Remove(tmpPath)
  403. id := s.TxnBegin()
  404. done := make(chan struct{})
  405. go func() {
  406. s.b.ForceCommit()
  407. done <- struct{}{}
  408. }()
  409. select {
  410. case <-done:
  411. t.Fatalf("failed to block ForceCommit")
  412. case <-time.After(100 * time.Millisecond):
  413. }
  414. s.TxnEnd(id)
  415. select {
  416. case <-done:
  417. case <-time.After(5 * time.Second): // wait 5 seconds for CI with slow IO
  418. testutil.FatalStack(t, "failed to execute ForceCommit")
  419. }
  420. }
  421. // TODO: test attach key to lessor
  422. func newTestRevBytes(rev revision) []byte {
  423. bytes := newRevBytes()
  424. revToBytes(rev, bytes)
  425. return bytes
  426. }
  427. func newTestKeyBytes(rev revision, tombstone bool) []byte {
  428. bytes := newRevBytes()
  429. revToBytes(rev, bytes)
  430. if tombstone {
  431. bytes = appendMarkTombstone(bytes)
  432. }
  433. return bytes
  434. }
  435. func newFakeStore() *store {
  436. b := &fakeBackend{&fakeBatchTx{
  437. Recorder: &testutil.RecorderBuffered{},
  438. rangeRespc: make(chan rangeResp, 5)}}
  439. fi := &fakeIndex{
  440. Recorder: &testutil.RecorderBuffered{},
  441. indexGetRespc: make(chan indexGetResp, 1),
  442. indexRangeRespc: make(chan indexRangeResp, 1),
  443. indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
  444. indexCompactRespc: make(chan map[revision]struct{}, 1),
  445. }
  446. return &store{
  447. b: b,
  448. le: &lease.FakeLessor{},
  449. kvindex: fi,
  450. currentRev: revision{},
  451. compactMainRev: -1,
  452. fifoSched: schedule.NewFIFOScheduler(),
  453. stopc: make(chan struct{}),
  454. }
  455. }
  456. type rangeResp struct {
  457. keys [][]byte
  458. vals [][]byte
  459. }
  460. type fakeBatchTx struct {
  461. testutil.Recorder
  462. rangeRespc chan rangeResp
  463. }
  464. func (b *fakeBatchTx) Lock() {}
  465. func (b *fakeBatchTx) Unlock() {}
  466. func (b *fakeBatchTx) UnsafeCreateBucket(name []byte) {}
  467. func (b *fakeBatchTx) UnsafePut(bucketName []byte, key []byte, value []byte) {
  468. b.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{bucketName, key, value}})
  469. }
  470. func (b *fakeBatchTx) UnsafeRange(bucketName []byte, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) {
  471. b.Recorder.Record(testutil.Action{Name: "range", Params: []interface{}{bucketName, key, endKey, limit}})
  472. r := <-b.rangeRespc
  473. return r.keys, r.vals
  474. }
  475. func (b *fakeBatchTx) UnsafeDelete(bucketName []byte, key []byte) {
  476. b.Recorder.Record(testutil.Action{Name: "delete", Params: []interface{}{bucketName, key}})
  477. }
  478. func (b *fakeBatchTx) Commit() {}
  479. func (b *fakeBatchTx) CommitAndStop() {}
  480. type fakeBackend struct {
  481. tx *fakeBatchTx
  482. }
  483. func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
  484. func (b *fakeBackend) Hash() (uint32, error) { return 0, nil }
  485. func (b *fakeBackend) Size() int64 { return 0 }
  486. func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
  487. func (b *fakeBackend) ForceCommit() {}
  488. func (b *fakeBackend) Close() error { return nil }
  489. type indexGetResp struct {
  490. rev revision
  491. created revision
  492. ver int64
  493. err error
  494. }
  495. type indexRangeResp struct {
  496. keys [][]byte
  497. revs []revision
  498. }
  499. type indexRangeEventsResp struct {
  500. revs []revision
  501. }
  502. type fakeIndex struct {
  503. testutil.Recorder
  504. indexGetRespc chan indexGetResp
  505. indexRangeRespc chan indexRangeResp
  506. indexRangeEventsRespc chan indexRangeEventsResp
  507. indexCompactRespc chan map[revision]struct{}
  508. }
  509. func (i *fakeIndex) Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) {
  510. i.Recorder.Record(testutil.Action{Name: "get", Params: []interface{}{key, atRev}})
  511. r := <-i.indexGetRespc
  512. return r.rev, r.created, r.ver, r.err
  513. }
  514. func (i *fakeIndex) Range(key, end []byte, atRev int64) ([][]byte, []revision) {
  515. i.Recorder.Record(testutil.Action{Name: "range", Params: []interface{}{key, end, atRev}})
  516. r := <-i.indexRangeRespc
  517. return r.keys, r.revs
  518. }
  519. func (i *fakeIndex) Put(key []byte, rev revision) {
  520. i.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{key, rev}})
  521. }
  522. func (i *fakeIndex) Restore(key []byte, created, modified revision, ver int64) {
  523. i.Recorder.Record(testutil.Action{Name: "restore", Params: []interface{}{key, created, modified, ver}})
  524. }
  525. func (i *fakeIndex) Tombstone(key []byte, rev revision) error {
  526. i.Recorder.Record(testutil.Action{Name: "tombstone", Params: []interface{}{key, rev}})
  527. return nil
  528. }
  529. func (i *fakeIndex) RangeSince(key, end []byte, rev int64) []revision {
  530. i.Recorder.Record(testutil.Action{Name: "rangeEvents", Params: []interface{}{key, end, rev}})
  531. r := <-i.indexRangeEventsRespc
  532. return r.revs
  533. }
  534. func (i *fakeIndex) Compact(rev int64) map[revision]struct{} {
  535. i.Recorder.Record(testutil.Action{Name: "compact", Params: []interface{}{rev}})
  536. return <-i.indexCompactRespc
  537. }
  538. func (i *fakeIndex) Equal(b index) bool { return false }
  539. func createBytesSlice(bytesN, sliceN int) [][]byte {
  540. rs := [][]byte{}
  541. for len(rs) != sliceN {
  542. v := make([]byte, bytesN)
  543. if _, err := rand.Read(v); err != nil {
  544. panic(err)
  545. }
  546. rs = append(rs, v)
  547. }
  548. return rs
  549. }