tros 1.7.6.2 → 1.7.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/tros/ipc.rb +6 -6
- data/lib/tros/schema.rb +11 -15
- data/lib/tros/version.rb +1 -1
- data/test/io_test.rb +3 -3
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/tros/ipc.rb
CHANGED
@@ -18,7 +18,7 @@ require "net/http"
|
|
18
18
|
|
19
19
|
module Tros::IPC
|
20
20
|
|
21
|
-
class
|
21
|
+
class AvroRemoteError < Tros::AvroError; end
|
22
22
|
|
23
23
|
HANDSHAKE_REQUEST_SCHEMA = Tros::Schema.parse <<-JSON
|
24
24
|
{
|
@@ -70,7 +70,7 @@ module Tros::IPC
|
|
70
70
|
BUFFER_SIZE = 8192
|
71
71
|
|
72
72
|
# Raised when an error message is sent by an Tros requestor or responder.
|
73
|
-
class
|
73
|
+
class AvroRemoteException < Tros::AvroError; end
|
74
74
|
|
75
75
|
class ConnectionClosedException < Tros::AvroError; end
|
76
76
|
|
@@ -226,7 +226,7 @@ module Tros::IPC
|
|
226
226
|
|
227
227
|
def read_error(writers_schema, readers_schema, decoder)
|
228
228
|
datum_reader = Tros::IO::DatumReader.new(writers_schema, readers_schema)
|
229
|
-
|
229
|
+
AvroRemoteError.new(datum_reader.read(decoder))
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
@@ -276,10 +276,10 @@ module Tros::IPC
|
|
276
276
|
# perform server logic
|
277
277
|
begin
|
278
278
|
response = call(local_message, request)
|
279
|
-
rescue
|
279
|
+
rescue AvroRemoteError => e
|
280
280
|
error = e
|
281
281
|
rescue Exception => e
|
282
|
-
error =
|
282
|
+
error = AvroRemoteError.new(e.to_s)
|
283
283
|
end
|
284
284
|
|
285
285
|
# write response using local protocol
|
@@ -293,7 +293,7 @@ module Tros::IPC
|
|
293
293
|
write_error(writers_schema, error, buffer_encoder)
|
294
294
|
end
|
295
295
|
rescue Tros::AvroError => e
|
296
|
-
error =
|
296
|
+
error = AvroRemoteException.new(e.to_s)
|
297
297
|
buffer_encoder = Tros::IO::BinaryEncoder.new(StringIO.new)
|
298
298
|
META_WRITER.write(response_metadata, buffer_encoder)
|
299
299
|
buffer_encoder.write_boolean(true)
|
data/lib/tros/schema.rb
CHANGED
@@ -92,18 +92,18 @@ module Tros
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# Determine if a ruby datum is an instance of a schema
|
95
|
-
def self.validate(expected_schema, datum)
|
96
|
-
return true if validate_strictly(expected_schema, datum)
|
95
|
+
def self.validate(expected_schema, datum, validator_method = :validate)
|
96
|
+
return true if validate_strictly(expected_schema, datum, validator_method)
|
97
97
|
case expected_schema.type_sym
|
98
98
|
when :float, :double
|
99
|
-
datum.is_a?(
|
99
|
+
datum.is_a?(Integer)
|
100
100
|
else
|
101
101
|
return false
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
# Determine if a ruby datum is an instance of a schema
|
106
|
-
def self.validate_strictly(expected_schema, datum)
|
106
|
+
def self.validate_strictly(expected_schema, datum, validator_method = :validate_strictly)
|
107
107
|
case expected_schema.type_sym
|
108
108
|
when :null
|
109
109
|
datum.nil?
|
@@ -112,11 +112,9 @@ module Tros
|
|
112
112
|
when :string, :bytes
|
113
113
|
datum.is_a? String
|
114
114
|
when :int
|
115
|
-
|
116
|
-
(INT_MIN_VALUE <= datum) && (datum <= INT_MAX_VALUE)
|
115
|
+
datum.is_a?(Integer) && (INT_MIN_VALUE <= datum) && (datum <= INT_MAX_VALUE)
|
117
116
|
when :long
|
118
|
-
|
119
|
-
(LONG_MIN_VALUE <= datum) && (datum <= LONG_MAX_VALUE)
|
117
|
+
datum.is_a?(Integer) && (LONG_MIN_VALUE <= datum) && (datum <= LONG_MAX_VALUE)
|
120
118
|
when :float, :double
|
121
119
|
datum.is_a?(Float)
|
122
120
|
when :fixed
|
@@ -125,15 +123,15 @@ module Tros
|
|
125
123
|
expected_schema.symbols.include? datum
|
126
124
|
when :array
|
127
125
|
datum.is_a?(Array) &&
|
128
|
-
datum.all?{|d|
|
126
|
+
datum.all?{|d| send(validator_method, expected_schema.items, d) }
|
129
127
|
when :map
|
130
128
|
datum.keys.all?{|k| k.is_a? String } &&
|
131
|
-
datum.values.all?{|v|
|
129
|
+
datum.values.all?{|v| send(validator_method, expected_schema.values, v) }
|
132
130
|
when :union
|
133
|
-
expected_schema.schemas.any?{|s|
|
131
|
+
expected_schema.schemas.any? { |s| send(validator_method, s, datum) }
|
134
132
|
when :record, :error, :request
|
135
133
|
datum.is_a?(Hash) &&
|
136
|
-
expected_schema.fields.all?{|f|
|
134
|
+
expected_schema.fields.all? { |f| send(validator_method, f.type, datum[f.name]) }
|
137
135
|
else
|
138
136
|
raise TypeError, "#{expected_schema.inspect} is not recognized as type."
|
139
137
|
end
|
@@ -347,9 +345,7 @@ module Tros
|
|
347
345
|
attr_reader :size
|
348
346
|
def initialize(name, space, size, names=nil)
|
349
347
|
# Ensure valid cto args
|
350
|
-
|
351
|
-
raise AvroError, 'Fixed Schema requires a valid integer for size property.'
|
352
|
-
end
|
348
|
+
raise AvroError, 'Fixed Schema requires a valid integer for size property.' unless size.is_a?(Integer)
|
353
349
|
super(:fixed, name, space, names)
|
354
350
|
@size = size
|
355
351
|
end
|
data/lib/tros/version.rb
CHANGED
data/test/io_test.rb
CHANGED
@@ -172,7 +172,7 @@ EOS
|
|
172
172
|
[-8193, '81 80 01'],
|
173
173
|
]
|
174
174
|
|
175
|
-
def
|
175
|
+
def avro_hexlify(reader)
|
176
176
|
bytes = []
|
177
177
|
current_byte = reader.read(1)
|
178
178
|
bytes << hexlify(current_byte)
|
@@ -196,7 +196,7 @@ EOS
|
|
196
196
|
datum_writer.write(value, encoder)
|
197
197
|
|
198
198
|
buffer.seek(0)
|
199
|
-
hex_val =
|
199
|
+
hex_val = avro_hexlify(buffer)
|
200
200
|
|
201
201
|
assert_equal hex_encoding, hex_val
|
202
202
|
end
|
@@ -211,7 +211,7 @@ EOS
|
|
211
211
|
|
212
212
|
# read it out of the buffer and hexlify it
|
213
213
|
buffer.seek(0)
|
214
|
-
hex_val =
|
214
|
+
hex_val = avro_hexlify(buffer)
|
215
215
|
|
216
216
|
assert_equal hex_encoding, hex_val
|
217
217
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tros
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.6.
|
4
|
+
version: 1.7.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
segments:
|
107
107
|
- 0
|
108
|
-
hash:
|
108
|
+
hash: -3591240749969273251
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash:
|
117
|
+
hash: -3591240749969273251
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
120
|
rubygems_version: 1.8.23
|