thrift 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/benchmark/gen-rb/benchmark_constants.rb +3 -2
  2. data/benchmark/gen-rb/benchmark_service.rb +52 -52
  3. data/benchmark/gen-rb/benchmark_types.rb +3 -2
  4. data/ext/binary_protocol_accelerated.c +5 -2
  5. data/ext/bytes.c +36 -0
  6. data/ext/bytes.h +31 -0
  7. data/ext/compact_protocol.c +7 -4
  8. data/ext/constants.h +4 -0
  9. data/ext/extconf.rb +3 -1
  10. data/ext/memory_buffer.c +11 -8
  11. data/ext/thrift_native.c +9 -0
  12. data/lib/thrift.rb +2 -0
  13. data/lib/thrift/bytes.rb +131 -0
  14. data/lib/thrift/protocol/base_protocol.rb +10 -0
  15. data/lib/thrift/protocol/binary_protocol.rb +5 -5
  16. data/lib/thrift/protocol/compact_protocol.rb +4 -3
  17. data/lib/thrift/protocol/json_protocol.rb +765 -0
  18. data/lib/thrift/transport/base_transport.rb +22 -20
  19. data/lib/thrift/transport/buffered_transport.rb +16 -10
  20. data/lib/thrift/transport/framed_transport.rb +11 -10
  21. data/lib/thrift/transport/http_client_transport.rb +7 -5
  22. data/lib/thrift/transport/io_stream_transport.rb +1 -1
  23. data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
  24. data/lib/thrift/transport/socket.rb +4 -2
  25. data/spec/ThriftSpec.thrift +52 -1
  26. data/spec/base_protocol_spec.rb +44 -45
  27. data/spec/base_transport_spec.rb +49 -50
  28. data/spec/binary_protocol_accelerated_spec.rb +9 -13
  29. data/spec/binary_protocol_spec.rb +15 -10
  30. data/spec/binary_protocol_spec_shared.rb +62 -12
  31. data/spec/bytes_spec.rb +160 -0
  32. data/spec/client_spec.rb +13 -14
  33. data/spec/compact_protocol_spec.rb +3 -2
  34. data/spec/exception_spec.rb +39 -40
  35. data/spec/gen-rb/nonblocking_service.rb +193 -193
  36. data/spec/gen-rb/thrift_spec_constants.rb +3 -2
  37. data/spec/gen-rb/thrift_spec_types.rb +455 -262
  38. data/spec/http_client_spec.rb +16 -9
  39. data/spec/json_protocol_spec.rb +513 -0
  40. data/spec/mongrel_http_server_spec.rb +19 -22
  41. data/spec/nonblocking_server_spec.rb +18 -20
  42. data/spec/processor_spec.rb +13 -16
  43. data/spec/serializer_spec.rb +17 -19
  44. data/spec/server_socket_spec.rb +6 -7
  45. data/spec/server_spec.rb +46 -58
  46. data/spec/socket_spec.rb +11 -11
  47. data/spec/socket_spec_shared.rb +1 -1
  48. data/spec/spec_helper.rb +13 -10
  49. data/spec/struct_nested_containers_spec.rb +191 -0
  50. data/spec/struct_spec.rb +84 -86
  51. data/spec/types_spec.rb +65 -66
  52. data/spec/union_spec.rb +44 -46
  53. data/spec/unix_socket_spec.rb +8 -9
  54. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +8 -7
  55. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +24 -23
  56. data/test/debug_proto/gen-rb/empty_service.rb +1 -1
  57. data/test/debug_proto/gen-rb/inherited.rb +3 -3
  58. data/test/debug_proto/gen-rb/reverse_order_service.rb +1 -1
  59. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +3 -3
  60. data/test/debug_proto/gen-rb/srv.rb +2 -2
  61. metadata +43 -49
@@ -35,22 +35,14 @@ module Thrift
35
35
  end
36
36
 
37
37
  module TransportUtils
38
- if RUBY_VERSION >= '1.9'
39
- def self.get_string_byte(string, index)
40
- string.getbyte(index)
41
- end
42
-
43
- def self.set_string_byte(string, index, byte)
44
- string.setbyte(index, byte)
45
- end
46
- else
47
- def self.get_string_byte(string, index)
48
- string[index]
49
- end
38
+ # Deprecated: Use Thrift::Bytes instead
39
+ def self.get_string_byte(string, index)
40
+ Bytes.get_string_byte(string, index)
41
+ end
50
42
 
