thrift 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/thrift/struct.rb +3 -1
- data/lib/thrift/transport/socket.rb +6 -5
- data/spec/socket_spec_shared.rb +1 -1
- data/spec/struct_spec.rb +16 -7
- data/thrift.gemspec +2 -2
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/thrift/struct.rb
CHANGED
@@ -21,7 +21,7 @@ require 'set'
|
|
21
21
|
|
22
22
|
module Thrift
|
23
23
|
module Struct
|
24
|
-
def initialize(d={})
|
24
|
+
def initialize(d={}, &block)
|
25
25
|
# get a copy of the default values to work on, removing defaults in favor of arguments
|
26
26
|
fields_with_defaults = fields_with_default_values.dup
|
27
27
|
|
@@ -50,6 +50,8 @@ module Thrift
|
|
50
50
|
instance_variable_set("@#{name}", (default_value.dup rescue default_value))
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
yield self if block_given?
|
53
55
|
end
|
54
56
|
|
55
57
|
def fields_with_default_values
|
@@ -97,12 +97,13 @@ module Thrift
|
|
97
97
|
data = @handle.readpartial(sz)
|
98
98
|
else
|
99
99
|
# it's possible to interrupt select for something other than the timeout
|
100
|
-
# so we need to ensure we've waited long enough
|
100
|
+
# so we need to ensure we've waited long enough, but not too long
|
101
101
|
start = Time.now
|
102
|
-
|
103
|
-
loop do
|
104
|
-
rd, = IO.select([@handle], nil, nil, @timeout)
|
105
|
-
|
102
|
+
timespent = 0
|
103
|
+
rd = loop do
|
104
|
+
rd, = IO.select([@handle], nil, nil, @timeout - timespent)
|
105
|
+
timespent = Time.now - start
|
106
|
+
break rd if (rd and not rd.empty?) or timespent >= @timeout
|
106
107
|
end
|
107
108
|
if rd.nil? or rd.empty?
|
108
109
|
raise TransportException.new(TransportException::TIMED_OUT, "Socket: Timed out reading #{sz} bytes from #{@desc}")
|
data/spec/socket_spec_shared.rb
CHANGED
@@ -91,7 +91,7 @@ shared_examples_for "a socket" do
|
|
91
91
|
it "should raise an error when read times out" do
|
92
92
|
@socket.timeout = 0.5
|
93
93
|
@socket.open
|
94
|
-
IO.should_receive(:select).
|
94
|
+
IO.should_receive(:select).once {sleep(0.5); nil}
|
95
95
|
lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
|
96
96
|
end
|
97
97
|
|
data/spec/struct_spec.rb
CHANGED
@@ -31,13 +31,22 @@ class ThriftStructSpec < Spec::ExampleGroup
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should initialize all fields to defaults" do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
validate_default_arguments(Foo.new)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should initialize all fields to defaults and accept a block argument" do
|
38
|
+
Foo.new do |f|
|
39
|
+
validate_default_arguments(f)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_default_arguments(object)
|
44
|
+
object.simple.should == 53
|
45
|
+
object.words.should == "words"
|
46
|
+
object.hello.should == Hello.new(:greeting => 'hello, world!')
|
47
|
+
object.ints.should == [1, 2, 2, 3]
|
48
|
+
object.complex.should be_nil
|
49
|
+
object.shorts.should == Set.new([5, 17, 239])
|
41
50
|
end
|
42
51
|
|
43
52
|
it "should not share default values between instances" do
|
data/thrift.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{thrift}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.5.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2.0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Kevin Ballard, Kevin Clark, Mark Slee"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-10-13}
|
10
10
|
s.description = %q{Ruby libraries for Thrift (a language-agnostic RPC system)}
|
11
11
|
s.email = ["kevin@sb.org", "kevin.clark@gmail.com", "mcslee@facebook.com"]
|
12
12
|
s.extensions = ["ext/extconf.rb"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kevin Ballard, Kevin Clark, Mark Slee
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-13 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|