/
common_test.go
1372 lines (1166 loc) · 49.4 KB
/
common_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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package functionaltests
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log" //"os"
"math/rand"
"net/http"
"os"
"os/user"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
"github.com/couchbase/cbauth"
c "github.com/couchbase/indexing/secondary/common"
json "github.com/couchbase/indexing/secondary/common/json"
"github.com/couchbase/indexing/secondary/logging"
qc "github.com/couchbase/indexing/secondary/queryport/client"
tc "github.com/couchbase/indexing/secondary/tests/framework/common"
"github.com/couchbase/indexing/secondary/tests/framework/datautility"
"github.com/couchbase/indexing/secondary/tests/framework/kvutility"
"github.com/couchbase/indexing/secondary/tests/framework/secondaryindex"
tv "github.com/couchbase/indexing/secondary/tests/framework/validation"
parsec "github.com/prataprc/goparsec"
"github.com/prataprc/monster"
"github.com/prataprc/monster/common"
)
///////////////////////////////////////////////////////////////////////////////
// common_test holds vars and funcs that are used by more than one test set, to
// avoid creating build dependencies between test sets, which enables running a
// single set in isolation by moving the other sets to a DISABLED/ directory.
///////////////////////////////////////////////////////////////////////////////
var docs, mut_docs tc.KeyValues
var defaultlimit int64 = 100000000000
var kvaddress, indexManagementAddress, indexScanAddress string
var clusterconfig tc.ClusterConfiguration
var dataFilePath, mutationFilePath string
var defaultIndexActiveTimeout int64 = 600 // 10 mins to wait for index to become active
var skipsetup bool
var indexerLogLevel string
var bucketOpWaitDur = time.Duration(15)
var seed int
var proddir, bagdir string
var reqscans = map[string]interface{}{
"scans": `[{"Seek":null,"Filter":[{"Low":"D","High":"F","Inclusion":3},{"Low":"A","High":"C","Inclusion":3}]},{"Seek":null,"Filter":[{"Low":"S","High":"V","Inclusion":3},{"Low":"A","High":"C","Inclusion":3}]}]`,
"projection": `{"EntryKeys":[0],"PrimaryKey":false}`,
"distinct": false,
"limit": 1000000,
"reverse": false,
"offset": int64(0),
"stale": "ok",
}
var reqscanscount = map[string]interface{}{
"scans": `[{"Seek":null,"Filter":[{"Low":"D","High":"F","Inclusion":3},{"Low":"A","High":"C","Inclusion":3}]},{"Seek":null,"Filter":[{"Low":"S","High":"V","Inclusion":3},{"Low":"A","High":"C","Inclusion":3}]}]`,
"projection": `{"EntryKeys":[0],"PrimaryKey":false}`,
"distinct": false,
"limit": 1000000,
"reverse": false,
"offset": int64(0),
"stale": "ok",
}
func TestMain(m *testing.M) {
log.Printf("In TestMain()")
logging.SetLogLevel(logging.Error)
var configpath string
flag.StringVar(&configpath, "cbconfig", "../config/clusterrun_conf.json", "Path of the configuration file with data about Couchbase Cluster")
flag.StringVar(&secondaryindex.UseClient, "useclient", "gsi", "Client to be used for tests. Values can be gsi or n1ql")
flag.BoolVar(&skipsetup, "skipsetup", false, "Skip setup steps like flush and drop all indexes")
flag.StringVar(&indexerLogLevel, "loglevel", "info", "indexer.settings.log_level. info / debug")
flag.Parse()
clusterconfig = tc.GetClusterConfFromFile(configpath)
kvaddress = clusterconfig.KVAddress
indexManagementAddress = clusterconfig.KVAddress
indexScanAddress = clusterconfig.KVAddress
seed = 1
proddir, bagdir = tc.FetchMonsterToolPath()
// setup cbauth
if _, err := cbauth.InternalRetryDefaultInit(kvaddress, clusterconfig.Username, clusterconfig.Password); err != nil {
log.Fatalf("Failed to initialize cbauth: %s", err)
}
//Disable backfill
err := secondaryindex.ChangeIndexerSettings("queryport.client.settings.backfillLimit", float64(0), clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
//Enable QE Rest server
err = secondaryindex.ChangeIndexerSettings("indexer.api.enableTestServer", true, clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
err = secondaryindex.ChangeIndexerSettings("indexer.settings.persisted_snapshot_init_build.moi.interval", float64(60000), clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
err = secondaryindex.ChangeIndexerSettings("indexer.settings.persisted_snapshot.moi.interval", float64(60000), clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
err = secondaryindex.ChangeIndexerSettings("indexer.settings.log_level", indexerLogLevel, clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
err = secondaryindex.ChangeIndexerSettings("indexer.settings.storage_mode.disable_upgrade", true, clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in change setting for indexer.settings.storage_mode.disable_upgrade")
if clusterconfig.IndexUsing != "" {
// Set clusterconfig.IndexUsing only if it is specified in config file. Else let it default to gsi
log.Printf("Using %v for creating indexes", clusterconfig.IndexUsing)
secondaryindex.IndexUsing = clusterconfig.IndexUsing
err := secondaryindex.ChangeIndexerSettings("indexer.settings.storage_mode", secondaryindex.IndexUsing, clusterconfig.Username, clusterconfig.Password, kvaddress)
tc.HandleError(err, "Error in ChangeIndexerSettings")
}
time.Sleep(5 * time.Second)
secondaryindex.CheckCollation = true
// Working with Users10k and Users_mut dataset.
u, _ := user.Current()
dataFilePath = filepath.Join(u.HomeDir, "testdata/Users10k.txt.gz")
mutationFilePath = filepath.Join(u.HomeDir, "testdata/Users_mut.txt.gz")
tc.DownloadDataFile(tc.IndexTypesStaticJSONDataS3, dataFilePath, true)
tc.DownloadDataFile(tc.IndexTypesMutationJSONDataS3, mutationFilePath, true)
docs = datautility.LoadJSONFromCompressedFile(dataFilePath, "docid")
mut_docs = datautility.LoadJSONFromCompressedFile(mutationFilePath, "docid")
if !skipsetup {
e := secondaryindex.DropAllSecondaryIndexes(indexManagementAddress)
tc.HandleError(e, "Error in DropAllSecondaryIndexes")
log.Printf("Emptying the default bucket")
kvutility.EnableBucketFlush("default", "", clusterconfig.Username, clusterconfig.Password, kvaddress)
kvutility.FlushBucket("default", "", clusterconfig.Username, clusterconfig.Password, kvaddress)
log.Printf("Create Index On the empty default Bucket()")
var indexName = "index_eyeColor"
var bucketName = "default"
err = secondaryindex.CreateSecondaryIndex(indexName, bucketName, indexManagementAddress, "", []string{"eyeColor"}, false, nil, true, defaultIndexActiveTimeout, nil)
tc.HandleError(err, "Error in creating the index")
// Populate the bucket now
log.Printf("Populating the default bucket")
kvutility.SetKeyValues(docs, "default", "", clusterconfig.KVAddress)
}
os.Exit(m.Run())
}
func FailTestIfError(err error, msg string, t *testing.T) {
if err != nil {
t.Fatalf("%v: %v\n", msg, err)
}
}
func FailTestIfNoError(err error, msg string, t *testing.T) {
if err == nil {
t.Fatalf("%v: %v\n", msg, err)
}
}
func addDocIfNotPresentInKV(docKey string) {
if _, present := docs[docKey]; present == false {
keysToBeSet := make(tc.KeyValues)
keysToBeSet[docKey] = mut_docs[docKey]
kvutility.SetKeyValues(keysToBeSet, "default", "", clusterconfig.KVAddress)
// Update docs object with newly added keys and remove those keys from mut_docs
docs[docKey] = mut_docs[docKey]
delete(mut_docs, docKey)
}
}
var options struct {
bagdir string
outfile string
nonterm string
seed int
count int
help bool
debug bool
}
func GenerateJsons(count, seed int, prodfile, bagdir string) tc.KeyValues {
runtime.GOMAXPROCS(50)
keyValues := make(tc.KeyValues)
options.outfile = "./out.txt"
options.bagdir = bagdir
options.count = count
options.seed = seed
var err error
// read production-file
text, err := ioutil.ReadFile(prodfile)
if err != nil {
log.Fatal(err)
}
// compile
scope := compile(parsec.NewScanner(text)).(common.Scope)
scope = monster.BuildContext(scope, uint64(seed), bagdir, prodfile)
nterms := scope["_nonterminals"].(common.NTForms)
// evaluate
for i := 0; i < options.count; i++ {
scope = scope.RebuildContext()
val := evaluate("root", scope, nterms["s"])
jsonString := val.(string)
byt := []byte(jsonString)
var dat map[string]interface{}
if err := json.Unmarshal(byt, &dat); err != nil {
panic(err)
}
dockey := dat["docid"].(string)
keyValues[dockey] = dat
}
return keyValues
}
func GenerateBinaryDocs(numDocs int, bucketName, bucketPassword, hostaddress, serverUsername, serverPassword string) tc.KeyValues {
docsToCreate := generateDocs(numDocs, "users.prod")
kvutility.SetBinaryValues(docsToCreate, bucketName, bucketPassword, hostaddress)
return docsToCreate
}
func GenerateBinaryDocsWithXATTRS(numDocs int, bucketName, bucketPassword, hostaddress, serverUsername, serverPassword string) tc.KeyValues {
docsToCreate := generateDocs(numDocs, "users.prod")
kvutility.SetBinaryValuesWithXattrs(docsToCreate, bucketName, bucketPassword, hostaddress, serverUsername, serverPassword)
return docsToCreate
}
func compile(s parsec.Scanner) parsec.ParsecNode {
defer func() {
if r := recover(); r != nil {
log.Printf("%v at %v", r, s.GetCursor())
}
}()
root, _ := monster.Y(s)
return root
}
func evaluate(name string, scope common.Scope, forms []*common.Form) interface{} {
defer func() {
if r := recover(); r != nil {
log.Printf("%v", r)
}
}()
return monster.EvalForms(name, scope, forms)
}
func generateDocs(numDocs int, prodFileName string) tc.KeyValues {
seed++
prodfile := filepath.Join(proddir, prodFileName)
docsToCreate := GenerateJsons(numDocs, seed, prodfile, bagdir)
return docsToCreate
}
// Copy newDocs to docs
func UpdateKVDocs(newDocs, docs tc.KeyValues) {
for k, v := range newDocs {
docs[k] = v
}
}
func CreateDocs(num int) {
i := 0
keysToBeSet := make(tc.KeyValues)
for key, value := range mut_docs {
keysToBeSet[key] = value
i++
if i == num {
break
}
}
kvutility.SetKeyValues(keysToBeSet, "default", "", clusterconfig.KVAddress)
// Update docs object with newly added keys and remove those keys from mut_docs
for key, value := range keysToBeSet {
docs[key] = value
delete(mut_docs, key)
}
}
func DeleteDocs(num int) {
i := 0
keysToBeDeleted := make(tc.KeyValues)
for key, value := range docs {
keysToBeDeleted[key] = value
i++
if i == num {
break
}
}
kvutility.DeleteKeys(keysToBeDeleted, "default", "", clusterconfig.KVAddress)
// Update docs object with deleted keys and add those keys from mut_docs
for key, value := range keysToBeDeleted {
delete(docs, key)
mut_docs[key] = value
}
}
// delete docs and do not update mut_docs object
func DeleteDocs2(num int) {
i := 0
keysToBeDeleted := make(tc.KeyValues)
for key, value := range docs {
keysToBeDeleted[key] = value
i++
if i == num {
break
}
}
kvutility.DeleteKeys(keysToBeDeleted, "default", "", clusterconfig.KVAddress)
// Update docs object with deleted keys
for key, _ := range keysToBeDeleted {
delete(docs, key)
}
}
func UpdateDocs(num int) {
i := 0
// Pick some docs from mut_docs
keysFromMutDocs := make(tc.KeyValues)
for key, value := range mut_docs {
keysFromMutDocs[key] = value
i++
if i == num {
break
}
}
// and , Add them to docs
keysToBeSet := make(tc.KeyValues)
for _, value := range keysFromMutDocs {
n := randomNum(0, float64(len(docs)-1))
i = 0
var k string
for k, _ = range docs {
if i == n {
break
}
i++
}
docs[k] = value
keysToBeSet[k] = value
}
log.Printf("Num of keysFromMutDocs: %d", len(keysFromMutDocs))
log.Printf("Updating number of documents: %d", len(keysToBeSet))
kvutility.SetKeyValues(keysToBeSet, "default", "", clusterconfig.KVAddress)
}
func randomNum(min, max float64) int {
rand.Seed(time.Now().UnixNano())
return int(rand.Float64()*(max-min) + min)
}
func randString(n int) string {
chars := []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,#")
rand.Seed(time.Now().UnixNano())
b := make([]rune, n)
for i := range b {
b[i] = chars[rand.Intn(len(chars))]
}
return string(b)
}
func randSpecialString(n int) string {
chars := []rune("0123vwxyz€ƒ†Š™š£§©®¶µß,#")
rand.Seed(time.Now().UnixNano())
b := make([]rune, n)
for i := range b {
b[i] = chars[rand.Intn(len(chars))]
}
return string(b)
}
func randomBool() bool {
rand.Seed(time.Now().UnixNano())
switch randomNum(0, 2) {
case 0:
return false
case 1:
return true
}
return true
}
func random_char() string {
chars := []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
return string(chars[rand.Intn(len(chars))])
}
func verifyDeletedPath(Pth string) error {
var err error
_, errStat := os.Stat(Pth)
if errStat == nil {
err = errors.New("os.Stat was successful for deleted directory")
return err
}
if !os.IsNotExist(errStat) {
errMsg := fmt.Sprintf("errStat = %v", errStat)
err = errors.New("Directory may exists even if it was expected to be deleted." + errMsg)
return err
}
return nil
}
func verifyPathExists(Pth string) (bool, error) {
_, errStat := os.Stat(Pth)
if errStat == nil {
return true, nil
}
if os.IsNotExist(errStat) {
return false, nil
}
return false, errStat
}
func forceKillMemcacheD() {
// restart mcd process
fmt.Println("Restarting memcached process ...")
tc.KillMemcacheD()
time.Sleep(20 * time.Second)
}
func forceKillIndexer() {
// restart the indexer
fmt.Println("Restarting indexer process ...")
tc.KillIndexer()
time.Sleep(20 * time.Second)
}
func restful_clonebody(src map[string]interface{}) map[string]interface{} {
dst := make(map[string]interface{})
for k, v := range src {
dst[k] = v
}
return dst
}
func restful_getall() (map[string]interface{}, error) {
url, err := makeurl("/internal/indexes")
if err != nil {
return nil, err
}
log.Printf("GET all indexes\n")
resp, err := http.Get(url)
if err != nil {
return nil, err
}
log.Printf("%v\n", resp.Status)
if restful_checkstatus(resp.Status) == true {
return nil, fmt.Errorf("restful_getall() status: %v", resp.Status)
}
indexes := make(map[string]interface{}, 0)
respbody, _ := ioutil.ReadAll(resp.Body)
if len(respbody) == 0 {
return nil, nil
}
err = json.Unmarshal(respbody, &indexes)
if err != nil {
return nil, err
}
return indexes, nil
}
func getscans(id string, body map[string]interface{}) ([]interface{}, error) {
url, err := makeurl(fmt.Sprintf("/internal/index/%v?multiscan=true", id))
if err != nil {
return nil, err
}
data, _ := json.Marshal(body)
req, err := http.NewRequest("GET", url, bytes.NewBuffer(data))
if err != nil {
return nil, err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
log.Printf("getscans status : %v\n", resp.Status)
dec := json.NewDecoder(resp.Body)
entries := make([]interface{}, 0)
for {
var result interface{}
if err := dec.Decode(&result); err != nil && err != io.EOF {
return nil, err
} else if result == nil {
break
}
switch resval := result.(type) {
case []interface{}:
// log.Printf("GOT CHUNK: %v\n", len(resval))
entries = append(entries, resval...)
default:
err := fmt.Errorf("ERROR CHUNK: %v\n", result)
return nil, err
}
}
return entries, nil
}
func getscanscount(id string, body map[string]interface{}) (int, error) {
url, err := makeurl(fmt.Sprintf("/internal/index/%v?multiscancount=true", id))
if err != nil {
return 0, err
}
data, _ := json.Marshal(body)
req, err := http.NewRequest("GET", url, bytes.NewBuffer(data))
if err != nil {
return 0, err
}
resp, respbody, err := doHttpRequestReturnBody(req)
if err != nil {
return 0, err
}
log.Printf("Status : %v\n", resp.Status)
var result interface{}
if len(respbody) == 0 {
return 0, nil
}
err = json.Unmarshal(respbody, &result)
if err != nil {
return 0, err
}
if count, ok := result.(float64); ok {
return int(count), nil
}
return 0, nil
}
func makeurl(path string) (string, error) {
indexers, _ := secondaryindex.GetIndexerNodesHttpAddresses(indexManagementAddress)
if len(indexers) == 0 {
return "", fmt.Errorf("no indexer node")
}
return fmt.Sprintf("http://%s:%s@%v%v",
clusterconfig.Username, clusterconfig.Password, indexers[0], path), nil
}
func restful_checkstatus(status string) bool {
st := strings.ToLower(status)
x := strings.Contains(st, strconv.Itoa(http.StatusBadRequest))
x = x || strings.Contains(st, strconv.Itoa(http.StatusInternalServerError))
x = x || strings.Contains(st, strconv.Itoa(http.StatusMethodNotAllowed))
x = x || strings.Contains(st, strconv.Itoa(http.StatusNotFound))
return x
}
// doHttpRequest is a helper that makes an HTTP request, then consumes and closes the body of the
// response to avoid leaking the TCP connection.
func doHttpRequest(req *http.Request) (resp *http.Response, err error) {
resp, err = http.DefaultClient.Do(req)
if err != nil {
return resp, err
}
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)
return resp, err
}
// doHttpRequestReturnBody is a helper that makes an HTTP request, then retrieves the contents of and
// closes the body of the response to avoid leaking the TCP connection. On success both the response
// and the contents of the body are returned.
func doHttpRequestReturnBody(req *http.Request) (resp *http.Response, respbody []byte, err error) {
resp, err = http.DefaultClient.Do(req)
if err != nil {
return resp, nil, err
}
defer resp.Body.Close()
respbody, err = ioutil.ReadAll(resp.Body)
return resp, respbody, err
}
func getScanAll_AllFiltersNil() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "S", High: "V", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "H", High: "J", Inclusion: qc.Inclusion(uint32(1))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getSingleSeek() qc.Scans {
scans := make(qc.Scans, 1)
eq := c.SecondaryKey([]interface{}{"UTARIAN", "Michelle Mckay"})
scans[0] = &qc.Scan{Seek: eq}
return scans
}
func getMultipleSeek() qc.Scans {
scans := make(qc.Scans, 2)
eq := c.SecondaryKey([]interface{}{"UTARIAN", "Michelle Mckay"})
scans[0] = &qc.Scan{Seek: eq}
eq = c.SecondaryKey([]interface{}{"JUMPSTACK", "Loretta Wilkerson"})
scans[1] = &qc.Scan{Seek: eq}
return scans
}
func getSimpleRange() qc.Scans {
scans := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "G", High: "N", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
return scans
}
func getNonOverlappingRanges() qc.Scans {
scans := make(qc.Scans, 3)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "G", High: "K", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 1)
filter2[0] = &qc.CompositeElementFilter{Low: "M", High: "R", Inclusion: qc.Inclusion(uint32(2))}
scans[1] = &qc.Scan{Filter: filter2}
filter3 := make([]*qc.CompositeElementFilter, 1)
filter3[0] = &qc.CompositeElementFilter{Low: "T", High: "X", Inclusion: qc.Inclusion(uint32(0))}
scans[2] = &qc.Scan{Filter: filter3}
return scans
}
func getOverlappingRanges() qc.Scans {
scans := make(qc.Scans, 3)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "G", High: "K", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 1)
filter2[0] = &qc.CompositeElementFilter{Low: "I", High: "Q", Inclusion: qc.Inclusion(uint32(2))}
scans[1] = &qc.Scan{Filter: filter2}
filter3 := make([]*qc.CompositeElementFilter, 1)
filter3[0] = &qc.CompositeElementFilter{Low: "M", High: "X", Inclusion: qc.Inclusion(uint32(0))}
scans[2] = &qc.Scan{Filter: filter3}
return scans
}
func getNonOverlappingFilters() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "D", High: "F", Inclusion: qc.Inclusion(uint32(0))}
filter1[1] = &qc.CompositeElementFilter{Low: "A", High: "C", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "S", High: "V", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "A", High: "C", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
// Noverlapping but first key is the same
func getNonOverlappingFilters2() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "DIGIAL", High: "DIGIAL", Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "A", High: "D", Inclusion: qc.Inclusion(uint32(3))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "DIGIAL", High: "DIGIAL", Inclusion: qc.Inclusion(uint32(3))}
filter2[1] = &qc.CompositeElementFilter{Low: "M", High: "Z", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getOverlappingFilters() qc.Scans {
scans := make(qc.Scans, 3)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "B", High: "H", Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "T", High: "X", Inclusion: qc.Inclusion(uint32(3))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "E", High: "M", Inclusion: qc.Inclusion(uint32(3))}
filter2[1] = &qc.CompositeElementFilter{Low: "C", High: "R", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
filter3 := make([]*qc.CompositeElementFilter, 2)
filter3[0] = &qc.CompositeElementFilter{Low: "S", High: "X", Inclusion: qc.Inclusion(uint32(3))}
filter3[1] = &qc.CompositeElementFilter{Low: "A", High: "D", Inclusion: qc.Inclusion(uint32(3))}
scans[2] = &qc.Scan{Filter: filter3}
return scans
}
func getBoundaryFilters() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "GEEKWAGON", High: "INJOY", Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "Hendrix Orr", High: "Trina Mcfadden", Inclusion: qc.Inclusion(uint32(3))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "INJOY", High: "ORBIN", Inclusion: qc.Inclusion(uint32(3))}
filter2[1] = &qc.CompositeElementFilter{Low: "Trina Mcfadden", High: "ZZZZZ", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getSeekAndFilters_NonOverlapping() qc.Scans {
scans := make(qc.Scans, 2)
eq := c.SecondaryKey([]interface{}{"UTARIAN", "Michelle Mckay"})
scans[0] = &qc.Scan{Seek: eq}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "F", High: "K", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "H", High: "L", Inclusion: qc.Inclusion(uint32(1))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getSeekAndFilters_Overlapping() qc.Scans {
scans := make(qc.Scans, 2)
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "F", High: "K", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "H", High: "L", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter2}
eq := c.SecondaryKey([]interface{}{"IMAGINART", "Janell Hyde"})
scans[1] = &qc.Scan{Seek: eq}
return scans
}
func getSimpleRangeLowUnbounded() qc.Scans {
scans := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: "N", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
return scans
}
func getSimpleRangeHighUnbounded() qc.Scans {
scans := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "P", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
return scans
}
func getSimpleRangeMultipleUnbounded() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: "N", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 1)
filter2[0] = &qc.CompositeElementFilter{Low: "D", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(1))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getFiltersWithUnbounded() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "E", High: "L", Inclusion: qc.Inclusion(uint32(0))}
filter1[1] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "P", High: "T", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "Q", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
return scans
}
func getFiltersLowGreaterThanHigh() qc.Scans {
scans := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "L", High: "E", Inclusion: qc.Inclusion(uint32(0))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "P", High: "T", Inclusion: qc.Inclusion(uint32(2))}
filter2[1] = &qc.CompositeElementFilter{Low: "Q", High: "Z", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
return scans
}
func getScanAllNoFilter() qc.Scans {
scans := make(qc.Scans, 1)
scans[0] = &qc.Scan{Filter: nil}
return scans
}
func getScanAllFilterNil() qc.Scans {
scans := make(qc.Scans, 2)
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "S", High: "V", Inclusion: qc.Inclusion(uint32(0))}
filter2[1] = &qc.CompositeElementFilter{Low: "H", High: "J", Inclusion: qc.Inclusion(uint32(3))}
scans[0] = &qc.Scan{Filter: filter2}
scans[1] = &qc.Scan{Filter: nil}
return scans
}
func getSingleIndexSimpleRange() qc.Scans {
scans := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "G", High: "N", Inclusion: qc.Inclusion(uint32(2))}
scans[0] = &qc.Scan{Filter: filter1}
return scans
}
func getSingleIndex_SimpleRanges_NonOverlapping() qc.Scans {
scans := make(qc.Scans, 3)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "B", High: "GZZZZZ", Inclusion: qc.Inclusion(uint32(0))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 1)
filter2[0] = &qc.CompositeElementFilter{Low: "J", High: "OZZZZZ", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
filter3 := make([]*qc.CompositeElementFilter, 1)
filter3[0] = &qc.CompositeElementFilter{Low: "R", High: "XZZZZZ", Inclusion: qc.Inclusion(uint32(1))}
scans[2] = &qc.Scan{Filter: filter3}
return scans
}
func getSingleIndex_SimpleRanges_Overlapping() qc.Scans {
scans := make(qc.Scans, 4)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "B", High: "OZZZZZ", Inclusion: qc.Inclusion(uint32(0))}
scans[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 1)
filter2[0] = &qc.CompositeElementFilter{Low: "E", High: "GZZZZZ", Inclusion: qc.Inclusion(uint32(3))}
scans[1] = &qc.Scan{Filter: filter2}
filter3 := make([]*qc.CompositeElementFilter, 1)
filter3[0] = &qc.CompositeElementFilter{Low: "J", High: "RZZZZZ", Inclusion: qc.Inclusion(uint32(1))}
scans[2] = &qc.Scan{Filter: filter3}
filter4 := make([]*qc.CompositeElementFilter, 1)
filter4[0] = &qc.CompositeElementFilter{Low: "S", High: "XZZZZZ", Inclusion: qc.Inclusion(uint32(1))}
scans[3] = &qc.Scan{Filter: filter4}
return scans
}
func get3FieldsSingleSeek() qc.Scans {
scans := make(qc.Scans, 1)
eq := c.SecondaryKey([]interface{}{"SOLAREN", "Michele Yang", int64(25)})
scans[0] = &qc.Scan{Seek: eq}
return scans
}
func get3FieldsMultipleSeeks() qc.Scans {
scans := make(qc.Scans, 3)
eq := c.SecondaryKey([]interface{}{"RODEOLOGY", "Tasha Dodson", int64(23)})
scans[0] = &qc.Scan{Seek: eq}
eq = c.SecondaryKey([]interface{}{"NETROPIC", "Lillian Mcneil", int64(24)})
scans[1] = &qc.Scan{Seek: eq}
eq = c.SecondaryKey([]interface{}{"ZYTREX", "Olga Patton", int64(29)})
scans[2] = &qc.Scan{Seek: eq}
return scans
}
func get3FieldsMultipleSeeks_Identical() qc.Scans {
scans := make(qc.Scans, 3)
eq := c.SecondaryKey([]interface{}{"RODEOLOGY", "Tasha Dodson", int64(23)})
scans[0] = &qc.Scan{Seek: eq}
eq = c.SecondaryKey([]interface{}{"NETROPIC", "Lillian Mcneil", int64(24)})
scans[1] = &qc.Scan{Seek: eq}
eq = c.SecondaryKey([]interface{}{"RODEOLOGY", "Tasha Dodson", int64(23)})
scans[2] = &qc.Scan{Seek: eq}
return scans
}
func getPrimaryFilter(low, high interface{}, incl int) []*qc.CompositeElementFilter {
filter := make([]*qc.CompositeElementFilter, 1)
filter[0] = &qc.CompositeElementFilter{Low: low, High: high, Inclusion: qc.Inclusion(uint32(incl))}
return filter
}
func getPrimaryRange() qc.Scans {
scans := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 1)
filter1[0] = &qc.CompositeElementFilter{Low: "A", High: "zzzzz", Inclusion: qc.Inclusion(uint32(1))}
scans[0] = &qc.Scan{Filter: filter1}
return scans
}
// Trailing high key unbounded
func getCompIndexHighUnbounded1() []qc.Scans {
manyscans := make([]qc.Scans, 0, 2)
scans1 := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: "KANGLE", Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "Daniel Beach", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(0))}
scans1[0] = &qc.Scan{Filter: filter1}
manyscans = append(manyscans, scans1)
scans2 := make(qc.Scans, 1)
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: "KANGLE", Inclusion: qc.Inclusion(uint32(0))}
filter2[1] = &qc.CompositeElementFilter{Low: "Daniel Beach", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(0))}
scans2[0] = &qc.Scan{Filter: filter2}
manyscans = append(manyscans, scans2)
scans3 := make(qc.Scans, 1)
filter3 := make([]*qc.CompositeElementFilter, 2)
filter3[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: "KANGLE", Inclusion: qc.Inclusion(uint32(3))}
filter3[1] = &qc.CompositeElementFilter{Low: "C", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
scans3[0] = &qc.Scan{Filter: filter3}
manyscans = append(manyscans, scans3)
return manyscans
}
// Leading high key unbounded
func getCompIndexHighUnbounded2() []qc.Scans {
manyscans := make([]qc.Scans, 0, 2)
scans1 := make(qc.Scans, 1)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "Daniel Beach", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(0))}
scans1[0] = &qc.Scan{Filter: filter1}
manyscans = append(manyscans, scans1)
scans2 := make(qc.Scans, 1)
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(0))}
filter2[1] = &qc.CompositeElementFilter{Low: "Daniel Beach", High: "P", Inclusion: qc.Inclusion(uint32(0))}
scans2[0] = &qc.Scan{Filter: filter2}
manyscans = append(manyscans, scans2)
scans3 := make(qc.Scans, 1)
filter3 := make([]*qc.CompositeElementFilter, 2)
filter3[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
filter3[1] = &qc.CompositeElementFilter{Low: "C", High: c.MaxUnbounded, Inclusion: qc.Inclusion(uint32(3))}
scans3[0] = &qc.Scan{Filter: filter3}
manyscans = append(manyscans, scans3)
return manyscans
}
// Trailing low key unbounded, Pratap's scenario
func getCompIndexHighUnbounded3() []qc.Scans {
manyscans := make([]qc.Scans, 0, 1)
scans1 := make(qc.Scans, 2)
filter1 := make([]*qc.CompositeElementFilter, 2)
filter1[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: "MEDIFAX", Inclusion: qc.Inclusion(uint32(3))}
filter1[1] = &qc.CompositeElementFilter{Low: "Snow Beach", High: "Travis Wilson", Inclusion: qc.Inclusion(uint32(0))}
scans1[0] = &qc.Scan{Filter: filter1}
filter2 := make([]*qc.CompositeElementFilter, 2)
filter2[0] = &qc.CompositeElementFilter{Low: "KANGLE", High: "OTHERWAY", Inclusion: qc.Inclusion(uint32(3))}
filter2[1] = &qc.CompositeElementFilter{Low: c.MinUnbounded, High: "Robert Horne", Inclusion: qc.Inclusion(uint32(0))}
scans1[1] = &qc.Scan{Filter: filter2}
manyscans = append(manyscans, scans1)
return manyscans
}
func getCompIndexHighUnbounded4() []qc.Scans {
manyscans := make([]qc.Scans, 0, 1)