51
- def self.set_string_byte(string, index, byte)
52
- string[index] = byte
53
- end
43
+ # Deprecated: Use Thrift::Bytes instead
44
+ def self.set_string_byte(string, index, byte)
45
+ Bytes.set_string_byte(string, index, byte)
54
46
  end
55
47
  end
56
48
 
@@ -61,6 +53,11 @@ module Thrift
61
53
 
62
54
  def close; end
63
55
 
56
+ # Reads a number of bytes from the transports. In Ruby 1.9+, the String returned will have a BINARY (aka ASCII8BIT) encoding.
57
+ #
58
+ # sz - The number of bytes to read from the transport.
59
+ #
60
+ # Returns a String acting as a byte buffer.
64
61
  def read(sz)
65
62
  raise NotImplementedError
66
63
  end
@@ -68,7 +65,7 @@ module Thrift
68
65
  # Returns an unsigned byte as a Fixnum in the range (0..255).
69
66
  def read_byte
70
67
  buf = read_all(1)
71
- return ::Thrift::TransportUtils.get_string_byte(buf, 0)
68
+ return Bytes.get_string_byte(buf, 0)
72
69
  end
73
70
 
74
71
  # Reads size bytes and copies them into buffer[0..size].
@@ -76,14 +73,14 @@ module Thrift
76
73
  tmp = read_all(size)
77
74
  i = 0
78
75
  tmp.each_byte do |byte|
79
- ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
76
+ Bytes.set_string_byte(buffer, i, byte)
80
77
  i += 1
81
78
  end
82
79
  i
83
80
  end
84
81
 
85
82
  def read_all(size)
86
- return '' if size <= 0
83
+ return Bytes.empty_byte_buffer if size <= 0
87
84
  buf = read(size)
88
85
  while (buf.length < size)
89
86
  chunk = read(size - buf.length)
@@ -92,7 +89,12 @@ module Thrift
92
89
 
93
90
  buf
94
91
  end
95
-
92
+
93
+ # Writes the byte buffer to the transport. In Ruby 1.9+, the buffer will be forced into BINARY encoding.
94
+ #
95
+ # buf - A String acting as a byte buffer.
96
+ #
97
+ # Returns nothing.
96
98
  def write(buf); end
97
99
  alias_method :<<, :write
98
100
 
@@ -104,4 +106,4 @@ module Thrift
104
106
  return trans
105
107
  end
106
108
  end
107
- end
109
+ end
@@ -24,8 +24,8 @@ module Thrift
24
24
 
25
25
  def initialize(transport)
26
26
  @transport = transport
27
- @wbuf = ''
28
- @rbuf = ''
27
+ @wbuf = Bytes.empty_byte_buffer
28
+ @rbuf = Bytes.empty_byte_buffer
29
29
  @index = 0
30
30
  end
31
31
 
@@ -44,12 +44,12 @@ module Thrift
44
44
 
45
45
  def read(sz)
46
46
  @index += sz
47
- ret = @rbuf.slice(@index - sz, sz) || ''
47
+ ret = @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer
48
48
 
49
49
  if ret.length == 0
50
50
  @rbuf = @transport.read([sz, DEFAULT_BUFFER].max)
51
51
  @index = sz
52
- ret = @rbuf.slice(0, sz) || ''
52
+ ret = @rbuf.slice(0, sz) || Bytes.empty_byte_buffer
53
53
  end
54
54
 
55
55
  ret
@@ -65,9 +65,15 @@ module Thrift
65
65
  # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
66
66
  # allocating a temp string of size 1 unnecessarily.
67
67
  @index += 1
68
- return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
68
+ return Bytes.get_string_byte(@rbuf, @index - 1)
69
69
  end
70
70
 
71
+ # Reads a number of bytes from the transport into the buffer passed.
72
+ #
73
+ # buffer - The String (byte buffer) to write data to; this is assumed to have a BINARY encoding.
74
+ # size - The number of bytes to read from the transport and write to the buffer.
75
+ #
76
+ # Returns the number of bytes read.
71
77
  def read_into_buffer(buffer, size)
72
78
  i = 0
73
79
  while i < size
@@ -78,8 +84,8 @@ module Thrift
78
84
  end
79
85
 
80
86
  # The read buffer has some data now, so copy bytes over to the output buffer.
