-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_t_test.go
1525 lines (1435 loc) · 52.1 KB
/
key_t_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
//////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2018-2022 YottaDB LLC and/or its subsidiaries. //
// All rights reserved. //
// //
// This source code contains the intellectual property //
// of its copyright holder(s), and is made available //
// under a license. If you do not know the terms of //
// the license, please stop and do not read further. //
// //
//////////////////////////////////////////////////////////////////
package yottadb_test
import (
"bytes"
"github.com/stretchr/testify/assert"
"lang.yottadb.com/go/yottadb"
. "lang.yottadb.com/go/yottadb/internal/test_helpers"
"strconv"
"sync"
"testing"
"time"
)
func TestDataST(t *testing.T) {
var dbkey yottadb.KeyT
var ovalue, cvalue yottadb.BufferT
var tptoken uint64 = yottadb.NOTTP
var err error
ovalue.Alloc(64)
cvalue.Alloc(128)
// Create a few nodes so we can check DataST() on them
err = yottadb.SetValE(tptoken, nil, "val1", "^tdaNoSubs", []string{})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, nil, "val2", "^tdaSubs", []string{"sub1", "sub2"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, nil, "val3", "^tdaSubs", []string{"sub1", "sub2", "sub3"})
Assertnoerr(err, t)
// Build query structs for DataST()
dbkey.Alloc(VarSiz, AryDim, SubSiz) // Reallocate the key
// Check against a non-existent node - should return 0
err = dbkey.Varnm.SetValStr(tptoken, nil, "^noExistGbl")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 0)
Assertnoerr(err, t)
dval, err := dbkey.DataST(tptoken, nil)
Assertnoerr(err, t)
if 0 != int(dval) {
t.Error("The DataST() value for ^noExistGbl expected to be 0 but was", dval)
}
// Check node with value but no subscripts - should be 1
err = dbkey.Varnm.SetValStr(tptoken, nil, "^tdaNoSubs")
Assertnoerr(err, t)
dval, err = dbkey.DataST(tptoken, nil)
Assertnoerr(err, t)
if yottadb.YDB_DATA_VALUE_NODESC != int(dval) {
t.Error("The DataST() value for ^tdaNoSubs expected to be 1 but was", dval)
}
// Check against a subscripted node with no value but has descendents
err = dbkey.Varnm.SetValStr(tptoken, nil, "^tdaSubs")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "sub1")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
Assertnoerr(err, t)
dval, err = dbkey.DataST(tptoken, nil)
Assertnoerr(err, t)
if yottadb.YDB_DATA_NOVALUE_DESC != int(dval) {
t.Error("The DataST() value for ^tdaSubs(\"sub1\") expected to be 10 but was", dval)
}
// Check against a subscripted node with a value and descendants
err = dbkey.Subary.SetValStr(tptoken, nil, 1, "sub2")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 2)
Assertnoerr(err, t)
dval, err = dbkey.DataST(tptoken, nil)
Assertnoerr(err, t)
if yottadb.YDB_DATA_VALUE_DESC != int(dval) {
t.Error("The DataST() value for ^tdaSubs(\"sub1\",\"sub2\") expected to be 11 but was", dval)
}
// Check if return value set correctly on an error by giving it an invalid var name
err = dbkey.Varnm.SetValStr(tptoken, nil, "1234") // Set invalid var name
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 0) // No subscripts
Assertnoerr(err, t)
dval, err = dbkey.DataST(tptoken, nil)
if yottadb.YDB_DATA_ERROR != int(dval) {
t.Error("The DataE() return value for an invalid varname expected to be YDB_DATA_NOERROR but was", dval)
}
}
func TestDataSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The DataST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The DataST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The DataST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The DataST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The DataST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestDeleteST(t *testing.T) {
var dbkey yottadb.KeyT
var tptoken uint64 = yottadb.NOTTP
var err error
defer dbkey.Free()
dbkey.Alloc(VarSiz, AryDim, SubSiz)
err = dbkey.Varnm.SetValStr(tptoken, nil, "^tdaSubs")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "sub2")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
// TODO: we should check to make sure error messages are correctly filled out (!UL replaced with number)
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 0) // No subs are included
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, nil, yottadb.YDB_DEL_TREE)
Assertnoerr(err, t)
dval, err := dbkey.DataST(tptoken, nil)
Assertnoerr(err, t)
if 0 != dval {
t.Error("FAIL - The ^tdaSubs node still exists after DeleteST() - DataST() returned:", dval)
}
}
func TestDeleteSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, &errstr, yottadb.YDB_DEL_TREE)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The DeleteST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED - from special variable
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, &errstr, yottadb.YDB_DEL_TREE)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The DeleteST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, &errstr, yottadb.YDB_DEL_TREE)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The DeleteST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, &errstr, yottadb.YDB_DEL_TREE)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The DeleteST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
_, err = dbkey.DataST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The DeleteST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_UNIMPLOP - from bad deltype parm (not YDB_DEL_NODE/TREE)
dbkey.Alloc(2, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^a")
Assertnoerr(err, t)
err = dbkey.DeleteST(tptoken, &errstr, 999)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_UNIMPLOP != errcode {
t.Error("The DeleteST() errorcode for ^ expected to be", yottadb.YDB_ERR_UNIMPLOP, "but was", errcode)
}
}
func TestValST(t *testing.T) {
// Not tested because it is already tested in TpST() via ValE()
}
func TestValSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr, retval yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
retval.Alloc(4)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The ValST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_GVUNDEF
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^doesnotexist")
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_GVUNDEF != errcode {
t.Error("The ValST() errorcode for ^doesnotexist expected to be", yottadb.YDB_ERR_GVUNDEF, "but was", errcode)
}
// YDB_ERR_LVUNDEF
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "doesnotexist")
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode {
t.Error("The ValST() errorcode for doesnotexist expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The SetValE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The ValST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
err = dbkey.ValST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The ValST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestIncrST(t *testing.T) {
var dbkey yottadb.KeyT
var tptoken uint64 = yottadb.NOTTP
var err error
var newval2i int
var incrval, dbval1, dbval2 yottadb.BufferT
var newval1, newval2 string
defer dbkey.Free()
dbkey.Alloc(VarSiz, AryDim, SubSiz)
defer dbval1.Free()
dbval1.Alloc(128)
defer dbval2.Free()
dbval2.Alloc(128)
defer incrval.Free()
incrval.Alloc(16)
// Create a simple subscripted node, then increment it, then fetch it and compare to returned value
err = dbkey.Varnm.SetValStr(tptoken, nil, "^ivar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "isub1")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
Assertnoerr(err, t)
err = dbval1.SetValStr(tptoken, nil, "42")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, nil, &dbval1) // Set the initial value into the node
err = incrval.SetValStr(tptoken, nil, "2")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, nil, &incrval, &dbval2)
Assertnoerr(err, t)
newval2, err = dbval2.ValStr(tptoken, nil)
Assertnoerr(err, t)
newval2i, err = strconv.Atoi(newval2)
Assertnoerr(err, t)
if newval2i != 44 {
t.Error("The expected increment value is 44 but it is", newval2)
}
// Fetch the value and verify same as what we got back from IncrST()
err = dbkey.ValST(tptoken, nil, &dbval1)
Assertnoerr(err, t)
newval1, err = dbval1.ValStr(tptoken, nil)
if newval1 != newval2 {
t.Error("Returned and post-increment fetch values not same - db :", newval1,
" returned: ", newval2)
}
// increment by nil which should increase global by 1
err = dbkey.Varnm.SetValStr(tptoken, nil, "^ivar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "isub1")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
Assertnoerr(err, t)
err = incrval.SetValStr(tptoken, nil, "")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, nil, &incrval, &dbval2)
Assertnoerr(err, t)
newval2, err = dbval2.ValStr(tptoken, nil)
Assertnoerr(err, t)
newval2i, err = strconv.Atoi(newval2)
Assertnoerr(err, t)
if newval2i != 45 {
t.Error("The expected increment value is 45 but it is", newval2)
}
// Fetch the value and verify same as what we got back from IncrST()
err = dbkey.ValST(tptoken, nil, &dbval1)
Assertnoerr(err, t)
newval1, err = dbval1.ValStr(tptoken, nil)
if newval1 != newval2 {
t.Error("Returned and post-increment fetch values not same - db :", newval1,
" returned: ", newval2)
}
// Increment a nonexistant node, check that it is set to the increment
err = dbkey.Varnm.SetValStr(tptoken, nil, "^ivar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "isub2")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
Assertnoerr(err, t)
err = incrval.SetValStr(tptoken, nil, "9001")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, nil, &incrval, &dbval2)
Assertnoerr(err, t)
newval2, err = dbval2.ValStr(tptoken, nil)
Assertnoerr(err, t)
newval2i, err = strconv.Atoi(newval2)
Assertnoerr(err, t)
if newval2i != 9001 {
t.Error("The expected increment value is 9001 but it is", newval2)
}
// Fetch the value and verify same as what we got back from IncrST()
err = dbkey.ValST(tptoken, nil, &dbval1)
Assertnoerr(err, t)
newval1, err = dbval1.ValStr(tptoken, nil)
if newval1 != newval2 {
t.Error("Returned and post-increment fetch values not same - db :", newval1,
" returned: ", newval2)
}
// Increment a non-cannonical number, check that it is foreced to a number
err = dbkey.Varnm.SetValStr(tptoken, nil, "^ivar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "isub1")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 1)
Assertnoerr(err, t)
err = dbval1.SetValStr(tptoken, nil, "This is not a number")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, nil, &dbval1) // Set the initial value into the node
err = incrval.SetValStr(tptoken, nil, "1337")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, nil, &incrval, &dbval2)
Assertnoerr(err, t)
newval2, err = dbval2.ValStr(tptoken, nil)
Assertnoerr(err, t)
newval2i, err = strconv.Atoi(newval2)
Assertnoerr(err, t)
if newval2i != 1337 {
t.Error("The expected increment value is 1337 but it is", newval2)
}
// Fetch the value and verify same as what we got back from IncrST()
err = dbkey.ValST(tptoken, nil, &dbval1)
Assertnoerr(err, t)
newval1, err = dbval1.ValStr(tptoken, nil)
if newval1 != newval2 {
t.Error("Returned and post-increment fetch values not same - db :", newval1,
" returned: ", newval2)
}
}
func TestIncrSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr, incrval, retval yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
incrval.Alloc(16)
retval.Alloc(128)
err = incrval.SetValStr(tptoken, nil, "")
Assertnoerr(err, t)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The IncrST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The IncrST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The IncrST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The IncrST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The IncrST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_NUMOFLOW
dbkey.Alloc(8, 1, 8)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^ivar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, &errstr, 0, "newsub")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 1)
Assertnoerr(err, t)
err = incrval.SetValStr(tptoken, &errstr, "1E12345")
Assertnoerr(err, t)
err = dbkey.IncrST(tptoken, &errstr, &incrval, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_NUMOFLOW != errcode {
t.Error("The IncrE() errorcode for incrementing by 1E12345 expected to be", yottadb.YDB_ERR_NUMOFLOW, "but was", errcode)
}
}
func TestLockIncrSt(t *testing.T) {
var dbkey yottadb.KeyT
var tptoken uint64 = yottadb.NOTTP
var err error
var incrval, dbval1, dbval2 yottadb.BufferT
var timeout uint64
var errors int
defer dbkey.Free()
dbkey.Alloc(VarSiz, AryDim, SubSiz)
defer dbval1.Free()
dbval1.Alloc(128)
defer dbval2.Free()
dbval2.Alloc(128)
defer incrval.Free()
incrval.Alloc(16)
// Increment a given lock 3 times then start decrementing it and after each check, the lock
// should still be there until we've decremented the 3rd time after which the lock should
// NOT be there.
//
// First, create the key for the lock we are incrementally locking/unlocking
err = dbkey.Varnm.SetValStr(tptoken, nil, "^lvar")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 0, "Don't")
Assertnoerr(err, t)
err = dbkey.Subary.SetValStr(tptoken, nil, 1, "Panic!")
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 2)
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, nil, timeout) // Lock it 3 times
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, nil, timeout) // Lock it 3 times
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, nil, timeout) // Lock it 3 times
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
// Start decrementing the lock checking each time it still exists
err = dbkey.LockDecrST(tptoken, nil)
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
err = dbkey.LockDecrST(tptoken, nil)
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
err = dbkey.LockDecrST(tptoken, nil) // Lock should be gone now
Assertnoerr(err, t)
if VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, false, t) {
t.Error("Lock should be gone but is not")
errors++
}
err = yottadb.LockST(tptoken, nil, 0) // Release all locks
Assertnoerr(err, t)
}
func TestLockIncrSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, 0)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The LockIncrST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, 0)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The LockIncrST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, 0)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The LockIncrST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, 0)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The LockIncrST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 35, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 35; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 35)
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, 0)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The LockIncrST() errorcode for node with 35 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_TIME2LONG
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
err = dbkey.LockIncrST(tptoken, &errstr, yottadb.YDB_MAX_TIME_NSEC+1)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_TIME2LONG != errcode {
t.Error("The LockIncrE() errorcode for timeout of YDB_ERR_MAX_TIME_NSEC+1 expected to be", yottadb.YDB_ERR_TIME2LONG, "but was", errcode)
}
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.LockDecrST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The LockDecrST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.LockDecrST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The LockDecrST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.LockDecrST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The LockDecrST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.LockDecrST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The LockDecrST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 35, 2)
dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
for i := 0; i < 35; i++ {
dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
}
dbkey.Subary.SetElemUsed(tptoken, &errstr, 35)
err = dbkey.LockDecrST(tptoken, &errstr)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The LockDecrST() errorcode for node with 35 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestNodeNextST(t *testing.T) {
var dbkey yottadb.KeyT
var tptoken uint64 = yottadb.NOTTP
var err error
var i, errors int
var incrval, dbval1, dbval2 yottadb.BufferT
var sublst yottadb.BufferTArray
defer dbkey.Free()
dbkey.Alloc(VarSiz, AryDim, SubSiz)
defer dbval1.Free()
dbval1.Alloc(128)
defer dbval2.Free()
dbval2.Alloc(128)
defer incrval.Free()
incrval.Alloc(16)
defer sublst.Free()
sublst.Alloc(AryDim, SubSiz)
// Need to start with a clean slate (empty database) so do that first
Dbdeleteall(tptoken, nil, &errors, t)
var subs [3][]string
subs[0] = []string{"sub0a", "sub0b", "sub0c", "sub0d"}
subs[1] = []string{"sub1a", "sub1b"}
subs[2] = []string{"sub2a", "sub2b", "sub2c"}
err = yottadb.SetValE(tptoken, nil, "val0", "^node", subs[0])
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, nil, "val1", "^node", subs[1])
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, nil, "val2", "^node", subs[2])
Assertnoerr(err, t)
err = dbkey.Varnm.SetValStr(tptoken, nil, "^node") // Initial search var
Assertnoerr(err, t)
err = dbkey.Subary.SetElemUsed(tptoken, nil, 0)
Assertnoerr(err, t)
err = sublst.SetElemUsed(tptoken, nil, AryDim)
Assertnoerr(err, t)
// Loop to test NodeNextST()
if DebugFlag {
t.Log(" Starting NodeNextST() loop")
}
for i = 0; ; i++ {
err = sublst.SetElemUsed(tptoken, nil, AryDim) // Reset each round to (re)set how many array elems are available
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, nil, &sublst)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("FAIL - NodeNextST() failed:", err)
}
Assertnoerr(err, t)
}
// Check if subscript list is as expected
retsubsp, err := Buftary2strary(tptoken, nil, &sublst, t)
Assertnoerr(err, t)
if DebugFlag {
t.Logf(" Retsubsp: %v [len=%d]\n", *retsubsp, len(*retsubsp))
}
if !Cmpstrary(retsubsp, &subs[i]) {
t.Error(" Expected subscript array and return array not the same for index", i)
t.Log(" Expected:", subs[i])
t.Log(" Returned:", *retsubsp)
}
// Move sublst into dbkey.Subary using the retsubsp subscript array as the source
for j, v := range *retsubsp {
err = dbkey.Subary.SetValStr(tptoken, nil, uint32(j), v)
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, nil, uint32(len(*retsubsp)))
Assertnoerr(err, t)
}
if 3 != i {
t.Errorf("Unexpected NodeNextST() loop count - expected 3 but got %d\n", i)
}
// Next run the loop in reverse to refetch things using NodePrev()
dbkey.Subary.SetValStr(tptoken, nil, 0, "~~~~~~~~~~") // Set a high-subscript so we find the "last node" doing a prev
dbkey.Subary.SetElemUsed(tptoken, nil, 1)
if DebugFlag {
t.Log(" Starting NodePrevST() loop")
}
for i = 2; ; i-- {
err = sublst.SetElemUsed(tptoken, nil, AryDim) // Reset each round to (re)set how many array elems are available
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, nil, &sublst)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("NodePrevST() failed:", err)
}
Assertnoerr(err, t)
}
// Check if subscript list is as expected
retsubsp, err := Buftary2strary(tptoken, nil, &sublst, t)
Assertnoerr(err, t)
if DebugFlag {
t.Logf(" Retsubsp: %v [len=%d]\n", *retsubsp, len(*retsubsp))
}
if !Cmpstrary(retsubsp, &subs[i]) {
t.Error(" Expected subscript array and return array not the same for index", i)
t.Log(" Expected:", subs[i])
t.Log(" Returned:", *retsubsp)
}
// Move sublst into dbkey.Subary using the retsubsp subscript array as the source
for j, v := range *retsubsp {
err = dbkey.Subary.SetValStr(tptoken, nil, uint32(j), v)
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, nil, uint32(len(*retsubsp)))
Assertnoerr(err, t)
}
if -1 != i {
t.Errorf("Unexpected NodePrevST() loop count - expected -1 but got %d\n", i)
}
}
func TestNodeNextSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
var retval yottadb.BufferTArray
var dbkey yottadb.KeyT
errstr.Alloc(128)
retval.Alloc(1, 128)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, &errstr, &retval)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The NodeNextST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The NodeNextST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The NodeNextST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The NodeNextST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
err = dbkey.NodeNextST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The NodeNextST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The NodePrevST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The NodePrevST() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The NodePrevST() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The NodePrevST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)
}
err = dbkey.Subary.SetElemUsed(tptoken, &errstr, 32)
Assertnoerr(err, t)
err = dbkey.NodePrevST(tptoken, &errstr, &retval)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The NodePrevST() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestSetValST(t *testing.T) {
// Already tested in tests for IncrST(), TpST() directly and several other tests using SetValST()
}
func TestSetValSTErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr, value yottadb.BufferT
var dbkey yottadb.KeyT
errstr.Alloc(128)
value.Alloc(128)
err = value.SetValStr(tptoken, &errstr, "A Value")
Assertnoerr(err, t)
// YDB_ERR_INVVARNAME
dbkey.Alloc(1, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "^")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, &errstr, &value)
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The SetValST() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_SVNOSET
dbkey.Alloc(8, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$ZCHSET")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, &errstr, &value)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_SVNOSET != errcode {
t.Error("The SetValE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_SVNOSET, "but was", errcode)
}
// YDB_ERR_INVSVN
dbkey.Alloc(16, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "$NOTATHING")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, &errstr, &value)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The SetValE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
dbkey.Alloc(64, 0, 0)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0")
Assertnoerr(err, t)
err = dbkey.SetValST(tptoken, &errstr, &value)
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The SetValST() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
dbkey.Alloc(1, 32, 2)
err = dbkey.Varnm.SetValStr(tptoken, &errstr, "a")
Assertnoerr(err, t)
for i := 0; i < 32; i++ {
err = dbkey.Subary.SetValStr(tptoken, &errstr, uint32(i), strconv.Itoa(i))
Assertnoerr(err, t)