thrifter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ require_relative './test_helper'
2
+
3
+ class StatsdMiddlewareTest < MiniTest::Unit::TestCase
4
+ attr_reader :rpc
5
+
6
+ def setup
7
+ super
8
+
9
+ @rpc = Thrifter::RPC.new(:foo, :args)
10
+ end
11
+
12
+ def test_times_each_rpc
13
+ app = stub
14
+ app.stubs(:call).with(rpc)
15
+
16
+ statsd = mock
17
+ statsd.expects(:time).with(rpc.name).yields.returns(:response)
18
+
19
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
20
+ result = middleware.call rpc
21
+
22
+ assert :response == result, 'Return value incorrect'
23
+ end
24
+
25
+ def test_counts_transport_exceptions_and_reraises
26
+ app = stub
27
+ app.stubs(:call).with(rpc).raises(Thrift::TransportException)
28
+
29
+ statsd = mock
30
+ statsd.expects(:time).yields
31
+ statsd.expects(:increment).with('errors.transport')
32
+
33
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
34
+
35
+ assert_raises Thrift::TransportException do
36
+ middleware.call rpc
37
+ end
38
+ end
39
+
40
+ def test_counts_protocol_exceptions
41
+ app = stub
42
+ app.stubs(:call).with(rpc).raises(Thrift::ProtocolException)
43
+
44
+ statsd = mock
45
+ statsd.expects(:time).yields
46
+ statsd.expects(:increment).with('errors.protocol')
47
+
48
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
49
+
50
+ assert_raises Thrift::ProtocolException do
51
+ middleware.call rpc
52
+ end
53
+ end
54
+
55
+ def test_counts_application_exceptions
56
+ app = stub
57
+ app.stubs(:call).with(rpc).raises(Thrift::ApplicationException)
58
+
59
+ statsd = mock
60
+ statsd.expects(:time).yields
61
+ statsd.expects(:increment).with('errors.application')
62
+
63
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
64
+
65
+ assert_raises Thrift::ApplicationException do
66
+ middleware.call rpc
67
+ end
68
+ end
69
+
70
+ def test_counts_timeouts
71
+ app = stub
72
+ app.stubs(:call).with(rpc).raises(Timeout::Error)
73
+
74
+ statsd = mock
75
+ statsd.expects(:time).yields
76
+ statsd.expects(:increment).with('errors.timeout')
77
+
78
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
79
+
80
+ assert_raises Timeout::Error do
81
+ middleware.call rpc
82
+ end
83
+ end
84
+
85
+ def test_counts_other_errors
86
+ app = stub
87
+ app.stubs(:call).with(rpc).raises(StandardError)
88
+
89
+ statsd = mock
90
+ statsd.expects(:time).yields
91
+ statsd.expects(:increment).with('errors.other')
92
+
93
+ middleware = Thrifter::StatsdMiddleware.new app, statsd
94
+
95
+ assert_raises StandardError do
96
+ middleware.call rpc
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,45 @@
1
+ require 'bundler/setup'
2
+ require 'thrifter'
3
+ require 'thrifter/queueing'
4
+
5
+ root = File.expand_path '../..', __FILE__
6
+ $LOAD_PATH << "#{root}/vendor/gen-rb"
7
+
8
+ require 'test_service'
9
+
10
+ require 'sidekiq'
11
+ require 'sidekiq/testing'
12
+ require 'minitest/autorun'
13
+ require 'mocha/mini_test'
14
+
15
+ Sidekiq::Testing.fake!
16
+
17
+ class FakeTransport
18
+ def initialize(*)
19
+
20
+ end
21
+
22
+ def open
23
+
24
+ end
25
+
26
+ def close
27
+
28
+ end
29
+ end
30
+
31
+ class FakeProtocol
32
+ def initialize(*)
33
+
34
+ end
35
+ end
36
+
37
+ class NullStatsd
38
+ def incr(*)
39
+
40
+ end
41
+
42
+ def time(*)
43
+ yield
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thrifter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thrifter"
8
+ spec.version = Thrifter::VERSION
9
+ spec.authors = ["ahawkins"]
10
+ spec.email = ["adam@hawkins.io"]
11
+ spec.summary = %q{Production ready Thrift client with improved semantics}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/saltside/thrifter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thrift"
22
+ spec.add_dependency "thrift-base64"
23
+ spec.add_dependency "statsd-ruby"
24
+ spec.add_dependency "concord"
25
+ spec.add_dependency "middleware"
26
+ spec.add_dependency "connection_pool"
27
+ spec.add_dependency "tnt"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.7"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "mocha"
32
+ spec.add_development_dependency "sidekiq"
33
+ spec.add_development_dependency "sidekiq-thrift_arguments"
34
+ spec.add_development_dependency "eventmachine"
35
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.2)
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,122 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.2)
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 TestService
11
+ class Client
12
+ include ::Thrift::Client
13
+
14
+ def echo(message)
15
+ send_echo(message)
16
+ return recv_echo()
17
+ end
18
+
19
+ def send_echo(message)
20
+ send_message('echo', Echo_args, :message => message)
21
+ end
22
+
23
+ def recv_echo()
24
+ result = receive_message(Echo_result)
25
+ return result.success unless result.success.nil?
26
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'echo failed: unknown result')
27
+ end
28
+
29
+ def onewayEcho(message)
30
+ send_onewayEcho(message)
31
+ end
32
+
33
+ def send_onewayEcho(message)
34
+ send_oneway_message('onewayEcho', OnewayEcho_args, :message => message)
35
+ end
36
+ end
37
+
38
+ class Processor
39
+ include ::Thrift::Processor
40
+
41
+ def process_echo(seqid, iprot, oprot)
42
+ args = read_args(iprot, Echo_args)
43
+ result = Echo_result.new()
44
+ result.success = @handler.echo(args.message)
45
+ write_result(result, oprot, 'echo', seqid)
46
+ end
47
+
48
+ def process_onewayEcho(seqid, iprot, oprot)
49
+ args = read_args(iprot, OnewayEcho_args)
50
+ @handler.onewayEcho(args.message)
51
+ return
52
+ end
53
+
54
+ end
55
+
56
+ # HELPER FUNCTIONS AND STRUCTURES
57
+
58
+ class Echo_args
59
+ include ::Thrift::Struct, ::Thrift::Struct_Union
60
+ MESSAGE = 1
61
+
62
+ FIELDS = {
63
+ MESSAGE => {:type => ::Thrift::Types::STRUCT, :name => 'message', :class => ::TestMessage}
64
+ }
65
+
66
+ def struct_fields; FIELDS; end
67
+
68
+ def validate
69
+ end
70
+
71
+ ::Thrift::Struct.generate_accessors self
72
+ end
73
+
74
+ class Echo_result
75
+ include ::Thrift::Struct, ::Thrift::Struct_Union
76
+ SUCCESS = 0
77
+
78
+ FIELDS = {
79
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::TestMessage}
80
+ }
81
+
82
+ def struct_fields; FIELDS; end
83
+
84
+ def validate
85
+ end
86
+
87
+ ::Thrift::Struct.generate_accessors self
88
+ end
89
+
90
+ class OnewayEcho_args
91
+ include ::Thrift::Struct, ::Thrift::Struct_Union
92
+ MESSAGE = 1
93
+
94
+ FIELDS = {
95
+ MESSAGE => {:type => ::Thrift::Types::STRUCT, :name => 'message', :class => ::TestMessage}
96
+ }
97
+
98
+ def struct_fields; FIELDS; end
99
+
100
+ def validate
101
+ end
102
+
103
+ ::Thrift::Struct.generate_accessors self
104
+ end
105
+
106
+ class OnewayEcho_result
107
+ include ::Thrift::Struct, ::Thrift::Struct_Union
108
+
109
+ FIELDS = {
110
+
111
+ }
112
+
113
+ def struct_fields; FIELDS; end
114
+
115
+ def validate
116
+ end
117
+
118
+ ::Thrift::Struct.generate_accessors self
119
+ end
120
+
121
+ end
122
+
@@ -0,0 +1,25 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.2)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+
9
+ class TestMessage
10
+ include ::Thrift::Struct, ::Thrift::Struct_Union
11
+ MESSAGE = 1
12
+
13
+ FIELDS = {
14
+ MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
15
+ }
16
+
17
+ def struct_fields; FIELDS; end
18
+
19
+ def validate
20
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field message is unset!') unless @message
21
+ end
22
+
23
+ ::Thrift::Struct.generate_accessors self
24
+ end
25
+
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thrifter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ahawkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thrift
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
+ - !ruby/object:Gem::Dependency
28
+ name: thrift-base64
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: statsd-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: concord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: connection_pool
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tnt
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: mocha
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: sidekiq
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sidekiq-thrift_arguments
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: eventmachine
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: ''
196
+ email:
197
+ - adam@hawkins.io
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".dockerignore"
203
+ - ".gitignore"
204
+ - Dockerfile
205
+ - Gemfile
206
+ - LICENSE.txt
207
+ - Makefile
208
+ - README.md
209
+ - Rakefile
210
+ - Vagrantfile
211
+ - circle.yml
212
+ - lib/thrifter.rb
213
+ - lib/thrifter/error_wrapping_middleware.rb
214
+ - lib/thrifter/ping.rb
215
+ - lib/thrifter/queueing.rb
216
+ - lib/thrifter/retry.rb
217
+ - lib/thrifter/statsd_middleware.rb
218
+ - lib/thrifter/version.rb
219
+ - script/monkey-client
220
+ - script/server
221
+ - test.thrift
222
+ - test/acceptance_test.rb
223
+ - test/error_wrapping_middleware_test.rb
224
+ - test/ping_test.rb
225
+ - test/queuing_test.rb
226
+ - test/retry_test.rb
227
+ - test/statsd_middleware_test.rb
228
+ - test/test_helper.rb
229
+ - thrifter.gemspec
230
+ - vendor/gen-rb/test_constants.rb
231
+ - vendor/gen-rb/test_service.rb
232
+ - vendor/gen-rb/test_types.rb
233
+ homepage: https://github.com/saltside/thrifter
234
+ licenses:
235
+ - MIT
236
+ metadata: {}
237
+ post_install_message:
238
+ rdoc_options: []
239
+ require_paths:
240
+ - lib
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 2.2.2
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: Production ready Thrift client with improved semantics
257
+ test_files:
258
+ - test/acceptance_test.rb
259
+ - test/error_wrapping_middleware_test.rb
260
+ - test/ping_test.rb
261
+ - test/queuing_test.rb
262
+ - test/retry_test.rb
263
+ - test/statsd_middleware_test.rb
264
+ - test/test_helper.rb