thrift-amqp 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d14bcafe0df88ac5a2ea265a68a070721b8b531
4
- data.tar.gz: 9f7d8a3e80b72a75df0205e2371bdbdca66fa11d
3
+ metadata.gz: 9685f8ce1ba29a7a558f03320150bd5ebd0fdc2b
4
+ data.tar.gz: eda997fc1353715d1a659ca05e02e3bc8061ca6c
5
5
  SHA512:
6
- metadata.gz: a7d06fecfa0209a2e2d4fd5b08f417030635d489ff98c701190698bcb5e31f832d917423a557a8136c403bdab69946fb9760dff184338c7132ff5afad22c0d4f
7
- data.tar.gz: b2f67470b1d9defaeefae2081f4369350c739f38860be7ef5110822ee7449429d41517f63edd29d3c479d5e9ae9cc1b4172cf4aa6b825610e75d757813ea05a4
6
+ metadata.gz: dcd92d6254706a1533185f2b4db1bcf5721e854330a19b4b31c24ce7ef929152c12029f6ebc4390a17a31d49071417cc7d3eba8d53a460ea1dacb0c2b5c02657
7
+ data.tar.gz: a1fe29ef097e8e0b867eaec863c788380e1ba43ba0d2c320538647d6673bfcea3e3473cfc7d58e79a3d0fa50b8f7ebd968ea04638578a7bc9f18026a8005fa68
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -3,13 +3,13 @@ require 'thrift'
3
3
  require 'bunny'
4
4
  require 'stringio'
5
5
  require 'timeout'
6
- require 'uuidtools'
6
+ require 'securerandom'
7
7
 
8
8
  module Thrift
9
9
  class AMQPClientTransport < BaseTransport
10
10
  def initialize(amqp_uri, exchange_name, routing_key)
11
11
  @outbuf = Bytes.empty_byte_buffer
12
- @inbuf = Bytes.empty_byte_buffer
12
+ @inbuf = StringIO.new
13
13
  @conn = Bunny.new(amqp_uri)
14
14
  @queue = Queue.new
15
15
 
@@ -20,11 +20,14 @@ module Thrift
20
20
  unless @channel
21
21
  @conn.start
22
22
  @channel = @conn.create_channel
23
+ @service_exchange = @channel.exchange(@exchange_name)
23
24
  @reply_queue = @channel.queue("", auto_delete: true, exclusive: true)
24
25
 
25
- @reply_queue.subscribe(block: false, ack: true) do |delivery_info, properties, payload|
26
+ @reply_queue.subscribe(block: false, manual_ack: true) do |delivery_info, properties, payload|
27
+ @inbuf.write payload
28
+ @inbuf.rewind
26
29
  @queue << true
27
- @inbuf << payload
30
+ @channel.acknowledge(delivery_info.delivery_tag, false)
28
31
  end
29
32
  end
30
33
  end
@@ -42,8 +45,8 @@ module Thrift
42
45
  end
43
46
 
44
47
  def read(sz)
45
- buf = @queue.pop
46
- @inbuf.read sz
48
+ @queue.pop if @inbuf.eof?
49
+ @inbuf.read(sz)
47
50
  end
48
51
 
49
52
  def write(buf)
@@ -58,14 +61,13 @@ module Thrift
58
61
  reply_to: @reply_queue.name
59
62
  )
60
63
 
61
-
62
64
  @outbuf = Bytes.empty_byte_buffer
63
65
  end
64
66
 
65
- prtected
67
+ protected
66
68
 
67
69
  def generate_uuid
68
- UUIDTools::UUID.timestamp_create.to_s
70
+ SecureRandom.hex(13)
69
71
  end
70
72
  end
71
73
  end
@@ -19,6 +19,29 @@ module Thrift
19
19
  @prefetch = opts[:prefetch]
20
20
  end
21
21
 
22
+ def handle(delivery_info, properties, payload)
23
+ input = StringIO.new payload
24
+ out = StringIO.new
25
+ transport = IOStreamTransport.new input, out
26
+ protocol = @iprot_factory.get_protocol transport
27
+
28
+ begin
29
+ @processor.process protocol, protocol
30
+
31
+ if out.length > 0
32
+ out.rewind
33
+ @channel.default_exchange.publish(
34
+ out.read(out.length),
35
+ routing_key: properties.reply_to
36
+ )
37
+ end
38
+ rescue => e
39
+ LOGGER.error("Processor failure #{e}")
40
+ end
41
+
42
+ @channel.acknowledge(delivery_info.delivery_tag, false)
43
+ end
44
+
22
45
  def serve
23
46
  @conn = Bunny.new(@amqp_uri)
24
47
 
@@ -32,20 +55,12 @@ module Thrift
32
55
  @channel.prefetch @prefetch
33
56
 
34
57
  loop do
