thrifter 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +78 -44
- data/lib/thrifter.rb +31 -13
- data/lib/thrifter/{ping.rb → extensions/ping.rb} +0 -0
- data/lib/thrifter/{queueing.rb → extensions/queueing.rb} +0 -0
- data/lib/thrifter/{retry.rb → extensions/retriable.rb} +0 -0
- data/lib/thrifter/{error_wrapping_middleware.rb → middleware/error_wrapping.rb} +1 -1
- data/lib/thrifter/{statsd_middleware.rb → middleware/metrics.rb} +1 -1
- data/lib/thrifter/middleware/validation.rb +34 -0
- data/lib/thrifter/version.rb +1 -1
- data/script/monkey-client +1 -1
- data/test/acceptance_test.rb +20 -0
- data/test/{ping_test.rb → extensions/ping_test.rb} +1 -1
- data/test/{queuing_test.rb → extensions/queueing_test.rb} +1 -1
- data/test/{retry_test.rb → extensions/retry_test.rb} +1 -1
- data/test/{error_wrapping_middleware_test.rb → middleware/error_wrapping_test.rb} +6 -6
- data/test/{statsd_middleware_test.rb → middleware/metrics_test.rb} +8 -8
- data/test/middleware/validation_test.rb +57 -0
- data/test/test_helper.rb +1 -1
- data/thrifter.gemspec +1 -0
- metadata +33 -16
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d17b3472039110ba6cb2226fb72e0ed490f3a0a9
         | 
| 4 | 
            +
              data.tar.gz: 0dc804e6e5de0d3e3107961d5841ca834db39d29
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ce63b7eae7e10ad4caa724be4ef43082b0673ebe54c734cd95f3a273fbae579b694769b9c377ad3671fd33b77dd31d7b5d81da15bc84d9399a20ed8df9f45d11
         | 
| 7 | 
            +
              data.tar.gz: 7d8f048ee242cf2dcdf03a4091f0ed3694e6b5a14fdaf0fed0019031ab0aee03cde8d0a2cc566921879c9a70ea4c7002452238fb2e14df704633d1a0fafb5e7d
         | 
    
        data/README.md
    CHANGED
    
    | @@ -81,37 +81,19 @@ class MyClient < Thrifer.build(MyService::Client) | |
| 81 81 | 
             
              config.uri = 'tcp://foo:2383'
         | 
| 82 82 | 
             
            end
         | 
| 83 83 |  | 
| 84 | 
            -
            #The common block form is supported as well
         | 
| 84 | 
            +
            # The common block form is supported as well
         | 
| 85 85 | 
             
            MyClient.configure do |config|
         | 
| 86 86 | 
             
              # ... same as above
         | 
| 87 87 | 
             
            end
         | 
| 88 88 | 
             
            ```
         | 
| 89 89 |  | 
| 90 | 
            -
            ###  | 
| 90 | 
            +
            ### Extensions
         | 
| 91 91 |  | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
            interface. `Thrifter` emits the following metrics:
         | 
| 96 | 
            -
             | 
| 97 | 
            -
            * time on each rpc calls
         | 
| 98 | 
            -
            * number of `Thrift::TransportException`
         | 
| 99 | 
            -
            * number of `Thrift::ProtocolExeption`
         | 
| 100 | 
            -
            * number of `Thrift::ApplicationExeption`
         | 
| 101 | 
            -
            * number of `Timeout::Error`
         | 
| 102 | 
            -
            * number of generic errors (e.g. none of the above known errors)
         | 
| 103 | 
            -
             | 
| 104 | 
            -
            It's recommended that the `statsd` object do namespacing
         | 
| 105 | 
            -
            (statsd-ruby has it built in). This ensures client metrics don't
         | 
| 106 | 
            -
            get intermingled with wider application metrics. Here's an example:
         | 
| 107 | 
            -
             | 
| 108 | 
            -
            ```ruby
         | 
| 109 | 
            -
            ServiceClient = Thrifter.build(MyService::Client)
         | 
| 110 | 
            -
            # Now in production.rb
         | 
