baza.rb 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +7 -4
- data/test/test_baza-rb.rb +29 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 308b7b84631ae61841fb9d58192f6c257fc5b60d68dd8b95c01caf5cf53f39a8
|
4
|
+
data.tar.gz: ddafe4b9c94292616c5a9588b057869b63ccfce655954bd87f79bb54182ac800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4077997c0ac3aea8d026c48fd63472f9c4d146f091656552a7ae3a72814fa507e915c2d75fc93d76fdb85640235503c611bc82de5489406449276023edd5e3e
|
7
|
+
data.tar.gz: e39d0fbdc6dadf2c53edc647c4ef7acf9194af9d9968299af4a7a2fafbbae6e7892a811e0337049e742f5e2353db8d86e7c2370291b3cde32e9a1d0ab5fda0a6
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -322,6 +322,7 @@ class BazaRb
|
|
322
322
|
# @raise [ServerFailure] If the save operation fails
|
323
323
|
def durable_save(id, file, chunk_size: 1_000_000)
|
324
324
|
raise 'The ID of the durable is nil' if id.nil?
|
325
|
+
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
325
326
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
326
327
|
raise 'The "file" of the durable is nil' if file.nil?
|
327
328
|
raise "The file '#{file}' is absent" unless File.exist?(file)
|
@@ -338,6 +339,7 @@ class BazaRb
|
|
338
339
|
# @raise [ServerFailure] If the load operation fails
|
339
340
|
def durable_load(id, file)
|
340
341
|
raise 'The ID of the durable is nil' if id.nil?
|
342
|
+
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
341
343
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
342
344
|
raise 'The "file" of the durable is nil' if file.nil?
|
343
345
|
elapsed(@loog) do
|
@@ -353,6 +355,7 @@ class BazaRb
|
|
353
355
|
# @raise [ServerFailure] If the lock operation fails
|
354
356
|
def durable_lock(id, owner)
|
355
357
|
raise 'The ID of the durable is nil' if id.nil?
|
358
|
+
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
356
359
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
357
360
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
358
361
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
@@ -372,6 +375,7 @@ class BazaRb
|
|
372
375
|
# @raise [ServerFailure] If the unlock operation fails
|
373
376
|
def durable_unlock(id, owner)
|
374
377
|
raise 'The ID of the durable is nil' if id.nil?
|
378
|
+
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
375
379
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
376
380
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
377
381
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
@@ -732,9 +736,9 @@ class BazaRb
|
|
732
736
|
def download(uri, file)
|
733
737
|
FileUtils.mkdir_p(File.dirname(file))
|
734
738
|
FileUtils.rm_f(file)
|
739
|
+
FileUtils.touch(file)
|
735
740
|
chunk = 0
|
736
741
|
elapsed(@loog) do
|
737
|
-
pos = 0
|
738
742
|
loop do
|
739
743
|
request = Typhoeus::Request.new(
|
740
744
|
uri.to_s,
|
@@ -742,7 +746,7 @@ class BazaRb
|
|
742
746
|
headers: headers.merge(
|
743
747
|
'Accept' => '*',
|
744
748
|
'Accept-Encoding' => 'gzip',
|
745
|
-
'Range' => "bytes=#{
|
749
|
+
'Range' => "bytes=#{File.size(file)}-"
|
746
750
|
),
|
747
751
|
connecttimeout: @timeout,
|
748
752
|
timeout: @timeout
|
@@ -782,9 +786,8 @@ class BazaRb
|
|
782
786
|
_b, e = range.split('-')
|
783
787
|
raise "Range is not valid (#{range.inspect})" unless e.match?(/^[0-9]+$/)
|
784
788
|
len = ret.headers['Content-Length'].to_i
|
785
|
-
pos = e.to_i
|
786
|
-
pos += 1 unless len.zero?
|
787
789
|
break if e.to_i == total.to_i - 1
|
790
|
+
break if total == '0'
|
788
791
|
chunk += 1
|
789
792
|
sleep(1) if len.zero?
|
790
793
|
end
|
data/test/test_baza-rb.rb
CHANGED
@@ -459,7 +459,7 @@ class TestBazaRb < Minitest::Test
|
|
459
459
|
WebMock.disable_net_connect!
|
460
460
|
Dir.mktmpdir do |dir|
|
461
461
|
file = File.join(dir, 'test.txt')
|
462
|
-
File.write(file,
|
462
|
+
File.write(file, "\x00\x00 hi, dude! \x00\xFF\xFE\x12")
|
463
463
|
stub_request(:put, 'https://example.org:443/durables/42')
|
464
464
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
465
465
|
.to_return(status: 200)
|
@@ -471,11 +471,24 @@ class TestBazaRb < Minitest::Test
|
|
471
471
|
WebMock.disable_net_connect!
|
472
472
|
Dir.mktmpdir do |dir|
|
473
473
|
file = File.join(dir, 'loaded.txt')
|
474
|
+
data = "\x00\xE0 привет \x00\x00\xFF\xFE\x12"
|
474
475
|
stub_request(:get, 'https://example.org:443/durables/42')
|
475
476
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
476
|
-
.to_return(status: 200, body:
|
477
|
+
.to_return(status: 200, body: data, headers: {})
|
477
478
|
fake_baza.durable_load(42, file)
|
478
|
-
assert_equal(
|
479
|
+
assert_equal(data, File.read(file))
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_durable_load_empty_content
|
484
|
+
WebMock.disable_net_connect!
|
485
|
+
Dir.mktmpdir do |dir|
|
486
|
+
file = File.join(dir, 'loaded.txt')
|
487
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
488
|
+
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
489
|
+
.to_return(status: 206, body: '', headers: { 'Content-Range' => 'bytes 0-0/0' })
|
490
|
+
fake_baza.durable_load(42, file)
|
491
|
+
assert_equal('', File.read(file))
|
479
492
|
end
|
480
493
|
end
|
481
494
|
|
@@ -483,13 +496,17 @@ class TestBazaRb < Minitest::Test
|
|
483
496
|
WebMock.disable_net_connect!
|
484
497
|
Dir.mktmpdir do |dir|
|
485
498
|
file = File.join(dir, 'loaded.txt')
|
486
|
-
stub_request(:get, 'https://example.org:443/durables/42')
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
499
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
500
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
501
|
+
.to_return(status: 206, body: '', headers: { 'Content-Range' => 'bytes 0-0/*' })
|
502
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
503
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
504
|
+
.to_return(status: 206, body: 'привет', headers: { 'Content-Range' => 'bytes 0-11/25' })
|
505
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
506
|
+
.with(headers: { 'Range' => 'bytes=12-' })
|
507
|
+
.to_return(status: 206, body: " друг \xFF\xFE\x12", headers: { 'Content-Range' => 'bytes 12-24/25' })
|
491
508
|
fake_baza.durable_load(42, file)
|
492
|
-
assert_equal(
|
509
|
+
assert_equal("привет друг \xFF\xFE\x12", File.read(file))
|
493
510
|
end
|
494
511
|
end
|
495
512
|
|
@@ -681,7 +698,7 @@ class TestBazaRb < Minitest::Test
|
|
681
698
|
with_sinatra_server do |baza|
|
682
699
|
file = File.join(dir, 'x.txt')
|
683
700
|
baza.durable_load(42, file)
|
684
|
-
assert_equal(
|
701
|
+
assert_equal("Hello, \xFF\xFE\x12!", File.read(file))
|
685
702
|
end
|
686
703
|
end
|
687
704
|
end
|
@@ -701,13 +718,13 @@ class TestBazaRb < Minitest::Test
|
|
701
718
|
'I am alive'
|
702
719
|
end
|
703
720
|
get '/durables/42' do
|
704
|
-
|
721
|
+
\"Hello, \\xFF\\xFE\\x12!\"
|
705
722
|
end
|
706
723
|
"
|
707
724
|
)
|
708
725
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
709
726
|
host = '127.0.0.1'
|
710
|
-
qbash("bundle exec ruby #{Shellwords.escape(app)} -p #{port}", log: Loog::
|
727
|
+
qbash("bundle exec ruby #{Shellwords.escape(app)} -p #{port}", log: Loog::NULL, accept: nil) do
|
711
728
|
loop do
|
712
729
|
break if Typhoeus::Request.get("http://#{host}:#{port}").code == 200
|
713
730
|
sleep(0.1)
|