avro-salsify-fork 1.9.0.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.
@@ -0,0 +1,171 @@
1
+ # -*- coding: utf-8 -*-
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, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'test_help'
19
+ require 'case_finder'
20
+
21
+ class TestSchemaNormalization < Test::Unit::TestCase
22
+ def test_primitives
23
+ %w[null boolean string bytes int long float double].each do |type|
24
+ schema = Avro::Schema.parse(<<-JSON)
25
+ { "type": "#{type}" }
26
+ JSON
27
+
28
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
29
+
30
+ assert_equal %("#{type}"), canonical_form
31
+ end
32
+ end
33
+
34
+ def test_records
35
+ schema = Avro::Schema.parse(<<-JSON)
36
+ {
37
+ "type": "record",
38
+ "name": "test",
39
+ "namespace": "random",
40
+ "doc": "some record",
41
+ "fields": [
42
+ { "name": "height", "type": "int", "doc": "the height" }
43
+ ]
44
+ }
45
+ JSON
46
+
47
+ expected_type = <<-JSON.strip
48
+ {"name":"random.test","type":"record","fields":[{"name":"height","type":"int"}]}
49
+ JSON
50
+
51
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
52
+
53
+ assert_equal expected_type, canonical_form
54
+ end
55
+
56
+ def test_recursive_records
57
+ schema = Avro::Schema.parse(<<-JSON)
58
+ {
59
+ "type": "record",
60
+ "name": "item",
61
+ "fields": [
62
+ { "name": "next", "type": "item" }
63
+ ]
64
+ }
65
+ JSON
66
+
67
+ expected_type = <<-JSON.strip
68
+ {"name":"item","type":"record","fields":[{"name":"next","type":"item"}]}
69
+ JSON
70
+
71
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
72
+
73
+ assert_equal expected_type, canonical_form
74
+ end
75
+
76
+ def test_enums
77
+ schema = Avro::Schema.parse(<<-JSON)
78
+ {
79
+ "type": "enum",
80
+ "name": "suit",
81
+ "namespace": "cards",
82
+ "doc": "the different suits of cards",
83
+ "symbols": ["club", "hearts", "diamond", "spades"]
84
+ }
85
+ JSON
86
+
87
+ expected_type = <<-JSON.strip
88
+ {"name":"cards.suit","type":"enum","symbols":["club","hearts","diamond","spades"]}
89
+ JSON
90
+
91
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
92
+
93
+ assert_equal expected_type, canonical_form
94
+ end
95
+
96
+ def test_fixed
97
+ schema = Avro::Schema.parse(<<-JSON)
98
+ {
99
+ "type": "fixed",
100
+ "name": "id",
101
+ "namespace": "db",
102
+ "size": 64
103
+ }
104
+ JSON
105
+
106
+ expected_type = <<-JSON.strip
107
+ {"name":"db.id","type":"fixed","size":64}
108
+ JSON
109
+
110
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
111
+
112
+ assert_equal expected_type, canonical_form
113
+ end
114
+
115
+ def test_arrays
116
+ schema = Avro::Schema.parse(<<-JSON)
117
+ {
118
+ "type": "array",
119
+ "doc": "the items",
120
+ "items": "int"
121
+ }
122
+ JSON
123
+
124
+ expected_type = <<-JSON.strip
125
+ {"type":"array","items":"int"}
126
+ JSON
127
+
128
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
129
+
130
+ assert_equal expected_type, canonical_form
131
+ end
132
+
133
+ def test_maps
134
+ schema = Avro::Schema.parse(<<-JSON)
135
+ {
136
+ "type": "map",
137
+ "doc": "the items",
138
+ "values": "int"
139
+ }
140
+ JSON
141
+
142
+ expected_type = <<-JSON.strip
143
+ {"type":"map","values":"int"}
144
+ JSON
145
+
146
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
147
+
148
+ assert_equal expected_type, canonical_form
149
+ end
150
+
151
+ def test_unions
152
+ schema = Avro::Schema.parse(<<-JSON)
153
+ ["int", "string"]
154
+ JSON
155
+
156
+ expected_type = <<-JSON.strip
157
+ ["int","string"]
158
+ JSON
159
+
160
+ canonical_form = Avro::SchemaNormalization.to_parsing_form(schema)
161
+
162
+ assert_equal expected_type, canonical_form
163
+ end
164
+
165
+ def test_shared_dataset
166
+ CaseFinder.cases.each do |test_case|
167
+ schema = Avro::Schema.parse(test_case.input)
168
+ assert_equal test_case.canonical, Avro::SchemaNormalization.to_parsing_form(schema)
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,40 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'test_help'
18
+
19
+ class TestSocketTransport < Test::Unit::TestCase
20
+ def test_buffer_writing
21
+ io = StringIO.new
22
+ st = Avro::IPC::SocketTransport.new(io)
23
+ buffer_length = "\000\000\000\006" # 6 in big-endian
24
+ message = 'abcdef'
25
+ null_ending = "\000\000\000\000" # 0 in big-endian
26
+ full = buffer_length + message + null_ending
27
+ st.write_framed_message('abcdef')
28
+ assert_equal full, io.string
29
+ end
30
+
31
+ def test_buffer_reading
32
+ buffer_length = "\000\000\000\005" # 5 in big-endian
33
+ message = "hello"
34
+ null_ending = "\000\000\000\000" # 0 in big-endian
35
+ full = buffer_length + message + null_ending
36
+ io = StringIO.new(full)
37
+ st = Avro::IPC::SocketTransport.new(io)
38
+ assert_equal 'hello', st.read_framed_message
39
+ end
40
+ end
@@ -0,0 +1,144 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'avro'
18
+ require 'webrick'
19
+ require 'uri'
20
+ require 'logger'
21
+
22
+ class GenericResponder < Avro::IPC::Responder
23
+ def initialize(proto, msg, datum)
24
+ proto_json = open(proto).read
25
+ super(Avro::Protocol.parse(proto_json))
26
+ @msg = msg
27
+ @datum = datum
28
+ end
29
+
30
+ def call(message, request)
31
+ if message.name == @msg
32
+ STDERR.puts "Message: #{message.name} Datum: #{@datum.inspect}"
33
+ @datum
34
+ end
35
+ end
36
+ end
37
+
38
+ class GenericHandler < WEBrick::HTTPServlet::AbstractServlet
39
+ def do_POST(req, resp)
40
+ call_request = Avro::IPC::FramedReader.new(StringIO.new(req.body)).read_framed_message
41
+ unframed_resp = $responder.respond(call_request)
42
+ writer = Avro::IPC::FramedWriter.new(StringIO.new)
43
+ writer.write_framed_message(unframed_resp)
44
+ resp.body = writer.to_s
45
+ @server.stop
46
+ end
47
+ end
48
+
49
+ def run_server(uri, proto, msg, datum)
50
+ uri = URI.parse(uri)
51
+ $responder = GenericResponder.new(proto, msg, datum)
52
+ server = WEBrick::HTTPServer.new(:BindAddress => uri.host,
53
+ :Port => uri.port,
54
+ :Logger => Logger.new(StringIO.new))
55
+ server.mount '/', GenericHandler
56
+ puts "Port: #{server.config[:Port]}"
57
+ STDOUT.flush
58
+ trap("INT") { server.stop }
59
+ trap("TERM") { server.stop }
60
+ server.start
61
+ end
62
+
63
+ def send_message(uri, proto, msg, datum)
64
+ uri = URI.parse(uri)
65
+ trans = Avro::IPC::HTTPTransceiver.new(uri.host, uri.port)
66
+ proto_json = open(proto).read
67
+ requestor = Avro::IPC::Requestor.new(Avro::Protocol.parse(proto_json),
68
+ trans)
69
+ p requestor.request(msg, datum)
70
+ end
71
+
72
+ def file_or_stdin(f)
73
+ f == "-" ? STDIN : open(f)
74
+ end
75
+
76
+ def main
77
+ if ARGV.size == 0
78
+ puts "Usage: #{$0} [dump|rpcreceive|rpcsend]"
79
+ return 1
80
+ end
81
+
82
+ case ARGV[0]
83
+ when "dump"
84
+ if ARGV.size != 3
85
+ puts "Usage: #{$0} dump input_file"
86
+ return 1
87
+ end
88
+ d = Avro::DataFile.new(file_or_stdin(ARGV[1]), Avro::IO::DatumReader.new)
89
+ d.each{|o| puts o.inspect }
90
+ d.close
91
+ when "rpcreceive"
92
+ usage_str = "Usage: #{$0} rpcreceive uri protocol_file "
93
+ usage_str += "message_name (-data d | -file f)"
94
+
95
+ unless [4, 6].include?(ARGV.size)
96
+ puts usage_str
97
+ return 1
98
+ end
99
+ uri, proto, msg = ARGV[1,3]
100
+ datum = nil
101
+ if ARGV.size > 4
102
+ case ARGV[4]
103
+ when "-file"
104
+ Avro::DataFile.open(ARGV[5]) {|f|
105
+ f.each{|d| datum = d; break }
106
+ }
107
+ when "-data"
108
+ puts "JSON Decoder not yet implemented."
109
+ return 1
110
+ else
111
+ puts usage_str
112
+ return 1
113
+ end
114
+ end
115
+ run_server(uri, proto, msg, datum)
116
+ when "rpcsend"
117
+ usage_str = "Usage: #{$0} rpcsend uri protocol_file "
118
+ usage_str += "message_name (-data d | -file f)"
119
+ unless [4,6].include?(ARGV.size)
120
+ puts usage_str
121
+ return 1
122
+ end
123
+ uri, proto, msg = ARGV[1,3]
124
+ datum = nil
125
+ if ARGV.size > 4
126
+ case ARGV[4]
127
+ when "-file"
128
+ Avro::DataFile.open(ARGV[5]){|f| f.each{|d| datum = d; break } }
129
+ when "-data"
130
+ puts "JSON Decoder not yet implemented"
131
+ return 1
132
+ else
133
+ puts usage_str
134
+ return 1
135
+ end
136
+ end
137
+ send_message(uri, proto, msg, datum)
138
+ end
139
+ return 0
140
+ end
141
+
142
+ if __FILE__ == $0
143
+ exit(main)
144
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avro-salsify-fork
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Apache Software Foundation / Salsify Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |-
28
+ Avro is a data serialization and RPC format.
29
+ This release contains the changes submitted in https://github.com/apache/avro/pull/116
30
+ to support logical types in the Ruby gem.
31
+ email: engineering@salsify.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files:
35
+ - CHANGELOG
36
+ - LICENSE
37
+ - lib/avro.rb
38
+ - lib/avro/data_file.rb
39
+ - lib/avro/io.rb
40
+ - lib/avro/ipc.rb
41
+ - lib/avro/logical_types.rb
42
+ - lib/avro/protocol.rb
43
+ - lib/avro/schema.rb
44
+ - lib/avro/schema_normalization.rb
45
+ files:
46
+ - CHANGELOG
47
+ - LICENSE
48
+ - Manifest
49
+ - NOTICE
50
+ - Rakefile
51
+ - avro-salsify-fork.gemspec
52
+ - avro.gemspec
53
+ - interop/test_interop.rb
54
+ - lib/avro.rb
55
+ - lib/avro/data_file.rb
56
+ - lib/avro/io.rb
57
+ - lib/avro/ipc.rb
58
+ - lib/avro/logical_types.rb
59
+ - lib/avro/protocol.rb
60
+ - lib/avro/schema.rb
61
+ - lib/avro/schema_normalization.rb
62
+ - test/case_finder.rb
63
+ - test/random_data.rb
64
+ - test/sample_ipc_client.rb
65
+ - test/sample_ipc_http_client.rb
66
+ - test/sample_ipc_http_server.rb
67
+ - test/sample_ipc_server.rb
68
+ - test/test_datafile.rb
69
+ - test/test_fingerprints.rb
70
+ - test/test_help.rb
71
+ - test/test_io.rb
72
+ - test/test_logical_types.rb
73
+ - test/test_protocol.rb
74
+ - test/test_schema.rb
75
+ - test/test_schema_normalization.rb
76
+ - test/test_socket_transport.rb
77
+ - test/tool.rb
78
+ homepage: https://github.com/salsify/avro
79
+ licenses:
80
+ - Apache License 2.0 (Apache-2.0)
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options:
84
+ - "--line-numbers"
85
+ - "--title"
86
+ - Avro-salsify-fork
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '1.2'
99
+ requirements: []
100
+ rubyforge_project: avro-salsify-fork
101
+ rubygems_version: 2.6.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Apache Avro for Ruby with logical types patch
105
+ test_files:
106
+ - test/test_datafile.rb
107
+ - test/test_fingerprints.rb
108
+ - test/test_help.rb
109
+ - test/test_io.rb
110
+ - test/test_logical_types.rb
111
+ - test/test_protocol.rb
112
+ - test/test_schema.rb
113
+ - test/test_schema_normalization.rb
114
+ - test/test_socket_transport.rb