| 111 | 
            -
            ServiceClient.config.statsd = Statsd.new namespace: 'my_service'
         | 
| 112 | 
            -
            ```
         | 
| 92 | 
            +
            Extensions add functionality to the client itself. They do not effect
         | 
| 93 | 
            +
            the request/response cycle in anyway. `Thrifter` includes a few
         | 
| 94 | 
            +
            extensions by default. This section covers each included extension.
         | 
| 113 95 |  | 
| 114 | 
            -
             | 
| 96 | 
            +
            #### Queuing
         | 
| 115 97 |  | 
| 116 98 | 
             
            Certain systems may need to queue RPCs to other systems. This is only
         | 
| 117 99 | 
             
            useful for `void` RPCs or for when an outside system may be flaky.
         | 
| @@ -119,8 +101,13 @@ Assume `MyService` has a `logStats` RPC. Your application is producing | |
| 119 101 | 
             
            stats that should make it upstream, but there are intermitent network
         | 
| 120 102 | 
             
            problems effeciting stats collection. Include `Thrift::Queueing` and
         | 
| 121 103 | 
             
            any RPC will automatically be sent to sidekiq for eventual processing.
         | 
| 104 | 
            +
            `sidekiq` must be available. This is an **opt-in** dependency, of if
         | 
| 105 | 
            +
            you want this funtionality, add `sidekiq` and
         | 
| 106 | 
            +
            `sidekiq-thrift_arguments` to your `Gemfile`.
         | 
| 122 107 |  | 
| 123 108 | 
             
            ```ruby
         | 
| 109 | 
            +
            require 'thrifter/extensions/queueing'
         | 
| 110 | 
            +
             | 
| 124 111 | 
             
            class ServiceClient < Thrifter.build(MyService::Client)
         | 
| 125 112 | 
             
              include Thrifter::Queuing
         | 
| 126 113 | 
             
            end
         | 
| @@ -144,7 +131,7 @@ end | |
| 144 131 | 
             
            All RPCs will be sent to the `thrift` sidekiq queue. They will follow
         | 
| 145 132 | 
             
            default sidekiq retry backoff and the like.
         | 
| 146 133 |  | 
| 147 | 
            -
             | 
| 134 | 
            +
            #### Retry Support
         | 
| 148 135 |  | 
| 149 136 | 
             
            Systems have syncrhonous RPCs. Unfortunately sometimes these don't
         | 
| 150 137 | 
             
            work for whatever reason. It's good practice to retry these RPCs
         | 
| @@ -178,13 +165,40 @@ end | |
| 178 165 | 
             
            Look into something like [retriable][] if you want a more robust
         | 
| 179 166 | 
             
            solution for different use cases.
         | 
| 180 167 |  | 
| 168 | 
            +
            #### Pinging
         | 
| 169 | 
            +
             | 
| 170 | 
            +
            Components in a system may need to inquire if other systems are
         | 
| 171 | 
            +
            available before continuing. `Thrifer::Ping` is just that.
         | 
| 172 | 
            +
            `Thrifter::Ping` assumes the service has a `ping` RPC. If your
         | 
| 173 | 
            +
            service does not have one (or is named differently) simply implement
         | 
| 174 | 
            +
            the `ping` method on the class. Any successful response will count as
         | 
| 175 | 
            +
            up, anything else will not.
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            ```ruby
         | 
| 178 | 
            +
            class MyService < Thrifer.build(MyService::Client)
         | 
| 179 | 
            +
              include Thrifer::Ping
         | 
| 180 | 
            +
             | 
| 181 | 
            +
              # Define a ping method if the service does not have one
         | 
| 182 | 
            +
              def ping
         | 
| 183 | 
            +
                my_other_rpc
         | 
| 184 | 
            +
              end
         | 
| 185 | 
            +
            end
         | 
| 186 | 
            +
             | 
| 187 | 
            +
            # my_service.up? # => true
         | 
| 188 | 
            +
            ```
         | 
| 189 | 
            +
             | 
| 181 190 | 
             
            ### Middleware
         | 
| 182 191 |  | 
| 183 192 | 
             
            The middleware approach is great for providing a flexible extension
         | 
