1 // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
10 . "github.com/onsi/ginkgo"
11 . "github.com/onsi/gomega"
13 "github.com/syndtr/goleveldb/leveldb/comparer"
14 . "github.com/syndtr/goleveldb/leveldb/iterator"
15 "github.com/syndtr/goleveldb/leveldb/testutil"
18 var _ = testutil.Defer(func() {
19 Describe("Merged iterator", func() {
20 Test := func(filled int, empty int) func() {
22 It("Should iterates and seeks correctly", func(done Done) {
23 rnd := testutil.NewRand()
26 filledKV := make([]testutil.KeyValue, filled)
27 kv := testutil.KeyValue_Generate(nil, 100, 1, 1, 10, 4, 4)
28 kv.Iterate(func(i int, key, value []byte) {
29 filledKV[rnd.Intn(filled)].Put(key, value)
33 iters := make([]Iterator, filled+empty)
34 for i := range iters {
35 if empty == 0 || (rnd.Int()%2 == 0 && filled > 0) {
37 Expect(filledKV[filled].Len()).ShouldNot(BeZero())
38 iters[i] = NewArrayIterator(filledKV[filled])
41 iters[i] = NewEmptyIterator(nil)
46 t := testutil.IteratorTesting{
48 Iter: NewMergedIterator(iters, comparer.DefaultComparer, true),
50 testutil.DoIteratorTesting(&t)
56 Describe("with three, all filled iterators", Test(3, 0))
57 Describe("with one filled, one empty iterators", Test(1, 1))
58 Describe("with one filled, two empty iterators", Test(1, 2))