-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_unified_tests.jl
845 lines (681 loc) · 28.8 KB
/
basic_unified_tests.jl
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
@testsetup module ReadWriteCases
using RustyObjectStore: get_object!, put_object, get_object_stream, put_object_stream,
AbstractConfig, delete_object, list_objects, list_objects_stream, next_chunk!, finish!
using CodecZlib
using RustyObjectStore
using Test: @testset, @test, @test_throws
export run_read_write_test_cases, run_stream_test_cases, run_sanity_test_cases, run_list_test_cases
function run_stream_test_cases(config::AbstractConfig)
# ReadStream
@testset "ReadStream small readbytes!" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^10; # 200 B
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 200
buffer = Vector{UInt8}(undef, 200)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 200
N = 19
buf = Vector{UInt8}(undef, N)
copyto!(buf, 1, buffer, 1, N)
@test buf == view(codeunits(multicsv), 1:N)
ioobj = get_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
readbytes!(ioobj, buf, N)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream large readbytes!" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20 MB
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 20 * 1000 * 1000
buffer = Vector{UInt8}(undef, 20 * 1000 * 1000)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 20 * 1000 * 1000
N = 1024*1024
buf = Vector{UInt8}(undef, N)
copyto!(buf, 1, buffer, 1, N)
@test buf == view(codeunits(multicsv), 1:N)
ioobj = get_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
readbytes!(ioobj, buf, N)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream small unsafe_read" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^10; # 200 B
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 200
buffer = Vector{UInt8}(undef, 200)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 200
N = 19
buf = Vector{UInt8}(undef, N)
copyto!(buf, 1, buffer, 1, N)
@test buf == view(codeunits(multicsv), 1:N)
ioobj = get_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
unsafe_read(ioobj, pointer(buf), nb)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream large unsafe_read" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20 MB
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 20 * 1000 * 1000
buffer = Vector{UInt8}(undef, 20 * 1000 * 1000)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 20 * 1000 * 1000
N = 1024*1024
buf = Vector{UInt8}(undef, N)
copyto!(buf, 1, buffer, 1, N)
@test buf == view(codeunits(multicsv), 1:N)
ioobj = get_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
unsafe_read(ioobj, pointer(buf), nb)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream small readbytes! decompress" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^100; # 2000 B
codec = ZlibCompressor()
CodecZlib.initialize(codec)
compressed = transcode(codec, codeunits(multicsv))
nbytes_written = put_object(compressed, "test.csv.gz", config)
@test nbytes_written == length(compressed)
CodecZlib.finalize(codec)
buffer = Vector{UInt8}(undef, length(compressed))
nbytes_read = get_object!(buffer, "test.csv.gz", config)
@test nbytes_read == length(compressed)
N = 19
buf = Vector{UInt8}(undef, N)
ioobj = get_object_stream("test.csv.gz", config; decompress="zlib")
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
readbytes!(ioobj, buf, N)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream large readbytes! decompress" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20 MB
codec = ZlibCompressor()
CodecZlib.initialize(codec)
compressed = transcode(codec, codeunits(multicsv))
nbytes_written = put_object(compressed, "test.csv.gz", config)
@test nbytes_written == length(compressed)
CodecZlib.finalize(codec)
buffer = Vector{UInt8}(undef, length(compressed))
nbytes_read = get_object!(buffer, "test.csv.gz", config)
@test nbytes_read == length(compressed)
N = 1024*1024
buf = Vector{UInt8}(undef, N)
ioobj = get_object_stream("test.csv.gz", config; decompress="zlib")
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv) - i : N
readbytes!(ioobj, buf, N)
@test view(buf, 1:nb) == view(codeunits(multicsv), i:i+nb-1)
i += N
end
close(ioobj)
end
@testset "ReadStream empty file readbytes! decompress" begin
multicsv = "" # 0 MB
codec = ZlibCompressor()
CodecZlib.initialize(codec)
compressed = transcode(codec, codeunits(multicsv))
nbytes_written = put_object(compressed, "test.csv.gz", config)
@test nbytes_written == length(compressed)
CodecZlib.finalize(codec)
buffer = Vector{UInt8}(undef, length(compressed))
nbytes_read = get_object!(buffer, "test.csv.gz", config)
@test nbytes_read == length(compressed)
N = 1024*1024
buf = ones(UInt8, N)
ioobj = get_object_stream("test.csv.gz", config; decompress="zlib")
readbytes!(ioobj, buf, N)
@test eof(ioobj)
@test all(buf .== 1)
close(ioobj)
end
@testset "ReadStream empty file readbytes!" begin
multicsv = "" # 0 MB
data = codeunits(multicsv)
nbytes_written = put_object(data, "test.csv", config)
@test nbytes_written == length(data)
buffer = Vector{UInt8}(undef, length(data))
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == length(data)
N = 1024*1024
buf = ones(UInt8, N)
ioobj = get_object_stream("test.csv", config)
readbytes!(ioobj, buf, N)
@test eof(ioobj)
@test all(buf .== 1)
close(ioobj)
end
@testset "ReadStream empty file unsafe_read" begin
multicsv = "" # 0 MB
data = codeunits(multicsv)
nbytes_written = put_object(data, "test.csv", config)
@test nbytes_written == length(data)
buffer = Vector{UInt8}(undef, length(data))
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == length(data)
N = 1024*1024
buf = ones(UInt8, N)
ioobj = get_object_stream("test.csv", config)
@test_throws EOFError unsafe_read(ioobj, pointer(buf), N)
@test eof(ioobj)
@test all(buf .== 1)
close(ioobj)
end
@testset "ReadStream read last byte" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20 MB
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 20 * 1000 * 1000
buffer = Vector{UInt8}(undef, 20 * 1000 * 1000)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 20 * 1000 * 1000
N = length(multicsv) - 1
buf = Vector{UInt8}(undef, N)
copyto!(buf, 1, buffer, 1, N)
@test buf == view(codeunits(multicsv), 1:N)
ioobj = get_object_stream("test.csv", config)
readbytes!(ioobj, buf, N)
@test buf == view(codeunits(multicsv), 1:N)
@test read(ioobj, UInt8) == UInt8(last(multicsv))
close(ioobj)
end
@testset "ReadStream read bytes into file" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20 MB
nbytes_written = put_object(codeunits(multicsv), "test.csv", config)
@test nbytes_written == 20 * 1000 * 1000
buffer = Vector{UInt8}(undef, 20 * 1000 * 1000)
nbytes_read = get_object!(buffer, "test.csv", config)
@test nbytes_read == 20 * 1000 * 1000
(path, io) = mktemp()
rs = get_object_stream("test.csv", config)
write(io, rs)
close(io)
io = open(path, "r")
filedata = read(io)
@test length(filedata) == length(codeunits(multicsv))
close(io)
@test buffer == codeunits(multicsv)
close(rs)
end
# WriteStream
@testset "WriteStream write small bytes" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^100; # 2000 B
N = 2000
ws = put_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv)-i+1 : N
buf = Vector{UInt8}(undef, nb)
copyto!(buf, 1, codeunits(multicsv), i, nb)
write(ws, buf)
i += N
end
close(ws)
rs = get_object_stream("test.csv", config)
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
@testset "WriteStream write large bytes" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20MB
N = 2000000
ws = put_object_stream("test.csv", config)
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv)-i+1 : N
buf = Vector{UInt8}(undef, nb)
copyto!(buf, 1, codeunits(multicsv), i, nb)
write(ws, buf)
i += N
end
close(ws)
rs = get_object_stream("test.csv", config)
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
@testset "WriteStream write empty" begin
multicsv = ""; # 0 B
ws = put_object_stream("test.csv", config)
write(ws, codeunits(multicsv))
close(ws)
rs = get_object_stream("test.csv", config)
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
@testset "WriteStream write small bytes and compress" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^100; # 2000 B
N = 2000
ws = put_object_stream("test.csv.gz", config; compress="gzip")
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv)-i+1 : N
buf = Vector{UInt8}(undef, nb)
copyto!(buf, 1, codeunits(multicsv), i, nb)
write(ws, buf)
i += N
end
close(ws)
rs = get_object_stream("test.csv.gz", config; decompress="gzip")
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
@testset "WriteStream write large bytes and compress" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20MB
N = 2000000
ws = put_object_stream("test.csv", config; compress="gzip")
i = 1
while i < sizeof(multicsv)
nb = i + N > length(multicsv) ? length(multicsv)-i+1 : N
buf = Vector{UInt8}(undef, nb)
copyto!(buf, 1, codeunits(multicsv), i, nb)
write(ws, buf)
i += N
end
close(ws)
rs = get_object_stream("test.csv", config; decompress="gzip")
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
@testset "WriteStream write bytes from file" begin
multicsv = "1,2,3,4,5,6,7,8,9,1\n"^1000000; # 20MB
N = 2000000
(path, io) = mktemp()
written = write(io, codeunits(multicsv))
@test written == length(codeunits(multicsv))
close(io)
ws = put_object_stream("test.csv", config)
io = open(path, "r")
write(ws, io)
close(ws)
rs = get_object_stream("test.csv", config)
objdata = read(rs)
@test objdata == codeunits(multicsv)
end
end
function run_read_write_test_cases(read_config::AbstractConfig, write_config::AbstractConfig = read_config)
@testset "0B file, 0B buffer" begin
buffer = Vector{UInt8}(undef, 0)
nbytes_written = put_object(codeunits(""), "empty.csv", write_config)
@test nbytes_written == 0
nbytes_read = get_object!(buffer, "empty.csv", read_config)
@test nbytes_read == 0
end
@testset "0B file, 1KB buffer" begin
buffer = Vector{UInt8}(undef, 1000)
nbytes_written = put_object(codeunits(""), "empty.csv", write_config)
@test nbytes_written == 0
nbytes_read = get_object!(buffer, "empty.csv", read_config)
@test nbytes_read == 0
end
@testset "100B file, 100B buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 5
buffer = Vector{UInt8}(undef, 100)
@assert sizeof(input) == 100
@assert sizeof(buffer) == sizeof(input)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 100
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 100
@test String(buffer[1:nbytes_read]) == input
end
@testset "100B file, 1KB buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 5
buffer = Vector{UInt8}(undef, 1000)
@assert sizeof(input) == 100
@assert sizeof(buffer) > sizeof(input)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 100
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 100
@test String(buffer[1:nbytes_read]) == input
end
@testset "1MB file, 1MB buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 50_000
buffer = Vector{UInt8}(undef, 1_000_000)
@assert sizeof(input) == 1_000_000 == sizeof(buffer)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 1_000_000
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 1_000_000
@test String(buffer[1:nbytes_read]) == input
end
@testset "delete_object" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 5
buffer = Vector{UInt8}(undef, 100)
@assert sizeof(input) == 100
@assert sizeof(buffer) == sizeof(input)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 100
delete_object("test100B.csv", write_config)
try
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test false # should throw
catch e
@test e isa RustyObjectStore.GetException
@test occursin("not found", e.msg)
end
end
# Large files should use multipart upload / download requests
@testset "20MB file, 20MB buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 1_000_000
buffer = Vector{UInt8}(undef, 20_000_000)
@assert sizeof(input) == 20_000_000 == sizeof(buffer)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 20_000_000
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 20_000_000
@test String(buffer[1:nbytes_read]) == input
end
@testset "20MB file, 21MB buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 1_000_000
buffer = Vector{UInt8}(undef, 21_000_000)
@assert sizeof(input) < sizeof(buffer)
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 20_000_000
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 20_000_000
@test String(buffer[1:nbytes_read]) == input
end
@testset "1MB file, 20MB buffer" begin
input = "1,2,3,4,5,6,7,8,9,1\n" ^ 50_000
nbytes_written = put_object(codeunits(input), "test100B.csv", write_config)
@test nbytes_written == 1_000_000
# Edge case for multpart download, file is less than threshold but buffer is greater
buffer = Vector{UInt8}(undef, 20_000_000)
nbytes_read = get_object!(buffer, "test100B.csv", read_config)
@test nbytes_read == 1_000_000
@test String(buffer[1:nbytes_read]) == input
end
end
function run_sanity_test_cases(read_config::AbstractConfig, write_config::AbstractConfig = read_config)
@testset "Round trip" begin
input = "1,2,3,4,5,6,7,8,9,1\n"
buffer = Vector{UInt8}(undef, length(input))
nbytes_written = put_object(codeunits(input), "roundtrip.csv", write_config)
@test nbytes_written == length(input)
nbytes_read = get_object!(buffer, "roundtrip.csv", read_config)
@test nbytes_read == length(input)
@test String(buffer[1:nbytes_read]) == input
end
end
function within_margin(a, b, margin = 32)
return all(abs.(a .- b) .<= margin)
end
function run_list_test_cases(config::AbstractConfig; strict_entry_size=true)
margin = strict_entry_size ? 0 : 32
@testset "basic listing" begin
for i in range(10; step=10, length=5)
nbytes_written = put_object(codeunits(repeat('=', i)), "list/$(i).csv", config)
@test nbytes_written == i
end
entries = list_objects("list/", config)
@test length(entries) == 5
@test within_margin(map(x -> x.size, entries), range(10; step=10, length=5), margin)
@test map(x -> x.location, entries) == ["list/10.csv", "list/20.csv", "list/30.csv", "list/40.csv", "list/50.csv"]
end
@testset "basic prefix" begin
for i in range(10; step=10, length=5)
nbytes_written = put_object(codeunits(repeat('=', i)), "other/$(i).csv", config)
@test nbytes_written == i
end
for i in range(110; step=10, length=5)
nbytes_written = put_object(codeunits(repeat('=', i)), "other/prefix/$(i).csv", config)
@test nbytes_written == i
end
entries = list_objects("other/", config)
@test length(entries) == 10
entries = list_objects("other/prefix/", config)
@test length(entries) == 5
@test within_margin(map(x -> x.size, entries), range(110; step=10, length=5), margin)
@test map(x -> x.location, entries) ==
["other/prefix/110.csv", "other/prefix/120.csv", "other/prefix/130.csv", "other/prefix/140.csv", "other/prefix/150.csv"]
entries = list_objects("other/nonexistent/", config)
@test length(entries) == 0
entries = list_objects("other/p/", config)
@test length(entries) == 0
entries = list_objects("other/prefix/150.csv", config)
@test length(entries) == 1
@test map(x -> x.location, entries) == ["other/prefix/150.csv"]
end
@testset "list empty entries" begin
for i in range(10; step=10, length=3)
nbytes_written = put_object(codeunits(""), "list_empty/$(i).csv", config)
@test nbytes_written == 0
end
entries = list_objects("list_empty/", config)
@test length(entries) == 3
@test within_margin(sort(map(x -> x.size, entries)), [0, 0, 0], margin)
@test map(x -> x.location, entries) == ["list_empty/10.csv", "list_empty/20.csv", "list_empty/30.csv"]
end
@testset "list stream" begin
data = range(10; step=10, length=1001)
for i in data
nbytes_written = put_object(codeunits(repeat('=', i)), "list/$(i).csv", config)
@test nbytes_written == i
end
stream = list_objects_stream("list/", config)
entries = next_chunk!(stream)
@test length(entries) == max_entries_per_chunk()
one_entry = next_chunk!(stream)
@test length(one_entry) == 1
@test isnothing(next_chunk!(stream))
append!(entries, one_entry)
@test within_margin(sort(map(x -> x.size, entries)), data, margin)
@test sort(map(x -> x.location, entries)) == sort(map(x -> "list/$(x).csv", data))
end
@testset "list stream finish" begin
data = range(10; step=10, length=1001)
for i in data
nbytes_written = put_object(codeunits(repeat('=', i)), "list/$(i).csv", config)
@test nbytes_written == i
end
stream = list_objects_stream("list/", config)
entries = next_chunk!(stream)
@test length(entries) == max_entries_per_chunk()
@test finish!(stream)
@test isnothing(next_chunk!(stream))
@test !finish!(stream)
end
@testset "list stream offset" begin
key(x) = "offset/$(lpad(x, 10, "0")).csv"
data = range(10; step=10, length=101)
for i in data
nbytes_written = put_object(codeunits(repeat('=', i)), key(i), config)
@test nbytes_written == i
end
stream = list_objects_stream("offset/", config; offset=key(data[50]))
entries = next_chunk!(stream)
@test length(entries) == 51
@test isnothing(next_chunk!(stream))
@test within_margin(sort(map(x -> x.size, entries)), data[51:end], margin)
@test sort(map(x -> x.location, entries)) == sort(map(x -> key(x), data[51:end]))
end
end
end # @testsetup
@testitem "Basic BlobStorage usage" setup=[InitializeObjectStore, ReadWriteCases] begin
using CloudBase.CloudTest: Azurite
using RustyObjectStore: AzureConfig, ClientOptions
# For interactive testing, use Azurite.run() instead of Azurite.with()
# conf, p = Azurite.run(; debug=true, public=false); atexit(() -> kill(p))
Azurite.with(; debug=true, public=false) do conf
_credentials, _container = conf
base_url = _container.baseurl
config = AzureConfig(;
storage_account_name=_credentials.auth.account,
container_name=_container.name,
storage_account_key=_credentials.auth.key,
host=base_url
)
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config)
config_padded = AzureConfig(;
storage_account_name=_credentials.auth.account * " \n",
container_name=_container.name * " \n",
storage_account_key=_credentials.auth.key * " \n",
host=base_url * " \n"
)
run_sanity_test_cases(config_padded)
end # Azurite.with
end # @testitem
# NOTE: PUT on azure always requires credentials, while GET on public containers doesn't
@testitem "Basic BlobStorage usage (anonymous read enabled)" setup=[InitializeObjectStore, ReadWriteCases] begin
using CloudBase.CloudTest: Azurite
using RustyObjectStore: AzureConfig, ClientOptions
# For interactive testing, use Azurite.run() instead of Azurite.with()
# conf, p = Azurite.run(; debug=true, public=true); atexit(() -> kill(p))
Azurite.with(; debug=true, public=true) do conf
_credentials, _container = conf
base_url = _container.baseurl
config = AzureConfig(;
storage_account_name=_credentials.auth.account,
container_name=_container.name,
storage_account_key=_credentials.auth.key,
host=base_url
)
config_no_creds = AzureConfig(;
storage_account_name=_credentials.auth.account,
container_name=_container.name,
host=base_url
)
run_read_write_test_cases(config_no_creds, config)
end # Azurite.with
end # @testitem
@testitem "Basic AWS S3 usage" setup=[InitializeObjectStore, ReadWriteCases] begin
using CloudBase.CloudTest: Minio
using RustyObjectStore: AWSConfig, ClientOptions
# For interactive testing, use Minio.run() instead of Minio.with()
# conf, p = Minio.run(; debug=true, public=false); atexit(() -> kill(p))
Minio.with(; debug=true, public=false) do conf
_credentials, _container = conf
base_url = _container.baseurl
default_region = "us-east-1"
config = AWSConfig(;
region=default_region,
bucket_name=_container.name,
access_key_id=_credentials.access_key_id,
secret_access_key=_credentials.secret_access_key,
host=base_url
)
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config)
config_padded = AWSConfig(;
region=default_region * " \n",
bucket_name=_container.name * " \n",
access_key_id=_credentials.access_key_id * " \n",
secret_access_key=_credentials.secret_access_key * " \n",
host=base_url * " \n"
)
run_sanity_test_cases(config_padded)
end # Minio.with
end # @testitem
@testitem "Basic AWS S3 usage (anonymous read enabled)" setup=[InitializeObjectStore, ReadWriteCases] begin
using CloudBase.CloudTest: Minio
using RustyObjectStore: AWSConfig, ClientOptions
# For interactive testing, use Minio.run() instead of Azurite.with()
# conf, p = Minio.run(; debug=true, public=true); atexit(() -> kill(p))
Minio.with(; debug=true, public=true) do conf
_credentials, _container = conf
base_url = _container.baseurl
default_region = "us-east-1"
config = AWSConfig(;
region=default_region,
bucket_name=_container.name,
access_key_id=_credentials.access_key_id,
secret_access_key=_credentials.secret_access_key,
host=base_url
)
config_no_creds = AWSConfig(;
region=default_region,
bucket_name=_container.name,
host=base_url
)
run_read_write_test_cases(config_no_creds, config)
end # Minio.with
end # @testitem
@testitem "Basic Snowflake Stage usage: AWS, non-encrypted" setup=[InitializeObjectStore, SnowflakeMock, ReadWriteCases] begin
using CloudBase.CloudTest: Minio
using RustyObjectStore: SnowflakeConfig, ClientOptions
# For interactive testing, use Minio.run() instead of Minio.with()
# conf, p = Minio.run(; debug=true, public=false); atexit(() -> kill(p))
Minio.with(; debug=true, public=false) do conf
credentials, container = conf
with(SFGatewayMock(credentials, container, false)) do config::SnowflakeConfig
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config)
run_sanity_test_cases(config)
end
end # Minio.with
end # @testitem
@testitem "Basic Snowflake Stage usage: AWS, encrypted" setup=[InitializeObjectStore, SnowflakeMock, ReadWriteCases] begin
using CloudBase.CloudTest: Minio
using RustyObjectStore: SnowflakeConfig, ClientOptions
# For interactive testing, use Minio.run() instead of Minio.with()
# conf, p = Minio.run(; debug=true, public=false); atexit(() -> kill(p))
Minio.with(; debug=true, public=false) do conf
credentials, container = conf
with(SFGatewayMock(credentials, container, true)) do config::SnowflakeConfig
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config; strict_entry_size=false)
run_sanity_test_cases(config)
end
end # Minio.with
end # @testitem
@testitem "Basic Snowflake Stage usage: Azure, non-encrypted" setup=[InitializeObjectStore, SnowflakeMock, ReadWriteCases] begin
using CloudBase.CloudTest: Azurite
using RustyObjectStore: SnowflakeConfig, ClientOptions
# For interactive testing, use Azurite.run() instead of Azurite.with()
# conf, p = Azurite.run(; debug=true, public=false); atexit(() -> kill(p))
Azurite.with(; debug=true, public=false) do conf
credentials, container = conf
with(SFGatewayMock(credentials, container, false)) do config::SnowflakeConfig
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config)
run_sanity_test_cases(config)
end
end # Azurite.with
end # @testitem
@testitem "Basic Snowflake Stage usage: Azure, encrypted" setup=[InitializeObjectStore, SnowflakeMock, ReadWriteCases] begin
using CloudBase.CloudTest: Azurite
using RustyObjectStore: SnowflakeConfig, ClientOptions
# For interactive testing, use Azurite.run() instead of Azurite.with()
# conf, p = Azurite.run(; debug=true, public=false); atexit(() -> kill(p))
Azurite.with(; debug=true, public=false) do conf
credentials, container = conf
with(SFGatewayMock(credentials, container, true)) do config::SnowflakeConfig
run_read_write_test_cases(config)
run_stream_test_cases(config)
run_list_test_cases(config; strict_entry_size=false)
run_sanity_test_cases(config)
end
end # Azurite.with
end # @testitem