| 184 193 | 
             
            points to hook into the RPC process. `Thrifter::Client` provides a
         | 
| 185 194 | 
             
            middleware implementation to common to many other ruby libraries.
         | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 195 | 
            +
            Unlike extensions, middleware modify the request/response cycle. They
         | 
| 196 | 
            +
            do not modify the client class directly. `Thrifter` includes a few
         | 
| 197 | 
            +
            helpful middlware which are documented below.
         | 
| 198 | 
            +
             | 
| 199 | 
            +
            #### Using Middleware
         | 
| 200 | 
            +
             | 
| 201 | 
            +
            Here's the most simple middlware example:
         | 
| 188 202 |  | 
| 189 203 | 
             
            ```ruby
         | 
| 190 204 | 
             
            class MyClient < Thrifter.build(MyService::Client)
         | 
| @@ -218,7 +232,31 @@ class LoggingMiddleware | |
| 218 232 | 
             
            end
         | 
| 219 233 | 
             
            ```
         | 
| 220 234 |  | 
| 221 | 
            -
             | 
| 235 | 
            +
            #### Metrics
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            Statsd metrics are **opt-in**. By default, `Thrifter` sets the statsd
         | 
| 238 | 
            +
            client to a null implementation. If you want metrics, set
         | 
| 239 | 
            +
            `config.statsd` to an object that implements the [statsd-ruby][]
         | 
| 240 | 
            +
            interface. `Thrifter` emits the following metrics:
         | 
| 241 | 
            +
             | 
| 242 | 
            +
            * time on each rpc calls
         | 
| 243 | 
            +
            * number of `Thrift::TransportException`
         | 
| 244 | 
            +
            * number of `Thrift::ProtocolExeption`
         | 
| 245 | 
            +
            * number of `Thrift::ApplicationExeption`
         | 
| 246 | 
            +
            * number of `Timeout::Error`
         | 
| 247 | 
            +
            * number of generic errors (e.g. none of the above known errors)
         | 
| 248 | 
            +
             | 
| 249 | 
            +
            It's recommended that the `statsd` object do namespacing
         | 
| 250 | 
            +
            (statsd-ruby has it built in). This ensures client metrics don't
         | 
| 251 | 
            +
            get intermingled with wider application metrics. Here's an example:
         | 
| 252 | 
            +
             | 
| 253 | 
            +
            ```ruby
         | 
| 254 | 
            +
            ServiceClient = Thrifter.build(MyService::Client)
         | 
| 255 | 
            +
            # Now in production.rb
         | 
| 256 | 
            +
            ServiceClient.config.statsd = Statsd.new namespace: 'my_service'
         | 
| 257 | 
            +
            ```
         | 
| 258 | 
            +
             | 
| 259 | 
            +
            #### Error Wrapping
         | 
| 222 260 |  | 
| 223 261 | 
             
            A lot of things can go wrong in the thrift stack. This means the
         | 
| 224 262 | 
             
            caller may need to deal with a large amount of different exceptions.
         | 
| @@ -249,26 +287,22 @@ end | |
| 249 287 | 
             
            Note, `Thrifter` will still count individual errors as described in
         | 
| 250 288 | 
             
            the metrics section.
         | 
| 251 289 |  | 
| 252 | 
            -
             | 
| 290 | 
            +
            #### Protocol Validation
         | 
| 253 291 |  | 
| 254 | 
            -
             | 
| 255 | 
            -
             | 
| 256 | 
            -
             | 
| 257 | 
            -
             | 
| 258 | 
            -
             | 
| 259 | 
            -
             | 
| 292 | 
            +
            Thrift requires that client & server communicate with the exact things
         | 
| 293 | 
            +
            specified in the protocol. Unfortunately ruby does not prevent us from
         | 
| 294 | 
            +
            making mistakes. It's possible to forget setting required members or
         | 
| 295 | 
            +
            assigning symbol instead of a string. Luckily ruby's dynamic traits
         | 
| 296 | 
            +
            make it possible to implement compiler like validation. `Thrifter`
         | 
