| 30 |
ashish |
1 |
#
|
|
|
2 |
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
# or more contributor license agreements. See the NOTICE file
|
|
|
4 |
# distributed with this work for additional information
|
|
|
5 |
# regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
# to you under the Apache License, Version 2.0 (the
|
|
|
7 |
# "License"); you may not use this file except in compliance
|
|
|
8 |
# with the License. You may obtain a copy of the License at
|
|
|
9 |
#
|
|
|
10 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
#
|
|
|
12 |
# Unless required by applicable law or agreed to in writing,
|
|
|
13 |
# software distributed under the License is distributed on an
|
|
|
14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
# KIND, either express or implied. See the License for the
|
|
|
16 |
# specific language governing permissions and limitations
|
|
|
17 |
# under the License.
|
|
|
18 |
#
|
|
|
19 |
|
|
|
20 |
require File.dirname(__FILE__) + '/spec_helper'
|
|
|
21 |
require File.dirname(__FILE__) + "/socket_spec_shared"
|
|
|
22 |
|
|
|
23 |
class ThriftSocketSpec < Spec::ExampleGroup
|
|
|
24 |
include Thrift
|
|
|
25 |
|
|
|
26 |
describe Socket do
|
|
|
27 |
before(:each) do
|
|
|
28 |
@socket = Socket.new
|
|
|
29 |
@handle = mock("Handle", :closed? => false)
|
|
|
30 |
@handle.stub!(:close)
|
|
|
31 |
@handle.stub!(:connect_nonblock)
|
|
|
32 |
::Socket.stub!(:new).and_return(@handle)
|
|
|
33 |
end
|
|
|
34 |
|
|
|
35 |
it_should_behave_like "a socket"
|
|
|
36 |
|
|
|
37 |
it "should raise a TransportException when it cannot open a socket" do
|
|
|
38 |
::Socket.should_receive(:new).and_raise(StandardError)
|
|
|
39 |
lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
|
|
|
40 |
end
|
|
|
41 |
|
|
|
42 |
it "should open a ::Socket with default args" do
|
|
|
43 |
::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true))
|
|
|
44 |
::Socket.should_receive(:getaddrinfo).with("localhost", 9090).and_return([[]])
|
|
|
45 |
::Socket.should_receive(:sockaddr_in)
|
|
|
46 |
@socket.open
|
|
|
47 |
end
|
|
|
48 |
|
|
|
49 |
it "should accept host/port options" do
|
|
|
50 |
::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true))
|
|
|
51 |
::Socket.should_receive(:getaddrinfo).with("my.domain", 1234).and_return([[]])
|
|
|
52 |
::Socket.should_receive(:sockaddr_in)
|
|
|
53 |
Socket.new('my.domain', 1234).open
|
|
|
54 |
end
|
|
|
55 |
|
|
|
56 |
it "should accept an optional timeout" do
|
|
|
57 |
::Socket.stub!(:new)
|
|
|
58 |
Socket.new('localhost', 8080, 5).timeout.should == 5
|
|
|
59 |
end
|
|
|
60 |
end
|
|
|
61 |
end
|