-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsharded_index_test.go
49 lines (37 loc) · 1.13 KB
/
sharded_index_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package rupture
import (
"io/ioutil"
"os"
"testing"
"github.com/blevesearch/bleve/v2"
"github.com/stretchr/testify/assert"
)
func TestShardedIndex(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "test")
assert.NoError(t, err)
defer os.RemoveAll(dir)
newIndex, err := NewShardedIndex(dir, bleve.NewIndexMapping(), 3)
assert.NoError(t, err)
addVehicles(t, newIndex.Index)
_, err = newIndex.Document("7")
assert.NoError(t, err)
assert.NoError(t, newIndex.Close())
openedIndex, err := OpenShardedIndex(dir)
assert.NoError(t, err)
result, err := openedIndex.Search(vehicleSearchRequest())
assert.NoError(t, err)
assert.EqualValues(t, result.Total, 7)
}
func TestShardedIndexFlushingBatch(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "test")
assert.NoError(t, err)
defer os.RemoveAll(dir)
index, err := NewShardedIndex(dir, bleve.NewIndexMapping(), 3)
assert.NoError(t, err)
batch := NewShardedFlushingBatch(index, 3)
addVehicles(t, batch.Index)
assert.NoError(t, batch.Flush())
result, err := index.Search(vehicleSearchRequest())
assert.NoError(t, err)
assert.EqualValues(t, result.Total, 7)
}