| 297 | 
            +
            includes a middlware that will checkout incoming & outgoing objects so
         | 
| 298 | 
            +
            that they're valid protocol message. [thrift-validator][] does all the
         | 
| 299 | 
            +
            heavy lifing here. Use `Thrifter::Validation` in the test
         | 
| 300 | 
            +
            environment to make sure things are correct. Here's an example.
         | 
| 260 301 |  | 
| 261 302 | 
             
            ```ruby
         | 
| 262 | 
            -
            class MyService <  | 
| 263 | 
            -
               | 
| 264 | 
            -
             | 
| 265 | 
            -
              # Define a ping method if the service does not have one
         | 
| 266 | 
            -
              def ping
         | 
| 267 | 
            -
                my_other_rpc
         | 
| 268 | 
            -
              end
         | 
| 303 | 
            +
            class MyService < Thrifter.build(MyService::Client)
         | 
| 304 | 
            +
              use Thrifter::Validation
         | 
| 269 305 | 
             
            end
         | 
| 270 | 
            -
             | 
| 271 | 
            -
            # my_service.up? # => true
         | 
| 272 306 | 
             
            ```
         | 
| 273 307 |  | 
| 274 308 | 
             
            ## Contributing
         | 
    
        data/lib/thrifter.rb
    CHANGED
    
    | @@ -1,11 +1,13 @@ | |
| 1 1 | 
             
            require 'thrifter/version'
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'forwardable'
         | 
| 4 | 
            +
            require 'delegate'
         | 
| 4 5 | 
             
            require 'uri'
         | 
| 5 6 | 
             
            require 'tnt'
         | 
| 6 7 | 
             
            require 'concord'
         | 
| 7 8 | 
             
            require 'thrift'
         | 
| 8 9 | 
             
            require 'thrift-base64'
         | 
| 10 | 
            +
            require 'thrift-validator'
         | 
| 9 11 | 
             
            require 'middleware'
         | 
| 10 12 | 
             
            require 'connection_pool'
         | 
| 11 13 |  | 
| @@ -84,6 +86,14 @@ module Thrifter | |
| 84 86 | 
             
                  end
         | 
| 85 87 | 
             
                end
         | 
| 86 88 |  | 
| 89 | 
            +
                class DirectDispatcher
         | 
| 90 | 
            +
                  include Concord.new(:app, :client)
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  def call(rpc)
         | 
| 93 | 
            +
                    client.send rpc.name, *rpc.args
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 87 97 | 
             
                class << self
         | 
| 88 98 | 
             
                  extend Forwardable
         | 
| 89 99 |  | 
| @@ -115,12 +125,14 @@ module Thrifter | |
| 115 125 | 
             
                  end
         | 
| 116 126 | 
             
                end
         | 
| 117 127 |  | 
| 118 | 
            -
                def initialize
         | 
| 119 | 
            -
                   | 
| 128 | 
            +
                def initialize(client = nil)
         | 
| 129 | 
            +
                  if client.nil?
         | 
| 130 | 
            +
                    fail ArgumentError, 'config.uri not set!' unless config.uri
         | 
| 120 131 |  | 
| 121 | 
            -
             | 
| 132 | 
            +
                    uri = URI(config.uri)
         | 
| 122 133 |  | 
| 123 | 
            -
             | 
| 134 | 
            +
                    fail ArgumentError, 'URI did not contain port' unless uri.port
         | 
| 135 | 
            +
                  end
         | 
| 124 136 |  | 
| 125 137 | 
             
                  @pool = ConnectionPool.new size: config.pool_size.to_i, timeout: config.pool_timeout.to_f do
         | 
| 126 138 | 
             
                    stack = MiddlewareStack.new
         | 
| @@ -130,13 +142,17 @@ module Thrifter | |
| 130 142 | 
             
                    # Insert metrics here so metrics are as close to the network
         | 
| 131 143 | 
             
                    # as possible. This excludes time in any middleware an
         | 
| 132 144 | 
             
                    # application may have configured.
         | 
| 133 | 
            -
                    stack.use  | 
| 145 | 
            +
                    stack.use Metrics, config.statsd
         | 
