forked from basho/riak-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
yz_commands_i_test.go
237 lines (213 loc) · 6.66 KB
/
yz_commands_i_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright 2015-present Basho Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build integration
package riak
import (
"fmt"
"testing"
"time"
)
// FetchIndex
// StoreIndex
func TestStoreFetchAndDeleteAYokozunaIndex(t *testing.T) {
cluster := integrationTestsBuildCluster()
defer func() {
if err := cluster.Stop(); err != nil {
t.Error(err.Error())
}
}()
var err error
var cmd Command
indexName := "indexName"
sbuilder := NewStoreIndexCommandBuilder()
cmd, err = sbuilder.WithIndexName(indexName).WithTimeout(time.Second * 30).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if scmd, ok := cmd.(*StoreIndexCommand); ok {
if expected, actual := true, scmd.Response; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
} else {
t.FailNow()
}
fbuilder := NewFetchIndexCommandBuilder()
cmd, err = fbuilder.WithIndexName(indexName).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if fcmd, ok := cmd.(*FetchIndexCommand); ok {
if fcmd.Response == nil {
t.Errorf("expected non-nil Response")
}
idx := fcmd.Response[0]
if expected, actual := indexName, idx.Name; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
if expected, actual := "_yz_default", idx.Schema; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
if expected, actual := uint32(3), idx.NVal; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
} else {
t.FailNow()
}
dbuilder := NewDeleteIndexCommandBuilder()
cmd, err = dbuilder.WithIndexName(indexName).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if dcmd, ok := cmd.(*DeleteIndexCommand); ok {
if expected, actual := true, dcmd.Response; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
} else {
t.FailNow()
}
}
// FetchSchema
// StoreSchema
func TestStoreFetchAndDeleteAYokozunaSchema(t *testing.T) {
cluster := integrationTestsBuildCluster()
defer func() {
if err := cluster.Stop(); err != nil {
t.Error(err.Error())
}
}()
var err error
var cmd Command
defaultSchemaName := "_yz_default"
schemaName := "schemaName"
schemaXml := "dummy"
fbuilder := NewFetchSchemaCommandBuilder()
cmd, err = fbuilder.WithSchemaName(defaultSchemaName).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err)
}
fcmd := cmd.(*FetchSchemaCommand)
if fcmd.Response == nil {
t.Fatal("expected non-nil Response")
}
sch := fcmd.Response
if expected, actual := defaultSchemaName, sch.Name; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
schemaXml = sch.Content
sbuilder := NewStoreSchemaCommandBuilder()
cmd, err = sbuilder.WithSchemaName(schemaName).WithSchema(schemaXml).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if scmd, ok := cmd.(*StoreSchemaCommand); ok {
if expected, actual := true, scmd.Response; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
} else {
t.FailNow()
}
}
// Search
func TestSearchViaYokozunaIndex(t *testing.T) {
cluster := integrationTestsBuildCluster()
defer func() {
if err := cluster.Stop(); err != nil {
t.Error(err.Error())
}
}()
var err error
var cmd Command
indexName := "myIndex"
b1 := NewStoreIndexCommandBuilder()
cmd, err = b1.WithIndexName(indexName).WithTimeout(time.Second * 20).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if scmd, ok := cmd.(*StoreIndexCommand); ok {
if expected, actual := true, scmd.Response; expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
} else {
t.FailNow()
}
searchBucket := fmt.Sprintf("%s_search", testBucketName)
b2 := NewStoreBucketPropsCommandBuilder()
cmd, err = b2.WithBucket(searchBucket).WithSearchIndex(indexName).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
stuffToStore := [...]string{
"{ \"content_s\":\"Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'\"}",
"{ \"content_s\":\"So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.\", \"multi_ss\":[\"this\",\"that\"]}",
"{ \"content_s\":\"The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.\"}",
}
for _, s := range stuffToStore {
b3 := NewStoreValueCommandBuilder()
obj := &Object{
ContentType: "application/json", // NB: *very* important for extractor
Value: []byte(s),
}
cmd, err = b3.WithBucket(searchBucket).WithContent(obj).Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
}
for count := 0; count < 10; count++ {
time.Sleep(time.Millisecond * 500)
b4 := NewSearchCommandBuilder()
cmd, err = b4.WithIndexName(indexName).WithQuery("multi_ss:t*").Build()
if err != nil {
t.Fatal(err.Error())
}
if err = cluster.Execute(cmd); err != nil {
t.Fatal(err.Error())
}
if scmd, ok := cmd.(*SearchCommand); ok {
resp := scmd.Response
if expected, actual := 1, len(resp.Docs); expected != actual {
if count < 10 {
t.Logf("expected %v, got %v - RETRYING", expected, actual)
} else {
t.Errorf("expected %v, got %v - DONE", expected, actual)
}
}
} else {
t.FailNow()
}
}
}