81
- byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
82
- ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
87
+ byte = Bytes.get_string_byte(@rbuf, @index)
88
+ Bytes.set_string_byte(buffer, i, byte)
83
89
  @index += 1
84
90
  i += 1
85
91
  end
@@ -87,13 +93,13 @@ module Thrift
87
93
  end
88
94
 
89
95
  def write(buf)
90
- @wbuf << buf
96
+ @wbuf << Bytes.force_binary_encoding(buf)
91
97
  end
92
98
 
93
99
  def flush
94
- if @wbuf != ''
100
+ unless @wbuf.empty?
95
101
  @transport.write(@wbuf)
96
- @wbuf = ''
102
+ @wbuf = Bytes.empty_byte_buffer
97
103
  end
98
104
 
99
105
  @transport.flush
@@ -22,8 +22,8 @@ module Thrift
22
22
  class FramedTransport < BaseTransport
23
23
  def initialize(transport, read=true, write=true)
24
24
  @transport = transport
25
- @rbuf = ''
26
- @wbuf = ''
25
+ @rbuf = Bytes.empty_byte_buffer
26
+ @wbuf = Bytes.empty_byte_buffer
27
27
  @read = read
28
28
  @write = write
29
29
  @index = 0
@@ -44,12 +44,12 @@ module Thrift
44
44
  def read(sz)
45
45
  return @transport.read(sz) unless @read
46
46
 
47
- return '' if sz <= 0
47
+ return Bytes.empty_byte_buffer if sz <= 0
48
48
 
49
49
  read_frame if @index >= @rbuf.length
50
50
 
51
51
  @index += sz
52
- @rbuf.slice(@index - sz, sz) || ''
52
+ @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer
53
53
  end
54
54
 
55
55
  def read_byte
@@ -60,7 +60,7 @@ module Thrift
60
60
  # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
61
61
  # allocating a temp string of size 1 unnecessarily.
62
62
  @index += 1
63
- return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
63
+ return Bytes.get_string_byte(@rbuf, @index - 1)
64
64
  end
65
65
 
66
66
  def read_into_buffer(buffer, size)
@@ -69,18 +69,18 @@ module Thrift
69
69
  read_frame if @index >= @rbuf.length
70
70
 
71
71
  # The read buffer has some data now, so copy bytes over to the output buffer.
72
- byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
73
- ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
72
+ byte = Bytes.get_string_byte(@rbuf, @index)
73
+ Bytes.set_string_byte(buffer, i, byte)
74
74
  @index += 1
75
75
  i += 1
76
76
  end
77
77
  i
78
78
  end
79
79
 
80
-
81
- def write(buf,sz=nil)
80
+ def write(buf, sz=nil)
82
81
  return @transport.write(buf) unless @write
83
82
 
83
+ buf = Bytes.force_binary_encoding(buf)
84
84
  @wbuf << (sz ? buf[0...sz] : buf)
85
85
  end
86
86
 
@@ -92,10 +92,11 @@ module Thrift
92
92
  return @transport.flush unless @write
93
93
 
94
94
  out = [@wbuf.length].pack('N')
95
+ # Array#pack should return a BINARY encoded String, so it shouldn't be necessary to force encoding
95
96
  out << @wbuf
96
97
  @transport.write(out)
97
98
  @transport.flush
98
- @wbuf = ''
99
+ @wbuf = Bytes.empty_byte_buffer
99
100
  end
100
101
 
101
102
  private
@@ -29,12 +29,12 @@ module Thrift
29
29
  def initialize(url)
30
30
  @url = URI url
31
31
  @headers = {'Content-Type' => 'application/x-thrift'}
32
- @outbuf = ""
32
+ @outbuf = Bytes.empty_byte_buffer
33
33
  end
34
34
 
35
35
  def open?; true end
36
36
  def read(sz); @inbuf.read sz end
37
- def write(buf); @outbuf << buf end
37
+ def write(buf); @outbuf << Bytes.force_binary_encoding(buf) end
38
38
 
39
39
  def add_headers(headers)
40
40
  @headers = @headers.merge(headers)
@@ -42,10 +42,12 @@ module Thrift
42
42
 
43
43
  def flush
44
44
  http = Net::HTTP.new @url.host, @url.port
45
- http.use_ssl = @url.scheme == "https"
46
- resp, data = http.post(@url.request_uri, @outbuf, @headers)
45
+ http.use_ssl = @url.scheme == 'https'
46
+ resp = http.post(@url.request_uri, @outbuf, @headers)
47
+ data = resp.body
48
+ data = Bytes.force_binary_encoding(data)
47
49
  @inbuf = StringIO.new data