| 134 146 |  | 
| 135 | 
            -
                     | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 147 | 
            +
                    if client.nil?
         | 
| 148 | 
            +
                      socket = Thrift::Socket.new uri.host, uri.port, config.rpc_timeout.to_f
         | 
| 149 | 
            +
                      transport = config.transport.new socket
         | 
| 150 | 
            +
                      protocol = config.protocol.new transport
         | 
| 138 151 |  | 
| 139 | 
            -
             | 
| 152 | 
            +
                      stack.use Dispatcher, transport, client_class.new(protocol)
         | 
| 153 | 
            +
                    else
         | 
| 154 | 
            +
                      stack.use DirectDispatcher, client
         | 
| 155 | 
            +
                    end
         | 
| 140 156 |  | 
| 141 157 | 
             
                    stack.finalize!
         | 
| 142 158 | 
             
                  end
         | 
| @@ -160,7 +176,9 @@ module Thrifter | |
| 160 176 | 
             
              end
         | 
| 161 177 | 
             
            end
         | 
| 162 178 |  | 
| 163 | 
            -
            require_relative 'thrifter/ | 
| 164 | 
            -
            require_relative 'thrifter/ | 
| 165 | 
            -
             | 
| 166 | 
            -
            require_relative 'thrifter/ | 
| 179 | 
            +
            require_relative 'thrifter/extensions/ping'
         | 
| 180 | 
            +
            require_relative 'thrifter/extensions/retriable'
         | 
| 181 | 
            +
             | 
| 182 | 
            +
            require_relative 'thrifter/middleware/error_wrapping'
         | 
| 183 | 
            +
            require_relative 'thrifter/middleware/validation'
         | 
| 184 | 
            +
            require_relative 'thrifter/middleware/metrics'
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module Thrifter
         | 
| 2 | 
            +
              ValidationError = Tnt.boom do |rpc, ex|
         | 
| 3 | 
            +
                "Invalid data in RPC #{rpc.name}! #{ex.message}"
         | 
| 4 | 
            +
              end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              class Validation
         | 
| 7 | 
            +
                include Concord.new(:app)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def call(rpc)
         | 
| 10 | 
            +
                  validate rpc, rpc.args
         | 
| 11 | 
            +
                  response = app.call rpc
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  validate rpc, Array(response)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  response
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                private
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def validate(rpc, objects)
         | 
| 21 | 
            +
                  objects.each do |item|
         | 
| 22 | 
            +
                    if item.is_a? Thrift::Struct
         | 
| 23 | 
            +
                      begin
         | 
| 24 | 
            +
                        Thrift::Validator.new.validate(item)
         | 
| 25 | 
            +
                      rescue Thrift::ProtocolException => ex
         | 
| 26 | 
            +
                        raise ValidationError.new(rpc, ex)
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    else
         | 
| 29 | 
            +
                      next
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
    
        data/lib/thrifter/version.rb
    CHANGED
    
    
    
        data/script/monkey-client
    CHANGED
    
    
    
        data/test/acceptance_test.rb
    CHANGED
    
    | @@ -190,6 +190,26 @@ class AcceptanceTest < MiniTest::Unit::TestCase | |
| 190 190 | 
             
                assert_match /testing/, result.message, 'Middleware not called'
         | 
| 191 191 | 
             
              end
         | 
| 192 192 |  | 
| 193 | 
            +
              def test_implementation_maybe_given_at_instantation_time
         | 
| 194 | 
            +
                implementation = stub echo: :stubbed_response
         | 
| 195 | 
            +
             | 
| 196 | 
            +
                client = Thrifter.build TestClient
         | 
| 197 | 
            +
                client.config.uri = uri
         | 
| 198 | 
            +
             | 
| 199 | 
            +
                thrifter = client.new implementation
         | 
| 200 | 
            +
                assert_equal :stubbed_response, thrifter.echo(:request)
         | 
| 201 | 
            +
              end
         | 
| 202 | 
            +
             | 
| 203 | 
            +
              def test_does_not_require_uri_when_providing_an_implementation
         | 
