8 require 'test/zentest_assertions'
16 attr_reader :lasterr, :lasterrstr
19 @responses = Hash.new { |h,k| h[k] = [] }
24 def method_missing(meth, *args)
26 if meth =~ /(.*)=$/ then
27 @responses[$1] << args.first
29 response = @responses[meth].shift
32 @lasterr = response.first
33 @lasterrstr = response.last
48 def initialize(read = '', write = StringIO.new)
49 @read_s = read.class.method_defined?(:sysread) ? read : StringIO.new(read)
56 @write_s.sync = do_sync
57 @read_s.sync = do_sync
74 ['AF_INET', 6001, 'localhost', '127.0.0.1']
81 def sysread(bytes, buf = '')
82 @read_s.sysread bytes, buf
85 def recv_nonblock(bytes, flags = 0)
86 ret = @read_s.sysread(bytes)
87 # Ruby doesn't expose pread(2)
88 if (flags & Socket::MSG_PEEK) != 0
89 @read_s.sysseek(-ret.size, IO::SEEK_CUR)
93 alias_method :recv, :recv_nonblock
100 @write_s.syswrite data
105 class MogileFS::Client
106 attr_writer :readonly
113 attr_accessor :connections
114 attr_accessor :sockets
119 raise Errno::ECONNREFUSED if @sockets.empty?
120 @connections << [host, port]
130 class TestMogileFS < Test::Unit::TestCase
132 undef_method :default_test
135 @tempdir = File.join Dir.tmpdir, "test_mogilefs_#{$$}"
136 @root = File.join @tempdir, 'root'
137 FileUtils.mkdir_p @root
139 @client = @klass.new :hosts => ['kaa:6001'], :domain => 'test',
141 @backend = FakeBackend.new
142 @client.instance_variable_set '@backend', @backend
144 TCPSocket.sockets = []
145 TCPSocket.connections = []
149 FileUtils.rm_rf @tempdir