-
Notifications
You must be signed in to change notification settings - Fork 199
/
client_object_test.go
1436 lines (1147 loc) · 40.6 KB
/
client_object_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
//go:build !as_performance && !app_engine
// Copyright 2014-2022 Aerospike, 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.
package aerospike_test
import (
"math"
"strconv"
"time"
as "github.com/aerospike/aerospike-client-go/v7"
gg "github.com/onsi/ginkgo/v2"
gm "github.com/onsi/gomega"
)
// ALL tests are isolated by SetName and Key, which are 50 random characters
var _ = gg.Describe("Aerospike", func() {
var nsup int
gg.BeforeEach(func() {
if *dbaas {
gg.Skip("Not supported in DBAAS environment")
}
})
for _, useBoolType := range []bool{false, true} {
gg.BeforeEach(func() {
as.UseNativeBoolTypeInReflection = useBoolType
})
gg.Describe("Data operations on objects", func() {
// connection data
var err error
var ns = *namespace
var set = randString(50)
var key *as.Key
gg.BeforeEach(func() {
key, err = as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
})
type SomeBool bool
type SomeByte byte
type SomeInt int
type SomeUint uint
type SomeInt8 int8
type SomeUint8 uint8
type SomeInt16 int16
type SomeUint16 uint16
type SomeInt32 int32
type SomeUint32 uint32
type SomeInt64 int64
type SomeUint64 uint64
type SomeFloat32 float32
type SomeFloat64 float64
type SomeString string
type SomeStruct struct {
A int
Self *SomeStruct
}
type testObject struct {
TTL uint32 `asm:"ttl"`
Gen uint32 `asm:"gen"`
Nil interface{}
NilP *int
Bool bool
BoolP *bool
Byte byte
ByteP *byte
Int int
Intp *int
Int8 int8
Int8P *int8
UInt8 uint8
UInt8P *uint8
Int16 int16
Int16P *int16
UInt16 uint16
UInt16P *uint16
Int32 int32
Int32P *int32
UInt32 uint32
UInt32P *uint32
Int64 int64
Int64P *int64
UInt64 uint64
UInt64P *uint64
F32 float32
F32P *float32
F64 float64
F64P *float64
String string
StringP *string
Interface interface{}
// InterfaceP interface{}
InterfacePP *interface{}
ByteArray []byte
ArrByteArray [][]byte
Array [3]interface{}
SliceString []string
SliceFloat64 []float64
SliceInt []interface{}
Slice []interface{}
ArrayOfMaps [1]map[int]string
SliceOfMaps []map[int]string
ArrayOfSlices [1][]interface{}
SliceOfSlices [][]interface{}
ArrayOfArrays [1][1]interface{}
SliceOfArrays [][1]interface{}
ArrayOfStructs [1]SomeStruct
SliceOfStructs []SomeStruct
Map map[interface{}]interface{}
MapOfMaps map[string]map[int64]byte
MapOfSlices map[string][]byte
MapOfArrays map[string][3]byte
MapOfStructs map[string]SomeStruct
MapOfPStructs map[string]*SomeStruct
CustomBool SomeBool
CustomBoolP *SomeBool
CustomByte SomeByte
CustomByteP *SomeByte
CustomInt SomeInt
CustomIntP *SomeInt
CustomUint SomeUint
CustomUintP *SomeUint
CustomInt8 SomeInt8
CustomInt8P *SomeInt8
CustomUint8 SomeUint8
CustomUint8P *SomeUint8
CustomInt16 SomeInt16
CustomInt16P *SomeInt16
CustomUint16 SomeUint16
CustomUint16P *SomeUint16
CustomInt32 SomeInt32
CustomInt32P *SomeInt32
CustomUint32 SomeUint32
CustomUint32P *SomeUint32
CustomInt64 SomeInt64
CustomInt64P *SomeInt64
CustomUint64 SomeUint64
CustomUint64P *SomeUint64
CustomFloat32 SomeFloat32
CustomFloat32P *SomeFloat32
CustomFloat64 SomeFloat64
CustomFloat64P *SomeFloat64
CustomString SomeString
CustomStringP *SomeString
NestedObj SomeStruct
NestedObjP *testObject
EmpNestedObjP *testObject
// Important: Used in ODMs
NestedObjSlice []SomeStruct
EmpNstdObjSlic []SomeStruct
NstdObjPSlice []*testObject
EmpNstdObjPSlc []*testObject
// std lib type
Tm time.Time
TmP *time.Time
Anonym struct {
SomeStruct
}
AnonymP *struct {
SomeStruct
}
}
type testObjectTagged struct {
TTL uint32 `asm:"ttl"`
Gen uint32 `asm:"gen"`
Nil interface{} `as:"nil"`
NilP *int `as:"nilp"`
Bool bool `as:"bool"`
BoolP *bool `as:"boolp"`
Byte byte `as:"byte"`
ByteP *byte `as:"bytep"`
Int int `as:"int"`
Intp *int `as:"intp"`
Int8 int8 `as:"int8"`
Int8P *int8 `as:"int8p"`
UInt8 uint8 `as:"uint8"`
UInt8P *uint8 `as:"uint8p"`
Int16 int16 `as:"int16"`
Int16P *int16 `as:"int16p"`
UInt16 uint16 `as:"uint16"`
UInt16P *uint16 `as:"uint16p"`
Int32 int32 `as:"int32"`
Int32P *int32 `as:"int32p"`
UInt32 uint32 `as:"uint32"`
UInt32P *uint32 `as:"uint32p"`
Int64 int64 `as:"int64"`
Int64P *int64 `as:"int64p"`
UInt64 uint64 `as:"uint64"`
UInt64P *uint64 `as:"uint64p"`
F32 float32 `as:"f32"`
F32P *float32 `as:"f32p"`
F64 float64 `as:"f64"`
F64P *float64 `as:"f64p"`
String string `as:"string"`
StringP *string `as:"stringp"`
Interface interface{} `as:"interface"`
// InterfaceP interface{} `as:"// interface"`
InterfacePP *interface{} `as:"interfacepp"`
ByteArray []byte `as:"bytearray"`
ArrByteArray [][]byte `as:"arrbytearray"`
Array [3]interface{} `as:"array"`
SliceString []string `as:"slicestring"`
SliceFloat64 []float64 `as:"slicefloat64"`
SliceInt []interface{} `as:"sliceint"`
Slice []interface{} `as:"slice"`
ArrayOfMaps [1]map[int]string `as:"arrayOfMaps"`
SliceOfMaps []map[int]string `as:"sliceOfMaps"`
ArrayOfSlices [1][]interface{} `as:"arrayOfSlices"`
SliceOfSlices [][]interface{} `as:"sliceOfSlices"`
ArrayOfArrays [1][1]interface{} `as:"arrayOfArrays"`
SliceOfArrays [][1]interface{} `as:"sliceOfArrays"`
ArrayOfStructs [1]SomeStruct `as:"ArrayOfStructs"`
SliceOfStructs []SomeStruct `as:"SliceOfStructs"`
Map map[interface{}]interface{} `as:"map"`
MapOfMaps map[string]map[int64]byte `as:"mapOfMaps"`
MapOfSlices map[string][]byte `as:"mapOfSlices"`
MapOfArrays map[string][3]byte `as:"MapOfArrays"`
MapOfStructs map[string]SomeStruct `as:"mapOfStructs"`
MapOfPStructs map[string]*SomeStruct `as:"mapOfPStructs"`
CustomBool SomeBool `as:"custombool"`
CustomBoolP *SomeBool `as:"customboolp"`
CustomByte SomeByte `as:"custombyte"`
CustomByteP *SomeByte `as:"custombytep"`
CustomInt SomeInt `as:"customint"`
CustomIntP *SomeInt `as:"customintp"`
CustomUint SomeUint `as:"customuint"`
CustomUintP *SomeUint `as:"customuintp"`
CustomInt8 SomeInt8 `as:"customint8"`
CustomInt8P *SomeInt8 `as:"customint8p"`
CustomUint8 SomeUint8 `as:"customuint8"`
CustomUint8P *SomeUint8 `as:"customuint8p"`
CustomInt16 SomeInt16 `as:"customint16"`
CustomInt16P *SomeInt16 `as:"customint16p"`
CustomUint16 SomeUint16 `as:"customuint16"`
CustomUint16P *SomeUint16 `as:"customuint16p"`
CustomInt32 SomeInt32 `as:"customint32"`
CustomInt32P *SomeInt32 `as:"customint32p"`
CustomUint32 SomeUint32 `as:"customuint32"`
CustomUint32P *SomeUint32 `as:"customuint32p"`
CustomInt64 SomeInt64 `as:"customint64"`
CustomInt64P *SomeInt64 `as:"customint64p"`
CustomUint64 SomeUint64 `as:"customuint64"`
CustomUint64P *SomeUint64 `as:"customuint64p"`
CustomFloat32 SomeFloat32 `as:"customfloat32"`
CustomFloat32P *SomeFloat32 `as:"customfloat32p"`
CustomFloat64 SomeFloat64 `as:"customfloat64"`
CustomFloat64P *SomeFloat64 `as:"customfloat64p"`
CustomString SomeString `as:"customstring"`
CustomStringP *SomeString `as:"customstringp"`
NestedObj SomeStruct `as:"nestedobj"`
NestedObjP *testObject `as:"nestedobjp"`
EmpNestedObjP *testObject `as:"empnestedobj"`
// Important: Used in ODMs `as:"// important"`
NestedObjSlice []SomeStruct `as:"nestedobjslice"`
EmpNstdObjSlic []SomeStruct `as:"empnstdobj"`
NstdObjPSlice []*testObject `as:"nstdobjpslice"`
EmpNstdObjPSlc []*testObject `as:"empnstdobjp"`
// std lib type `as:"// std lib"`
Tm time.Time `as:"tm time."`
TmP *time.Time `as:"tmp"`
Anonym struct {
SomeStruct
} `as:"anonym"`
AnonymP *struct {
SomeStruct
} `as:"anonymp"`
}
makeTestObject := func() *testObject {
bl := true
b := byte(0)
ip := 11
p8 := int8(4)
up8 := uint8(6)
p16 := int16(8)
up16 := uint16(10)
p32 := int32(12)
up32 := uint32(14)
p64 := int64(16)
up64 := uint64(math.MaxUint64)
f32p := float32(math.MaxFloat32)
f64p := math.MaxFloat64
str := "pointer to a string"
iface := interface{}("a string")
ctbl := SomeBool(true)
ctb := SomeByte(100)
cti := SomeInt(math.MinInt64)
ctui := SomeUint(math.MaxInt64)
cti8 := SomeInt8(103)
ctui8 := SomeUint8(math.MaxUint8)
cti16 := SomeInt16(math.MinInt16)
ctui16 := SomeUint16(math.MaxUint16)
cti32 := SomeInt32(math.MinInt32)
ctui32 := SomeUint32(math.MaxUint32)
cti64 := SomeInt64(math.MinInt64)
ctui64 := SomeUint64(math.MaxUint64)
cf32 := SomeFloat32(math.SmallestNonzeroFloat32)
cf64 := SomeFloat64(math.SmallestNonzeroFloat64)
ctstr := SomeString("Some string")
now := time.Now().Round(time.Nanosecond)
return &testObject{
Bool: true,
BoolP: &bl,
Nil: nil,
NilP: nil,
Byte: byte(0),
ByteP: &b,
Int: 1,
Intp: &ip,
Int8: 3,
Int8P: &p8,
UInt8: 5,
UInt8P: &up8,
Int16: 7,
Int16P: &p16,
UInt16: 9,
UInt16P: &up16,
Int32: 11,
Int32P: &p32,
UInt32: 13,
UInt32P: &up32,
Int64: math.MaxInt64,
Int64P: &p64,
UInt64: math.MaxUint64,
UInt64P: &up64,
F32: 1.87132794,
F32P: &f32p,
F64: 59285092891.502818573,
F64P: &f64p,
String: "string",
StringP: &str,
Interface: iface,
// InterfaceP: ifaceP, // NOTICE: NOT SUPPORTED
InterfacePP: &iface,
ByteArray: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
ArrByteArray: [][]byte{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
Array: [3]interface{}{1, "string", nil},
SliceString: []string{"string1", "string2", "string3"},
SliceFloat64: []float64{1.1, 2.2, 3.3, 4.4},
SliceInt: []interface{}{1, 2, 3},
Slice: []interface{}{1, "string", []byte{1, 11, 111}, nil, true},
ArrayOfMaps: [1]map[int]string{{1: "str"}},
SliceOfMaps: []map[int]string{{1: "str"}},
ArrayOfSlices: [1][]interface{}{{1, 2, 3}},
SliceOfSlices: [][]interface{}{{1, 2, 3}, {4, 5, 6}},
ArrayOfArrays: [1][1]interface{}{{1}},
SliceOfArrays: [][1]interface{}{{1}, {2}, {3}},
ArrayOfStructs: [1]SomeStruct{{A: 1, Self: &SomeStruct{A: 1}}},
SliceOfStructs: []SomeStruct{{A: 1, Self: &SomeStruct{A: 1}}},
Map: map[interface{}]interface{}{1: "string", "string": nil /*nil: map[interface{}]interface{}{"1": ip}, true: false*/},
MapOfMaps: map[string]map[int64]byte{"1": {1: 1, 2: 2}},
MapOfSlices: map[string][]byte{"1": {1, 2}, "2": {3, 4}},
MapOfArrays: map[string][3]byte{"1": {1, 2, 3}, "2": {3, 4, 5}},
MapOfStructs: map[string]SomeStruct{"1": {A: 10, Self: &SomeStruct{A: 10}}},
MapOfPStructs: map[string]*SomeStruct{"1": {A: 10, Self: &SomeStruct{A: 10}}},
CustomBool: true,
CustomBoolP: &ctbl,
CustomByte: 100,
CustomByteP: &ctb,
CustomInt: 100,
CustomIntP: &cti,
CustomUint: 100,
CustomUintP: &ctui,
CustomInt8: 100,
CustomInt8P: &cti8,
CustomUint8: 100,
CustomUint8P: &ctui8,
CustomInt16: 100,
CustomInt16P: &cti16,
CustomUint16: 100,
CustomUint16P: &ctui16,
CustomInt32: 100,
CustomInt32P: &cti32,
CustomUint32: 100,
CustomUint32P: &ctui32,
CustomInt64: 100,
CustomInt64P: &cti64,
CustomUint64: 100,
CustomUint64P: &ctui64,
CustomFloat32: cf32,
CustomFloat32P: &cf32,
CustomFloat64: cf64,
CustomFloat64P: &cf64,
CustomString: ctstr,
CustomStringP: &ctstr,
NestedObj: SomeStruct{A: 1, Self: &SomeStruct{A: 999}},
NestedObjP: &testObject{Int: 1, Intp: &ip, Tm: now},
NestedObjSlice: []SomeStruct{{A: 1, Self: &SomeStruct{A: 999}}, {A: 2, Self: &SomeStruct{A: 998}}},
NstdObjPSlice: []*testObject{{Int: 1, Intp: &ip, Tm: now}, {Int: 2, Intp: &ip, Tm: now}},
Tm: now,
TmP: &now,
Anonym: struct{ SomeStruct }{SomeStruct{A: 1, Self: &SomeStruct{A: 999}}},
AnonymP: &(struct{ SomeStruct }{SomeStruct{A: 1, Self: &SomeStruct{A: 999}}}),
}
}
makeTestObjectTagged := func() *testObjectTagged {
bl := true
b := byte(0)
ip := 11
p8 := int8(4)
up8 := uint8(6)
p16 := int16(8)
up16 := uint16(10)
p32 := int32(12)
up32 := uint32(14)
p64 := int64(16)
up64 := uint64(math.MaxUint64)
f32p := float32(math.MaxFloat32)
f64p := math.MaxFloat64
str := "pointer to a string"
iface := interface{}("a string")
ctbl := SomeBool(true)
ctb := SomeByte(100)
cti := SomeInt(math.MinInt64)
ctui := SomeUint(math.MaxInt64)
cti8 := SomeInt8(103)
ctui8 := SomeUint8(math.MaxUint8)
cti16 := SomeInt16(math.MinInt16)
ctui16 := SomeUint16(math.MaxUint16)
cti32 := SomeInt32(math.MinInt32)
ctui32 := SomeUint32(math.MaxUint32)
cti64 := SomeInt64(math.MinInt64)
ctui64 := SomeUint64(math.MaxUint64)
cf32 := SomeFloat32(math.SmallestNonzeroFloat32)
cf64 := SomeFloat64(math.SmallestNonzeroFloat64)
ctstr := SomeString("Some string")
now := time.Now().Round(time.Nanosecond)
return &testObjectTagged{
Bool: true,
BoolP: &bl,
Nil: nil,
NilP: nil,
Byte: byte(0),
ByteP: &b,
Int: 1,
Intp: &ip,
Int8: 3,
Int8P: &p8,
UInt8: 5,
UInt8P: &up8,
Int16: 7,
Int16P: &p16,
UInt16: 9,
UInt16P: &up16,
Int32: 11,
Int32P: &p32,
UInt32: 13,
UInt32P: &up32,
Int64: math.MaxInt64,
Int64P: &p64,
UInt64: math.MaxUint64,
UInt64P: &up64,
F32: 1.87132794,
F32P: &f32p,
F64: 59285092891.502818573,
F64P: &f64p,
String: "string",
StringP: &str,
Interface: iface,
// InterfaceP: ifaceP, // NOTICE: NOT SUPPORTED
InterfacePP: &iface,
ByteArray: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
ArrByteArray: [][]byte{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
Array: [3]interface{}{1, "string", nil},
SliceString: []string{"string1", "string2", "string3"},
SliceFloat64: []float64{1.1, 2.2, 3.3, 4.4},
SliceInt: []interface{}{1, 2, 3},
Slice: []interface{}{1, "string", []byte{1, 11, 111}, nil, true},
ArrayOfMaps: [1]map[int]string{{1: "str"}},
SliceOfMaps: []map[int]string{{1: "str"}},
ArrayOfSlices: [1][]interface{}{{1, 2, 3}},
SliceOfSlices: [][]interface{}{{1, 2, 3}, {4, 5, 6}},
ArrayOfArrays: [1][1]interface{}{{1}},
SliceOfArrays: [][1]interface{}{{1}, {2}, {3}},
ArrayOfStructs: [1]SomeStruct{{A: 1, Self: &SomeStruct{A: 1}}},
SliceOfStructs: []SomeStruct{{A: 1, Self: &SomeStruct{A: 1}}},
Map: map[interface{}]interface{}{1: "string", "string": nil /*nil: map[interface{}]interface{}{"1": ip}, true: false*/},
MapOfMaps: map[string]map[int64]byte{"1": {1: 1, 2: 2}},
MapOfSlices: map[string][]byte{"1": {1, 2}, "2": {3, 4}},
MapOfArrays: map[string][3]byte{"1": {1, 2, 3}, "2": {3, 4, 5}},
MapOfStructs: map[string]SomeStruct{"1": {A: 10, Self: &SomeStruct{A: 10}}},
MapOfPStructs: map[string]*SomeStruct{"1": {A: 10, Self: &SomeStruct{A: 10}}},
CustomBool: true,
CustomBoolP: &ctbl,
CustomByte: 100,
CustomByteP: &ctb,
CustomInt: 100,
CustomIntP: &cti,
CustomUint: 100,
CustomUintP: &ctui,
CustomInt8: 100,
CustomInt8P: &cti8,
CustomUint8: 100,
CustomUint8P: &ctui8,
CustomInt16: 100,
CustomInt16P: &cti16,
CustomUint16: 100,
CustomUint16P: &ctui16,
CustomInt32: 100,
CustomInt32P: &cti32,
CustomUint32: 100,
CustomUint32P: &ctui32,
CustomInt64: 100,
CustomInt64P: &cti64,
CustomUint64: 100,
CustomUint64P: &ctui64,
CustomFloat32: cf32,
CustomFloat32P: &cf32,
CustomFloat64: cf64,
CustomFloat64P: &cf64,
CustomString: ctstr,
CustomStringP: &ctstr,
NestedObj: SomeStruct{A: 1, Self: &SomeStruct{A: 999}},
NestedObjP: &testObject{Int: 1, Intp: &ip, Tm: now},
NestedObjSlice: []SomeStruct{{A: 1, Self: &SomeStruct{A: 999}}, {A: 2, Self: &SomeStruct{A: 998}}},
NstdObjPSlice: []*testObject{{Int: 1, Intp: &ip, Tm: now}, {Int: 2, Intp: &ip, Tm: now}},
Tm: now,
TmP: &now,
Anonym: struct{ SomeStruct }{SomeStruct{A: 1, Self: &SomeStruct{A: 999}}},
AnonymP: &(struct{ SomeStruct }{SomeStruct{A: 1, Self: &SomeStruct{A: 999}}}),
}
}
gg.Context("PutObject operations", func() {
gg.It("must respect `UseNativeBoolTypeInReflection` option", func() {
type T struct {
T, F bool
}
t := &T{
T: true,
F: false,
}
// Use native bools
as.UseNativeBoolTypeInReflection = true
key, _ := as.NewKey(ns, set, randString(50))
err = client.PutObject(nil, key, t)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{"T": t.T, "F": t.F}))
// Use integers
as.UseNativeBoolTypeInReflection = false
key, _ = as.NewKey(ns, set, randString(50))
err = client.PutObject(nil, key, t)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err = client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{"T": 1, "F": 0}))
})
gg.It("must respect `,omitempty` option", func() {
type Inner struct {
V1 int `as:" v1,ommitempty "`
V2 string `as:" v2,ommitempty "`
}
type T struct {
Name string `as:" name "`
Description string `as:" desc ,omitempty"`
Age int `as:" ,omitempty"`
InnerVal Inner `as:"inner,omitempty"`
}
t := &T{
Name: "Ada Lovelace",
Description: "Was doing it before it was cool",
Age: 31,
}
key, _ := as.NewKey(ns, set, randString(50))
err = client.PutObject(nil, key, t)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{"name": t.Name, "desc": t.Description, "Age": 31, "inner": map[interface{}]interface{}{"v1": 0, "v2": ""}}))
key, _ = as.NewKey(ns, set, randString(50))
t = &T{
Name: "",
Description: "",
Age: 0,
}
err = client.PutObject(nil, key, t)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err = client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{"name": t.Name, "inner": map[interface{}]interface{}{"v1": 0, "v2": ""}}))
})
gg.It("must save an object with the most complex structure possible and retrieve it via BatchGetObject", func() {
testObj := makeTestObject()
err := client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
resObj := &testObject{}
err = client.GetObject(nil, key, resObj)
// set the Gen and TTL
testObj.TTL = resObj.TTL
testObj.Gen = resObj.Gen
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj).To(gm.Equal(testObj))
gm.Expect(resObj.AnonymP).NotTo(gm.BeNil())
// should not panic if read back to an object with none of the bins
T := struct {
NonExisting int `as:"nonexisting"`
}{-1}
err = client.GetObject(nil, key, &T)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(T.NonExisting).To(gm.Equal(-1))
// get the same object via BatchGetObject
resObj = &testObject{}
found, err := client.BatchGetObjects(nil, []*as.Key{key}, []interface{}{resObj})
gm.Expect(len(found)).To(gm.Equal(1))
gm.Expect(found[0]).To(gm.BeTrue())
gm.Expect(err).ToNot(gm.HaveOccurred())
// set the Gen and TTL
testObj.TTL = resObj.TTL
testObj.Gen = resObj.Gen
gm.Expect(resObj).To(gm.Equal(testObj))
gm.Expect(resObj.AnonymP).NotTo(gm.BeNil())
})
gg.It("must save a tagged object with the most complex structure possible", func() {
testObj := makeTestObjectTagged()
err := client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
resObj := &testObjectTagged{}
err = client.GetObject(nil, key, resObj)
// set the Gen and TTL
testObj.TTL = resObj.TTL
testObj.Gen = resObj.Gen
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj).To(gm.Equal(testObj))
gm.Expect(resObj.AnonymP).NotTo(gm.BeNil())
})
gg.It("must save an object and read it back respecting the tags", func() {
type InnerStruct struct {
Strings []string `as:"b"`
PersistNot int `as:"-"`
PersistAsInner1 int `as:"inner1"`
}
type TaggedStruct struct {
Strings []string `as:"b"`
DontPersist int `as:"-"`
PersistAsFld1 int `as:"fld1"`
Bytes []byte `as:"fldbytes"`
IStruct InnerStruct `as:"istruct"`
}
testObj := TaggedStruct{Strings: []string{"a", "b", "c"}, DontPersist: 1, PersistAsFld1: 2, Bytes: []byte{1, 2, 3, 4}, IStruct: InnerStruct{Strings: []string{"d", "e", "f", "g"}, PersistNot: 10, PersistAsInner1: 11}}
err := client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
resObj := &TaggedStruct{}
err = client.GetObject(nil, key, resObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj.DontPersist).To(gm.Equal(0))
gm.Expect(resObj.PersistAsFld1).To(gm.Equal(2))
gm.Expect(resObj.IStruct.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.IStruct.PersistAsInner1).To(gm.Equal(11))
// get the bins and check for bin names
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(
as.BinMap{
"b": []interface{}{"a", "b", "c"},
"fld1": 2,
"fldbytes": []byte{1, 2, 3, 4},
"istruct": map[interface{}]interface{}{
"b": []interface{}{"d", "e", "f", "g"},
"inner1": 11,
},
}))
gm.Expect(len(rec.Bins)).To(gm.Equal(4))
gm.Expect(rec.Bins["DontPersist"]).To(gm.BeNil())
gm.Expect(rec.Bins["fld1"]).To(gm.Equal(2))
innerStruct := rec.Bins["istruct"].(map[interface{}]interface{})
gm.Expect(len(innerStruct)).To(gm.Equal(2))
gm.Expect(innerStruct["PersistNot"]).To(gm.BeNil())
gm.Expect(innerStruct["inner1"]).To(gm.Equal(11))
})
gg.It("must save an object *pointer* and read it back respecting the tags", func() {
type InnerStruct struct {
PersistNot int `as:"-"`
PersistAsInner1 int `as:"inner1"`
}
type TaggedStruct struct {
DontPersist int `as:"-"`
PersistAsFld1 int `as:"fld1"`
IStruct *InnerStruct
}
testObj := &TaggedStruct{DontPersist: 1, PersistAsFld1: 2, IStruct: &InnerStruct{PersistNot: 10, PersistAsInner1: 11}}
err := client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
resObj := &TaggedStruct{IStruct: &InnerStruct{}}
err = client.GetObject(nil, key, resObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj.DontPersist).To(gm.Equal(0))
gm.Expect(resObj.PersistAsFld1).To(gm.Equal(2))
gm.Expect(resObj.IStruct.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.IStruct.PersistAsInner1).To(gm.Equal(11))
// get the bins and check for bin names
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(len(rec.Bins)).To(gm.Equal(2))
gm.Expect(rec.Bins["DontPersist"]).To(gm.BeNil())
gm.Expect(rec.Bins["fld1"]).To(gm.Equal(2))
innerStruct := rec.Bins["IStruct"].(map[interface{}]interface{})
gm.Expect(len(innerStruct)).To(gm.Equal(1))
gm.Expect(innerStruct["PersistNot"]).To(gm.BeNil())
gm.Expect(innerStruct["inner1"]).To(gm.Equal(11))
})
gg.It("must put and get pre-assigned lists and maps", func() {
type MyObject struct {
List []string
Map map[int]string
}
var t, o1, o2 MyObject
o1.List = nil // the default is nil anyways
o1.Map = nil // the default is nil anyways
o2.List = []string{"Should be overwritten"}
o2.Map = map[int]string{666: "Nope"}
t = MyObject{
List: []string{"Apple", "Orange"},
Map: map[int]string{1: "Apple", 2: "Orange"},
}
err := client.PutObject(nil, key, &t)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{
"Map": map[interface{}]interface{}{1: "Apple", 2: "Orange"},
"List": []interface{}{"Apple", "Orange"},
}))
err = client.GetObject(nil, key, &o1)
gm.Expect(err).ToNot(gm.HaveOccurred())
err = client.GetObject(nil, key, &o2)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(o1).To(gm.Equal(o2))
gm.Expect(t).To(gm.Equal(o1))
gm.Expect(t).To(gm.Equal(o2))
})
}) // PutObject context
gg.Context("Metadata operations", func() {
gg.It("must save an object and read its metadata back", func() {
type objMeta struct {
TTL1, TTL2 uint32 `asm:"ttl"`
GEN1, GEN2 uint32 `asm:"gen"`
Val int `as:"val"`
}
testObj := objMeta{Val: 1}
err := client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Bins).To(gm.Equal(as.BinMap{"val": 1}))
resObj := &objMeta{}
err = client.GetObject(nil, key, resObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj.TTL1).NotTo(gm.Equal(uint32(0)))
gm.Expect(resObj.TTL1).To(gm.Equal(resObj.TTL2))
gm.Expect(resObj.GEN1).To(gm.Equal(uint32(1)))
gm.Expect(resObj.GEN2).To(gm.Equal(uint32(1)))
// put it again to check the generation
err = client.PutObject(nil, key, &testObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
err = client.GetObject(nil, key, resObj)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(resObj.TTL1).NotTo(gm.Equal(uint32(0)))
gm.Expect(resObj.TTL1).To(gm.Equal(resObj.TTL2))
if *dbaas {
gg.Skip("Not supported in DBAAS environment")
}
defaultTTL, nerr := strconv.Atoi(nsInfo(ns, "default-ttl"))
gm.Expect(nerr).ToNot(gm.HaveOccurred())
switch defaultTTL {
case 0:
gm.Expect(resObj.TTL1).To(gm.Equal(uint32(math.MaxUint32)))
default:
gm.Expect(resObj.TTL1).To(gm.Equal(uint32(defaultTTL)))
}
gm.Expect(resObj.GEN1).To(gm.Equal(uint32(2)))
gm.Expect(resObj.GEN2).To(gm.Equal(uint32(2)))
})
}) // PutObject context
gg.Context("BatchGetObjects operations", func() {
var keys []*as.Key
var resObjects []interface{}
var objects []*testObjectTagged
gg.BeforeEach(func() {
set = randString(50)
keys = nil
resObjects = nil
objects = nil
nsup = nsupPeriod(ns)
var wpolicy *as.WritePolicy
if nsup > 0 {
wpolicy = as.NewWritePolicy(0, 500)
} else {
wpolicy = as.NewWritePolicy(0, 0)
}
for i := 0; i < 100; i++ {
key, err = as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
keys = append(keys, key)
resObjects = append(resObjects, new(testObjectTagged))
// only put odd objects in the db
if i%2 == 0 {
objects = append(objects, new(testObjectTagged))
continue
}