cleanup unused variable warnings
[ruby-mogilefs-client.git] / test / test_mogilefs_integration_large_pipe.rb
blob0ddffb2924dbe441cd7c3e9ff40bd662087794bf
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     th.join
27     @client.get_file_data("a") do |rd|
28       assert_equal(nr * junk.size, @client.store_file("b", nil, rd))
29     end
30     a = Thread.new { @client.get_file_data("a") { |rd| sha1read(rd) } }
31     b = Thread.new { @client.get_file_data("b") { |rd| sha1read(rd) } }
32     a = a.value
33     b = b.value
34     assert_equal a, b
35     assert_equal sha1, a
36   end
38   def sha1read(rd)
39     buf = ""
40     d = Digest::SHA1.new
41     while rd.read(16384, buf)
42       d << buf
43     end
44     d
45   end
46 end