48
- @outbuf = ""
50
+ @outbuf = Bytes.empty_byte_buffer
49
51
  end
50
52
  end
51
53
  end
@@ -32,7 +32,7 @@ module Thrift
32
32
 
33
33
  def open?; not @input.closed? or not @output.closed? end
34
34
  def read(sz); @input.read(sz) end
35
- def write(buf); @output.write(buf) end
35
+ def write(buf); @output.write(Bytes.force_binary_encoding(buf)) end
36
36
  def close; @input.close; @output.close end
37
37
  def to_io; @input end # we're assuming this is used in a IO.select for reading
38
38
  end
@@ -28,7 +28,7 @@ module Thrift
28
28
  # this behavior is no longer required. If you wish to change it
29
29
  # go ahead, just make sure the specs pass
30
30
  def initialize(buffer = nil)
31
- @buf = buffer || ''
31
+ @buf = buffer ? Bytes.force_binary_encoding(buffer) : Bytes.empty_byte_buffer
32
32
  @index = 0
33
33
  end
34
34
 
@@ -48,7 +48,7 @@ module Thrift
48
48
 
49
49
  # this method does not use the passed object directly but copies it
50
50
  def reset_buffer(new_buf = '')
51
- @buf.replace new_buf
51
+ @buf.replace Bytes.force_binary_encoding(new_buf)
52
52
  @index = 0
53
53
  end
54
54
 
@@ -72,7 +72,7 @@ module Thrift
72
72
 
73
73
  def read_byte
74
74
  raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size
75
- val = ::Thrift::TransportUtils.get_string_byte(@buf, @index)
75
+ val = Bytes.get_string_byte(@buf, @index)
76
76
  @index += 1
77
77
  if @index >= GARBAGE_BUFFER_SIZE
78
78
  @buf = @buf.slice(@index..-1)
@@ -87,8 +87,8 @@ module Thrift
87
87
  raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size
88
88
 
89
89
  # The read buffer has some data now, so copy bytes over to the output buffer.
90
- byte = ::Thrift::TransportUtils.get_string_byte(@buf, @index)
91
- ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
90
+ byte = Bytes.get_string_byte(@buf, @index)
91
+ Bytes.set_string_byte(buffer, i, byte)
92
92
  @index += 1
93
93
  i += 1
94
94
  end
@@ -100,7 +100,7 @@ module Thrift
100
100
  end
101
101
 
102
102
  def write(wbuf)
103
- @buf << wbuf
103
+ @buf << Bytes.force_binary_encoding(wbuf)
104
104
  end
105
105
 
106
106
  def flush
@@ -34,8 +34,9 @@ module Thrift
34
34
 
35
35
  def open
36
36
  begin
37
- addrinfo = ::Socket::getaddrinfo(@host, @port).first
37
+ addrinfo = ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM).first
38
38
  @handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
39
+ @handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
39
40
  sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
40
41
  begin
41
42
  @handle.connect_nonblock(sockaddr)
@@ -60,6 +61,7 @@ module Thrift
60
61
 
61
62
  def write(str)
62
63
  raise IOError, "closed stream" unless open?
64
+ str = Bytes.force_binary_encoding(str)
63
65
  begin
64
66
  if @timeout.nil? or @timeout == 0
65
67
  @handle.write(str)
@@ -134,4 +136,4 @@ module Thrift
134
136
  @handle
135
137
  end
136
138
  end