| 204 | 
            +
                implementation = stub echo: :stubbed_response
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                client = Thrifter.build TestClient
         | 
| 207 | 
            +
                client.config.uri = nil
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                thrifter = client.new implementation
         | 
| 210 | 
            +
                assert_equal :stubbed_response, thrifter.echo(:request)
         | 
| 211 | 
            +
              end
         | 
| 212 | 
            +
             | 
| 193 213 | 
             
              def test_close_the_transport_on_successful_rpc
         | 
| 194 214 | 
             
                transport = mock
         | 
| 195 215 | 
             
                client = Thrifter.build TestClient
         | 
| @@ -1,12 +1,12 @@ | |
| 1 | 
            -
            require_relative ' | 
| 1 | 
            +
            require_relative '../test_helper'
         | 
| 2 2 |  | 
| 3 | 
            -
            class  | 
| 3 | 
            +
            class ErrorWrappingTest < MiniTest::Unit::TestCase
         | 
| 4 4 | 
             
              TestError = Class.new StandardError
         | 
| 5 5 |  | 
| 6 6 | 
             
              attr_reader :rpc
         | 
| 7 7 |  | 
| 8 8 | 
             
              def known_errors
         | 
| 9 | 
            -
                Thrifter:: | 
| 9 | 
            +
                Thrifter::ErrorWrapping.wrapped
         | 
| 10 10 | 
             
              end
         | 
| 11 11 |  | 
| 12 12 | 
             
              def setup
         | 
| @@ -19,7 +19,7 @@ class ErrorWrappingMiddlewareTest < MiniTest::Unit::TestCase | |
| 19 19 | 
             
                app = stub
         | 
| 20 20 | 
             
                app.stubs(:call).with(rpc).raises(known_errors.first)
         | 
| 21 21 |  | 
| 22 | 
            -
                middleware = Thrifter:: | 
| 22 | 
            +
                middleware = Thrifter::ErrorWrapping.new app
         | 
| 23 23 |  | 
| 24 24 | 
             
                assert_raises Thrifter::ClientError do
         | 
| 25 25 | 
             
                  middleware.call rpc
         | 
| @@ -30,7 +30,7 @@ class ErrorWrappingMiddlewareTest < MiniTest::Unit::TestCase | |
| 30 30 | 
             
                app = stub
         | 
| 31 31 | 
             
                app.stubs(:call).with(rpc).raises(TestError)
         | 
| 32 32 |  | 
| 33 | 
            -
                middleware = Thrifter:: | 
| 33 | 
            +
                middleware = Thrifter::ErrorWrapping.new app, [ TestError ]
         | 
| 34 34 |  | 
| 35 35 | 
             
                assert_raises Thrifter::ClientError do
         | 
| 36 36 | 
             
                  middleware.call rpc
         | 
| @@ -41,7 +41,7 @@ class ErrorWrappingMiddlewareTest < MiniTest::Unit::TestCase | |
| 41 41 | 
             
                app = stub
         | 
| 42 42 | 
             
                app.stubs(:call).with(rpc).raises(TestError.new('testing 123'))
         | 
| 43 43 |  | 
| 44 | 
            -
                middleware = Thrifter:: | 
| 44 | 
            +
                middleware = Thrifter::ErrorWrapping.new app, [ TestError ]
         | 
| 45 45 |  | 
| 46 46 | 
             
                error = assert_raises Thrifter::ClientError do
         | 
| 47 47 | 
             
                  middleware.call rpc
         | 
| @@ -1,6 +1,6 @@ | |
| 1 | 
            -
            require_relative ' | 
| 1 | 
            +
            require_relative '../test_helper'
         | 
| 2 2 |  | 
| 3 | 
            -
            class  | 
| 3 | 
            +
            class MetricsTest < MiniTest::Unit::TestCase
         | 
| 4 4 | 
             
              attr_reader :rpc
         | 
| 5 5 |  | 
| 6 6 | 
             
              def setup
         | 
| @@ -16,7 +16,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 16 16 | 
             
                statsd = mock
         | 
| 17 17 | 
             
                statsd.expects(:time).with(rpc.name).yields.returns(:response)
         | 
