This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bulk_test.go
79 lines (68 loc) · 1.74 KB
/
bulk_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package bucket
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/rs/xid"
)
func TestGetBulk(t *testing.T) {
const webshopStatus = "success"
for i := 0; i < 10; i++ {
ws := generate()
ws.Status = "success"
_, _, err := th.Insert(context.Background(), "webshop", xid.New().String(), ws, 0)
if err != nil {
t.Fatal(err)
}
}
waitUntilFtsIndexCompleted(context.Background(), "webshop_fts_index")
searchMatch := "success"
res, err := th.SimpleSearch(context.Background(), "webshop_fts_index", &SearchQuery{
Query: searchMatch,
})
if err != nil {
t.Fatal(err)
}
var ws = make([]webshop, len(res))
err = th.GetBulk(context.Background(), res, &ws)
if err != nil {
t.Error(err)
}
if len(ws) > 0 {
assert.Equal(t, webshopStatus, ws[0].Status)
assert.Equal(t, "Free shipping", ws[0].ShippingMethod)
assert.Equal(t, "active", ws[0].Product.Status)
assert.Equal(t, "productshop", ws[0].Store.Name)
} else {
t.Errorf("Empty resultset of the search")
}
}
func BenchmarkGetBulk(b *testing.B) {
b.StopTimer()
for i := 0; i < 10; i++ {
ws := generate()
_, _, err := th.Insert(context.Background(), "webshop", xid.New().String(), ws, 0)
//_, err := th.state.bucket.Insert("order::"+order.Token, order, 0)
if err != nil {
b.Fatal(err)
}
}
if err := createFullTextSearchIndex("webshop_fts_index", false, "webshop"); err != nil {
b.Fatal(err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
searchMatch := "processed"
res, err := th.SimpleSearch(context.Background(), "webshop_fts_idx", &SearchQuery{
Query: searchMatch,
})
if err != nil {
b.Fatal(err)
}
var ws = make([]webshop, len(res))
err = th.GetBulk(context.Background(), res, &ws)
if err != nil {
b.Error(err)
}
}
}