137
- end
139
+ end
@@ -129,4 +129,55 @@ struct Struct_with_union {
129
129
 
130
130
  struct StructWithEnumMap {
131
131
  1: map<SomeEnum, list<SomeEnum>> my_map;
132
- }
132
+ }
133
+
134
+ # Nested lists
135
+ struct NestedListInList {
136
+ 1: list<list<byte>> value
137
+ }
138
+
139
+ struct NestedListInSet {
140
+ 1: set<list<byte>> value
141
+ }
142
+
143
+ struct NestedListInMapKey {
144
+ 1: map<list<byte>, byte> value
145
+ }
146
+
147
+ struct NestedListInMapValue {
148
+ 1: map<byte, list<byte>> value
149
+ }
150
+
151
+ # Nested sets
152
+ struct NestedSetInList {
153
+ 1: list<set<byte>> value
154
+ }
155
+
156
+ struct NestedSetInSet {
157
+ 1: set<set<byte>> value
158
+ }
159
+
160
+ struct NestedSetInMapKey {
161
+ 1: map<set<byte>, byte> value
162
+ }
163
+
164
+ struct NestedSetInMapValue {
165
+ 1: map<byte, set<byte>> value
166
+ }
167
+
168
+ # Nested maps
169
+ struct NestedMapInList {
170
+ 1: list<map<byte, byte>> value
171
+ }
172
+
173
+ struct NestedMapInSet {
174
+ 1: set<map<byte, byte>> value
175
+ }
176
+
177
+ struct NestedMapInMapKey {
178
+ 2: map<map<byte, byte>, byte> value
179
+ }
180
+
181
+ struct NestedMapInMapValue {
182
+ 2: map<byte, map<byte, byte>> value
183
+ }
@@ -17,17 +17,16 @@
17
17
  # under the License.
18
18
  #
19
19
 
20
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
20
+ require 'spec_helper'
21
21
 
22
- class ThriftBaseProtocolSpec < Spec::ExampleGroup
23
- include Thrift
22
+ describe 'BaseProtocol' do
24
23
 
25
24
  before(:each) do
26
25
  @trans = mock("MockTransport")
27
- @prot = BaseProtocol.new(@trans)
26
+ @prot = Thrift::BaseProtocol.new(@trans)
28
27
  end
29
28
 
30
- describe BaseProtocol do
29
+ describe Thrift::BaseProtocol do
31
30
  # most of the methods are stubs, so we can ignore them
32
31
 
33
32
  it "should make trans accessible" do
@@ -51,16 +50,16 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
51
50
  @prot.should_receive(:write_string).with('string').ordered
52
51
  struct = mock('Struct')
53
52
  struct.should_receive(:write).with(@prot).ordered
54
- @prot.write_type(Types::BOOL, 'bool')
55
- @prot.write_type(Types::BYTE, 'byte')
56
- @prot.write_type(Types::DOUBLE, 'double')
57
- @prot.write_type(Types::I16, 'i16')
58
- @prot.write_type(Types::I32, 'i32')
59
- @prot.write_type(Types::I64, 'i64')
60
- @prot.write_type(Types::STRING, 'string')
61
- @prot.write_type(Types::STRUCT, struct)
53
+ @prot.write_type(Thrift::Types::BOOL, 'bool')
54
+ @prot.write_type(Thrift::Types::BYTE, 'byte')
55
+ @prot.write_type(Thrift::Types::DOUBLE, 'double')
56
+ @prot.write_type(Thrift::Types::I16, 'i16')
57
+ @prot.write_type(Thrift::Types::I32, 'i32')
58
+ @prot.write_type(Thrift::Types::I64, 'i64')
59
+ @prot.write_type(Thrift::Types::STRING, 'string')
60
+ @prot.write_type(Thrift::Types::STRUCT, struct)
62
61
  # all other types are not implemented
63
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
62
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
64
63
  lambda { @prot.write_type(type, type.to_s) }.should raise_error(NotImplementedError)
65
64
  end
66
65
  end
@@ -73,15 +72,15 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
73
72
  @prot.should_receive(:read_i64).ordered
74
73
  @prot.should_receive(:read_double).ordered
75
74
  @prot.should_receive(:read_string).ordered
76
- @prot.read_type(Types::BOOL)
77
- @prot.read_type(Types::BYTE)
78
- @prot.read_type(Types::I16)
79
- @prot.read_type(Types::I32)
80
- @prot.read_type(Types::I64)
81
- @prot.read_type(Types::DOUBLE)
82
- @prot.read_type(Types::STRING)
75
+ @prot.read_type(Thrift::Types::BOOL)
76
+ @prot.read_type(Thrift::Types::BYTE)
77
+ @prot.read_type(Thrift::Types::I16)
78
+ @prot.read_type(Thrift::Types::I32)
79
+ @prot.read_type(Thrift::Types::I64)
80
+ @prot.read_type(Thrift::Types::DOUBLE)
81
+ @prot.read_type(Thrift::Types::STRING)
83
82
  # all other types are not implemented
84
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
83
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
85
84
  lambda { @prot.read_type(type) }.should raise_error(NotImplementedError)
86
85
  end
87
86
  end