35
- LOGGER.error("Fetching message from #{@queue_name}")
58
+ LOGGER.info("Fetching message from #{@queue_name}")
36
59
  queue.subscribe(
37
60
  manual_ack: true,
38
61
  block: true
39
- ) do |delivery_info, _properties, payload|
40
- trans = MemoryBufferTransport.new(payload)
41
- iprot = @iprot_factory.get_protocol(trans)
42
-
43
- begin
44
- @processor.process(iprot, nil)
45
- rescue => e
46
- LOGGER.error("Processor failure #{e}")
47
- end
48
- @channel.acknowledge(delivery_info.delivery_tag, false)
62
+ ) do |delivery_info, properties, payload|
63
+ handle delivery_info, properties, payload
49
64
  end
50
65
  end
51
66
  rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::ConnectionClosedError
@@ -1,5 +1,5 @@
1
1
  module Thrift
2
2
  module AMQP
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'Client' do
5
+ before(:all) do
6
+ @pid = fork do
7
+ run_server
8
+ end
9
+ end
10
+
11
+ after(:all) do
12
+ Process.kill "TERM", @pid
13
+ end
14
+
15
+ let!(:client) { client, @trans = build_client; client }
16
+
17
+ before(:each) do
18
+ @trans.open
19
+ end
20
+
21
+ after(:each) do
22
+ @trans.close
23
+ end
24
+
25
+ it do
26
+ client.bar(1, 2)
27
+ sleep 0.5
28
+ expect(File.read('/tmp/test-rspec')).to eq("3")
29
+ end
30
+
31
+ it do
32
+ expect(client.foo(1, 2)).to eq(3)
33
+ end
34
+ end
@@ -0,0 +1,96 @@
1
+ $: << 'spec/support/gen-rb'
2
+ $: << 'spec/support/handlers'
3
+
4
+ require 'test'
5
+ require 'thrift_helpers'
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need
18
+ # it.
19
+ #
20
+ # The `.rspec` file also contains a few flags that are not defaults but that
21
+ # users commonly want.
22
+ #
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ # rspec-expectations config goes here. You can use an alternate
26
+ # assertion/expectation library such as wrong or the stdlib/minitest
27
+ # assertions if you prefer.
28
+ config.expect_with :rspec do |expectations|
29
+ # This option will default to `true` in RSpec 4. It makes the `description`
30
+ # and `failure_message` of custom matchers include text for helper methods
31
+ # defined using `chain`, e.g.:
32
+ # be_bigger_than(2).and_smaller_than(4).description
33
+ # # => "be bigger than 2 and smaller than 4"
34
+ # ...rather than:
35
+ # # => "be bigger than 2"
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ end
38
+
39
+ # rspec-mocks config goes here. You can use an alternate test double
40
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
41
+ config.mock_with :rspec do |mocks|
42
+ # Prevents you from mocking or stubbing a method that does not exist on
43
+ # a real object. This is generally recommended, and will default to
44
+ # `true` in RSpec 4.
45
+ mocks.verify_partial_doubles = true
46
+ end
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+ =begin
51
+ # These two settings work together to allow you to limit a spec run
52
+ # to individual examples or groups you care about by tagging them with
53
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
54
+ # get run.
55
+ config.filter_run :focus
56
+ config.run_all_when_everything_filtered = true
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
@@ -0,0 +1,126 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (1.0.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 'test_types'
9
+
10
+ module Test
11
+ class Client
12
+ include ::Thrift::Client
13
+
14
+ def foo(t1, t2)
15
+ send_foo(t1, t2)
16
+ return recv_foo()
17
+ end
18
+
19
+ def send_foo(t1, t2)
20
+ send_message('foo', Foo_args, :t1 => t1, :t2 => t2)
21
+ end
22
+
23
+ def recv_foo()
24
+ result = receive_message(Foo_result)
25
+ return result.success unless result.success.nil?
26
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'foo failed: unknown result')
27
+ end
28
+
29
+ def bar(t1, t2)
30
+ send_bar(t1, t2)
31
+ end
32
+
33
+ def send_bar(t1, t2)
34
+ send_oneway_message('bar', Bar_args, :t1 => t1, :t2 => t2)
35
+ end
36
+ end
37
+
38
+ class Processor
39
+ include ::Thrift::Processor
40
+
41
+ def process_foo(seqid, iprot, oprot)
42
+ args = read_args(iprot, Foo_args)
43
+ result = Foo_result.new()
44
+ result.success = @handler.foo(args.t1, args.t2)
45
+ write_result(result, oprot, 'foo', seqid)
46
+ end
47
+
48
+ def process_bar(seqid, iprot, oprot)
49
+ args = read_args(iprot, Bar_args)
50
+ @handler.bar(args.t1, args.t2)
51
+ return
52
+ end
53
+
54
+ end
55
+
56
+ # HELPER FUNCTIONS AND STRUCTURES
57
+
58
+ class Foo_args
59
+ include ::Thrift::Struct, ::Thrift::Struct_Union
60
+ T1 = 1
61
+ T2 = 2
62
+
63
+ FIELDS = {
64
+ T1 => {:type => ::Thrift::Types::I16, :name => 't1'},
65
+ T2 => {:type => ::Thrift::Types::I16, :name => 't2'}
66
+ }
67
+
68
+ def struct_fields; FIELDS; end
69
+
70
+ def validate
71
+ end
72
+
73
+ ::Thrift::Struct.generate_accessors self
74
+ end
75
+
76
+ class Foo_result
77
+ include ::Thrift::Struct, ::Thrift::Struct_Union
78
+ SUCCESS = 0
79
+
80
+ FIELDS = {
81
+ SUCCESS => {:type => ::Thrift::Types::I16, :name => 'success'}
82
+ }
83
+
84
+ def struct_fields; FIELDS; end
85
+
86
+ def validate
87
+ end
88
+
89
+ ::Thrift::Struct.generate_accessors self
90
+ end
91
+
92
+ class Bar_args
93
+ include ::Thrift::Struct, ::Thrift::Struct_Union
94
+ T1 = 1
95
+ T2 = 2
96
+
97
+ FIELDS = {
98
+ T1 => {:type => ::Thrift::Types::I16, :name => 't1'},
99
+ T2 => {:type => ::Thrift::Types::I16, :name => 't2'}
100
+ }
101
+
102
+ def struct_fields; FIELDS; end
103
+
104
+ def validate
105
+ end
106
+
107
+ ::Thrift::Struct.generate_accessors self
108
+ end
109
+
110
+ class Bar_result
111
+ include ::Thrift::Struct, ::Thrift::Struct_Union
112
+
113
+ FIELDS = {
114
+
115
+ }
116
+
117
+ def struct_fields; FIELDS; end
118
+
119
+ def validate
120
+ end
121
+
122
+ ::Thrift::Struct.generate_accessors self
123
+ end
124
+
125
+ end
126
+
@@ -0,0 +1,9 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (1.0.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 'test_types'
9
+
@@ -0,0 +1,8 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (1.0.0-upfluence)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+
@@ -0,0 +1,12 @@
1
+ class TestHandler
2
+ def foo(x, y)
3
+ x + y
4
+ end
5
+
6
+ def bar(x, y)
7
+ f = File.open('/tmp/test-rspec', 'w')
8
+ f << x + y
9
+ f.flush
10
+ f.close
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ require 'thrift'
2
+ require 'thrift/amqp/server'
3
+ require 'thrift/amqp/client'
4
+ require 'test'
5
+ require 'test_handler'
6
+
7
+ def run_server
8
+ processor = Test::Processor.new(TestHandler.new)
9
+ prot_factory = Thrift::JsonProtocolFactory.new
10
+
11
+ Thrift::AMQPServer.new(
12
+ processor, prot_factory, nil,
13
+ amqp_uri: ENV['RABBITMQ_URL'] || 'amqp://guest:guest@127.0.0.1:5672/%2f',
14
+ routing_key: 'test',
15
+ exchange_name: 'test',
16
+ queue_name: 'test', prefetch: ENV['PREFETCH'] || 1
17
+ ).serve
18
+ end
19
+
20
+ def build_client
21
+ trans = Thrift::AMQPClientTransport.new(
22
+ ENV['RABBITMQ_URL'] || 'amqp://guest:guest@127.0.0.1:5672/%2f',
23
+ 'test', 'test'
24
+ )
25
+
26
+ prot = Thrift::JsonProtocol.new(trans)
27
+
28
+ [Test::Client.new(prot), trans]
29
+ end
@@ -0,0 +1,4 @@
1
+ service Test {
2
+ i16 foo(1:i16 t1, 2:i16 t2),
3
+ oneway void bar(1:i16 t1, 2:i16 t2),
4
+ }
data/thrift-amqp.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'thrift/amqp/version'
@@ -20,7 +19,7 @@ Gem::Specification.new do |spec|
20
19
 
21
20
  spec.add_development_dependency "bundler", "~> 1.6"
22
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
23
  spec.add_dependency "bunny"
24
24
  spec.add_dependency "thrift"
25
- spec.add_dependency "uuidtools"
26
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Montagne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,13 +39,13 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bunny
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: thrift
56
+ name: bunny
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: uuidtools
70
+ name: thrift
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".DS_Store"
91
91
  - ".gitignore"
92
+ - ".rspec"
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
@@ -97,6 +98,14 @@ files:
97
98
  - lib/thrift/amqp/client.rb
98
99
  - lib/thrift/amqp/server.rb
99
100
  - lib/thrift/amqp/version.rb
101
+ - spec/integration/client_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/gen-rb/test.rb
104
+ - spec/support/gen-rb/test_constants.rb
105
+ - spec/support/gen-rb/test_types.rb
106
+ - spec/support/handlers/test_handler.rb
107
+ - spec/support/handlers/thrift_helpers.rb
108
+ - spec/support/test.thrift
100
109
  - thrift-amqp.gemspec
101
110
  homepage: ''
102
111
  licenses:
@@ -122,4 +131,12 @@ rubygems_version: 2.2.2
122
131
  signing_key:
123
132
  specification_version: 4
124
133
  summary: Thrift transport layer over AMQP
125
- test_files: []
134
+ test_files:
135
+ - spec/integration/client_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/gen-rb/test.rb
138
+ - spec/support/gen-rb/test_constants.rb
139
+ - spec/support/gen-rb/test_types.rb
140
+ - spec/support/handlers/test_handler.rb
141
+ - spec/support/handlers/thrift_helpers.rb
142
+ - spec/support/test.thrift