| 18 18 |  | 
| 19 | 
            -
                middleware = Thrifter:: | 
| 19 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 20 20 | 
             
                result = middleware.call rpc
         | 
| 21 21 |  | 
| 22 22 | 
             
                assert :response == result, 'Return value incorrect'
         | 
| @@ -30,7 +30,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 30 30 | 
             
                statsd.expects(:time).yields
         | 
| 31 31 | 
             
                statsd.expects(:increment).with('errors.transport')
         | 
| 32 32 |  | 
| 33 | 
            -
                middleware = Thrifter:: | 
| 33 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 34 34 |  | 
| 35 35 | 
             
                assert_raises Thrift::TransportException do
         | 
| 36 36 | 
             
                  middleware.call rpc
         | 
| @@ -45,7 +45,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 45 45 | 
             
                statsd.expects(:time).yields
         | 
| 46 46 | 
             
                statsd.expects(:increment).with('errors.protocol')
         | 
| 47 47 |  | 
| 48 | 
            -
                middleware = Thrifter:: | 
| 48 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 49 49 |  | 
| 50 50 | 
             
                assert_raises Thrift::ProtocolException do
         | 
| 51 51 | 
             
                  middleware.call rpc
         | 
| @@ -60,7 +60,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 60 60 | 
             
                statsd.expects(:time).yields
         | 
| 61 61 | 
             
                statsd.expects(:increment).with('errors.application')
         | 
| 62 62 |  | 
| 63 | 
            -
                middleware = Thrifter:: | 
| 63 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 64 64 |  | 
| 65 65 | 
             
                assert_raises Thrift::ApplicationException do
         | 
| 66 66 | 
             
                  middleware.call rpc
         | 
| @@ -75,7 +75,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 75 75 | 
             
                statsd.expects(:time).yields
         | 
| 76 76 | 
             
                statsd.expects(:increment).with('errors.timeout')
         | 
| 77 77 |  | 
| 78 | 
            -
                middleware = Thrifter:: | 
| 78 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 79 79 |  | 
| 80 80 | 
             
                assert_raises Timeout::Error do
         | 
| 81 81 | 
             
                  middleware.call rpc
         | 
| @@ -90,7 +90,7 @@ class StatsdMiddlewareTest < MiniTest::Unit::TestCase | |
| 90 90 | 
             
                statsd.expects(:time).yields
         | 
| 91 91 | 
             
                statsd.expects(:increment).with('errors.other')
         | 
| 92 92 |  | 
| 93 | 
            -
                middleware = Thrifter:: | 
| 93 | 
            +
                middleware = Thrifter::Metrics.new app, statsd
         | 
| 94 94 |  | 
| 95 95 | 
             
                assert_raises StandardError do
         | 
| 96 96 | 
             
                  middleware.call rpc
         | 
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            require_relative '../test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class ValidationTest < MiniTest::Unit::TestCase
         | 
| 4 | 
            +
              attr_reader :rpc, :invalid_struct, :valid_struct
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def setup
         | 
| 7 | 
            +
                super
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                @rpc = Thrifter::RPC.new :echo
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                @invalid_struct = TestMessage.new
         | 
| 12 | 
            +
                @valid_struct = TestMessage.new message: 'testing'
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def test_fails_if_args_contains_invalid_structs
         | 
| 16 | 
            +
                rpc.args = [ invalid_struct ]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                client = stub call: valid_struct
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                middleware = Thrifter::Validation.new client
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                assert_raises Thrifter::ValidationError do
         | 
| 23 | 
            +
                  middleware.call rpc
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              def test_does_not_validate_primitive_request_values
         | 
| 28 | 
            +
                rpc.args = [ 1, 2, 3 ]
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                client = stub call: valid_struct
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                middleware = Thrifter::Validation.new client
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                assert_equal valid_struct, middleware.call(rpc)
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def test_fails_if_repsonse_contains_invalid_structs
         | 
| 38 | 
            +
                rpc.args = [ valid_struct ]
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                client = stub call: invalid_struct
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                middleware = Thrifter::Validation.new client
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                assert_raises Thrifter::ValidationError do
         | 