@@ -94,67 +93,67 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
94
93
  @prot.should_receive(:read_i64).ordered
95
94
  @prot.should_receive(:read_double).ordered
96
95
  @prot.should_receive(:read_string).ordered
97
- @prot.skip(Types::BOOL)
98
- @prot.skip(Types::BYTE)
99
- @prot.skip(Types::I16)
100
- @prot.skip(Types::I32)
101
- @prot.skip(Types::I64)
102
- @prot.skip(Types::DOUBLE)
103
- @prot.skip(Types::STRING)
104
- @prot.skip(Types::STOP) # should do absolutely nothing
96
+ @prot.skip(Thrift::Types::BOOL)
97
+ @prot.skip(Thrift::Types::BYTE)
98
+ @prot.skip(Thrift::Types::I16)
99
+ @prot.skip(Thrift::Types::I32)
100
+ @prot.skip(Thrift::Types::I64)
101
+ @prot.skip(Thrift::Types::DOUBLE)
102
+ @prot.skip(Thrift::Types::STRING)
103
+ @prot.skip(Thrift::Types::STOP) # should do absolutely nothing
105
104
  end
106
105
 
107
106
  it "should skip structs" do
108
107
  real_skip = @prot.method(:skip)
109
108
  @prot.should_receive(:read_struct_begin).ordered
110
109
  @prot.should_receive(:read_field_begin).exactly(4).times.and_return(
111
- ['field 1', Types::STRING, 1],
112
- ['field 2', Types::I32, 2],
113
- ['field 3', Types::MAP, 3],
114
- [nil, Types::STOP, 0]
110
+ ['field 1', Thrift::Types::STRING, 1],
111
+ ['field 2', Thrift::Types::I32, 2],
112
+ ['field 3', Thrift::Types::MAP, 3],
113
+ [nil, Thrift::Types::STOP, 0]
115
114
  )
116
115
  @prot.should_receive(:read_field_end).exactly(3).times
117
116
  @prot.should_receive(:read_string).exactly(3).times
118
117
  @prot.should_receive(:read_i32).ordered
119
- @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRING, 1])
118
+ @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
120
119
  # @prot.should_receive(:read_string).exactly(2).times
121
120
  @prot.should_receive(:read_map_end).ordered
122
121
  @prot.should_receive(:read_struct_end).ordered
123
- real_skip.call(Types::STRUCT)
122
+ real_skip.call(Thrift::Types::STRUCT)
124
123
  end
125
124
 
126
125
  it "should skip maps" do
127
126
  real_skip = @prot.method(:skip)
128
- @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRUCT, 1])
127
+ @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
129
128
  @prot.should_receive(:read_string).ordered
130
129
  @prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
131
- @prot.should_receive(:read_field_begin).ordered.and_return([nil, Types::STOP, nil]);
130
+ @prot.should_receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
132
131
  @prot.should_receive(:read_struct_end).ordered
133
132
  @prot.should_receive(:read_map_end).ordered
134
- real_skip.call(Types::MAP)
133
+ real_skip.call(Thrift::Types::MAP)
135
134
  end
136
135
 
137
136
  it "should skip sets" do
138
137
  real_skip = @prot.method(:skip)
139
- @prot.should_receive(:read_set_begin).ordered.and_return([Types::I64, 9])
138
+ @prot.should_receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
140
139
  @prot.should_receive(:read_i64).ordered.exactly(9).times
141
140
  @prot.should_receive(:read_set_end)
142
- real_skip.call(Types::SET)
141
+ real_skip.call(Thrift::Types::SET)
143
142
  end
144
143
 
145
144
  it "should skip lists" do
146
145
  real_skip = @prot.method(:skip)
147
- @prot.should_receive(:read_list_begin).ordered.and_return([Types::DOUBLE, 11])
146
+ @prot.should_receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
148
147
  @prot.should_receive(:read_double).ordered.exactly(11).times
149
148
  @prot.should_receive(:read_list_end)
150
- real_skip.call(Types::LIST)
149
+ real_skip.call(Thrift::Types::LIST)
151
150
  end
152
151
  end
153
152
 
154
- describe BaseProtocolFactory do
153
+ describe Thrift::BaseProtocolFactory do
155
154
  it "should raise NotImplementedError" do
156
155
  # returning nil since Protocol is just an abstract class
157
- lambda {BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
156
+ lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
158
157
  end
159
158
  end
160
159
  end