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)
57 @write_s.sync = do_sync
58 @read_s.sync = do_sync
75 ['AF_INET', 6001, 'localhost', '127.0.0.1']
82 def sysread(bytes, buf = '')
83 @read_s.sysread bytes, buf
86 def recv_nonblock(bytes, flags = 0)
87 ret = @read_s.sysread(bytes)
88 # Ruby doesn't expose pread(2)
89 if (flags & Socket::MSG_PEEK) != 0
90 if @read_s.respond_to?(:sysseek)
91 @read_s.sysseek(-ret.size, IO::SEEK_CUR)
93 @read_s.seek(-ret.size, IO::SEEK_CUR)
98 alias_method :recv, :recv_nonblock
105 @write_s.syswrite data
110 class MogileFS::Client
111 attr_writer :readonly
118 attr_accessor :connections
119 attr_accessor :sockets
124 raise Errno::ECONNREFUSED if @sockets.empty?
125 @connections << [host, port]
135 class TestMogileFS < Test::Unit::TestCase
137 undef_method :default_test
140 @tempdir = File.join Dir.tmpdir, "test_mogilefs_#{$$}"
141 @root = File.join @tempdir, 'root'
142 FileUtils.mkdir_p @root
144 @client = @klass.new :hosts => ['kaa:6001'], :domain => 'test',
146 @backend = FakeBackend.new
147 @client.instance_variable_set '@backend', @backend
149 TCPSocket.sockets = []
150 TCPSocket.connections = []
154 FileUtils.rm_rf @tempdir