upfluence-thrift 1.0.11 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/thrift.rb +6 -4
- data/lib/thrift/client.rb +31 -1
- data/lib/thrift/definition.rb +64 -0
- data/lib/thrift/exceptions.rb +5 -5
- data/lib/thrift/middleware.rb +50 -0
- data/lib/thrift/processor.rb +3 -3
- data/lib/thrift/protocol/json_protocol.rb +6 -6
- data/lib/thrift/server/rack_application.rb +30 -19
- data/lib/thrift/struct.rb +10 -10
- data/lib/thrift/transport/base_transport.rb +9 -7
- data/lib/thrift/transport/server_socket.rb +6 -6
- data/lib/thrift/types.rb +4 -4
- data/lib/thrift/types/known/any.rb +179 -0
- data/lib/thrift/types/known/any_constants.rb +17 -0
- data/lib/thrift/types/known/any_types.rb +43 -0
- data/lib/thrift/types/known/duration.rb +27 -0
- data/lib/thrift/types/known/duration_constants.rb +17 -0
- data/lib/thrift/types/known/duration_types.rb +43 -0
- data/lib/thrift/types/known/timestamp.rb +31 -0
- data/lib/thrift/types/known/timestamp_constants.rb +17 -0
- data/lib/thrift/types/known/timestamp_types.rb +43 -0
- data/lib/thrift/types/value.rb +114 -0
- data/lib/thrift/types/value_constants.rb +15 -0
- data/lib/thrift/types/value_types.rb +213 -0
- data/spec/binary_protocol_spec_shared.rb +57 -60
- data/spec/client_spec.rb +2 -2
- data/spec/compact_protocol_spec.rb +26 -20
- data/spec/http_client_spec.rb +7 -20
- data/spec/nonblocking_server_spec.rb +1 -1
- data/spec/processor_spec.rb +1 -1
- data/spec/rack_application_spec.rb +1 -1
- data/spec/struct_spec.rb +2 -2
- data/spec/types/known/any_spec.rb +44 -0
- data/spec/types/known/duration_spec.rb +20 -0
- data/spec/types/known/timestamp_spec.rb +17 -0
- data/spec/types/value_spec.rb +43 -0
- data/spec/types_spec.rb +2 -2
- metadata +50 -87
- data/benchmark/gen-rb/benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -10
- data/spec/gen-rb/base/base_service.rb +0 -80
- data/spec/gen-rb/base/base_service_constants.rb +0 -11
- data/spec/gen-rb/base/base_service_types.rb +0 -26
- data/spec/gen-rb/extended/extended_service.rb +0 -78
- data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
- data/spec/gen-rb/extended/extended_service_types.rb +0 -12
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/flat/referenced_constants.rb +0 -11
- data/spec/gen-rb/flat/referenced_types.rb +0 -17
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
- data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
- data/spec/gen-rb/thrift_spec_constants.rb +0 -11
- data/spec/gen-rb/thrift_spec_types.rb +0 -538
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -274
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -761
- data/test/debug_proto/gen-rb/empty_service.rb +0 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'thrift/types/known/timestamp_types'
|
2
|
+
|
3
|
+
module Thrift
|
4
|
+
module Types
|
5
|
+
module Known
|
6
|
+
module Timestamp
|
7
|
+
class << self
|
8
|
+
def from_time(v)
|
9
|
+
Timestamp.from_time(v)
|
10
|
+
end
|
11
|
+
|
12
|
+
def now
|
13
|
+
from_time(Time.now)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Timestamp
|
18
|
+
class << self
|
19
|
+
def from_time(v)
|
20
|
+
Timestamp.new(seconds: v.to_i, nanos: v.nsec)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_time
|
25
|
+
Time.at(seconds, nanos, :nsec)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (2.3.0-upfluence)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'timestamp_types'
|
9
|
+
|
10
|
+
module Thrift
|
11
|
+
module Types
|
12
|
+
module Known
|
13
|
+
module Timestamp
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (2.3.0-upfluence)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Thrift
|
10
|
+
module Types
|
11
|
+
module Known
|
12
|
+
module Timestamp
|
13
|
+
class Timestamp; end
|
14
|
+
|
15
|
+
class Timestamp
|
16
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
17
|
+
|
18
|
+
NAME = 'Timestamp'.freeze
|
19
|
+
NAMESPACE = 'types.known.timestamp'.freeze
|
20
|
+
|
21
|
+
THRIFT_FIELD_INDEX_SECONDS = 1
|
22
|
+
THRIFT_FIELD_INDEX_NANOS = 2
|
23
|
+
|
24
|
+
FIELDS = {
|
25
|
+
THRIFT_FIELD_INDEX_SECONDS => {type: ::Thrift::Types::I64, name: 'seconds'},
|
26
|
+
THRIFT_FIELD_INDEX_NANOS => {type: ::Thrift::Types::I32, name: 'nanos'}
|
27
|
+
}
|
28
|
+
|
29
|
+
def struct_fields; FIELDS; end
|
30
|
+
|
31
|
+
def validate
|
32
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field seconds is unset!') unless @seconds
|
33
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field nanos is unset!') unless @nanos
|
34
|
+
end
|
35
|
+
|
36
|
+
::Thrift::Struct.generate_accessors self
|
37
|
+
::Thrift.register_struct_type self
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'thrift/types/value_types'
|
2
|
+
|
3
|
+
module Thrift
|
4
|
+
module Types
|
5
|
+
module Value
|
6
|
+
class ListValue
|
7
|
+
def to_array
|
8
|
+
values.map(&:to_object)
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def from_array(v)
|
13
|
+
ListValue.new(values: v.map { |vv| Value.from_object(vv) })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class MapValue
|
19
|
+
def to_hash
|
20
|
+
entries.reduce({}) do |acc, e|
|
21
|
+
acc.merge(e.key.to_object => e.value.to_object)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def from_hash(v)
|
27
|
+
MapValue.new(
|
28
|
+
entries: v.reduce([]) do |acc, (k, vv)|
|
29
|
+
acc + [
|
30
|
+
MapEntry.new(
|
31
|
+
key: Value.from_object(k),
|
32
|
+
value: Value.from_object(vv)
|
33
|
+
)
|
34
|
+
]
|
35
|
+
end
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class StructValue
|
42
|
+
def to_hash
|
43
|
+
fields.reduce({}) do |acc, (k, v)|
|
44
|
+
acc.merge(k => v.to_object)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class << self
|
49
|
+
def from_object(v)
|
50
|
+
StructValue.new(
|
51
|
+
fields: v.instance_variables.reduce({}) do |acc, k|
|
52
|
+
acc.merge(
|
53
|
+
k.to_s[1..-1] => Value.from_object(v.instance_variable_get(k))
|
54
|
+
)
|
55
|
+
end
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
def from_object(v)
|
63
|
+
Value.from_object(v)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Value
|
68
|
+
def to_object
|
69
|
+
case get_value.class
|
70
|
+
when NullValue
|
71
|
+
nil
|
72
|
+
when ListValue
|
73
|
+
list_value.to_array
|
74
|
+
when MapValue
|
75
|
+
map_value.to_hash
|
76
|
+
when StructValue
|
77
|
+
struct_value.to_hash
|
78
|
+
else
|
79
|
+
get_value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class << self
|
84
|
+
def from_object(v)
|
85
|
+
case v
|
86
|
+
when NilClass
|
87
|
+
Value.new(null_value: NullValue.new)
|
88
|
+
when Symbol
|
89
|
+
Value.new(string_value: v.to_s)
|
90
|
+
when String
|
91
|
+
if v.encoding.eql?(Encoding::UTF_8) && v.valid_encoding?
|
92
|
+
Value.new(string_value: v)
|
93
|
+
else
|
94
|
+
Value.new(binary_value: v)
|
95
|
+
end
|
96
|
+
when Integer
|
97
|
+
Value.new(integer_value: v)
|
98
|
+
when Float
|
99
|
+
Value.new(double_value: v)
|
100
|
+
when TrueClass, FalseClass
|
101
|
+
Value.new(bool_value: v)
|
102
|
+
when Array
|
103
|
+
Value.new(list_value: ListValue.from_array(v))
|
104
|
+
when Hash
|
105
|
+
Value.new(map_value: MapValue.from_hash(v))
|
106
|
+
else
|
107
|
+
Value.new(struct_value: StructValue.from_object(v))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (2.3.0-upfluence)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Thrift
|
10
|
+
module Types
|
11
|
+
module Value
|
12
|
+
class NullValue; end
|
13
|
+
|
14
|
+
class ListValue; end
|
15
|
+
|
16
|
+
class MapEntry; end
|
17
|
+
|
18
|
+
class MapValue; end
|
19
|
+
|
20
|
+
class StructValue; end
|
21
|
+
|
22
|
+
class Value < ::Thrift::Union; end
|
23
|
+
|
24
|
+
class NullValue
|
25
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
26
|
+
|
27
|
+
NAME = 'NullValue'.freeze
|
28
|
+
NAMESPACE = 'types.value'.freeze
|
29
|
+
|
30
|
+
|
31
|
+
FIELDS = {
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
def struct_fields; FIELDS; end
|
36
|
+
|
37
|
+
def validate
|
38
|
+
end
|
39
|
+
|
40
|
+
::Thrift::Struct.generate_accessors self
|
41
|
+
::Thrift.register_struct_type self
|
42
|
+
end
|
43
|
+
|
44
|
+
class ListValue
|
45
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
46
|
+
|
47
|
+
NAME = 'ListValue'.freeze
|
48
|
+
NAMESPACE = 'types.value'.freeze
|
49
|
+
|
50
|
+
THRIFT_FIELD_INDEX_VALUES = 1
|
51
|
+
|
52
|
+
FIELDS = {
|
53
|
+
THRIFT_FIELD_INDEX_VALUES => {type: ::Thrift::Types::LIST, name: 'values', element: {type: ::Thrift::Types::STRUCT, class: ::Thrift::Types::Value::Value}}
|
54
|
+
}
|
55
|
+
|
56
|
+
def struct_fields; FIELDS; end
|
57
|
+
|
58
|
+
def validate
|
59
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field values is unset!') unless @values
|
60
|
+
end
|
61
|
+
|
62
|
+
::Thrift::Struct.generate_accessors self
|
63
|
+
::Thrift.register_struct_type self
|
64
|
+
end
|
65
|
+
|
66
|
+
class MapEntry
|
67
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
68
|
+
|
69
|
+
NAME = 'MapEntry'.freeze
|
70
|
+
NAMESPACE = 'types.value'.freeze
|
71
|
+
|
72
|
+
THRIFT_FIELD_INDEX_KEY = 1
|
73
|
+
THRIFT_FIELD_INDEX_VALUE = 2
|
74
|
+
|
75
|
+
FIELDS = {
|
76
|
+
THRIFT_FIELD_INDEX_KEY => {type: ::Thrift::Types::STRUCT, name: 'key', class: ::Thrift::Types::Value::Value},
|
77
|
+
THRIFT_FIELD_INDEX_VALUE => {type: ::Thrift::Types::STRUCT, name: 'value', class: ::Thrift::Types::Value::Value}
|
78
|
+
}
|
79
|
+
|
80
|
+
def struct_fields; FIELDS; end
|
81
|
+
|
82
|
+
def validate
|
83
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field key is unset!') unless @key
|
84
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field value is unset!') unless @value
|
85
|
+
end
|
86
|
+
|
87
|
+
::Thrift::Struct.generate_accessors self
|
88
|
+
::Thrift.register_struct_type self
|
89
|
+
end
|
90
|
+
|
91
|
+
class MapValue
|
92
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
93
|
+
|
94
|
+
NAME = 'MapValue'.freeze
|
95
|
+
NAMESPACE = 'types.value'.freeze
|
96
|
+
|
97
|
+
THRIFT_FIELD_INDEX_ENTRIES = 1
|
98
|
+
|
99
|
+
FIELDS = {
|
100
|
+
THRIFT_FIELD_INDEX_ENTRIES => {type: ::Thrift::Types::LIST, name: 'entries', element: {type: ::Thrift::Types::STRUCT, class: ::Thrift::Types::Value::MapEntry}}
|
101
|
+
}
|
102
|
+
|
103
|
+
def struct_fields; FIELDS; end
|
104
|
+
|
105
|
+
def validate
|
106
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field entries is unset!') unless @entries
|
107
|
+
end
|
108
|
+
|
109
|
+
::Thrift::Struct.generate_accessors self
|
110
|
+
::Thrift.register_struct_type self
|
111
|
+
end
|
112
|
+
|
113
|
+
class StructValue
|
114
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
115
|
+
|
116
|
+
NAME = 'StructValue'.freeze
|
117
|
+
NAMESPACE = 'types.value'.freeze
|
118
|
+
|
119
|
+
THRIFT_FIELD_INDEX_FIELDS = 1
|
120
|
+
|
121
|
+
FIELDS = {
|
122
|
+
THRIFT_FIELD_INDEX_FIELDS => {type: ::Thrift::Types::MAP, name: 'fields', key: {type: ::Thrift::Types::STRING}, value: {type: ::Thrift::Types::STRUCT, class: ::Thrift::Types::Value::Value}}
|
123
|
+
}
|
124
|
+
|
125
|
+
def struct_fields; FIELDS; end
|
126
|
+
|
127
|
+
def validate
|
128
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field fields is unset!') unless @fields
|
129
|
+
end
|
130
|
+
|
131
|
+
::Thrift::Struct.generate_accessors self
|
132
|
+
::Thrift.register_struct_type self
|
133
|
+
end
|
134
|
+
|
135
|
+
class Value < ::Thrift::Union
|
136
|
+
include ::Thrift::Struct_Union
|
137
|
+
|
138
|
+
NAME = 'Value'.freeze
|
139
|
+
NAMESPACE = 'types.value'.freeze
|
140
|
+
|
141
|
+
class << self
|
142
|
+
def null_value(val)
|
143
|
+
Value.new(:null_value, val)
|
144
|
+
end
|
145
|
+
|
146
|
+
def string_value(val)
|
147
|
+
Value.new(:string_value, val)
|
148
|
+
end
|
149
|
+
|
150
|
+
def binary_value(val)
|
151
|
+
Value.new(:binary_value, val)
|
152
|
+
end
|
153
|
+
|
154
|
+
def integer_value(val)
|
155
|
+
Value.new(:integer_value, val)
|
156
|
+
end
|
157
|
+
|
158
|
+
def double_value(val)
|
159
|
+
Value.new(:double_value, val)
|
160
|
+
end
|
161
|
+
|
162
|
+
def bool_value(val)
|
163
|
+
Value.new(:bool_value, val)
|
164
|
+
end
|
165
|
+
|
166
|
+
def list_value(val)
|
167
|
+
Value.new(:list_value, val)
|
168
|
+
end
|
169
|
+
|
170
|
+
def map_value(val)
|
171
|
+
Value.new(:map_value, val)
|
172
|
+
end
|
173
|
+
|
174
|
+
def struct_value(val)
|
175
|
+
Value.new(:struct_value, val)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
THRIFT_FIELD_INDEX_NULL_VALUE = 1
|
180
|
+
THRIFT_FIELD_INDEX_STRING_VALUE = 2
|
181
|
+
THRIFT_FIELD_INDEX_BINARY_VALUE = 3
|
182
|
+
THRIFT_FIELD_INDEX_INTEGER_VALUE = 4
|
183
|
+
THRIFT_FIELD_INDEX_DOUBLE_VALUE = 5
|
184
|
+
THRIFT_FIELD_INDEX_BOOL_VALUE = 6
|
185
|
+
THRIFT_FIELD_INDEX_LIST_VALUE = 7
|
186
|
+
THRIFT_FIELD_INDEX_MAP_VALUE = 8
|
187
|
+
THRIFT_FIELD_INDEX_STRUCT_VALUE = 9
|
188
|
+
|
189
|
+
FIELDS = {
|
190
|
+
THRIFT_FIELD_INDEX_NULL_VALUE => {type: ::Thrift::Types::STRUCT, name: 'null_value', class: ::Thrift::Types::Value::NullValue},
|
191
|
+
THRIFT_FIELD_INDEX_STRING_VALUE => {type: ::Thrift::Types::STRING, name: 'string_value'},
|
192
|
+
THRIFT_FIELD_INDEX_BINARY_VALUE => {type: ::Thrift::Types::STRING, name: 'binary_value', binary: true},
|
193
|
+
THRIFT_FIELD_INDEX_INTEGER_VALUE => {type: ::Thrift::Types::I64, name: 'integer_value'},
|
194
|
+
THRIFT_FIELD_INDEX_DOUBLE_VALUE => {type: ::Thrift::Types::DOUBLE, name: 'double_value'},
|
195
|
+
THRIFT_FIELD_INDEX_BOOL_VALUE => {type: ::Thrift::Types::BOOL, name: 'bool_value'},
|
196
|
+
THRIFT_FIELD_INDEX_LIST_VALUE => {type: ::Thrift::Types::STRUCT, name: 'list_value', class: ::Thrift::Types::Value::ListValue},
|
197
|
+
THRIFT_FIELD_INDEX_MAP_VALUE => {type: ::Thrift::Types::STRUCT, name: 'map_value', class: ::Thrift::Types::Value::MapValue},
|
198
|
+
THRIFT_FIELD_INDEX_STRUCT_VALUE => {type: ::Thrift::Types::STRUCT, name: 'struct_value', class: ::Thrift::Types::Value::StructValue}
|
199
|
+
}
|
200
|
+
|
201
|
+
def struct_fields; FIELDS; end
|
202
|
+
|
203
|
+
def validate
|
204
|
+
raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?
|
205
|
+
end
|
206
|
+
|
207
|
+
::Thrift::Union.generate_accessors self
|
208
|
+
::Thrift.register_struct_type self
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -38,25 +38,25 @@ shared_examples_for 'a binary protocol' do
|
|
38
38
|
|
39
39
|
it "should make strict_write readable" do
|
40
40
|
@prot.strict_write.should eql(true)
|
41
|
-
end
|
41
|
+
end
|
42
42
|
|
43
43
|
it "should write the message header" do
|
44
44
|
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
|
45
45
|
@trans.read(@trans.available).should == [protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N")
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should write the message header without version when writes are not strict" do
|
49
49
|
@prot = protocol_class.new(@trans, true, false) # no strict write
|
50
50
|
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
|
51
51
|
@trans.read(@trans.available).should == "\000\000\000\vtestMessage\001\000\000\000\021"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should write the message header with a version when writes are strict" do
|
55
55
|
@prot = protocol_class.new(@trans) # strict write
|
56
56
|
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
|
57
57
|
@trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
|
61
61
|
# message footer is a noop
|
62
62
|
|
@@ -64,44 +64,44 @@ shared_examples_for 'a binary protocol' do
|
|
64
64
|
@prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
|
65
65
|
@trans.read(@trans.available).should == [Thrift::Types::DOUBLE, 3].pack("cn")
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# field footer is a noop
|
69
|
-
|
69
|
+
|
70
70
|
it "should write the STOP field" do
|
71
71
|
@prot.write_field_stop
|
72
72
|
@trans.read(1).should == "\000"
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should write the map header" do
|
76
76
|
@prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
|
77
77
|
@trans.read(@trans.available).should == [Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN");
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# map footer is a noop
|
81
|
-
|
81
|
+
|
82
82
|
it "should write the list header" do
|
83
83
|
@prot.write_list_begin(Thrift::Types::I16, 42)
|
84
84
|
@trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# list footer is a noop
|
88
|
-
|
88
|
+
|
89
89
|
it "should write the set header" do
|
90
90
|
@prot.write_set_begin(Thrift::Types::I16, 42)
|
91
91
|
@trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it "should write a bool" do
|
95
95
|
@prot.write_bool(true)
|
96
96
|
@prot.write_bool(false)
|
97
97
|
@trans.read(@trans.available).should == "\001\000"
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "should treat a nil bool as false" do
|
101
101
|
@prot.write_bool(nil)
|
102
102
|
@trans.read(1).should == "\000"
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should write a byte" do
|
106
106
|
# byte is small enough, let's check -128..127
|
107
107
|
(-128..127).each do |i|
|
@@ -117,11 +117,11 @@ shared_examples_for 'a binary protocol' do
|
|
117
117
|
# and lastly, a Bignum is going to error out
|
118
118
|
lambda { @prot.write_byte(2**65) }.should raise_error(RangeError)
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
it "should error gracefully when trying to write a nil byte" do
|
122
122
|
lambda { @prot.write_byte(nil) }.should raise_error
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it "should write an i16" do
|
126
126
|
# try a random scattering of values
|
127
127
|
# include the signed i16 minimum/maximum
|
@@ -130,17 +130,17 @@ shared_examples_for 'a binary protocol' do
|
|
130
130
|
end
|
131
131
|
# and try something out of signed range, it should clip
|
132
132
|
@prot.write_i16(2**15 + 5)
|
133
|
-
|
133
|
+
|
134
134
|
@trans.read(@trans.available).should == "\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005"
|
135
|
-
|
135
|
+
|
136
136
|
# a Bignum should error
|
137
137
|
# lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
it "should error gracefully when trying to write a nil i16" do
|
141
141
|
lambda { @prot.write_i16(nil) }.should raise_error
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it "should write an i32" do
|
145
145
|
# try a random scattering of values
|
146
146
|
# include the signed i32 minimum/maximum
|
@@ -150,14 +150,14 @@ shared_examples_for 'a binary protocol' do
|
|
150
150
|
# try something out of signed range, it should clip
|
151
151
|
@trans.read(@trans.available).should == "\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377"
|
152
152
|
[2 ** 31 + 5, 2 ** 65 + 5].each do |i|
|
153
|
-
lambda { @prot.write_i32(i) }.should raise_error(RangeError)
|
153
|
+
lambda { @prot.write_i32(i) }.should raise_error(RangeError)
|
154
154
|
end
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "should error gracefully when trying to write a nil i32" do
|
158
158
|
lambda { @prot.write_i32(nil) }.should raise_error
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
it "should write an i64" do
|
162
162
|
# try a random scattering of values
|
163
163
|
# try the signed i64 minimum/maximum
|
@@ -176,11 +176,11 @@ shared_examples_for 'a binary protocol' do
|
|
176
176
|
"\177\377\377\377\377\377\377\377"].join("")
|
177
177
|
lambda { @prot.write_i64(2 ** 65 + 5) }.should raise_error(RangeError)
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
it "should error gracefully when trying to write a nil i64" do
|
181
181
|
lambda { @prot.write_i64(nil) }.should raise_error
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
it "should write a double" do
|
185
185
|
# try a random scattering of values, including min/max
|
186
186
|
values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
|
@@ -189,7 +189,7 @@ shared_examples_for 'a binary protocol' do
|
|
189
189
|
@trans.read(@trans.available).should == [f].pack("G")
|
190
190
|
end
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
it "should error gracefully when trying to write a nil double" do
|
194
194
|
lambda { @prot.write_double(nil) }.should raise_error
|
195
195
|
end
|
@@ -246,28 +246,28 @@ shared_examples_for 'a binary protocol' do
|
|
246
246
|
it "should error gracefully when trying to write a nil string" do
|
247
247
|
lambda { @prot.write_string(nil) }.should raise_error
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
it "should write the message header without version when writes are not strict" do
|
251
251
|
@prot = protocol_class.new(@trans, true, false) # no strict write
|
252
252
|
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
|
253
253
|
@trans.read(@trans.available).should == "\000\000\000\vtestMessage\001\000\000\000\021"
|
254
254
|
end
|
255
|
-
|
255
|
+
|
256
256
|
it "should write the message header with a version when writes are strict" do
|
257
257
|
@prot = protocol_class.new(@trans) # strict write
|
258
258
|
@prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
|
259
259
|
@trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
# message footer is a noop
|
263
|
-
|
263
|
+
|
264
264
|
it "should read a field header" do
|
265
265
|
@trans.write([Thrift::Types::STRING, 3].pack("cn"))
|
266
266
|
@prot.read_field_begin.should == [nil, Thrift::Types::STRING, 3]
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
# field footer is a noop
|
270
|
-
|
270
|
+
|
271
271
|
it "should read a stop field" do
|
272
272
|
@trans.write([Thrift::Types::STOP].pack("c"));
|
273
273
|
@prot.read_field_begin.should == [nil, Thrift::Types::STOP, 0]
|
@@ -277,36 +277,36 @@ shared_examples_for 'a binary protocol' do
|
|
277
277
|
@trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
|
278
278
|
@prot.read_map_begin.should == [Thrift::Types::DOUBLE, Thrift::Types::I64, 42]
|
279
279
|
end
|
280
|
-
|
280
|
+
|
281
281
|
# map footer is a noop
|
282
|
-
|
282
|
+
|
283
283
|
it "should read a list header" do
|
284
284
|
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
|
285
285
|
@prot.read_list_begin.should == [Thrift::Types::STRING, 17]
|
286
286
|
end
|
287
|
-
|
287
|
+
|
288
288
|
# list footer is a noop
|
289
|
-
|
289
|
+
|
290
290
|
it "should read a set header" do
|
291
291
|
@trans.write([Thrift::Types::STRING, 17].pack("cN"))
|
292
292
|
@prot.read_set_begin.should == [Thrift::Types::STRING, 17]
|
293
293
|
end
|
294
|
-
|
294
|
+
|
295
295
|
# set footer is a noop
|
296
|
-
|
296
|
+
|
297
297
|
it "should read a bool" do
|
298
298
|
@trans.write("\001\000");
|
299
299
|
@prot.read_bool.should == true
|
300
300
|
@prot.read_bool.should == false
|
301
301
|
end
|
302
|
-
|
302
|
+
|
303
303
|
it "should read a byte" do
|
304
304
|
[-128, -57, -3, 0, 17, 24, 127].each do |i|
|
305
305
|
@trans.write([i].pack("c"))
|
306
306
|
@prot.read_byte.should == i
|
307
307
|
end
|
308
308
|
end
|
309
|
-
|
309
|
+
|
310
310
|
it "should read an i16" do
|
311
311
|
# try a scattering of values, including min/max
|
312
312
|
[-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
|
@@ -314,7 +314,7 @@ shared_examples_for 'a binary protocol' do
|
|
314
314
|
@prot.read_i16.should == i
|
315
315
|
end
|
316
316
|
end
|
317
|
-
|
317
|
+
|
318
318
|
it "should read an i32" do
|
319
319
|
# try a scattering of values, including min/max
|
320
320
|
[-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
|
@@ -322,7 +322,7 @@ shared_examples_for 'a binary protocol' do
|
|
322
322
|
@prot.read_i32.should == i
|
323
323
|
end
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
it "should read an i64" do
|
327
327
|
# try a scattering of values, including min/max
|
328
328
|
[-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
|
@@ -330,7 +330,7 @@ shared_examples_for 'a binary protocol' do
|
|
330
330
|
@prot.read_i64.should == i
|
331
331
|
end
|
332
332
|
end
|
333
|
-
|
333
|
+
|
334
334
|
it "should read a double" do
|
335
335
|
# try a random scattering of values, including min/max
|
336
336
|
[Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
|
@@ -383,23 +383,20 @@ shared_examples_for 'a binary protocol' do
|
|
383
383
|
|
384
384
|
it "should perform a complete rpc with no args or return" do
|
385
385
|
srv_test(
|
386
|
-
proc {|client| client.
|
387
|
-
proc {|client| client.recv_voidMethod.should == nil}
|
386
|
+
proc {|client| client.voidMethod().should == nil },
|
388
387
|
)
|
389
388
|
end
|
390
389
|
|
391
390
|
it "should perform a complete rpc with a primitive return type" do
|
392
391
|
srv_test(
|
393
|
-
proc {|client| client.
|
394
|
-
proc {|client| client.recv_primitiveMethod.should == 1}
|
392
|
+
proc {|client| client.primitiveMethod.should == 1}
|
395
393
|
)
|
396
394
|
end
|
397
395
|
|
398
396
|
it "should perform a complete rpc with a struct return type" do
|
399
397
|
srv_test(
|
400
|
-
proc {|client| client.send_structMethod()},
|
401
398
|
proc {|client|
|
402
|
-
result = client.
|
399
|
+
result = client.structMethod
|
403
400
|
result.set_byte_map = nil
|
404
401
|
result.map_byte_map = nil
|
405
402
|
result.should == Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
|
@@ -410,14 +407,14 @@ shared_examples_for 'a binary protocol' do
|
|
410
407
|
def get_socket_connection
|
411
408
|
server = Thrift::ServerSocket.new("localhost", 9090)
|
412
409
|
server.listen
|
413
|
-
|
410
|
+
|
414
411
|
clientside = Thrift::Socket.new("localhost", 9090)
|
415
412
|
clientside.open
|
416
413
|
serverside = server.accept
|
417
414
|
[clientside, serverside, server]
|
418
415
|
end
|
419
416
|
|
420
|
-
def srv_test(
|
417
|
+
def srv_test(block)
|
421
418
|
clientside, serverside, server = get_socket_connection
|
422
419
|
|
423
420
|
clientproto = protocol_class.new(clientside)
|
@@ -425,29 +422,29 @@ shared_examples_for 'a binary protocol' do
|
|
425
422
|
|
426
423
|
processor = Srv::Processor.new(SrvHandler.new)
|
427
424
|
|
428
|
-
client = Srv::Client.new(clientproto
|
425
|
+
client = Srv::Client.new(clientproto)
|
426
|
+
|
427
|
+
t = Thread.new { processor.process(serverproto, serverproto) }
|
429
428
|
|
430
|
-
|
431
|
-
firstblock.call(client)
|
429
|
+
resp = block.call(client)
|
432
430
|
|
433
|
-
|
431
|
+
t.join
|
434
432
|
|
435
|
-
|
436
|
-
secondblock.call(client)
|
433
|
+
resp
|
437
434
|
ensure
|
438
435
|
clientside.close
|
439
436
|
serverside.close
|
440
437
|
server.close
|
441
438
|
end
|
442
439
|
|
443
|
-
class SrvHandler
|
440
|
+
class SrvHandler
|
444
441
|
def voidMethod()
|
445
442
|
end
|
446
|
-
|
443
|
+
|
447
444
|
def primitiveMethod
|
448
445
|
1
|
449
446
|
end
|
450
|
-
|
447
|
+
|
451
448
|
def structMethod
|
452
449
|
Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
|
453
450
|
end
|