tros 1.7.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
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_helper'
18
+
19
+ class SchemaTest < Minitest::Test
20
+
21
+ def test_default_namespace
22
+ schema = Tros::Schema.parse <<-SCHEMA
23
+ {"type": "record", "name": "OuterRecord", "fields": [
24
+ {"name": "field1", "type": {
25
+ "type": "record", "name": "InnerRecord", "fields": []
26
+ }},
27
+ {"name": "field2", "type": "InnerRecord"}
28
+ ]}
29
+ SCHEMA
30
+
31
+ assert_equal schema.name, 'OuterRecord'
32
+ assert_equal schema.fullname, 'OuterRecord'
33
+ assert_nil schema.namespace
34
+
35
+ schema.fields.each do |field|
36
+ assert_equal field.type.name, 'InnerRecord'
37
+ assert_equal field.type.fullname, 'InnerRecord'
38
+ assert_nil field.type.namespace
39
+ end
40
+ end
41
+
42
+ def test_inherited_namespace
43
+ schema = Tros::Schema.parse <<-SCHEMA
44
+ {"type": "record", "name": "OuterRecord", "namespace": "my.name.space",
45
+ "fields": [
46
+ {"name": "definition", "type": {
47
+ "type": "record", "name": "InnerRecord", "fields": []
48
+ }},
49
+ {"name": "relativeReference", "type": "InnerRecord"},
50
+ {"name": "absoluteReference", "type": "my.name.space.InnerRecord"}
51
+ ]}
52
+ SCHEMA
53
+
54
+ assert_equal schema.name, 'OuterRecord'
55
+ assert_equal schema.fullname, 'my.name.space.OuterRecord'
56
+ assert_equal schema.namespace, 'my.name.space'
57
+ schema.fields.each do |field|
58
+ assert_equal field.type.name, 'InnerRecord'
59
+ assert_equal field.type.fullname, 'my.name.space.InnerRecord'
60
+ assert_equal field.type.namespace, 'my.name.space'
61
+ end
62
+ end
63
+
64
+ def test_inherited_namespace_from_dotted_name
65
+ schema = Tros::Schema.parse <<-SCHEMA
66
+ {"type": "record", "name": "my.name.space.OuterRecord", "fields": [
67
+ {"name": "definition", "type": {
68
+ "type": "enum", "name": "InnerEnum", "symbols": ["HELLO", "WORLD"]
69
+ }},
70
+ {"name": "relativeReference", "type": "InnerEnum"},
71
+ {"name": "absoluteReference", "type": "my.name.space.InnerEnum"}
72
+ ]}
73
+ SCHEMA
74
+
75
+ assert_equal schema.name, 'OuterRecord'
76
+ assert_equal schema.fullname, 'my.name.space.OuterRecord'
77
+ assert_equal schema.namespace, 'my.name.space'
78
+ schema.fields.each do |field|
79
+ assert_equal field.type.name, 'InnerEnum'
80
+ assert_equal field.type.fullname, 'my.name.space.InnerEnum'
81
+ assert_equal field.type.namespace, 'my.name.space'
82
+ end
83
+ end
84
+
85
+ def test_nested_namespaces
86
+ schema = Tros::Schema.parse <<-SCHEMA
87
+ {"type": "record", "name": "outer.OuterRecord", "fields": [
88
+ {"name": "middle", "type": {
89
+ "type": "record", "name": "middle.MiddleRecord", "fields": [
90
+ {"name": "inner", "type": {
91
+ "type": "record", "name": "InnerRecord", "fields": [
92
+ {"name": "recursive", "type": "MiddleRecord"}
93
+ ]
94
+ }}
95
+ ]
96
+ }}
97
+ ]}
98
+ SCHEMA
99
+
100
+ assert_equal schema.name, 'OuterRecord'
101
+ assert_equal schema.fullname, 'outer.OuterRecord'
102
+ assert_equal schema.namespace, 'outer'
103
+ middle = schema.fields.first.type
104
+ assert_equal middle.name, 'MiddleRecord'
105
+ assert_equal middle.fullname, 'middle.MiddleRecord'
106
+ assert_equal middle.namespace, 'middle'
107
+ inner = middle.fields.first.type
108
+ assert_equal inner.name, 'InnerRecord'
109
+ assert_equal inner.fullname, 'middle.InnerRecord'
110
+ assert_equal inner.namespace, 'middle'
111
+ assert_equal inner.fields.first.type, middle
112
+ end
113
+
114
+ def test_to_avro_includes_namespaces
115
+ schema = Tros::Schema.parse <<-SCHEMA
116
+ {"type": "record", "name": "my.name.space.OuterRecord", "fields": [
117
+ {"name": "definition", "type": {
118
+ "type": "fixed", "name": "InnerFixed", "size": 16
119
+ }},
120
+ {"name": "reference", "type": "InnerFixed"}
121
+ ]}
122
+ SCHEMA
123
+
124
+ assert_equal schema.to_avro, {
125
+ 'type' => 'record', 'name' => 'OuterRecord', 'namespace' => 'my.name.space',
126
+ 'fields' => [
127
+ {'name' => 'definition', 'type' => {
128
+ 'type' => 'fixed', 'name' => 'InnerFixed', 'namespace' => 'my.name.space',
129
+ 'size' => 16
130
+ }},
131
+ {'name' => 'reference', 'type' => 'my.name.space.InnerFixed'}
132
+ ]
133
+ }
134
+ end
135
+ 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_helper'
18
+
19
+ class SocketTransportTest < Minitest::Test
20
+ def test_buffer_writing
21
+ io = StringIO.new
22
+ st = Tros::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 = Tros::IPC::SocketTransport.new(io)
38
+ assert_equal 'hello', st.read_framed_message
39
+ end
40
+ end
@@ -0,0 +1,26 @@
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 "minitest/autorun"
18
+ require "stringio"
19
+
20
+ TEST_DIR = File.expand_path('..', __FILE__)
21
+ ROOT_DIR = File.expand_path('..', TEST_DIR)
22
+ TMP_DIR = File.join(ROOT_DIR, 'tmp')
23
+ Dir.mkdir(TMP_DIR) unless File.exist?(TMP_DIR)
24
+
25
+ require "tros"
26
+ require "helpers/random_data"
@@ -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 'tros'
18
+ require 'webrick'
19
+ require 'uri'
20
+ require 'logger'
21
+
22
+ class GenericResponder < Tros::IPC::Responder
23
+ def initialize(proto, msg, datum)
24
+ proto_json = open(proto).read
25
+ super(Tros::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 = Tros::IPC::FramedReader.new(StringIO.new(req.body)).read_framed_message
41
+ unframed_resp = $responder.respond(call_request)
42
+ writer = Tros::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 = Tros::IPC::HTTPTransceiver.new(uri.host, uri.port)
66
+ proto_json = open(proto).read
67
+ requestor = Tros::IPC::Requestor.new(Tros::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 = Tros::DataFile.new(file_or_stdin(ARGV[1]), Tros::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
+ Tros::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
+ Tros::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
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'tros/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'tros'
9
+
10
+ # Do not change the version and date fields by hand. This will be done
11
+ # automatically by the gem release script.
12
+ s.version = Tros::VERSION
13
+
14
+ s.summary = "This is a fork of the official avro gem."
15
+ s.description = <<-EOT
16
+ This fork of the official Avro gem exists to fix some specific issues, that
17
+ cannot wait for a release of the full AVRO suite.
18
+ EOT
19
+
20
+ s.authors = ['Willem van Bergen']
21
+ s.email = ['willem@railsdoctors.com']
22
+ s.homepage = 'http://avro.apache.org'
23
+ s.license = 'Apache-2.0'
24
+
25
+ s.add_development_dependency('rake')
26
+ s.add_development_dependency('minitest', '~> 5')
27
+
28
+ s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
29
+
30
+ s.files = `git ls-files`.split($/)
31
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
32
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tros
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.6.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Willem van Bergen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '5'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '5'
46
+ description: ! " This fork of the official Avro gem exists to fix some specific
47
+ issues, that\n cannot wait for a release of the full AVRO suite.\n"
48
+ email:
49
+ - willem@railsdoctors.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .travis.yml
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - README.md
59
+ - Rakefile
60
+ - lib/tros.rb
61
+ - lib/tros/data_file.rb
62
+ - lib/tros/io.rb
63
+ - lib/tros/ipc.rb
64
+ - lib/tros/protocol.rb
65
+ - lib/tros/schema.rb
66
+ - lib/tros/version.rb
67
+ - test/datafile_test.rb
68
+ - test/fixtures/schemas/org/apache/avro/data/Json.avsc
69
+ - test/fixtures/schemas/org/apache/avro/ipc/HandshakeRequest.avsc
70
+ - test/fixtures/schemas/org/apache/avro/ipc/HandshakeResponse.avsc
71
+ - test/fixtures/schemas/org/apache/avro/ipc/trace/avroTrace.avdl
72
+ - test/fixtures/schemas/org/apache/avro/ipc/trace/avroTrace.avpr
73
+ - test/fixtures/schemas/org/apache/avro/mapred/tether/InputProtocol.avpr
74
+ - test/fixtures/schemas/org/apache/avro/mapred/tether/OutputProtocol.avpr
75
+ - test/helpers/random_data.rb
76
+ - test/io_test.rb
77
+ - test/protocol_test.rb
78
+ - test/sample_ipc_client.rb
79
+ - test/sample_ipc_http_client.rb
80
+ - test/sample_ipc_http_server.rb
81
+ - test/sample_ipc_server.rb
82
+ - test/schema_test.rb
83
+ - test/socket_transport_test.rb
84
+ - test/test_helper.rb
85
+ - test/tool.rb
86
+ - tros.gemspec
87
+ homepage: http://avro.apache.org
88
+ licenses:
89
+ - Apache-2.0
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --title
93
+ - tros
94
+ - --main
95
+ - README.rdoc
96
+ - --line-numbers
97
+ - --inline-source
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.23
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: This is a fork of the official avro gem.
118
+ test_files:
119
+ - test/datafile_test.rb
120
+ - test/fixtures/schemas/org/apache/avro/data/Json.avsc
121
+ - test/fixtures/schemas/org/apache/avro/ipc/HandshakeRequest.avsc
122
+ - test/fixtures/schemas/org/apache/avro/ipc/HandshakeResponse.avsc
123
+ - test/fixtures/schemas/org/apache/avro/ipc/trace/avroTrace.avdl
124
+ - test/fixtures/schemas/org/apache/avro/ipc/trace/avroTrace.avpr
125
+ - test/fixtures/schemas/org/apache/avro/mapred/tether/InputProtocol.avpr
126
+ - test/fixtures/schemas/org/apache/avro/mapred/tether/OutputProtocol.avpr
127
+ - test/helpers/random_data.rb
128
+ - test/io_test.rb
129
+ - test/protocol_test.rb
130
+ - test/sample_ipc_client.rb
131
+ - test/sample_ipc_http_client.rb
132
+ - test/sample_ipc_http_server.rb
133
+ - test/sample_ipc_server.rb
134
+ - test/schema_test.rb
135
+ - test/socket_transport_test.rb
136
+ - test/test_helper.rb
137
+ - test/tool.rb