http_file: remove unnecessary check
[ruby-mogilefs-client.git] / test / test_mogilefs_integration_large_pipe.rb
blob304ad16a52d3d5330b2e7d1f54ca3e28eb0d8472
1 # -*- encoding: binary -*-
2 require './test/integration'
3 require "digest/sha1"
5 class TestMogileFSLargePipe< TestMogIntegration
6   def setup
7     super
8     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
9   end
11   def test_large_pipe_test
12     junk = File.open("/dev/urandom") { |fp| fp.read(1024) }
13     junk *= 32
14     nr = rand(666) + 1024
15     r, w = IO.pipe
16     sha1 = Digest::SHA1.new
17     th = Thread.new do
18       nr.times do
19         sha1.update(junk)
20         w.write(junk)
21       end
22       w.close
23     end
24     assert_equal(nr * junk.size, @client.store_file("a", nil, r))
25     r.close
26     @client.get_file_data("a") do |rd|
27       assert_equal(nr * junk.size, @client.store_file("b", nil, rd))
28     end
29     a = Thread.new { @client.get_file_data("a") { |rd| sha1read(rd) } }
30     b = Thread.new { @client.get_file_data("b") { |rd| sha1read(rd) } }
31     a = a.value
32     b = b.value
33     assert_equal a, b
34     assert_equal sha1, a
35   end
37   def sha1read(rd)
38     buf = ""
39     d = Digest::SHA1.new
40     while rd.read(16384, buf)
41       d << buf
42     end
43     d
44   end
45 end