| 45 | 
            +
                  middleware.call rpc
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def test_does_not_validate_primitive_response_values
         | 
| 50 | 
            +
                rpc.args = [ valid_struct ]
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                client = stub call: [ 1, 2 ]
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                middleware = Thrifter::Validation.new client
         | 
| 55 | 
            +
                assert_equal [ 1,2 ], middleware.call(rpc)
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    CHANGED
    
    
    
        data/thrifter.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: thrifter
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - ahawkins
         | 
| @@ -38,6 +38,20 @@ dependencies: | |
| 38 38 | 
             
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: thrift-validator
         | 
| 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'
         | 
| 41 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 56 | 
             
              name: statsd-ruby
         | 
| 43 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -210,21 +224,23 @@ files: | |
| 210 224 | 
             
            - Vagrantfile
         | 
| 211 225 | 
             
            - circle.yml
         | 
| 212 226 | 
             
            - lib/thrifter.rb
         | 
| 213 | 
            -
            - lib/thrifter/ | 
| 214 | 
            -
            - lib/thrifter/ | 
| 215 | 
            -
            - lib/thrifter/ | 
| 216 | 
            -
            - lib/thrifter/ | 
| 217 | 
            -
            - lib/thrifter/ | 
| 227 | 
            +
            - lib/thrifter/extensions/ping.rb
         | 
| 228 | 
            +
            - lib/thrifter/extensions/queueing.rb
         | 
| 229 | 
            +
            - lib/thrifter/extensions/retriable.rb
         | 
| 230 | 
            +
            - lib/thrifter/middleware/error_wrapping.rb
         | 
| 231 | 
            +
            - lib/thrifter/middleware/metrics.rb
         | 
| 232 | 
            +
            - lib/thrifter/middleware/validation.rb
         | 
| 218 233 | 
             
            - lib/thrifter/version.rb
         | 
| 219 234 | 
             
            - script/monkey-client
         | 
| 220 235 | 
             
            - script/server
         | 
| 221 236 | 
             
            - test.thrift
         | 
| 222 237 | 
             
            - test/acceptance_test.rb
         | 
| 223 | 
            -
            - test/ | 
| 224 | 
            -
            - test/ | 
| 225 | 
            -
            - test/ | 
| 226 | 
            -
            - test/ | 
| 227 | 
            -
            - test/ | 
| 238 | 
            +
            - test/extensions/ping_test.rb
         | 
| 239 | 
            +
            - test/extensions/queueing_test.rb
         | 
| 240 | 
            +
            - test/extensions/retry_test.rb
         | 
| 241 | 
            +
            - test/middleware/error_wrapping_test.rb
         | 
| 242 | 
            +
            - test/middleware/metrics_test.rb
         | 
| 243 | 
            +
            - test/middleware/validation_test.rb
         | 
| 228 244 | 
             
            - test/test_helper.rb
         | 
| 229 245 | 
             
            - thrifter.gemspec
         | 
| 230 246 | 
             
            - vendor/gen-rb/test_constants.rb
         | 
| @@ -256,9 +272,10 @@ specification_version: 4 | |
| 256 272 | 
             
            summary: Production ready Thrift client with improved semantics
         | 
| 257 273 | 
             
            test_files:
         | 
| 258 274 | 
             
            - test/acceptance_test.rb
         | 
| 259 | 
            -
            - test/ | 
| 260 | 
            -
            - test/ | 
| 261 | 
            -
            - test/ | 
| 262 | 
            -
            - test/ | 
| 263 | 
            -
            - test/ | 
| 275 | 
            +
            - test/extensions/ping_test.rb
         | 
| 276 | 
            +
            - test/extensions/queueing_test.rb
         | 
| 277 | 
            +
            - test/extensions/retry_test.rb
         | 
| 278 | 
            +
            - test/middleware/error_wrapping_test.rb
         | 
| 279 | 
            +
            - test/middleware/metrics_test.rb
         | 
| 280 | 
            +
            - test/middleware/validation_test.rb
         | 
| 264 281 | 
             
            - test/test_helper.rb
         |